Java Developer Tools

Audit - Rules - Import Usage

Description
This group contains audit rules that check the import statements for adherence to common coding practices.

Rules:

Details

Duplicate Import Declarations

Summary
Types and packages should only be imported once within a compilation unit.

Description
This audit rule checks to ensure that there are never more than one import declaration with the same package or type name. This does not flag the case where a package is imported (a demand import) and a type from the package is separately imported explicitly. (Such a situation is sometimes required to disambiguate names.)

Example
    import java.util.Vector;
    import java.util.Vector;

Import of Implicit Package

Summary
Packages that are implicitly imported should never be explicitly imported.

Description
This audit rule checks to ensure that none of the import declarations imports from a package that is implicitly imported (either java.lang or the package containing the compilation unit being audited).

Example
    import java.lang.*;

Import Order

Summary
Import declarations should be consistently ordered.

Description
This audit rule finds import declarations that are not in the specified order.

Example
If the order of the import declarations has been configured such that packages that start with "com" should appear before packages that begin with "org", the following imports would be flagged as being in the wrong order:

    import org.eclipse.core.resources.*;
    import com.instantiations.codePro.*;

Import Style

Summary
Only one style of import should be used.

Description
This audit rule checks to ensure that all of the import declarations have the same style, either demand imports (such as "java.util.*"), or explicit imports (such as "java.util.List").

Example
If the rule is configured such that only explicit imports are allowed, the following import would be flagged as a violation:

    import java.util.*;

Restricted Packages

Summary
Some packages contain internal implementation details and should never be imported.

Description
This audit rule allows the user to specify a list of package names that should not be imported and will check that none of the packages on the list are imported. For example, if the package name internal is included in the list, then any import that contains the identifier internal as one of the components of the package name would be flagged.

Example
    import org.eclipse.core.internal.runtime.*;

Unnecessary Import Declarations

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.