Package org.jibx.schema.codegen
Class ClassBuilder
java.lang.Object
org.jibx.schema.codegen.ClassBuilder
Builder for a class definition. This wraps the AST with convenience methods and added control information.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ASTNode
Type declaration for class.private final ArrayList
Fields added to class.private final ArrayList
Builders for inner classes of this class.private final ArrayList
Directly-added inner classes of this class.private final ArrayList
Methods added to class.private final SourceBuilder
Source file containing this class. -
Constructor Summary
ConstructorsConstructorDescriptionClassBuilder
(AbstractTypeDeclaration clas, ClassBuilder outer) Constructor for an inner class.ClassBuilder
(AbstractTypeDeclaration clas, SourceBuilder source) Constructor.ClassBuilder
(AnonymousClassDeclaration clas, ClassBuilder outer) Constructor for an anonymous inner class. -
Method Summary
Modifier and TypeMethodDescriptionaddConstructor
(String name) Add constructor declaration.void
addEnumConstant
(String value, String doc) Add a constant to a Java 5 enum definition.void
addEnumConstant
(String name, String doc, String value) Add a constant to a Java 5 enum definition.void
addField
(FieldDeclaration field) Add separately-constructed field declaration.Add field declaration.void
addInterface
(String type) Add an interface to this class definition.addIntField
(String name, String value) Addint
field declaration with constant initialization.void
addJavaDoc
(String doc, BodyDeclaration decl) Add JavaDoc to a declaration.Add method declaration.void
addMethod
(MethodDeclaration method) Add separately-constructed method declaration.void
addSourceComment
(String text) Set source comment for this class.void
addType
(TypeDeclaration type) Add separately-constructed inner class declaration.buildArrayIndexAccess
(String aname, String iname) Build array access expression for a named array variable and named index variable.buildCast
(Type type) Build a cast expression.buildInfix
(Operator op) Build general infix expression.buildNameOp
(String name, Operator op) Build infix expression involving a local variable or field name as the left operand.buildPreincrement
(String name) Build a preincrement expression using a local variable or field name as the operand.Build a string concatenation expression starting from from a string literal.ASTNode
clone
(ASTNode node) Clone an AST node.createExpressionMethodCall
(ExpressionBuilderBase expr, String mname) Create method call builder on the reference result of an expression.Create internal static method call builder.createMemberMethodCall
(String mname) Create internal member method call builder.createNormalMethodCall
(String name, String mname) Create method call builder on a local variable or field value.Type
createParameterizedType
(String type, String param) Create a parameterized type.Type
createParameterizedType
(String type, Type param) Create a parameterized type.createStaticMethodCall
(String fname) Create a static method call builder.createStaticMethodCall
(String cname, String mname) Create a static method call builder.Type
createType
(String type) Create type definition.(package private) Name
createTypeName
(String type) Create type name.void
finish()
Finish building the source file data structures.(package private) AST
getAST()
AST access for related classes.FieldDeclaration[]
Get the fields defined in this class.String[]
Get the interfaces implemented by this class.MethodDeclaration[]
Get the methods defined in this class.Get a sorted array of the field names and types defined in this class.newArrayBuilder
(String type) Create new instance of array type.newBlock()
Create a new block.newInstance
(Type type) Build new instance creator of type using a no-argument constructor.newInstanceFromString
(String type, String value) Build new instance creator of a simple type using a constructor that takes a single string value.newInstanceFromStrings
(String type, String value1, String value2) Build new instance creator of a simple type using a constructor that takes a pair of string values.void
Set the abstract flag for this class.void
setSuperclass
(String name) Set the superclass for this class.
-
Field Details
-
m_source
Source file containing this class. -
m_class
private final ASTNode m_classType declaration for class. -
m_fields
Fields added to class. -
m_methods
Methods added to class. -
m_innerBuilders
Builders for inner classes of this class. -
m_innerClasses
Directly-added inner classes of this class.
-
-
Constructor Details
-
ClassBuilder
ClassBuilder(AbstractTypeDeclaration clas, SourceBuilder source) Constructor.- Parameters:
clas
-source
-
-
ClassBuilder
ClassBuilder(AbstractTypeDeclaration clas, ClassBuilder outer) Constructor for an inner class.- Parameters:
clas
-outer
-
-
ClassBuilder
Constructor for an anonymous inner class.- Parameters:
clas
-outer
-
-
-
Method Details
-
getAST
AST getAST()AST access for related classes.- Returns:
- AST
-
addField
public void addField(FieldDeclaration field) Add separately-constructed field declaration.- Parameters:
field
-
-
addMethod
public void addMethod(MethodDeclaration method) Add separately-constructed method declaration.- Parameters:
method
-
-
addType
public void addType(TypeDeclaration type) Add separately-constructed inner class declaration.- Parameters:
type
-
-
setSuperclass
Set the superclass for this class.- Parameters:
name
-
-
createTypeName
Create type name.- Parameters:
type
- fully qualified type name- Returns:
- name
-
clone
public ASTNode clone(ASTNode node) Clone an AST node. The cloned node will have no parent.- Parameters:
node
-- Returns:
- clone
-
createType
Create type definition. This uses the supplied type name, which may include array suffixes, to construct the actual type definition.- Parameters:
type
- fully qualified type name, or primitive type name- Returns:
- constructed typed definition
-
createParameterizedType
Create a parameterized type. Both the type itself and the parameter type are given as names in this variation.- Parameters:
type
- fully qualified type nameparam
- fully qualified parameter type name- Returns:
- type
-
createParameterizedType
Create a parameterized type. The type itself is given as a name, while the parameter type is an actual type in this variation.- Parameters:
type
- fully qualified type nameparam
- type parameter- Returns:
- type
-
addSourceComment
Set source comment for this class.- Parameters:
text
- comment text
-
setAbstract
public void setAbstract()Set the abstract flag for this class. -
getInterfaces
Get the interfaces implemented by this class.- Returns:
- interface names
-
getFields
public FieldDeclaration[] getFields()Get the fields defined in this class.- Returns:
- fields
-
getMethods
public MethodDeclaration[] getMethods()Get the methods defined in this class.- Returns:
- methods
-
addInterface
Add an interface to this class definition.- Parameters:
type
- interface type
-
addJavaDoc
Add JavaDoc to a declaration.- Parameters:
doc
- documentation text, ornull
if nonedecl
-
-
addEnumConstant
Add a constant to a Java 5 enum definition. This method is used for enums which use the name as the value.- Parameters:
value
-doc
- documentation text, ornull
if none
-
addEnumConstant
Add a constant to a Java 5 enum definition. This method is used for enums which have a value separate from the name.- Parameters:
name
-doc
- documentation text, ornull
if nonevalue
-
-
newArrayBuilder
Create new instance of array type.- Parameters:
type
- base type name- Returns:
- array creation
-
newInstance
Build new instance creator of type using a no-argument constructor.- Parameters:
type
- actual type- Returns:
- instance creation
-
newInstanceFromString
Build new instance creator of a simple type using a constructor that takes a single string value.- Parameters:
type
- simple type namevalue
- string value to be passed to constructor- Returns:
- instance creation
-
newInstanceFromStrings
Build new instance creator of a simple type using a constructor that takes a pair of string values.- Parameters:
type
- simple type namevalue1
- first string value to be passed to constructorvalue2
- second string value to be passed to constructor- Returns:
- instance creation
-
addField
Add field declaration.- Parameters:
name
- field nametype
- field type- Returns:
- field builder
-
addIntField
Addint
field declaration with constant initialization.- Parameters:
name
- variable namevalue
- initial value- Returns:
- field builder
-
addConstructor
Add constructor declaration.- Parameters:
name
- simple class name- Returns:
- constructor builder
-
addMethod
Add method declaration.- Parameters:
name
-type
-- Returns:
- method builder
-
createMemberMethodCall
Create internal member method call builder.- Parameters:
mname
- method name- Returns:
- builder
-
createLocalStaticMethodCall
Create internal static method call builder.- Parameters:
mname
- method name- Returns:
- builder
-
createStaticMethodCall
Create a static method call builder.- Parameters:
cname
- fully qualified class namemname
- method name- Returns:
- builder
-
createStaticMethodCall
Create a static method call builder.- Parameters:
fname
- fully-qualified class and method name- Returns:
- builder
-
createNormalMethodCall
Create method call builder on a local variable or field value.- Parameters:
name
- local variable or field namemname
- method name- Returns:
- builder
-
createExpressionMethodCall
Create method call builder on the reference result of an expression.- Parameters:
expr
- instance expressionmname
- method name- Returns:
- builder
-
buildInfix
Build general infix expression.- Parameters:
op
- operator- Returns:
- expression
-
buildNameOp
Build infix expression involving a local variable or field name as the left operand.- Parameters:
name
- local variable or field nameop
- operator- Returns:
- expression
-
buildStringConcatenation
Build a string concatenation expression starting from from a string literal.- Parameters:
text
- literal text- Returns:
- string concatenation expression
-
buildPreincrement
Build a preincrement expression using a local variable or field name as the operand.- Parameters:
name
- local variable or field name- Returns:
- expression
-
buildCast
Build a cast expression.- Parameters:
type
- result type- Returns:
- expression
-
buildArrayIndexAccess
Build array access expression for a named array variable and named index variable.- Parameters:
aname
-iname
-- Returns:
- array access
-
newBlock
Create a new block.- Returns:
- block builder
-
finish
public void finish()Finish building the source file data structures. -
getSortedFields
Get a sorted array of the field names and types defined in this class.- Returns:
- sorted pairs
-