OverviewDownloadDocumentationPlug-insLinksContact
Features | History | Manual | FAQ | Javadoc
This page generated: December 10 2003

4.3.7. Imports

Controls the handling of import declarations.

4.3.7.1. General

Enables the sorting of import statements. Sorting the import statements makes it simple to browse a long list of imports.

  • Sort import statements

    Enables or disables the sorting of import statements. Enabling this option will sort all imports lexicographically.

4.3.7.2. Grouping

In addition to sorting, associated packages can be grouped together to reduce complexity by packing related information into a common unit.

  • Default grouping depth

    Lets you define the default grouping depth. Only takes effect if sorting is enabled.

    The grouping depth specifies the number of package name parts that are to be taken into account in order to determine whether two import statements are to be grouped together. For certain packages you may want to specify a grouping depth that differs from the default.

    Statements are to be grouped together, if all relevant parts are equal. So via the grouping depth you can effectively specify how many parts are relevant.

    To disable grouping at all, set the grouping depth to "0".

    Example 4.137. Grouping depth java='1'

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.List;
    

    Example 4.138. Grouping depth java='2'

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import java.util.ArrayList;
    import java.util.List;
    

    Example 4.139. Grouping depth java= '3'

    import java.awt.Color;
    import java.awt.Component;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import java.util.ArrayList;
    import java.util.List;
    

You can add/remove package fragments (e.g. javax, javax.swing or com.foo.sarah) via the Add... and Remove buttons to fine-tune the appearance for certain packages.

To specify the order in which related statements should appear, you may want to use the Up and Down buttons.

Note that the asterix represents all undefined packages.

4.3.7.3. Optimize

Optimizes the import statements by either expanding or collapsing them. This is a nice feature that is currently only available with the Ant and JBuilder Plug-in.

  • Expand on-demand imports

    If enabled, tries to expand all on-demand import statements.

    Expanding means to resolve all on-demand import statements (sometimes called wildcard imports) and replace them with single-type import statements (sometimes called explicit imports) of the types that are actually used in the source file.

    So the following on-demand import statement may be expanded into two single-type import statements that reference the needed types for this package.

    Example 4.140. On-demand import statement

    import java.util.*;
    

    Example 4.141. Single-type import statements

    import java.util.ArrayList;
    import java.util.List;
    

    Using single-type imports is quite useful and an absolute requirement in the open source community as this code is usually really reviewed. Using single-type imports makes it easy for the code reader to quickly find out the package a particular type is in: You just search for the type name from the start of the source file.

  • Collapse single-type imports

    If enabled, tries to collapse all single-type statements.

    Collapsing means to remove all single-type imports of a given package and replace them with one on-demand import statement.

to top