Home

 

Import generation

The Java editor simplifies the task of finding the correct import statements to use in the Java code.

Simply right-click the unknown type in the code and select Source Æ Add Import, or select the type and press Ctrl+Shift+M. If the type is unambiguous, the import statement is directly added. If the type exists in more than one package, a window with all the types is displayed and you can select the correct type for the import statement.

Figure | -54 shows an example where the selected type (BigDecimal) exists in several packages. After you have determined that the java.math package is what you want, double-click the entry in the list, or select it and click OK, and the import statement is generated in the code.

Figure 8-54 Java editor with import generation

You can also add the required import statements for the whole compilation unit. Right-click a project, package, or Java type in the Package Explorer, and select Source Æ Organize Imports, or select the project, package, or Java type and press Ctrl+Shift+O. The code in the compilation unit is analyzed and the appropriate import statements are added.

ibm.com/redbooks