Interface Field

All Known Implementing Classes:
MapField, OneOfField, SingleField

public interface Field
Interface for SingleFields and OneOfFields
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    Field type enum for use in field classes
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The default maximum size of a repeated or length-encoded field (Bytes, String, Message, etc.).
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addAllNeededImports(Set<String> imports, boolean modelImports, boolean codecImports, boolean testImports)
    Add all the needed imports for this field to the supplied set.
    Get the java doc comment for this field, cleaned and ready to insert in output
    boolean
    Get if this field is deprecated or not
    static String
    Extract the name of the Java model class for a message type, or null if the type is not a message.
    static String
    Extract the name of the Java package for a given FileType for a message type, or null if the type is not a message.
    int
    Get the field number, the number of the field in the parent message
    Get the java code default value for this field, "null" for object types
    Get the Java field type for this field
    Get the Java field type for this field.
    default long
    Returns the field's max size relevant to repeated or length-encoded fields.
    default String
    Get the message type for this field if it is of type message otherwise null
    Get the name for this type that is added to write/sizeof etc.
    Get this fields name in original case and format
    default String
    Get this fields name converted to camel case with the first letter lower case
    default String
    Get this fields name converted to camel case with the first letter upper case
    default boolean
    Get if this field is an optional value type, optionals are handled in protobuf by value type objects for primitives
    default OneOfField
    Get the parent field for this field, null if there is no parent like in the case of a single field.
    Get the java code to parse the value for this field from input
    Get the case statement for setting this method to go in parser set method code
    Get the protobuf field type for this field
    boolean
    Is this field a repeated field.
    Get the field definitions line of code for schema file for this field.
    Get the schema case statement for getting the field definition by field number
    Get the field type for this field, the field type is independent of repeated
  • Field Details

    • DEFAULT_MAX_SIZE

      static final long DEFAULT_MAX_SIZE
      The default maximum size of a repeated or length-encoded field (Bytes, String, Message, etc.).
      See Also:
  • Method Details

    • repeated

      boolean repeated()
      Is this field a repeated field. Repeated fields are lists of values rather than a single value.
      Returns:
      true if this field is a list and false if it is a single value
    • maxSize

      default long maxSize()
      Returns the field's max size relevant to repeated or length-encoded fields. The returned value has no meaning for scalar fields (BOOL, INT, etc.).
    • fieldNumber

      int fieldNumber()
      Get the field number, the number of the field in the parent message
      Returns:
      this fields number
    • name

      String name()
      Get this fields name in original case and format
      Returns:
      this fields name
    • nameCamelFirstUpper

      default String nameCamelFirstUpper()
      Get this fields name converted to camel case with the first letter upper case
      Returns:
      this fields name converted
    • nameCamelFirstLower

      @NonNull default String nameCamelFirstLower()
      Get this fields name converted to camel case with the first letter lower case
      Returns:
      this fields name converted
    • type

      Get the field type for this field, the field type is independent of repeated
      Returns:
      this fields type
    • protobufFieldType

      String protobufFieldType()
      Get the protobuf field type for this field
      Returns:
      this fields type in protobuf format
    • javaFieldType

      String javaFieldType()
      Get the Java field type for this field
      Returns:
      this fields type in Java format
    • javaFieldTypeBase

      String javaFieldTypeBase()
      Get the Java field type for this field. Unlike javaFieldType(), this method returns the base type for repeated and oneOf fields.
      Returns:
      this fields type in Java format
    • methodNameType

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

      void addAllNeededImports(Set<String> imports, boolean modelImports, boolean codecImports, boolean testImports)
      Add all the needed imports for this field to the supplied set.
      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

      String parseCode()
      Get the java code to parse the value for this field from input
      Returns:
      java source code to parse
    • javaDefault

      String javaDefault()
      Get the java code default value for this field, "null" for object types
      Returns:
      code for default value
    • schemaFieldsDef

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

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

      String parserFieldsSetMethodCase()
      Get the case statement for setting this method to go in parser set method code
      Returns:
      java source code for case statement setting this field
    • comment

      String comment()
      Get the java doc comment for this field, cleaned and ready to insert in output
      Returns:
      java doc comment
    • deprecated

      boolean deprecated()
      Get if this field is deprecated or not
      Returns:
      true if field is deprecated, otherwise false
    • messageType

      default String messageType()
      Get the message type for this field if it is of type message otherwise null
      Returns:
      message type or null if not a message type field
    • optionalValueType

      default boolean optionalValueType()
      Get if this field is an optional value type, optionals are handled in protobuf by value type objects for primitives
      Returns:
      true if this field is option by use of a protobuf value type, otherwise false
    • parent

      default OneOfField parent()
      Get the parent field for this field, null if there is no parent like in the case of a single field.
      Returns:
      this fields parent field for oneof fields
    • extractMessageTypeName

      static String extractMessageTypeName(Protobuf3Parser.Type_Context typeContext)
      Extract the name of the Java model class for a message type, or null if the type is not a message.
    • extractMessageTypePackage

      static String extractMessageTypePackage(Protobuf3Parser.Type_Context typeContext, FileType fileType, ContextualLookupHelper lookupHelper)
      Extract the name of the Java package for a given FileType for a message type, or null if the type is not a message.