Class ClassBuilder

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

public class ClassBuilder extends Object
Builder for a class definition. This wraps the AST with convenience methods and added control information.
  • Field Details

    • 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 ArrayList m_fields
      Fields added to class.
    • m_methods

      private final ArrayList m_methods
      Methods added to class.
    • m_innerBuilders

      private final ArrayList m_innerBuilders
      Builders for inner classes of this class.
    • m_innerClasses

      private final ArrayList 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

      public ClassBuilder(AnonymousClassDeclaration clas, ClassBuilder outer)
      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

      public void setSuperclass(String name)
      Set the superclass for this class.
      Parameters:
      name -
    • createTypeName

      Name createTypeName(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(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(String type, 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(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(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 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(String type)
      Add an interface to this class definition.
      Parameters:
      type - interface type
    • addJavaDoc

      public void addJavaDoc(String doc, BodyDeclaration decl)
      Add JavaDoc to a declaration.
      Parameters:
      doc - documentation text, or null if none
      decl -
    • addEnumConstant

      public void addEnumConstant(String value, 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(String name, String doc, 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(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(String type, 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(String type, String value1, 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(String name, Type type)
      Add field declaration.
      Parameters:
      name - field name
      type - field type
      Returns:
      field builder
    • addIntField

      public FieldBuilder addIntField(String name, String value)
      Add int field declaration with constant initialization.
      Parameters:
      name - variable name
      value - initial value
      Returns:
      field builder
    • addConstructor

      public MethodBuilder addConstructor(String name)
      Add constructor declaration.
      Parameters:
      name - simple class name
      Returns:
      constructor builder
    • addMethod

      public MethodBuilder addMethod(String name, Type type)
      Add method declaration.
      Parameters:
      name -
      type -
      Returns:
      method builder
    • createMemberMethodCall

      public InvocationBuilder createMemberMethodCall(String mname)
      Create internal member method call builder.
      Parameters:
      mname - method name
      Returns:
      builder
    • createLocalStaticMethodCall

      public InvocationBuilder createLocalStaticMethodCall(String mname)
      Create internal static method call builder.
      Parameters:
      mname - method name
      Returns:
      builder
    • createStaticMethodCall

      public InvocationBuilder createStaticMethodCall(String cname, String mname)
      Create a static method call builder.
      Parameters:
      cname - fully qualified class name
      mname - method name
      Returns:
      builder
    • createStaticMethodCall

      public InvocationBuilder createStaticMethodCall(String fname)
      Create a static method call builder.
      Parameters:
      fname - fully-qualified class and method name
      Returns:
      builder
    • createNormalMethodCall

      public InvocationBuilder createNormalMethodCall(String name, 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, 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(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(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(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(String aname, 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