Record Class OneOfField

java.lang.Object
java.lang.Record
com.hedera.pbj.compiler.impl.OneOfField
All Implemented Interfaces:
Field

public record OneOfField(String parentMessageName, String name, String comment, List<Field> fields, boolean repeated, boolean deprecated, boolean comparable) extends Record implements Field
An implementation of Field for OneOf fields
  • Constructor Details

    • OneOfField

      public OneOfField(Protobuf3Parser.OneofContext oneOfContext, String parentMessageName, ContextualLookupHelper lookupHelper)
      Create a OneOf field from parser context
      Parameters:
      oneOfContext - the parsed one of field
      parentMessageName - the name of the parent message
      lookupHelper - helper for accessing global context
    • OneOfField

      public OneOfField(String parentMessageName, String name, String comment, List<Field> fields, boolean repeated, boolean deprecated, boolean comparable)
      Creates an instance of a OneOfField record class.
      Parameters:
      parentMessageName - the value for the parentMessageName record component
      name - the value for the name record component
      comment - the value for the comment record component
      fields - the value for the fields record component
      repeated - the value for the repeated record component
      deprecated - the value for the deprecated record component
      comparable - the value for the comparable record component
  • Method Details

    • type

      public Field.FieldType type()
      Get the field type for this field, the field type is independent of repeated
      Specified by:
      type in interface Field
      Returns:
      this fields type
    • fieldNumber

      public int fieldNumber()
      Get the field number, the number of the field in the parent message
      Specified by:
      fieldNumber in interface Field
      Returns:
      this fields number
    • protobufFieldType

      public String protobufFieldType()
      Get the protobuf field type for this field
      Specified by:
      protobufFieldType in interface Field
      Returns:
      this fields type in protobuf format
    • javaFieldType

      public String javaFieldType()
      Get the Java field type for this field
      Specified by:
      javaFieldType in interface Field
      Returns:
      this fields type in Java format
    • className

      public String className()
    • javaFieldTypeBase

      public String javaFieldTypeBase()
      Description copied from interface: Field
      Get the Java field type for this field. Unlike Field.javaFieldType(), this method returns the base type for repeated and oneOf fields.
      Specified by:
      javaFieldTypeBase in interface Field
      Returns:
      this fields type in Java format
    • methodNameType

      public String methodNameType()
      Get the name for this type that is added to write/sizeof etc. methods.
      Specified by:
      methodNameType in interface Field
      Returns:
      Name for type used in method names
    • addAllNeededImports

      public void addAllNeededImports(Set<String> imports, boolean modelImports, boolean codecImports, boolean testImports)
      Add all the needed imports for this field to the supplied set.
      Specified by:
      addAllNeededImports in interface Field
      Parameters:
      imports - set of imports to add to, this contains packages not classes. They are always imported as ".*".
      modelImports - if imports for this field's generated model classes should be added
      codecImports - if imports for this field's generated codec classes should be added
      testImports - if imports for this field's generated test classes should be added
    • parseCode

      public String parseCode()
      N/A for OneOfField
      Specified by:
      parseCode in interface Field
      Returns:
      java source code to parse
    • javaDefault

      public String javaDefault()
      Get the java code default value for this field, "null" for object types
      Specified by:
      javaDefault in interface Field
      Returns:
      code for default value
    • schemaFieldsDef

      public String schemaFieldsDef()
      Get the field definitions line of code for schema file for this field. One line for single fields and multiple for oneofs.
      Specified by:
      schemaFieldsDef in interface Field
      Returns:
      field definition lines of code
    • schemaGetFieldsDefCase

      public String schemaGetFieldsDefCase()
      Get the schema case statement for getting the field definition by field number
      Specified by:
      schemaGetFieldsDefCase in interface Field
      Returns:
      java source code for case statement to get field def for field number
    • parserFieldsSetMethodCase

      public String parserFieldsSetMethodCase()
      Get the case statement for setting this method to go in parser set method code
      Specified by:
      parserFieldsSetMethodCase in interface Field
      Returns:
      java source code for case statement setting this field
    • getEnumClassRef

      public String getEnumClassRef()
      Get reference to enum class in Java code
      Returns:
      enum class reference
    • toString

      public String toString()
      Helpful debug toString
      Specified by:
      toString in class Record
      Returns:
      debug toString
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • parentMessageName

      public String parentMessageName()
      Returns the value of the parentMessageName record component.
      Returns:
      the value of the parentMessageName record component
    • name

      public String name()
      Returns the value of the name record component.
      Specified by:
      name in interface Field
      Returns:
      the value of the name record component
    • comment

      public String comment()
      Returns the value of the comment record component.
      Specified by:
      comment in interface Field
      Returns:
      the value of the comment record component
    • fields

      public List<Field> fields()
      Returns the value of the fields record component.
      Returns:
      the value of the fields record component
    • repeated

      public boolean repeated()
      Returns the value of the repeated record component.
      Specified by:
      repeated in interface Field
      Returns:
      the value of the repeated record component
    • deprecated

      public boolean deprecated()
      Returns the value of the deprecated record component.
      Specified by:
      deprecated in interface Field
      Returns:
      the value of the deprecated record component
    • comparable

      public boolean comparable()
      Returns the value of the comparable record component.
      Returns:
      the value of the comparable record component