Class JBBPToJavaConverter

java.lang.Object
com.igormaznitsa.jbbp.compiler.conversion.CompiledBlockVisitor
com.igormaznitsa.jbbp.compiler.conversion.JBBPToJavaConverter

public class JBBPToJavaConverter extends CompiledBlockVisitor
Converter to produce Java class sources (1.6+) from JBBPParser. If a parser contains variable field, custom fields or external values in expressions then the result class will be abstract one and its abstract methods must be implemented in successor.
Since:
1.3.0
  • Method Details

    • makeBuilder

      public static JBBPToJavaConverter.Builder makeBuilder(JBBPParser parser)
      Make new builder.
      Parameters:
      parser - parser instance to be used as the base for translation, must not be null
      Returns:
      the new builder instance, must not be null.
    • convert

      public String convert()
      Do conversion.
      Returns:
      generated class with needed parameters as text, must not be null.
    • visitStart

      public void visitStart()
      Description copied from class: CompiledBlockVisitor
      Called before visit of each item.
      Overrides:
      visitStart in class CompiledBlockVisitor
    • getResult

      public String getResult()
      Get result of the conversion process.
      Returns:
      the result, it will not be null if the process completed without errors.
    • visitEnd

      public void visitEnd()
      Description copied from class: CompiledBlockVisitor
      Called after visit each item.
      Overrides:
      visitEnd in class CompiledBlockVisitor
    • visitStructureStart

      public void visitStructureStart(int offsetInCompiledBlock, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPIntegerValueEvaluator nullableArraySize)
      Description copied from class: CompiledBlockVisitor
      Visit a structure field.
      Overrides:
      visitStructureStart in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      byteOrder - byte order for the field, must not be null
      readWholeStream - true if whole stream should be read as array of var type, false otherwise
      nullableNameFieldInfo - field info, null if the field is anonymous one
      nullableArraySize - if not null then evaluator of array size to be read from stream
    • visitStructureEnd

      public void visitStructureEnd(int offsetInCompiledBlock, JBBPNamedFieldInfo nullableNameFieldInfo)
      Description copied from class: CompiledBlockVisitor
      End visit of a structure
      Overrides:
      visitStructureEnd in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      nullableNameFieldInfo - field info, null if the field is anonymous one
    • visitValField

      public void visitValField(int offsetInCompiledBlock, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nameFieldInfo, JBBPIntegerValueEvaluator expression)
      Description copied from class: CompiledBlockVisitor
      Visit field contains virtual field defined through VAL type.
      Overrides:
      visitValField in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      byteOrder - byteOrder
      nameFieldInfo - name of the field, must not be null
      expression - expression to calculate value
    • visitPrimitiveField

      public void visitPrimitiveField(int offsetInCompiledBlock, int primitiveType, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStreamAsArray, boolean altFieldType, JBBPIntegerValueEvaluator nullableArraySize)
      Description copied from class: CompiledBlockVisitor
      Visit a primitive data field
      Overrides:
      visitPrimitiveField in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      primitiveType - the primitive type
      nullableNameFieldInfo - field info, null if the field is anonymous one
      byteOrder - byte order for the field, must not be null
      readWholeStreamAsArray - if true then it is an array with unknown size till the stream end
      altFieldType - flag shows that field type is alternative one, INT should be recognized as FLOAT and LONG as DOUBLE and BOOL as STRING
      nullableArraySize - array size if the field is array, null if the field is not array or variable length array
      See Also:
    • visitBitField

      public void visitBitField(int offsetInCompiledBlock, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nullableNameFieldInfo, boolean readWholeStream, JBBPIntegerValueEvaluator notNullFieldSize, JBBPIntegerValueEvaluator nullableArraySize)
      Description copied from class: CompiledBlockVisitor
      Visit a custom type field.
      Overrides:
      visitBitField in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      byteOrder - byte order for the field, must not be null
      nullableNameFieldInfo - field info, null if the field is anonymous one
      readWholeStream - true if whole stream should be read as array of var type, false otherwise
      notNullFieldSize - evaluator to calculate size of the field, must not be null
      nullableArraySize - if not null then evaluator of array size to be read from stream
    • visitCustomField

      public void visitCustomField(int offsetInCompiledBlock, JBBPFieldTypeParameterContainer notNullFieldType, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPIntegerValueEvaluator nullableArraySizeEvaluator, JBBPIntegerValueEvaluator extraDataValueEvaluator)
      Description copied from class: CompiledBlockVisitor
      Visit a custom type field.
      Overrides:
      visitCustomField in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      notNullFieldType - field type info, must not be null
      nullableNameFieldInfo - field info, null if the field is anonymous one
      byteOrder - byte order for the field, must not be null
      readWholeStream - true if whole stream should be read as array of var type, false otherwise
      nullableArraySizeEvaluator - if not null then evaluator of array size to be read from stream
      extraDataValueEvaluator - if not null then extra data evaluator for the var field
    • visitVarField

      public void visitVarField(int offsetInCompiledBlock, JBBPNamedFieldInfo nullableNameFieldInfo, JBBPByteOrder byteOrder, boolean readWholeStream, JBBPIntegerValueEvaluator nullableArraySizeEvaluator, JBBPIntegerValueEvaluator extraDataValue)
      Description copied from class: CompiledBlockVisitor
      Visit a variable field (which is defined with var data type)
      Overrides:
      visitVarField in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      nullableNameFieldInfo - field info, null if the field is anonymous one
      byteOrder - byte order for the field, must not be null
      readWholeStream - true if whole stream should be read as array of var type, false otherwise
      nullableArraySizeEvaluator - if not null then evaluator of array size to be read from stream
      extraDataValue - if not null then extra data evaluator for the var field
    • visitActionItem

      public void visitActionItem(int offsetInCompiledBlock, int actionType, JBBPIntegerValueEvaluator nullableArgument)
      Description copied from class: CompiledBlockVisitor
      Visit an action item (like skip, align or reset counter command)
      Overrides:
      visitActionItem in class CompiledBlockVisitor
      Parameters:
      offsetInCompiledBlock - offset in the compiled block
      actionType - the action type
      nullableArgument - argument for action, it can be null
      See Also: