|
Arch4J 1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.arch4j.generator.JavaSourceFile
This class represents the structure of a Java source file. It defines all the sections of a well-formed Java source file. The sections are built up sequentially by calling various methods. The methods can be called in any order.
Once all the desired sections are set, the Java source can be generated.
The source can be generated as a String generateSource()
or it
can be written to a file generate()
.
Field Summary | |
protected String |
classComment
A comment describing the source file. |
protected List |
constructors
A list of constructor methods, of type JavaConstructorDefinition. |
protected String |
copyrightComment
The comment that can be used as a separate copyright comment. |
protected List |
fields
A list of class or instance variables, of type JavaFieldDefinition. |
static String |
FILE_EXTENSION
The standard Java file extension. |
protected boolean |
importFullClassNames
Use fully qualified class names in import statements? Default = false. |
protected List |
imports
A list of imported classes, expressed as JavaType objects. |
protected List |
methods
A list of methods, expressed as JavaMethodDefinition objects. |
protected JavaObjectDefinition |
objectDefinition
The class or interface specification for the source file. |
protected String |
packageName
The package this source file belongs to. |
protected String |
sourcePath
The root source directory. |
Fields inherited from interface org.arch4j.generator.JavaKeywordConstants |
ABSTRACT, CATCH, CLASS, DEFAULT_ACCESS, EXTENDS, FALSE, FINAL, FINALLY, IMPLEMENTS, IMPORT, INTERFACE, NATIVE, NEW, NULL, PACKAGE, PRIVATE, PROTECTED, PUBLIC, RETURN, STATIC, STRICTFP, SUPER, SYNCHRONIZED, THIS, THROW, THROWS, TRANSIENT, TRUE, TRY, VOID, VOLATILE |
Fields inherited from interface org.arch4j.generator.JavaPrimitiveConstants |
BOOLEAN, BYTE, CHAR, DOUBLE, FLOAT, INT, LONG, SHORT |
Constructor Summary | |
JavaSourceFile(String sourcePath,
JavaObjectDefinition objectDef)
Creates a new JavaSourceFile instance
with the given root source directory and object definition. |
Method Summary | |
void |
addConstructor(JavaConstructorDefinition constructor)
Add a constructor method definition to the source file. |
void |
addConstructors(List constructors)
Add a list of constructor methods to the source file. |
void |
addField(JavaFieldDefinition field)
Add a class or instance variable (field) to the source file. |
void |
addFields(List fields)
Add a list of class or instance variables (fields) to the source file. |
void |
addImport(JavaType importType)
Add an import directive for the source file. |
void |
addImport(String importName)
Add an import directive for the source file. |
void |
addImports(List imports)
Add a list of import directives for the source file. |
void |
addMethod(JavaMethodDefinition method)
Add a method definition to the source file. |
void |
addMethods(List methods)
Add a list of methods to the source file. |
protected void |
checkContents()
Perform a set of tasks to prepare the source file for generation. |
protected void |
gatherImports()
Gather additional imports from the various parts of the source file. |
void |
generate()
Generate the Java source file. |
protected void |
generateClassComments(CodeBuffer buffer)
Write the class comments to the given CodeBuffer . |
protected void |
generateClassDefinition(CodeBuffer buffer)
Write the class or interface definition to the given CodeBuffer . |
protected void |
generateConstructors(CodeBuffer buffer)
Write the constructor method definitions to the given CodeBuffer . |
protected void |
generateCopyrightComments(CodeBuffer buffer)
Write the copyright comments to the given CodeBuffer . |
protected void |
generateEndOfFile(CodeBuffer buffer)
Write the end of class string to the given CodeBuffer . |
protected void |
generateFields(CodeBuffer buffer)
Write the class or instance variable field definitions to the given CodeBuffer . |
protected void |
generateFullImports(CodeBuffer buffer)
|
protected void |
generateImports(CodeBuffer buffer)
Write the import directives to the given CodeBuffer . |
protected void |
generateMethods(CodeBuffer buffer)
Write the method definitions to the given CodeBuffer . |
protected void |
generatePackage(CodeBuffer buffer)
Write the package statement to the given CodeBuffer . |
protected void |
generateSettersAndGetters(CodeBuffer buffer)
Write the setter and getter method definitions to the given CodeBuffer . |
String |
generateSource()
Generate the Java source representation of the source file as a multi-line String. |
protected void |
generateStarredImports(CodeBuffer buffer)
|
void |
setClassComment(String classComment)
Set the class comment for the source file. |
void |
setCopyrightComment(String copyrightComment)
Set the copyright comment for the source file. |
void |
setImportFullClassNames(boolean value)
Set whether fully qualified class names are used in import statements. |
void |
setObjectDefinition(JavaObjectDefinition objectDef)
Set the class or interface definition for the class file. |
void |
setPackageName(String packageName)
Set the package name for the source file. |
void |
setSourcePath(String sourcePath)
Set the root source directory for the receiver. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String FILE_EXTENSION
protected boolean importFullClassNames
protected String sourcePath
protected String copyrightComment
protected String packageName
protected List imports
protected String classComment
protected JavaObjectDefinition objectDefinition
protected List fields
protected List constructors
protected List methods
Constructor Detail |
public JavaSourceFile(String sourcePath, JavaObjectDefinition objectDef)
JavaSourceFile
instance
with the given root source directory and object definition.
sourcePath
- The root source directory used for file generation.objectDef
- The class or interface specification.Method Detail |
public void setImportFullClassNames(boolean value)
value
- true for fully qualified names.public void setSourcePath(String sourcePath)
sourcePath
- The root source directory used for file generation.public void setCopyrightComment(String copyrightComment)
CodeBuffer
. Create it with an initial indentation level of zero.
copyrightComment
- The copyright comments for the source file.public void setPackageName(String packageName)
org.arch4j./code>.
If the package name is left unset, the package will be determined by
looking for a package name in the object definition.
- Parameters:
packageName
- The package that the source file is part of.- See Also:
setObjectDefinition(JavaObjectDefinition)
public void addImport(String importName)
importName
- The import name.public void addImport(JavaType importType)
importType
- The import type.public void addImports(List imports)
imports
- The list of import names or types to add.public void setClassComment(String classComment)
CodeBuffer
. Create it with an initial indentation level of zero.
classComment
- The class-level comments for the source file.public void setObjectDefinition(JavaObjectDefinition objectDef)
objectDef
- The class or interface specification.setPackageName(String)
public void addField(JavaFieldDefinition field)
field
- The field definition.public void addFields(List fields)
fields
- The list of field definitions to add.public void addConstructor(JavaConstructorDefinition constructor)
constructor
- The constructor definition.public void addConstructors(List constructors)
constructors
- The list of constructor definitions to add.public void addMethod(JavaMethodDefinition method)
method
- The method definition.public void addMethods(List methods)
methods
- The list of method definitions to add.public void generate() throws IOException
The Java source file will be created (or overwritten) as a .java file in one of two places. If no package is specified (the default package), the file will be created in the root source directory. If a package name is specified, the package name will be converted to a pathname and the file will be written to that directory.
IOException
- If a file error occurs.setSourcePath(String)
,
setPackageName(String)
,
generateSource()
public String generateSource()
protected void checkContents()
protected void gatherImports()
protected void generateCopyrightComments(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generatePackage(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateImports(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateFullImports(CodeBuffer buffer)
protected void generateStarredImports(CodeBuffer buffer)
protected void generateClassComments(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateClassDefinition(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateFields(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateConstructors(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateSettersAndGetters(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateMethods(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.protected void generateEndOfFile(CodeBuffer buffer)
CodeBuffer
.
buffer
- The CodeBuffer with which to append the data.
|
Arch4J 1.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |