A abstract base class for representations of the Java Source code for a Java Class.
addConstructor
public void addConstructor(JConstructor constructor)
Adds the given Constructor to this classes list of constructors. The
constructor must have been created with this JClass' createConstructor.
constructor
- The constructor to add.
addMethod
public final void addMethod(JMethod jMethod)
Adds the given JMethod to this JClass.
jMethod
- The JMethod to add.
addMethod
public final void addMethod(JMethod jMethod,
boolean importReturnType)
Adds the given JMethod to this JClass.
jMethod
- The JMethod to add.importReturnType
- true if we add the importReturnType to the class
import lists. It could be useful to set it to false when all
types are fully qualified.
addMethods
public final void addMethods(JMethod[] jMethods)
Adds the given array of JMethods to this JClass.
jMethods
- The JMethod[] to add.
createConstructor
public final JConstructor createConstructor()
Creates a new JConstructor and adds it to this JClass.
- The newly created constructor.
createConstructor
public final JConstructor createConstructor(JParameter[] params)
Creates a new JConstructor and adds it to this JClass.
params
- A list of parameters for this constructor.
- The newly created constructor.
createInnerClass
public final JClass createInnerClass(String localname)
Creates and returns an inner-class for this JClass.
localname
- The name of the class (no package name).
getConstructor
public final JConstructor getConstructor(int index)
Returns the constructor at the specified index.
index
- The index of the constructor to return.
- The JConstructor at the specified index.
getConstructors
public final JConstructor[] getConstructors()
Returns the an array of the JConstructors contained within this JClass.
- An array of JConstructor.
getContructorsCount
public final int getContructorsCount()
getFieldCount
public final int getFieldCount()
Returns the amount of fields.
getInnerClassCount
public final int getInnerClassCount()
getInnerClasses
public final JClass[] getInnerClasses()
Returns an array of JClass (the inner classes) contained within this
JClass.
- An array of JClass contained within this JClass.
getMethod
public final JMethod getMethod(String name,
int startIndex)
Returns the first occurance of the method with the given name, starting
from the specified index.
name
- The name of the method to look for.startIndex
- The starting index to begin the search.
- The method if found, otherwise null.
getMethod
public final JMethod getMethod(int index)
Returns the JMethod located at the specified index.
index
- The index of the JMethod to return.
getMethodCount
public final int getMethodCount()
getMethods
public final JMethod[] getMethods()
Returns an array of all the JMethods of this JClass.
- An array of all the JMethods of this JClass.
getStaticInitializationCode
public final JSourceCode getStaticInitializationCode()
Returns the JSourceCode for the static initializer of this JClass.
- The JSourceCode for the static initializer of this JClass.
print
public abstract void print(JSourceWriter jsw,
boolean classOnly)
Prints the source code for this JClass to the given JSourceWriter.
jsw
- The JSourceWriter to print to. Must not be null.classOnly
- If true, the file header, package declaration, and
imports are not printed.
printClassHeaders
protected final void printClassHeaders(JSourceWriter jsw)
Writes to the JSourceWriter the headers for this class file. Headers
include the comment-header, the package declaration, and the imports.
jsw
- The JSourceWriter to be used.
printConstructors
protected final void printConstructors(JSourceWriter jsw)
Writes to the JSourceWriter all constructors for this class.
jsw
- The JSourceWriter to be used.
printInnerClasses
protected final void printInnerClasses(JSourceWriter jsw)
Writes to the JSourceWriter all inner classes belonging to this class.
jsw
- The JSourceWriter to be used.
printMemberVariables
protected final void printMemberVariables(JSourceWriter jsw)
Writes to the JSourceWriter the member variables of this class.
jsw
- The JSourceWriter to be used.
printMethods
protected final void printMethods(JSourceWriter jsw)
Writes to the JSourceWriter all methods belonging to this class.
jsw
- The JSourceWriter to be used.
printStaticInitializers
protected final void printStaticInitializers(JSourceWriter jsw)
Writes to the JSourceWriter any static initialization used by this class.
jsw
- The JSourceWriter to be used.
removeConstructor
public final boolean removeConstructor(JConstructor constructor)
Removes the given constructor from this JClass.
constructor
- The JConstructor to remove.
- true if the constructor was removed, otherwise false.
removeField
public final JField removeField(String name)
Removes the field with the given name from this JClass.
name
- The name of the field to remove.
- The JField if it was found and removed.
removeField
public final boolean removeField(JField jField)
Removes the given JField from this JClass.
jField
- The JField to remove.
- true if the field was found and removed.
removeInnerClass
public final boolean removeInnerClass(JClass jClass)
Removes the given inner-class (JClass) from this JClass.
jClass
- The JClass (inner-class) to remove.
- true if the JClass was removed, otherwise false.
removeMethod
public final boolean removeMethod(JMethod method)
Removes the given method from this JClass.
method
- The JMethod to remove.
- true if the method was removed, otherwise false.