org.jibx.schema.codegen
Class ClassBuilder

java.lang.Object
  extended by org.jibx.schema.codegen.ClassBuilder

public class ClassBuilder
extends java.lang.Object

Builder for a class definition. This wraps the AST with convenience methods and added control information.


Field Summary
private static java.lang.String[] EMPTY_STRING_ARRAY
          Empty array of strings.
private  ASTNode m_class
          Type declaration for class.
private  java.util.ArrayList m_fields
          Fields added to class.
private  java.util.ArrayList m_innerBuilders
          Builders for inner classes of this class.
private  java.util.ArrayList m_innerClasses
          Directly-added inner classes of this class.
private  java.util.ArrayList m_methods
          Methods added to class.
private  SourceBuilder m_source
          Source file containing this class.
 
Constructor Summary
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
 MethodBuilder addConstructor(java.lang.String name)
          Add constructor declaration.
 void addEnumConstant(java.lang.String value, java.lang.String doc)
          Add a constant to a Java 5 enum definition.
 void addEnumConstant(java.lang.String name, java.lang.String doc, java.lang.String value)
          Add a constant to a Java 5 enum definition.
 void addField(FieldDeclaration field)
          Add separately-constructed field declaration.
 FieldBuilder addField(java.lang.String name, Type type)
          Add field declaration.
 void addInterface(java.lang.String type)
          Add an interface to this class definition.
 FieldBuilder addIntField(java.lang.String name, java.lang.String value)
          Add int field declaration with constant initialization.
 void addJavaDoc(java.lang.String doc, BodyDeclaration decl)
          Add JavaDoc to a declaration.
 void addMethod(MethodDeclaration method)
          Add separately-constructed method declaration.
 MethodBuilder addMethod(java.lang.String name, Type type)
          Add method declaration.
 void addSourceComment(java.lang.String text)
          Set source comment for this class.
 void addType(TypeDeclaration type)
          Add separately-constructed inner class declaration.
 ArrayAccessBuilder buildArrayIndexAccess(java.lang.String aname, java.lang.String iname)
          Build array access expression for a named array variable and named index variable.
 CastBuilder buildCast(Type type)
          Build a cast expression.
 InfixExpressionBuilder buildInfix(Operator op)
          Build general infix expression.
 InfixExpressionBuilder buildNameOp(java.lang.String name, Operator op)
          Build infix expression involving a local variable or field name as the left operand.
 PrefixExpressionBuilder buildPreincrement(java.lang.String name)
          Build a preincrement expression using a local variable or field name as the operand.
 InfixExpressionBuilder buildStringConcatenation(java.lang.String text)
          Build a string concatenation expression starting from from a string literal.
 ASTNode clone(ASTNode node)
          Clone an AST node.
 InvocationBuilder createExpressionMethodCall(ExpressionBuilderBase expr, java.lang.String mname)
          Create method call builder on the reference result of an expression.
 InvocationBuilder createLocalStaticMethodCall(java.lang.String mname)
          Create internal static method call builder.
 InvocationBuilder createMemberMethodCall(java.lang.String mname)
          Create internal member method call builder.
 InvocationBuilder createNormalMethodCall(java.lang.String name, java.lang.String mname)
          Create method call builder on a local variable or field value.
 Type createParameterizedType(java.lang.String type, java.lang.String param)
          Create a parameterized type.
 Type createParameterizedType(java.lang.String type, Type param)
          Create a parameterized type.
 InvocationBuilder createStaticMethodCall(java.lang.String fname)
          Create a static method call builder.
 InvocationBuilder createStaticMethodCall(java.lang.String cname, java.lang.String mname)
          Create a static method call builder.
 Type createType(java.lang.String type)
          Create type definition.
(package private)  Name createTypeName(java.lang.String type)
          Create type name.
 void finish()
          Finish building the source file data structures.
(package private)  AST getAST()
          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.
 NewArrayBuilder newArrayBuilder(java.lang.String type)
          Create new instance of array type.
 BlockBuilder newBlock()
          Create a new block.
 NewInstanceBuilder newInstance(Type type)
          Build new instance creator of type using a no-argument constructor.
 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.
 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.
 void setAbstract()
          Set the abstract flag for this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING_ARRAY

private static final java.lang.String[] EMPTY_STRING_ARRAY
Empty array of strings.


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 -

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 name
param - 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 name
param - 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, or null if none
decl -

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, or null if 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, or null if none
value -

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 name
value - 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 name
value1 - first string value to be passed to constructor
value2 - 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 name
type - field type
Returns:
field builder

addIntField

public FieldBuilder addIntField(java.lang.String name,
                                java.lang.String value)
Add int field declaration with constant initialization.

Parameters:
name - variable name
value - 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 name
mname - 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 name
mname - 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 expression
mname - 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 name
op - 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


Project Web Site