net.percederberg.grammatica.code.java
Class JavaImport

java.lang.Object
  |
  +--net.percederberg.grammatica.code.CodeElement
        |
        +--net.percederberg.grammatica.code.java.JavaImport
All Implemented Interfaces:
java.lang.Comparable

public class JavaImport
extends CodeElement

A class generating a Java import declaration.

Version:
1.0
Author:
Per Cederberg,

Constructor Summary
JavaImport(JavaPackage pkg)
          Creates a new import declaration, importing all classes of a specified package.
JavaImport(JavaPackage pkg, JavaClass cls)
          Creates a new import declaration, importing the selected class from the specified package.
JavaImport(java.lang.String packageName)
          Creates a new import declaration, importing all classes of a specified package.
JavaImport(java.lang.String packageName, java.lang.String className)
          Creates a new import declaration, importing the selected class from the specified package.
 
Method Summary
 int category()
          Returns a numeric category number for the code element.
 int compareTo(java.lang.Object obj)
          Compares this object to another one.
 boolean equals(java.lang.Object obj)
          Returns true if this object is equal to another import.
 void print(java.io.PrintWriter out, CodeStyle style, int indent)
          Prints the code element to the specified output stream.
 java.lang.String toString()
          Returns a string description of the imported packages.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JavaImport

public JavaImport(JavaPackage pkg)
Creates a new import declaration, importing all classes of a specified package.

Parameters:
pkg - the package to import

JavaImport

public JavaImport(java.lang.String packageName)
Creates a new import declaration, importing all classes of a specified package.

Parameters:
packageName - the fully qualified package name

JavaImport

public JavaImport(JavaPackage pkg,
                  JavaClass cls)
Creates a new import declaration, importing the selected class from the specified package.

Parameters:
pkg - the package containing the specified class
cls - the class to import

JavaImport

public JavaImport(java.lang.String packageName,
                  java.lang.String className)
Creates a new import declaration, importing the selected class from the specified package.

Parameters:
packageName - the fully qualified package name
className - the class name
Method Detail

compareTo

public int compareTo(java.lang.Object obj)
Compares this object to another one. The comparison is based primarily on the code element category, and secondarily on the package name.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class CodeElement
Parameters:
obj - the object to compare to
Returns:
negative if this object preceeds the other one, zero (0) if the objects are equal, or positive if this object succeeds the other one

equals

public boolean equals(java.lang.Object obj)
Returns true if this object is equal to another import.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare to
Returns:
true if the objects are equal, or false otherwise

toString

public java.lang.String toString()
Returns a string description of the imported packages.

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this import

category

public int category()
Returns a numeric category number for the code element. A lower category number implies that the code element should be placed before code elements with a higher category number within a declaration.

Specified by:
category in class CodeElement
Returns:
the category number

print

public void print(java.io.PrintWriter out,
                  CodeStyle style,
                  int indent)
Prints the code element to the specified output stream.

Specified by:
print in class CodeElement
Parameters:
out - the output stream
style - the code style to use
indent - the indentation level