public final class IOJavaClassWriter extends Object implements JavaClassWriter
JavaClassWriter
interface is based on
simple StringBuilder
"println" type statements.
The order of the generated code in this implementation depends on the initialization. The default order is to accept fields and methods in any order and generate all fields together and all methods together (by member category). Specifying the ordered parameter in the constructor will lead to a slightly different order: generation of fields and methods interspersed among each other in exactly the order they were added (no member categories).
Constructor and Description |
---|
IOJavaClassWriter()
Creates a new instance of IOJavaClassWriter which maintains the
order of member input but groups them by category.
|
IOJavaClassWriter(boolean maintainCategories)
Creates a new instance of IOJavaClassWriter in which the order of the
generated code depends on the specified flag.
|
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.
|
String |
toString()
Returns a string representation of this object.
|
public IOJavaClassWriter()
IOJavaClassWriter(boolean)
public IOJavaClassWriter(boolean maintainCategories)
maintainCategories
- If true
, the order of members is
preserved within category groups. If false
, the
generation of fields and methods will be interspersed among each other
in exactly the order they were added with no member categories.public void setClassDeclaration(int modifiers, String className, String[] comments)
setClassDeclaration
in interface JavaClassWriter
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.Modifier
public void setSuperclass(String name)
setSuperclass
in interface JavaClassWriter
name
- The name of the superclass.public void addInterface(String name)
addInterface
in interface JavaClassWriter
name
- The name of the interface.public void addField(String name, int modifiers, String type, String initialValue, String[] comments)
addField
in interface JavaClassWriter
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.Modifier
public void addInitializer(boolean isStatic, String[] body, String[] comments)
addInitializer
in interface JavaClassWriter
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.public void addConstructor(String name, int modifiers, String[] parameterNames, String[] parameterTypes, String[] exceptions, String[] body, String[] comments)
addConstructor
in interface JavaClassWriter
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.Modifier
public void addMethod(String name, int modifiers, String returnType, String[] parameterNames, String[] parameterTypes, String[] exceptions, String[] body, String[] comments)
addMethod
in interface JavaClassWriter
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.Modifier
public void addClass(JavaClassWriter classWriter)
addClass
in interface JavaClassWriter
classWriter
- The definition of the inner class.Copyright © 2019. All rights reserved.