Perhaps one of the most uniquely challenging aspects of handling the device fragmentation problem has been managing differences in code between distributions of an application. The NetBeans approach to the problem has been to integrate a preprocessor into the build process that activates or deactivates sections of code based on which configuration is active at compile time. The NetBeans preprocessor is a low-impact tool that uses Java comments both to define code sections and to activate and deactivate these sections. As such, all files before and after preprocessing can be valid, syntactically correct Java source. This also ensures that the preprocessed files integrate seamlessly with the debugger.
A series of context-menu commands exist to assist you in adding these special comments to your source files. These commands are described in the following sections. Duplicating a Code BlockSometimes, there is a section of code that must be defined differently for some configurations and that must exist even for configurations that don't explicitly define a code block in the section. An example of this would be if your class definition is fragmented. For example, all of your configurations that will be deployed to Nokia devices might define your Canvas object like this public class MIDPCanvas extends com.nokia.mid.ui.FullCanvas { while the rest of your configurations would just extend Canvas. After adding the appropriate code blocks, you would be left with the code shown in Figure 14-6. Figure 14-6. Duplicated code blocks in the Source Editor
These types of blocks can be created in one step using the Create If / Else Block context-menu command:
How to Interpret Code Block VisualizationThe visualization of code blocks within the IDE is that of color highlighted sections. This visualization can help you quickly determine some information about code sections:
|