public interface JavaClassWriter
Object.toString(), but the entire
source definition is only available when used with a JavaFileWriter.
The order of the generated code is up to the implementation. For example, one implementation may accept fields and methods in any order and generate all fields together and all methods together, but maintain the order within the list of fields and methods. Another implementation may take the same input and generate fields and methods interspersed among each other in exactly the order they were added. Still another implementation may make no guarantee as to the order of members at all.
| Modifier and Type | Method and Description |
|---|---|
void |
addClass(JavaClassWriter classWriter)
Adds an inner class to this class.
|
void |
addConstructor(String name,
int modifiers,
String[] parameterNames,
String[] parameterTypes,
String[] exceptions,
String[] body,
String[] comments)
Adds a constructor to this class.
|
void |
addField(String name,
int modifiers,
String type,
String initialValue,
String[] comments)
Adds a field to the list of those declared by this class.
|
void |
addInitializer(boolean isStatic,
String[] body,
String[] comments)
Adds an initializer to this class.
|
void |
addInterface(String name)
Adds an interface to the list of those implemented by this class.
|
void |
addMethod(String name,
int modifiers,
String returnType,
String[] parameterNames,
String[] parameterTypes,
String[] exceptions,
String[] body,
String[] comments)
Adds a method to this class.
|
void |
setClassDeclaration(int modifiers,
String className,
String[] comments)
Sets the information for the class declaration including modifiers,
name, and comments.
|
void |
setSuperclass(String name)
Sets the superclass of this class.
|
void setClassDeclaration(int modifiers,
String className,
String[] comments)
throws IOException
modifiers - The modifier flags for this class.className - The (non-qualified) name of this class.comments - The comments shown just above the class declaration.
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 class declaration information cannot be set.Modifiervoid setSuperclass(String name) throws IOException
name - The name of the superclass.IOException - If the superclass cannot be set.void addInterface(String name) throws IOException
name - The name of the interface.IOException - If the interface cannot be added.void addField(String name, int modifiers, String type, String initialValue, String[] comments) throws IOException
name - The name of the field.modifiers - The modifier flags for this field.type - A string representing the type of this field.initialValue - A string representing the initial value of
this field.comments - The comments shown just above the declaration of
this field. 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 field information cannot be added.Modifiervoid addInitializer(boolean isStatic,
String[] body,
String[] comments)
throws IOException
isStatic - True if this is a static initializer, false otherwise.body - The implementation block of the initializer. The body of
the implementation is passed as an array so the line separators can
be added by the implementation.comments - The comments shown just above the initializer block.
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 initializer information cannot be added.void addConstructor(String name, int modifiers, String[] parameterNames, String[] parameterTypes, String[] exceptions, String[] body, String[] comments) throws IOException
name - The name of the constructor - should be the same as the
name of the class.modifiers - The modifier flags for this constructor.parameterNames - A list of parameter names.parameterTypes - A list of parameter types.exceptions - A list of exceptions.body - The implementation block of the constructor. The body of
the implementation is passed as an array so the line separators can
be added by the implementation.comments - The comments shown just above the constructor. 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 constructor information cannot be added.Modifiervoid addMethod(String name, int modifiers, String returnType, String[] parameterNames, String[] parameterTypes, String[] exceptions, String[] body, String[] comments) throws IOException
name - The name of the method.modifiers - The modifier flags for this method.returnType - A string representing the return type of this method.parameterNames - A list of parameter names.parameterTypes - A list of parameter types.exceptions - A list of exceptions.body - The implementation block of the method. The body of
the implementation is passed as an array so the line separators can
be added by the implementation.comments - The comments shown just above the method. 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 method information cannot be added.Modifiervoid addClass(JavaClassWriter classWriter) throws IOException
classWriter - The definition of the inner class.IOException - If the class information cannot be added.Copyright © 2017. All rights reserved.