Package org.jibx.schema.codegen
Class ClassBuilder
- java.lang.Object
-
- org.jibx.schema.codegen.ClassBuilder
-
public class ClassBuilder extends java.lang.ObjectBuilder for a class definition. This wraps the AST with convenience methods and added control information.
-
-
Field Summary
Fields Modifier and Type Field Description private ASTNodem_classType declaration for class.private java.util.ArrayListm_fieldsFields added to class.private java.util.ArrayListm_innerBuildersBuilders for inner classes of this class.private java.util.ArrayListm_innerClassesDirectly-added inner classes of this class.private java.util.ArrayListm_methodsMethods added to class.private SourceBuilderm_sourceSource file containing this class.
-
Constructor Summary
Constructors Constructor Description ClassBuilder(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MethodBuilderaddConstructor(java.lang.String name)Add constructor declaration.voidaddEnumConstant(java.lang.String value, java.lang.String doc)Add a constant to a Java 5 enum definition.voidaddEnumConstant(java.lang.String name, java.lang.String doc, java.lang.String value)Add a constant to a Java 5 enum definition.voidaddField(FieldDeclaration field)Add separately-constructed field declaration.FieldBuilderaddField(java.lang.String name, Type type)Add field declaration.voidaddInterface(java.lang.String type)Add an interface to this class definition.FieldBuilderaddIntField(java.lang.String name, java.lang.String value)Addintfield declaration with constant initialization.voidaddJavaDoc(java.lang.String doc, BodyDeclaration decl)Add JavaDoc to a declaration.MethodBuilderaddMethod(java.lang.String name, Type type)Add method declaration.voidaddMethod(MethodDeclaration method)Add separately-constructed method declaration.voidaddSourceComment(java.lang.String text)Set source comment for this class.voidaddType(TypeDeclaration type)Add separately-constructed inner class declaration.ArrayAccessBuilderbuildArrayIndexAccess(java.lang.String aname, java.lang.String iname)Build array access expression for a named array variable and named index variable.CastBuilderbuildCast(Type type)Build a cast expression.InfixExpressionBuilderbuildInfix(Operator op)Build general infix expression.InfixExpressionBuilderbuildNameOp(java.lang.String name, Operator op)Build infix expression involving a local variable or field name as the left operand.PrefixExpressionBuilderbuildPreincrement(java.lang.String name)Build a preincrement expression using a local variable or field name as the operand.InfixExpressionBuilderbuildStringConcatenation(java.lang.String text)Build a string concatenation expression starting from from a string literal.ASTNodeclone(ASTNode node)Clone an AST node.InvocationBuildercreateExpressionMethodCall(ExpressionBuilderBase expr, java.lang.String mname)Create method call builder on the reference result of an expression.InvocationBuildercreateLocalStaticMethodCall(java.lang.String mname)Create internal static method call builder.InvocationBuildercreateMemberMethodCall(java.lang.String mname)Create internal member method call builder.InvocationBuildercreateNormalMethodCall(java.lang.String name, java.lang.String mname)Create method call builder on a local variable or field value.TypecreateParameterizedType(java.lang.String type, java.lang.String param)Create a parameterized type.TypecreateParameterizedType(java.lang.String type, Type param)Create a parameterized type.InvocationBuildercreateStaticMethodCall(java.lang.String fname)Create a static method call builder.InvocationBuildercreateStaticMethodCall(java.lang.String cname, java.lang.String mname)Create a static method call builder.TypecreateType(java.lang.String type)Create type definition.(package private) NamecreateTypeName(java.lang.String type)Create type name.voidfinish()Finish building the source file data structures.(package private) ASTgetAST()AST access for related classes.FieldDeclaration[]getFields()Get the fields defined in this class.java.lang.String[]getInterfaces()Get the interfaces implemented by this class.MethodDeclaration[]getMethods()Get the methods defined in this class.StringPair[]getSortedFields()Get a sorted array of the field names and types defined in this class.NewArrayBuildernewArrayBuilder(java.lang.String type)Create new instance of array type.BlockBuildernewBlock()Create a new block.NewInstanceBuildernewInstance(Type type)Build new instance creator of type using a no-argument constructor.NewInstanceBuildernewInstanceFromString(java.lang.String type, java.lang.String value)Build new instance creator of a simple type using a constructor that takes a single string value.NewInstanceBuildernewInstanceFromStrings(java.lang.String type, java.lang.String value1, java.lang.String value2)Build new instance creator of a simple type using a constructor that takes a pair of string values.voidsetAbstract()Set the abstract flag for this class.voidsetSuperclass(java.lang.String name)Set the superclass for this class.
-
-
-
Field Detail
-
m_source
private final SourceBuilder m_source
Source file containing this class.
-
m_class
private final ASTNode m_class
Type declaration for class.
-
m_fields
private final java.util.ArrayList m_fields
Fields added to class.
-
m_methods
private final java.util.ArrayList m_methods
Methods added to class.
-
m_innerBuilders
private final java.util.ArrayList m_innerBuilders
Builders for inner classes of this class.
-
m_innerClasses
private final java.util.ArrayList m_innerClasses
Directly-added inner classes of this class.
-
-
Constructor Detail
-
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
public ClassBuilder(AnonymousClassDeclaration clas, ClassBuilder outer)Constructor for an anonymous inner class.- Parameters:
clas-outer-
-
-
Method Detail
-
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
public void setSuperclass(java.lang.String name)
Set the superclass for this class.- Parameters:
name-
-
createTypeName
Name createTypeName(java.lang.String type)
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
public Type createType(java.lang.String type)
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
public Type createParameterizedType(java.lang.String type, java.lang.String param)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
public Type createParameterizedType(java.lang.String type, Type param)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
public void addSourceComment(java.lang.String text)
Set source comment for this class.- Parameters:
text- comment text
-
setAbstract
public void setAbstract()
Set the abstract flag for this class.
-
getInterfaces
public java.lang.String[] 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
public void addInterface(java.lang.String type)
Add an interface to this class definition.- Parameters:
type- interface type
-
addJavaDoc
public void addJavaDoc(java.lang.String doc, BodyDeclaration decl)Add JavaDoc to a declaration.- Parameters:
doc- documentation text, ornullif nonedecl-
-
addEnumConstant
public void addEnumConstant(java.lang.String value, java.lang.String doc)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, ornullif none
-
addEnumConstant
public void addEnumConstant(java.lang.String name, java.lang.String doc, java.lang.String value)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, ornullif nonevalue-
-
newArrayBuilder
public NewArrayBuilder newArrayBuilder(java.lang.String type)
Create new instance of array type.- Parameters:
type- base type name- Returns:
- array creation
-
newInstance
public NewInstanceBuilder newInstance(Type type)
Build new instance creator of type using a no-argument constructor.- Parameters:
type- actual type- Returns:
- instance creation
-
newInstanceFromString
public NewInstanceBuilder newInstanceFromString(java.lang.String type, java.lang.String value)
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
public NewInstanceBuilder newInstanceFromStrings(java.lang.String type, java.lang.String value1, java.lang.String value2)
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
public FieldBuilder addField(java.lang.String name, Type type)
Add field declaration.- Parameters:
name- field nametype- field type- Returns:
- field builder
-
addIntField
public FieldBuilder addIntField(java.lang.String name, java.lang.String value)
Addintfield declaration with constant initialization.- Parameters:
name- variable namevalue- initial value- Returns:
- field builder
-
addConstructor
public MethodBuilder addConstructor(java.lang.String name)
Add constructor declaration.- Parameters:
name- simple class name- Returns:
- constructor builder
-
addMethod
public MethodBuilder addMethod(java.lang.String name, Type type)
Add method declaration.- Parameters:
name-type-- Returns:
- method builder
-
createMemberMethodCall
public InvocationBuilder createMemberMethodCall(java.lang.String mname)
Create internal member method call builder.- Parameters:
mname- method name- Returns:
- builder
-
createLocalStaticMethodCall
public InvocationBuilder createLocalStaticMethodCall(java.lang.String mname)
Create internal static method call builder.- Parameters:
mname- method name- Returns:
- builder
-
createStaticMethodCall
public InvocationBuilder createStaticMethodCall(java.lang.String cname, java.lang.String mname)
Create a static method call builder.- Parameters:
cname- fully qualified class namemname- method name- Returns:
- builder
-
createStaticMethodCall
public InvocationBuilder createStaticMethodCall(java.lang.String fname)
Create a static method call builder.- Parameters:
fname- fully-qualified class and method name- Returns:
- builder
-
createNormalMethodCall
public InvocationBuilder createNormalMethodCall(java.lang.String name, java.lang.String mname)
Create method call builder on a local variable or field value.- Parameters:
name- local variable or field namemname- method name- Returns:
- builder
-
createExpressionMethodCall
public InvocationBuilder createExpressionMethodCall(ExpressionBuilderBase expr, java.lang.String mname)
Create method call builder on the reference result of an expression.- Parameters:
expr- instance expressionmname- method name- Returns:
- builder
-
buildInfix
public InfixExpressionBuilder buildInfix(Operator op)
Build general infix expression.- Parameters:
op- operator- Returns:
- expression
-
buildNameOp
public InfixExpressionBuilder buildNameOp(java.lang.String name, Operator op)
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
public InfixExpressionBuilder buildStringConcatenation(java.lang.String text)
Build a string concatenation expression starting from from a string literal.- Parameters:
text- literal text- Returns:
- string concatenation expression
-
buildPreincrement
public PrefixExpressionBuilder buildPreincrement(java.lang.String name)
Build a preincrement expression using a local variable or field name as the operand.- Parameters:
name- local variable or field name- Returns:
- expression
-
buildCast
public CastBuilder buildCast(Type type)
Build a cast expression.- Parameters:
type- result type- Returns:
- expression
-
buildArrayIndexAccess
public ArrayAccessBuilder buildArrayIndexAccess(java.lang.String aname, java.lang.String iname)
Build array access expression for a named array variable and named index variable.- Parameters:
aname-iname-- Returns:
- array access
-
newBlock
public BlockBuilder newBlock()
Create a new block.- Returns:
- block builder
-
finish
public void finish()
Finish building the source file data structures.
-
getSortedFields
public StringPair[] getSortedFields()
Get a sorted array of the field names and types defined in this class.- Returns:
- sorted pairs
-
-