org.exolab.javasource
Class AbstractJClass

java.lang.Object
  extended by org.exolab.javasource.JType
      extended by org.exolab.javasource.JStructure
          extended by org.exolab.javasource.AbstractJClass
All Implemented Interfaces:
JAnnotatedElement
Direct Known Subclasses:
JClass, JEnum

public abstract class AbstractJClass
extends JStructure

A abstract base class for representations of the Java Source code for a Java Class.

Since:
1.1
Version:
$Revision: 6668 $ $Date: 2005-05-08 12:32:06 -0600 (Sun, 08 May 2005) $
Author:
Ralf Joachim

Field Summary
 
Fields inherited from class org.exolab.javasource.JType
BOOLEAN, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORT
 
Constructor Summary
protected AbstractJClass(java.lang.String name)
          Creates a new AbstractJClass with the given name.
 
Method Summary
 void addConstructor(JConstructor constructor)
          Adds the given Constructor to this classes list of constructors.
 void addField(JField jField)
          Adds the given JField to this JStructure.
 void addMethod(JMethod jMethod)
          Adds the given JMethod to this JClass.
 void addMethod(JMethod jMethod, boolean importReturnType)
          Adds the given JMethod to this JClass.
 void addMethods(JMethod[] jMethods)
          Adds the given array of JMethods to this JClass.
 JConstructor createConstructor()
          Creates a new JConstructor and adds it to this JClass.
 JConstructor createConstructor(JParameter[] params)
          Creates a new JConstructor and adds it to this JClass.
 JClass createInnerClass(java.lang.String localname)
          Creates and returns an inner-class for this JClass.
 JConstructor getConstructor(int index)
          Returns the constructor at the specified index.
 JConstructor[] getConstructors()
          Returns the an array of the JConstructors contained within this JClass.
 JField getField(java.lang.String name)
          Returns the field with the given name, or null if no field was found with that name.
 JField[] getFields()
          Returns an array of all the JFields of this JStructure.
 JClass[] getInnerClasses()
          Returns an array of JClass (the inner classes) contained within this JClass.
 JMethod getMethod(int index)
          Returns the JMethod located at the specified index.
 JMethod getMethod(java.lang.String name, int startIndex)
          Returns the first occurance of the method with the given name, starting from the specified index.
 JMethod[] getMethods()
          Returns an array of all the JMethods of this JClass.
 JSourceCode getStaticInitializationCode()
          Returns the JSourceCode for the static initializer of this JClass.
 void print(JSourceWriter jsw)
          Prints the source code for this JStructure to the given JSourceWriter.
abstract  void print(JSourceWriter jsw, boolean classOnly)
          Prints the source code for this JClass to the given JSourceWriter.
protected  void printClassHeaders(JSourceWriter jsw)
          Writes to the JSourceWriter the headers for this class file.
protected  void printConstructors(JSourceWriter jsw)
          Writes to the JSourceWriter all constructors for this class.
protected  void printInnerClasses(JSourceWriter jsw)
          Writes to the JSourceWriter all inner classes belonging to this class.
protected  void printMemberVariables(JSourceWriter jsw)
          Writes to the JSourceWriter the member variables of this class.
protected  void printMethods(JSourceWriter jsw)
          Writes to the JSourceWriter all methods belonging to this class.
protected  void printStaticInitializers(JSourceWriter jsw)
          Writes to the JSourceWriter any static initialization used by this class.
 boolean removeConstructor(JConstructor constructor)
          Removes the given constructor from this JClass.
 boolean removeField(JField jField)
          Removes the given JField from this JClass.
 JField removeField(java.lang.String name)
          Removes the field with the given name from this JClass.
 boolean removeInnerClass(JClass jClass)
          Removes the given inner-class (JClass) from this JClass.
 boolean removeMethod(JMethod method)
          Removes the given method from this JClass.
 
Methods inherited from class org.exolab.javasource.JStructure
addAnnotation, addImport, addImport, addImport, addImportInternal, addInterface, addMember, getAnnotatedElementHelper, getAnnotation, getAnnotations, getFilename, getHeader, getImports, getInterfaceCount, getInterfaces, getJDocComment, getModifiers, getPackageName, hasAnnotations, hasImport, isAnnotationPresent, print, printHeader, printImportDeclarations, printPackageDeclaration, removeAnnotation, removeImport, setHeader, toString
 
Methods inherited from class org.exolab.javasource.JType
getLocalName, getName, isArray, isPrimitive, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractJClass

protected AbstractJClass(java.lang.String name)
Creates a new AbstractJClass with the given name.

Parameters:
name - The name of the AbstractJClass to create.
Method Detail

getStaticInitializationCode

public final JSourceCode getStaticInitializationCode()
Returns the JSourceCode for the static initializer of this JClass.

Returns:
The JSourceCode for the static initializer of this JClass.

getField

public final JField getField(java.lang.String name)
Returns the field with the given name, or null if no field was found with that name.

Specified by:
getField in class JStructure
Parameters:
name - The name of the field to return.
Returns:
The field with the given name, or null if no field was found with the given name.

getFields

public final JField[] getFields()
Returns an array of all the JFields of this JStructure.

Specified by:
getFields in class JStructure
Returns:
An array of all the JFields of this JStructure.

addField

public final void addField(JField jField)
Adds the given JField to this JStructure.
This method is implemented by subclasses and should only accept the proper fields for the subclass otherwise an IllegalArgumentException will be thrown. For example a JInterface will only accept static fields.

Specified by:
addField in class JStructure
Parameters:
jField - The JField to add.

removeField

public final JField removeField(java.lang.String name)
Removes the field with the given name from this JClass.

Parameters:
name - The name of the field to remove.
Returns:
The JField if it was found and removed.

removeField

public final boolean removeField(JField jField)
Removes the given JField from this JClass.

Parameters:
jField - The JField to remove.
Returns:
true if the field was found and removed.

createConstructor

public final JConstructor createConstructor()
Creates a new JConstructor and adds it to this JClass.

Returns:
The newly created constructor.

createConstructor

public final JConstructor createConstructor(JParameter[] params)
Creates a new JConstructor and adds it to this JClass.

Parameters:
params - A list of parameters for this constructor.
Returns:
The newly created constructor.

getConstructor

public final JConstructor getConstructor(int index)
Returns the constructor at the specified index.

Parameters:
index - The index of the constructor to return.
Returns:
The JConstructor at the specified index.

getConstructors

public final JConstructor[] getConstructors()
Returns the an array of the JConstructors contained within this JClass.

Returns:
An array of JConstructor.

addConstructor

public final void addConstructor(JConstructor constructor)
Adds the given Constructor to this classes list of constructors. The constructor must have been created with this JClass' createConstructor.

Parameters:
constructor - The constructor to add.

removeConstructor

public final boolean removeConstructor(JConstructor constructor)
Removes the given constructor from this JClass.

Parameters:
constructor - The JConstructor to remove.
Returns:
true if the constructor was removed, otherwise false.

getMethods

public final JMethod[] getMethods()
Returns an array of all the JMethods of this JClass.

Returns:
An array of all the JMethods of this JClass.

getMethod

public final JMethod getMethod(java.lang.String name,
                               int startIndex)
Returns the first occurance of the method with the given name, starting from the specified index.

Parameters:
name - The name of the method to look for.
startIndex - The starting index to begin the search.
Returns:
The method if found, otherwise null.

getMethod

public final JMethod getMethod(int index)
Returns the JMethod located at the specified index.

Parameters:
index - The index of the JMethod to return.
Returns:
The JMethod.

addMethod

public final void addMethod(JMethod jMethod,
                            boolean importReturnType)
Adds the given JMethod to this JClass.

Parameters:
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.

addMethod

public final void addMethod(JMethod jMethod)
Adds the given JMethod to this JClass.

Parameters:
jMethod - The JMethod to add.

addMethods

public final void addMethods(JMethod[] jMethods)
Adds the given array of JMethods to this JClass.

Parameters:
jMethods - The JMethod[] to add.

removeMethod

public final boolean removeMethod(JMethod method)
Removes the given method from this JClass.

Parameters:
method - The JMethod to remove.
Returns:
true if the method was removed, otherwise false.

createInnerClass

public final JClass createInnerClass(java.lang.String localname)
Creates and returns an inner-class for this JClass.

Parameters:
localname - The name of the class (no package name).
Returns:
the new JClass.

getInnerClasses

public final JClass[] getInnerClasses()
Returns an array of JClass (the inner classes) contained within this JClass.

Returns:
An array of JClass contained within this JClass.

removeInnerClass

public final boolean removeInnerClass(JClass jClass)
Removes the given inner-class (JClass) from this JClass.

Parameters:
jClass - The JClass (inner-class) to remove.
Returns:
true if the JClass was removed, otherwise false.

print

public final void print(JSourceWriter jsw)
Prints the source code for this JStructure to the given JSourceWriter.

Specified by:
print in class JStructure
Parameters:
jsw - The JSourceWriter to print to.

print

public abstract void print(JSourceWriter jsw,
                           boolean classOnly)
Prints the source code for this JClass to the given JSourceWriter.

Parameters:
classOnly - If true, the file header, package declaration, and imports are not printed.
jsw - The JSourceWriter to print to. Must not be null.

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.

Parameters:
jsw - The JSourceWriter to be used.

printMemberVariables

protected final void printMemberVariables(JSourceWriter jsw)
Writes to the JSourceWriter the member variables of this class.

Parameters:
jsw - The JSourceWriter to be used.

printStaticInitializers

protected final void printStaticInitializers(JSourceWriter jsw)
Writes to the JSourceWriter any static initialization used by this class.

Parameters:
jsw - The JSourceWriter to be used.

printConstructors

protected final void printConstructors(JSourceWriter jsw)
Writes to the JSourceWriter all constructors for this class.

Parameters:
jsw - The JSourceWriter to be used.

printMethods

protected final void printMethods(JSourceWriter jsw)
Writes to the JSourceWriter all methods belonging to this class.

Parameters:
jsw - The JSourceWriter to be used.

printInnerClasses

protected final void printInnerClasses(JSourceWriter jsw)
Writes to the JSourceWriter all inner classes belonging to this class.

Parameters:
jsw - The JSourceWriter to be used.


Intalio Inc. (C) 1999-2007. All rights reserved http://www.intalio.com