Record Class SingleField

java.lang.Object
java.lang.Record
com.hedera.pbj.compiler.impl.SingleField
Record Components:
repeated - If this is a repeated field, ie protobuf equivalent of array
type - The type of this single field
fieldNumber - The protobuf field number
name - The name of this filed
messageType - The message type of this field is of type message
messageTypeCodecPackage -
All Implemented Interfaces:
Field

public record SingleField(boolean repeated, Field.FieldType type, int fieldNumber, String name, String messageType, String messageTypeModelPackage, String messageTypeCodecPackage, String messageTypeTestPackage, String comment, boolean deprecated, OneOfField parent) extends Record implements Field
Record for Field in Protobuf file. Contains all logic and special cases for fields
  • Constructor Details

    • SingleField

      public SingleField(Protobuf3Parser.FieldContext fieldContext, ContextualLookupHelper lookupHelper)
      Construct a SingleField from a parsed field context
      Parameters:
      fieldContext - the field context to extra field data from
      lookupHelper - lookup helper for finding packages and other global context data
    • SingleField

      public SingleField(Protobuf3Parser.OneofFieldContext fieldContext, OneOfField parent, ContextualLookupHelper lookupHelper)
      Construct a SingleField from a parsed oneof subfield context
      Parameters:
      fieldContext - the field context to extra field data from
      lookupHelper - lookup helper for finding packages and other global context data
    • SingleField

      public SingleField(boolean repeated, Field.FieldType type, int fieldNumber, String name, String messageType, String messageTypeModelPackage, String messageTypeCodecPackage, String messageTypeTestPackage, String comment, boolean deprecated, OneOfField parent)
      Creates an instance of a SingleField record class.
      Parameters:
      repeated - the value for the repeated record component
      type - the value for the type record component
      fieldNumber - the value for the fieldNumber record component
      name - the value for the name record component
      messageType - the value for the messageType record component
      messageTypeModelPackage - the value for the messageTypeModelPackage record component
      messageTypeCodecPackage - the value for the messageTypeCodecPackage record component
      messageTypeTestPackage - the value for the messageTypeTestPackage record component
      comment - the value for the comment record component
      deprecated - the value for the deprecated record component
      parent - the value for the parent record component
  • Method Details

    • optionalValueType

      public boolean optionalValueType()
      Get if this field is an optional value type, optionals are handled in protobuf by value type objects for primitives
      Specified by:
      optionalValueType in interface Field
      Returns:
      true if this field is option by use of a protobuf value type, otherwise false
    • 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
    • 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
    • javaFieldTypeForTest

      public String javaFieldTypeForTest()
    • 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()
      Get the java code to parse the value for this field from input
      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
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
    • 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
    • type

      public Field.FieldType type()
      Returns the value of the type record component.
      Specified by:
      type in interface Field
      Returns:
      the value of the type record component
    • fieldNumber

      public int fieldNumber()
      Returns the value of the fieldNumber record component.
      Specified by:
      fieldNumber in interface Field
      Returns:
      the value of the fieldNumber 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
    • messageType

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

      public String messageTypeModelPackage()
      Returns the value of the messageTypeModelPackage record component.
      Returns:
      the value of the messageTypeModelPackage record component
    • messageTypeCodecPackage

      public String messageTypeCodecPackage()
      Returns the value of the messageTypeCodecPackage record component.
      Returns:
      the value of the messageTypeCodecPackage record component
    • messageTypeTestPackage

      public String messageTypeTestPackage()
      Returns the value of the messageTypeTestPackage record component.
      Returns:
      the value of the messageTypeTestPackage 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
    • 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
    • parent

      public OneOfField parent()
      Returns the value of the parent record component.
      Specified by:
      parent in interface Field
      Returns:
      the value of the parent record component