Public Member Functions | |
abstract void | addField (JField jField) throws IllegalArgumentException |
abstract void | addMember (JMember jMember) throws IllegalArgumentException |
void | addImport (String className) |
void | addInterface (String interfaceName) |
void | addInterface (JInterface jInterface) |
abstract JField | getField (String name) |
abstract JField[] | getFields () |
String | getFilename (String destDir) |
JComment | getHeader () |
Enumeration | getImports () |
Enumeration | getInterfaces () |
JDocComment | getJDocComment () |
JModifiers | getModifiers () |
String | getPackageName () |
String | getName (boolean stripPackage) |
boolean | hasImport (String classname) |
boolean | removeImport (String className) |
void | print () |
void | print (String destDir, String lineSeparator) |
abstract void | print (JSourceWriter jsw) |
void | printHeader (JSourceWriter jsw) |
void | printImportDeclarations (JSourceWriter jsw) |
void | printPackageDeclaration (JSourceWriter jsw) |
void | setHeader (JComment comment) |
void | setPackageName (String packageName) |
void | addAnnotation (JAnnotation annotation) |
JAnnotation | getAnnotation (JAnnotationType annotationType) |
JAnnotation[] | getAnnotations () |
boolean | isAnnotationPresent (JAnnotationType annotationType) |
JAnnotation | removeAnnotation (JAnnotationType annotationType) |
boolean | hasAnnotations () |
Static Public Member Functions | |
static boolean | isValidClassName (String name) |
Protected Member Functions | |
JStructure (String name) throws IllegalArgumentException | |
void | addImport (JAnnotation annotation) |
void | addImport (JAnnotation[] annotations) |
JAnnotatedElementHelper | getAnnotatedElementHelper () |
int | getInterfaceCount () |
Static Protected Member Functions | |
static void | printlnWithPrefix (String prefix, String source, JSourceWriter jsw) |
static String | getPackageFromClassName (String className) |
Static Package Attributes | |
static final String | DEFAULT_HEADER = "Id$" |
static final String | version = "Date$" |
This class represents the basic Java "structure" for a Java source file. This is the base class for JClass and JInterface.
This is a useful utility when creating in memory source code. The code in this package was modelled after the Java Reflection API as much as possible to reduce the learning curve.
org.exolab.javasource.JStructure.JStructure | ( | String | name | ) | throws IllegalArgumentException [protected] |
Creates a new JStructure with the given name.
name | the name of the JStructure. |
IllegalArgumentException | when the given name is not a valid Class name. |
References org.exolab.javasource.JDocComment.addDescriptor(), org.exolab.javasource.JType.getLocalName(), org.exolab.javasource.JStructure.getPackageFromClassName(), org.exolab.javasource.JStructure.isValidClassName(), and org.exolab.javasource.JStructure.version.
void org.exolab.javasource.JStructure.addAnnotation | ( | JAnnotation | annotation | ) |
Adds a JAnnotation to this source element. An IllegalArgumentException is thrown if one already exists for the associated JAnnotationType.
annotation |
Implements org.exolab.javasource.JAnnotatedElement.
References org.exolab.javasource.JStructure.addImport().
abstract void org.exolab.javasource.JStructure.addField | ( | JField | jField | ) | throws IllegalArgumentException [pure virtual] |
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.
jField,the | JField to add |
Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.
void org.exolab.javasource.JStructure.addImport | ( | JAnnotation | annotation | ) | [protected] |
Adds approprite import for this JAnnotation
annotation |
References org.exolab.javasource.JStructure.addImport(), org.exolab.javasource.JAnnotation.getAnnotationType(), and org.exolab.javasource.JStructure.getName().
void org.exolab.javasource.JStructure.addImport | ( | JAnnotation[] | annotations | ) | [protected] |
Adds approprite imports for these JAnnotation's
annotation |
References org.exolab.javasource.JStructure.addImport(), and org.exolab.javasource.JType.getName().
void org.exolab.javasource.JStructure.addImport | ( | String | className | ) |
Adds the given import to this JStructure
the | className of the class to import. |
References org.exolab.javasource.JStructure.getPackageFromClassName().
Referenced by org.exolab.javasource.JStructure.addAnnotation(), org.exolab.javasource.JClass.addConstructor(), org.exolab.javasource.JAnnotationType.addElement(), org.exolab.javasource.JInterface.addField(), org.exolab.javasource.JClass.addField(), org.exolab.javasource.JStructure.addImport(), org.exolab.javasource.JInterface.addMethod(), org.exolab.javasource.JClass.addMethod(), org.exolab.javasource.JConstructor.addParameter(), org.exolab.castor.builder.SourceFactory.createSourceCode(), org.exolab.castor.builder.SourceFactory.createTestableMethods(), org.exolab.javasource.JClass.main(), and org.exolab.javasource.JClass.print().
void org.exolab.javasource.JStructure.addInterface | ( | String | interfaceName | ) |
Adds the given interface to the list of interfaces this JStructure inherits method declarations from, and either implements (JClass) or extends (JInterface).
interfaceName | the name of the interface to "inherit" method declarations from. |
Referenced by org.exolab.castor.builder.SourceFactory.createSourceCode(), and org.exolab.castor.builder.SourceFactory.createTestableMethods().
void org.exolab.javasource.JStructure.addInterface | ( | JInterface | jInterface | ) |
Adds the given interface to the list of interfaces this JStructure inherits method declarations from, and either implements (JClass) or extends (JInterface).
jInterface | the JInterface to inherit from. |
References org.exolab.javasource.JStructure.getName().
abstract void org.exolab.javasource.JStructure.addMember | ( | JMember | jMember | ) | throws IllegalArgumentException [pure virtual] |
Adds the given JMember to this JStructure.
This method is implemented by subclasses and should only accept the proper types for the subclass otherwise an IllegalArgumentException will be thrown.
jMember | the JMember to add to this JStructure. |
IllegalArgumentException | when the given JMember has the same name of an existing JField or JMethod respectively. |
Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.
JAnnotatedElementHelper org.exolab.javasource.JStructure.getAnnotatedElementHelper | ( | ) | [protected] |
Returns the object managing the annotations for this JStructure
Referenced by org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().
JAnnotation org.exolab.javasource.JStructure.getAnnotation | ( | JAnnotationType | annotationType | ) |
Retrieves a JAnnotation for the given JAnnotationType, returns null if no annotation has been set.
annotationType |
Implements org.exolab.javasource.JAnnotatedElement.
JAnnotation [] org.exolab.javasource.JStructure.getAnnotations | ( | ) |
Returns a list of JAnnotation's already set on this source element
Implements org.exolab.javasource.JAnnotatedElement.
Referenced by org.exolab.javasource.JClass.addConstructor(), org.exolab.javasource.JInterface.addMethod(), and org.exolab.javasource.JClass.addMethod().
abstract JField org.exolab.javasource.JStructure.getField | ( | String | name | ) | [pure virtual] |
Adds the given JMethodSignature to this JClass
jMethodSig | the JMethodSignature to add. |
IllegalArgumentException | when the given JMethodSignature conflicts with an existing method signature. Returns the field with the given name, or null if no field was found with the given name. |
name | the name of the field to return. |
Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.
abstract JField [] org.exolab.javasource.JStructure.getFields | ( | ) | [pure virtual] |
Returns an array of all the JFields of this JStructure
Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.
String org.exolab.javasource.JStructure.getFilename | ( | String | destDir | ) |
Returns the name of the file that this JStructure would be printed to, given a call to print.
destDir | the destination directory. This may be null. |
References org.exolab.javasource.JType.getLocalName().
Referenced by org.exolab.javasource.JStructure.print().
JComment org.exolab.javasource.JStructure.getHeader | ( | ) |
Returns the JComment header to display at the top of the source file for this JStructure, or null if no header was set.
Referenced by org.exolab.javasource.JStructure.printHeader().
Enumeration org.exolab.javasource.JStructure.getImports | ( | ) |
Returns an Enumeration of imported package and class names for this JStructure.
Referenced by org.exolab.javasource.JCompUnit.getImports(), and org.exolab.javasource.JClass.print().
int org.exolab.javasource.JStructure.getInterfaceCount | ( | ) | [protected] |
Referenced by org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().
Enumeration org.exolab.javasource.JStructure.getInterfaces | ( | ) |
Returns an Enumeration of interface names that this JStructure inherits from.
Referenced by org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().
JDocComment org.exolab.javasource.JStructure.getJDocComment | ( | ) |
Returns the Java Doc comment for this JStructure
Referenced by org.exolab.castor.builder.SourceFactory.createSourceCode(), org.exolab.javasource.JAnnotationType.JAnnotationType(), org.exolab.javasource.JClass.JClass(), org.exolab.javasource.JInterface.JInterface(), org.exolab.javasource.JInterface.print(), org.exolab.javasource.JClass.print(), and org.exolab.javasource.JAnnotationType.print().
JModifiers org.exolab.javasource.JStructure.getModifiers | ( | ) |
Returns an array of all the JMethodSignatures of this JInterface.
name | the name of the JMethodSignature to return. | |
startIndex | the starting index to begin searching from. |
index | the index of the JMethodSignature to return. |
Referenced by org.exolab.javasource.JClass.addMethod(), org.exolab.castor.builder.SourceFactory.createSourceCode(), org.exolab.javasource.JInterface.print(), org.exolab.javasource.JClass.print(), org.exolab.javasource.JAnnotationType.print(), and org.exolab.javasource.JCompUnit.printStructures().
String org.exolab.javasource.JStructure.getName | ( | boolean | stripPackage | ) |
Returns the name of the interface.
stripPackage | a boolean that when true indicates that only the local name (no package) should be returned. |
Referenced by org.exolab.javasource.JMethodSignature.addException(), org.exolab.javasource.JStructure.addImport(), org.exolab.javasource.JStructure.addInterface(), org.exolab.javasource.JMethod.addParameter(), org.exolab.javasource.JConstructor.addParameter(), org.exolab.javasource.JCompUnit.addStructure(), org.exolab.castor.builder.SourceFactory.createEqualsMethod(), org.exolab.castor.builder.DescriptorSourceFactory.createSource(), org.exolab.castor.builder.SourceFactory.createTestableMethods(), org.exolab.javasource.JMethodSignature.getParameterClassNames(), org.exolab.castor.builder.SGStateInfo.getProcessed(), org.exolab.javasource.JMethodSignature.print(), org.exolab.castor.builder.SGStateInfo.processed(), org.exolab.javasource.JConstructor.toString(), and org.exolab.castor.builder.types.XSClass.XSClass().
static String org.exolab.javasource.JStructure.getPackageFromClassName | ( | String | className | ) | [static, protected] |
Returns the package name from the given class name
Referenced by org.exolab.javasource.JStructure.addImport(), and org.exolab.javasource.JStructure.JStructure().
String org.exolab.javasource.JStructure.getPackageName | ( | ) |
Returns the name of the package that this JStructure is a member of.
Referenced by org.exolab.javasource.JClass.createInnerClass(), and org.exolab.javasource.JCompUnit.JCompUnit().
boolean org.exolab.javasource.JStructure.hasAnnotations | ( | ) |
Returns true if annotations have been added to this source element
Implements org.exolab.javasource.JAnnotatedElement.
boolean org.exolab.javasource.JStructure.hasImport | ( | String | classname | ) |
Returns true if the given classname exists in the imports of this JStructure
classname | the class name to check for |
Referenced by org.exolab.javasource.JClass.print().
boolean org.exolab.javasource.JStructure.isAnnotationPresent | ( | JAnnotationType | annotationType | ) |
Returns true if a JAnnotation exists for the given JAnnotationType
annotationType |
Implements org.exolab.javasource.JAnnotatedElement.
static boolean org.exolab.javasource.JStructure.isValidClassName | ( | String | name | ) | [static] |
Referenced by org.exolab.javasource.JStructure.JStructure().
void org.exolab.javasource.JStructure.print | ( | String | destDir, | |
String | lineSeparator | |||
) |
Prints the source code for this JStructure to the destination directory. Sub-directories will be created if necessary for the package.
lineSeparator | the line separator to use at the end of each line. If null, then the default line separator for the runtime platform will be used. |
References org.exolab.javasource.JSourceWriter.close(), org.exolab.javasource.JStructure.getFilename(), org.exolab.javasource.JType.getLocalName(), org.exolab.javasource.JStructure.print(), and org.exolab.javasource.JSourceWriter.setLineSeparator().
void org.exolab.javasource.JStructure.print | ( | ) |
Prints the source code for this JStructure in the current working directory. Sub-directories will be created if necessary for the package.
Referenced by org.exolab.javasource.JStructure.print(), org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().
abstract void org.exolab.javasource.JStructure.print | ( | JSourceWriter | jsw | ) | [pure virtual] |
Prints the source code for this JStructure to the given JSourceWriter.
jsw | the JSourceWriter to print to. |
Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.
void org.exolab.javasource.JStructure.printHeader | ( | JSourceWriter | jsw | ) |
A utility method that prints the header to the given JSourceWriter
jsw | the JSourceWriter to print to. |
References org.exolab.javasource.JStructure.DEFAULT_HEADER, org.exolab.javasource.JSourceWriter.flush(), org.exolab.javasource.JStructure.getHeader(), org.exolab.javasource.JComment.print(), and org.exolab.javasource.JSourceWriter.writeln().
Referenced by org.exolab.javasource.JInterface.print(), org.exolab.javasource.JClass.print(), and org.exolab.javasource.JAnnotationType.print().
void org.exolab.javasource.JStructure.printImportDeclarations | ( | JSourceWriter | jsw | ) |
A utility method that prints the imports to the given JSourceWriter
jsw | the JSourceWriter to print to. |
References org.exolab.javasource.JSourceWriter.flush(), org.exolab.javasource.JSourceWriter.write(), and org.exolab.javasource.JSourceWriter.writeln().
Referenced by org.exolab.javasource.JInterface.print(), org.exolab.javasource.JClass.print(), and org.exolab.javasource.JAnnotationType.print().
static void org.exolab.javasource.JStructure.printlnWithPrefix | ( | String | prefix, | |
String | source, | |||
JSourceWriter | jsw | |||
) | [static, protected] |
Prints the given source string to the JSourceWriter using the given prefix at the beginning of each new line.
prefix | the prefix for each new line. | |
source | the source code to print | |
jsw | the JSourceWriter to print to. |
References org.exolab.javasource.JSourceWriter.write(), and org.exolab.javasource.JSourceWriter.writeln().
void org.exolab.javasource.JStructure.printPackageDeclaration | ( | JSourceWriter | jsw | ) |
A utility method that prints the packageDeclaration to the given JSourceWriter
jsw | the JSourceWriter to print to. |
References org.exolab.javasource.JSourceWriter.flush(), org.exolab.javasource.JSourceWriter.write(), and org.exolab.javasource.JSourceWriter.writeln().
Referenced by org.exolab.javasource.JInterface.print(), org.exolab.javasource.JClass.print(), and org.exolab.javasource.JAnnotationType.print().
JAnnotation org.exolab.javasource.JStructure.removeAnnotation | ( | JAnnotationType | annotationType | ) |
Removes the JAnnotation from this source element for the given JAnnotationType, throws a IllegalArgumentException if no JAnnotation has been added.
annotation |
Implements org.exolab.javasource.JAnnotatedElement.
boolean org.exolab.javasource.JStructure.removeImport | ( | String | className | ) |
Referenced by org.exolab.javasource.JClass.print().
void org.exolab.javasource.JStructure.setHeader | ( | JComment | comment | ) |
Prints the source code for this JStructure to the given JSourceWriter.
jsw | the JSourceWriter to print to. |
public abstract void print(JSourceWriter jsw);
StringBuffer buffer = new StringBuffer();
printHeader(); printPackageDeclaration(); printImportDeclarations();
------------/
jdc.print(jsw);
-- print class information -- we need to add some JavaDoc API adding comments
buffer.setLength(0);
if (modifiers.isPrivate()) { buffer.append("private "); } else if (modifiers.isPublic()) { buffer.append("public "); }
if (modifiers.isAbstract()) { buffer.append("abstract "); }
buffer.append("interface "); buffer.append(getLocalName()); buffer.append(' '); if (interfaces.size() > 0) { boolean endl = false; if (interfaces.size() > 1) { jsw.writeln(buffer.toString()); buffer.setLength(0); endl = true; } buffer.append("extends "); for (int i = 0; i < interfaces.size(); i++) { if (i > 0) buffer.append(", "); buffer.append(interfaces.elementAt(i)); } if (endl) { jsw.writeln(buffer.toString()); buffer.setLength(0); } else buffer.append(' '); }
buffer.append('{'); jsw.writeln(buffer.toString()); buffer.setLength(0); jsw.writeln();
jsw.indent();
-- print method signatures
if (methods.size() > 0) { jsw.writeln(); jsw.writeln(" //-----------/"); jsw.writeln(" //- Methods -/"); jsw.writeln("//-----------/"); jsw.writeln(); }
for (int i = 0; i < methods.size(); i++) { JMethodSignature signature = (JMethodSignature) methods.elementAt(i); signature.print(jsw); jsw.writeln(';'); }
jsw.unindent(); jsw.writeln('}'); jsw.flush(); jsw.close(); } //-- printSource Sets the header comment for this JStructure
comment | the comment to display at the top of the source file when printed |
void org.exolab.javasource.JStructure.setPackageName | ( | String | packageName | ) |
Allows changing the package name of this JStructure
packageName | the package name to use |
Reimplemented in org.exolab.javasource.JClass.JInnerClass.
References org.exolab.javasource.JType.changePackage().
final String org.exolab.javasource.JStructure.DEFAULT_HEADER = "Id$" [static, package] |
The Id for Source control systems I needed to separate this line to prevent CVS from expanding it here! ;-)
Referenced by org.exolab.javasource.JStructure.printHeader().
final String org.exolab.javasource.JStructure.version = "Date$" [static, package] |
The source control version for listed in the JavaDoc I needed to separate this line to prevent CVS from expanding it here! ;-)
Referenced by org.exolab.javasource.JStructure.JStructure().