Class ImportDeclaration

java.lang.Object
org.faktorips.codegen.ImportDeclaration

public class ImportDeclaration extends Object
An ImportDeclaration is an ordered set of import statements.

When adding new import statements it is checked that no unnecessary statements are added, for example if you add java.util.ArrayList and then java.util.* only the latter statement is kept. Also import statements for classes residing in java.lang and for primitive types are ignored.

Author:
Jan Ortmann
  • Constructor Details

    • ImportDeclaration

      public ImportDeclaration()
      Creates a new import declaration.
    • ImportDeclaration

      public ImportDeclaration(ImportDeclaration decl)
      Copy constructor.
    • ImportDeclaration

      public ImportDeclaration(ImportDeclaration decl, String packageName)
      Constructs a new import declaration that contains all import statements from the given declaration that are not covered by the package.
  • Method Details

    • isPackageImport

      public static final boolean isPackageImport(String importSpec)
      Returns true if this is a package import, e.g. java.util.* Returns false if importSpec is null.
    • add

      public void add(Class<?> clazz)
      Adds the class to the import list.
    • add

      public void add(ImportDeclaration decl)
      Adds all imports in the given import declaration to this declaration. Does nothing if the given import decl is null.
    • add

      public void add(String[] importSpecs)
      Adds the import specifications to the list of imports. Does nothing if the given importSpecs is null.
    • add

      public void add(String importSpec)
      Adds the import specification to the list of imports. Does nothing if the given importSpecs is null.
    • isCovered

      public boolean isCovered(Class<?> clazz)
      Returns true if the class is covered by the import declaration. That is, if either an import for that class exists or the package the class resides in is imported.
      Throws:
      NullPointerException - if clazz is null.
    • isCovered

      public boolean isCovered(String importSpec)
      Returns true if the import specification is covered by this import declaration.
      Throws:
      NullPointerException - if importSpec is null.
    • iterator

      public Iterator<String> iterator()
      Returns an Iterator over the import statements as Strings.
    • getImports

      public Set<String> getImports()
    • getNoOfImports

      public int getNoOfImports()
      Returns the number of imports.
    • getUncoveredImports

      public ImportDeclaration getUncoveredImports(ImportDeclaration importsToTest)
      Returns those imports in the importsToTest declaration that are not covered this one. Returns an empty import declaration if either all imports are covered or importsToTest is null.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Returns the import statements as a string. The import statements are separated by a line separator. Each line has a trailing "import " and ends with a semicolon (;).
      Overrides:
      toString in class Object