|
|||||||||||||||||||
|
Preprocessing Device fragmentation is a difficult issue in the Micro Edition world. Devices are constrained in a variety of different and inconsistent ways. While there are many techniques that can be used to deal with these inconsistencies, the limited memory and processing power of many mobile devices points to a solution that occurs off-device rather than something that happens at runtime. EclipseME provides some help in the area of device fragmentation through the inclusion of a source code "preprocessor". Using the limited processing power of the preprocessor, it is possible to do some build time source code transformations. Enabling and Disabling PreprocessingUse of the preprocessing functionality is an optional part of the EclipseME functionality. Preprocessing is enabled or disabled on a project-level basis, allowing significant flexibility in the structure of workspace projects. Enabling PreprocessingEnabling preprocessing functionality can be accomplished in two different ways. During the creation of a new Midlet Suite, preprocessing may be enabled on the first page of the wizard.
After a project has been created preprocessing may be enabled via the J2ME project context menu option.
Disabling PreprocessingProjects with preprocessing functionality enabled, may also disable the functionality if it is no longer necessary or useful. Disabling the preprocessor is done via the project context menu, just as enablement is done. For projects with processing enabled, there will be a "Disable Preprocessing" menu item rather than an item to enable processing. Controlling CompilationPreprocessing controls the final compiled code using a set of preprocessor directives. The preprocessor supports the following directives inside a Java source file. All directives must follow a "//" comment that starts at the beginning of a line (whitespace is allowed left of them, but no Java code). That way, they don't interfere with normal Java compilation. Directives must not span multiple lines of code.
Defining SymbolsThe compilation directive expressions are dependent on the definition of a set of "symbols". These symbols are either defined/true or undefined/false. It is possible to control whether a particular symbol is defined or undefined directly via preprocessing directives or indirectly through the definition of symbol definition sets. Direct Definitions
The Symbol Definition SetsSymbol definition sets provide a means to define a group of related symbols with a particular name to reference that group. A definition set may then be specified for a project via the user interface to control the compilation. Symbol definition sets are most useful for controlling definitions without the need to alter source code. For example, symbol definition sets can be used to remove debugging information to create a production build. Start by defining a "Debug" symbol definition set in which the symbol "DEBUG" has been defined. Wrap the debugging code in your project with "#ifdef DEBUG" directives. When building a production version of the code, use a different symbol definition set that does not have DEBUG defined and the debugging code will be removed.
...
// #ifdef DEBUG
System.out.println("Some debug output");
// #endif
...
Defining Symbol Definition SetsSymbol set definitions are accessed via the EclipseME preferences. From the Window menu, choose the Preferences... menu item. Expand the J2ME category and select the Symbol Set Definitions category.
Creating a New SetCreating a new symbol definition set is accomplished by specifying the name of the definition set and selecting the Add button. An empty set will be created. Defining SymbolsTo define a new symbol:
Removing SymbolsTo remove a symbol from the set:
Removing a SetIf a symbol definition set is no longer necessary, it can be removed:
Referencing Symbol Definition SetsOnce a Symbol Definition Set has been defined, it may be referenced by a project. This is accomplished from the J2ME category of the project properties dialog.
The symbols that are defined in the set will then be used by the preprocessor directives in processing the source code. |
||||||||||||||||||
|
Copyright © 2005, http://www.eclipseme.org.
All rights reserved.
|
|||||||||||||||||||