public interface JavaFileWriter
Object.toString()
or saved to a file by calling save(). The semantics of this
interface are as follows:
- Resource allocation is deferred to save - there is no need to worry about
resource cleanup if an IOException is thrown from other methods (addImport,
setPackage, addClass).
- Any implementation of this interface must handle the closing of resources
during save if an exception is thrown.
Use this interface in conjunction with one or more JavaClassWriter
instances to describe the class(es) in a java file.
| Modifier and Type | Method and Description |
|---|---|
void |
addClass(JavaClassWriter classWriter)
Adds a class to this source file.
|
void |
addImport(String importName,
String[] comments)
Adds an import statement for this source file.
|
void |
save()
Saves the file by writing out the source contents to whatever
file (or alternate representation) was specified (usually by the
constructor of the implementation class.
|
void |
setPackage(String packageName,
String[] comments)
Sets the package for this file.
|
void setPackage(String packageName, String[] comments) throws IOException
packageName - The name of the package for this source file.comments - The comments shown just above the package statement.
The comments are passed as an array so the line separators can be added
by the implementation. Note that not all implementations will choose
to make use of this comment.IOException - If the package cannot be set.void addImport(String importName, String[] comments) throws IOException
importName - Name of the class or package (including the *) to be
imported. This string should not contain "import" or the ;comments - The comments shown just above the import statement.
The comments are passed as an array so the line separators can be added
by the implementation. Note that not all implementations will choose
to make use of this comment.IOException - If the import information cannot be added.void addClass(JavaClassWriter classWriter) throws IOException
classWriter - The definition of the class.IOException - If the class information cannot be added.void save() throws IOException
IOException - If the file cannot be saved.Copyright © 2019. All rights reserved.