Class AbstractJClass
java.lang.Object
org.exolab.javasource.JType
org.exolab.javasource.JStructure
org.exolab.javasource.AbstractJClass
- All Implemented Interfaces:
JAnnotatedElement
- Direct Known Subclasses:
JClass
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 JType
BOOLEAN, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORTModifier and TypeFieldDescriptionstatic final JPrimitiveTypeJType for a boolean (Boolean).static final JPrimitiveTypeJType instance for a byte (Byte).static final JPrimitiveTypeJType instance for a char (Char).static final JPrimitiveTypeJType instance for a double (Double).static final JPrimitiveTypeJType instance for a float (Float).static final JPrimitiveTypeJType instance for a int (Integer).static final JPrimitiveTypeJType instance for a long (Long).static final JPrimitiveTypeJType instance for a short (Short). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractJClass(String name) Creates a new AbstractJClass with the given name.protectedAbstractJClass(String name, boolean useOldFieldNaming) Creates a new AbstractJClass with the given name. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddConstant(JConstant jConstant) voidaddConstructor(JConstructor constructor) Adds the given Constructor to this classes list of constructors.final voidAdds the given JField to this JStructure.final voidAdds the given JMethod to this JClass.final voidAdds the given JMethod to this JClass.final voidaddMethods(JMethod[] jMethods) Adds the given array of JMethods to this JClass.voidaddSourceCode(String sourceCode) Adds a complete source code fragment (method) to this class.final JConstructorCreates a new JConstructor and adds it to this JClass.final JConstructorcreateConstructor(JParameter[] params) Creates a new JConstructor and adds it to this JClass.final JClasscreateInnerClass(String localname) Creates and returns an inner-class for this JClass.final JConstantgetConstant(String name) final intReturns the amount of constants.final JConstant[]final JConstructorgetConstructor(int index) Returns the constructor at the specified index.final JConstructor[]Returns the an array of the JConstructors contained within this JClass.final intfinal JFieldReturns the field with the given name, or null if no field was found with that name.final intReturns the amount of fields.final JField[]Returns an array of all the JFields of this JStructure.final intfinal JClass[]Returns an array of JClass (the inner classes) contained within this JClass.final JMethodgetMethod(int index) Returns the JMethod located at the specified index.final JMethodReturns the first occurance of the method with the given name, starting from the specified index.final intfinal JMethod[]Returns an array of all the JMethods of this JClass.String[]Returns a collection of (complete) source code fragments.final intfinal JSourceCodeReturns the JSourceCode for the static initializer of this JClass.final voidprint(JSourceWriter jsw) Deprecated.Please use the Velocity-template based approach instead.abstract voidprint(JSourceWriter jsw, boolean classOnly) Deprecated.Please use the Velocity-template based approach instead.protected final voidWrites to the JSourceWriter the headers for this class file.protected final voidWrites to theJSourceWriterthe constant definitions of this class.protected final voidWrites to the JSourceWriter all constructors for this class.protected final voidWrites to the JSourceWriter all inner classes belonging to this class.protected final voidWrites to the JSourceWriter the member variables of this class.protected final voidWrites to the JSourceWriter all methods belonging to this class.protected final voidprintSourceCodeFragments(JSourceWriter sourceWriter) protected final voidWrites to the JSourceWriter any static initialization used by this class.final JConstantremoveConstant(String name) Removes the constant with the given name from thisJClass.final booleanremoveConstant(JConstant jConstant) final booleanremoveConstructor(JConstructor constructor) Removes the given constructor from this JClass.final JFieldremoveField(String name) Removes the field with the given name from this JClass.final booleanremoveField(JField jField) Removes the given JField from this JClass.final booleanremoveInnerClass(JClass jClass) Removes the given inner-class (JClass) from this JClass.final booleanremoveMethod(JMethod method) Removes the given method from this JClass.Methods inherited from class JStructure
addAnnotation, addImport, addImport, addImport, addImportInternal, addInterface, addMember, getAnnotatedElementHelper, getAnnotation, getAnnotations, getFilename, getHeader, getImportCount, getImports, getInterfaceCount, getInterfaces, getJDocComment, getModifiers, getPackageName, hasAnnotations, hasImport, isAnnotationPresent, print, printHeader, printImportDeclarations, printPackageDeclaration, removeAnnotation, removeImport, removeInterface, setHeader, toStringModifier and TypeMethodDescriptionfinal voidaddAnnotation(JAnnotation annotation) Adds a JAnnotation to this source element.abstract voidAdds the given import to this JStructure.protected final voidaddImport(JAnnotation annotation) Adds appropriate import for this JAnnotation.protected final voidaddImport(JAnnotation[] annotations) Adds appropriate imports for each JAnnotation in the given Array.protected final voidaddImportInternal(String className) Adds the given import to this JStructure.final voidaddInterface(String interfaceName) Adds the given interface to the list of interfaces this JStructure inherits method declarations from, and either implements (JClass) or extends (JInterface).abstract voidAdds the given JMember to this JStructure.protected final JAnnotatedElementHelperReturns the object managing the annotations for this JStructure.final JAnnotationgetAnnotation(JAnnotationType annotationType) Retrieves a JAnnotation for the given JAnnotationType, returns null if no annotation has been set.final JAnnotation[]Returns a list of JAnnotation's already set on this source element.final StringgetFilename(String destDir) Returns the name of the file that this JStructure would be printed to, given a call toJStructure.print(String, String).final JCommentReturns the JComment header to display at the top of the source file for this JStructure, or null if no header was set.final intReturns the amount of imports.final Enumeration<String> Returns an Enumeration of imported package and class names for this JStructure.final intReturn the count of the number of Interfaces that have been added to this JStructure.final Enumeration<String> Returns an Enumeration of interface names that this JStructure inherits from.final JDocCommentReturns the JavaDoc comment for this JStructure.final JModifiersReturns the JModifiers, which allows the qualifiers to be changed.final StringReturns the name of the package that this JStructure is a member of.final booleanReturns true if this source element has any annotations.final booleanReturns true if the given classname exists in the imports of this JStructure.final booleanisAnnotationPresent(JAnnotationType annotationType) Returns true if a JAnnotation exists for the given JAnnotationType.final voidPrints the source code for this JStructure to the destination directory.final voidprintHeader(JSourceWriter jsw) A utility method that prints the header to the given JSourceWriter.protected final voidA utility method that prints the imports to the given JSourceWriter.final voidA utility method that prints the packageDeclaration to the given JSourceWriter.final JAnnotationremoveAnnotation(JAnnotationType annotationType) Removes the JAnnotation from this source element for the given JAnnotationType.final booleanremoveImport(String className) Remove the import of the given class name from this JStucture, returning true if the import was found and removed.final booleanremoveInterface(String interfaceName) Removes the given interface from the list of interfaces thisJStructurehas.final voidSets the header comment for this JStructure.final StringtoString()
Returns the String representation of this JType.Methods inherited from class JType
getLocalName, getName, isArray, isPrimitive, setNameModifier and TypeMethodDescriptionfinal StringReturns the unqualified Java type name (i.e.final StringgetName()Returns the qualified Java type name.final booleanisArray()Returns true if this type represents an Array.final booleanReturns true if this type represents a Java primitive type.protected voidSets the qualified name of this type.
-
Constructor Details
-
AbstractJClass
Creates a new AbstractJClass with the given name.- Parameters:
name- The name of the AbstractJClass to create.
-
AbstractJClass
Creates a new AbstractJClass with the given name.- Parameters:
name- The name of the AbstractJClass to create.
-
-
Method Details
-
getSourceCodeEntries
Returns a collection of (complete) source code fragments.- Returns:
- A collection of (complete) source code fragments.
-
getStaticInitializationCode
Returns the JSourceCode for the static initializer of this JClass.- Returns:
- The JSourceCode for the static initializer of this JClass.
-
getField
Returns the field with the given name, or null if no field was found with that name.- Specified by:
getFieldin classJStructure- 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.
-
getConstant
-
getFields
Returns an array of all the JFields of this JStructure.- Specified by:
getFieldsin classJStructure- Returns:
- An array of all the JFields of this JStructure.
-
getConstants
-
getFieldCount
public final int getFieldCount()Returns the amount of fields.- Returns:
- The amount of fields.
-
getConstantCount
public final int getConstantCount()Returns the amount of constants.- Returns:
- The amount of constants.
-
addField
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:
addFieldin classJStructure- Parameters:
jField- The JField to add.
-
addConstant
-
removeField
-
removeConstant
-
removeField
Removes the given JField from this JClass.- Parameters:
jField- The JField to remove.- Returns:
- true if the field was found and removed.
-
removeConstant
-
createConstructor
Creates a new JConstructor and adds it to this JClass.- Returns:
- The newly created constructor.
-
createConstructor
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
Returns the constructor at the specified index.- Parameters:
index- The index of the constructor to return.- Returns:
- The JConstructor at the specified index.
-
getConstructors
Returns the an array of the JConstructors contained within this JClass.- Returns:
- An array of JConstructor.
-
getContructorsCount
public final int getContructorsCount() -
addConstructor
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
Removes the given constructor from this JClass.- Parameters:
constructor- The JConstructor to remove.- Returns:
- true if the constructor was removed, otherwise false.
-
getMethods
Returns an array of all the JMethods of this JClass.- Returns:
- An array of all the JMethods of this JClass.
-
getMethod
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
Returns the JMethod located at the specified index.- Parameters:
index- The index of the JMethod to return.- Returns:
- The JMethod.
-
getMethodCount
public final int getMethodCount() -
addMethod
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
Adds the given JMethod to this JClass.- Parameters:
jMethod- The JMethod to add.
-
addMethods
Adds the given array of JMethods to this JClass.- Parameters:
jMethods- The JMethod[] to add.
-
removeMethod
Removes the given method from this JClass.- Parameters:
method- The JMethod to remove.- Returns:
- true if the method was removed, otherwise false.
-
createInnerClass
-
getInnerClasses
Returns an array of JClass (the inner classes) contained within this JClass.- Returns:
- An array of JClass contained within this JClass.
-
getInnerClassCount
public final int getInnerClassCount() -
removeInnerClass
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
Deprecated.Please use the Velocity-template based approach instead.Prints the source code for this JStructure to the given JSourceWriter.- Specified by:
printin classJStructure- Parameters:
jsw- The JSourceWriter to print to.- See Also:
-
print
Deprecated.Please use the Velocity-template based approach instead.Prints the source code for this JClass to the given JSourceWriter.- Parameters:
jsw- The JSourceWriter to print to. Must not be null.classOnly- If true, the file header, package declaration, and imports are not printed.- See Also:
-
printClassHeaders
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.
-
printConstantDefinitions
Writes to theJSourceWriterthe constant definitions of this class.- Parameters:
jsw- The JSourceWriter to be used.
-
printMemberVariables
Writes to the JSourceWriter the member variables of this class.- Parameters:
jsw- The JSourceWriter to be used.
-
printStaticInitializers
Writes to the JSourceWriter any static initialization used by this class.- Parameters:
jsw- The JSourceWriter to be used.
-
printConstructors
Writes to the JSourceWriter all constructors for this class.- Parameters:
jsw- The JSourceWriter to be used.
-
printMethods
Writes to the JSourceWriter all methods belonging to this class.- Parameters:
jsw- The JSourceWriter to be used.
-
printSourceCodeFragments
-
printInnerClasses
Writes to the JSourceWriter all inner classes belonging to this class.- Parameters:
jsw- The JSourceWriter to be used.
-
addSourceCode
Adds a complete source code fragment (method) to this class.- Parameters:
sourceCode- The complete source code fragment to be added.
-
getSourceCodeEntryCount
public final int getSourceCodeEntryCount()
-