Class Common

java.lang.Object
com.hedera.pbj.compiler.impl.Common

public final class Common extends Object
Common functions and constants for code generation
  • Field Details

    • FIELD_INDENT

      public static final String FIELD_INDENT
      The indent for fields, default 4 spaces
    • DEFAULT_INDENT

      public static final int DEFAULT_INDENT
      See Also:
    • TYPE_VARINT

      public static final int TYPE_VARINT
      Wire format code for var int
      See Also:
    • TYPE_FIXED64

      public static final int TYPE_FIXED64
      Wire format code for fixed 64bit number
      See Also:
    • TYPE_LENGTH_DELIMITED

      public static final int TYPE_LENGTH_DELIMITED
      Wire format code for length delimited, all the complex types
      See Also:
    • TYPE_FIXED32

      public static final int TYPE_FIXED32
      Wire format code for fixed 32bit number
      See Also:
  • Constructor Details

    • Common

      public Common()
  • Method Details

    • getTag

      public static int getTag(int wireType, int fieldNumber)
      Makes a tag value given a field number and wire type.
      Parameters:
      wireType - the wire type part of tag
      fieldNumber - the field number part of tag
      Returns:
      packed encoded tag
    • capitalizeFirstLetter

      public static String capitalizeFirstLetter(String name)
      Make sure first character of a string is upper case
      Parameters:
      name - string input who's first character can be upper or lower case
      Returns:
      name with first character converted to upper case
    • snakeToCamel

      @NonNull public static String snakeToCamel(@NonNull String name, boolean firstUpper)
      Convert names like "hello_world" to "HelloWorld" or "helloWorld" depending on firstUpper. Also handles special case like "HELLO_WORLD" to same output as "hello_world", while "HelloWorld_Two" still becomes "helloWorldTwo".
      Parameters:
      name - input name in snake case
      firstUpper - if true then first char is upper case otherwise it is lower
      Returns:
      out name in camel case
    • camelToUpperSnake

      public static String camelToUpperSnake(String name)
      Convert a camel case name to upper case snake case
      Parameters:
      name - the input name in camel case
      Returns:
      output name in upper snake case
    • buildCleanFieldJavaDoc

      public static String buildCleanFieldJavaDoc(int fieldNumber, Protobuf3Parser.DocCommentContext docContext)
      Build a clean java doc comment for a field
      Parameters:
      fieldNumber - The field proto number
      docContext - The parsed field comment contact
      Returns:
      clean comment
    • buildCleanFieldJavaDoc

      public static String buildCleanFieldJavaDoc(List<Integer> fieldNumbers, Protobuf3Parser.DocCommentContext docContext)
      Build a clean java doc comment for an oneof field
      Parameters:
      fieldNumbers - The field proto numbers for all fields in oneof
      docContext - The parsed field comment contact
      Returns:
      clean comment
    • cleanJavaDocComment

      public static String cleanJavaDocComment(String fieldComment)
      Clean up a java doc style comment removing all the "*" etc.
      Parameters:
      fieldComment - raw Java doc style comment
      Returns:
      clean multi-line content of the comment
    • cleanDocStr

      public static String cleanDocStr(String docStr)
      Clean a string so that it can be included in JavaDoc. Does things like replace unsupported HTML tags.
      Parameters:
      docStr - The string to clean
      Returns:
      cleaned output
    • javaPrimitiveToObjectType

      public static String javaPrimitiveToObjectType(String primitiveFieldType)
      Convert a field type like "long" to the Java object wrapper type "Long", or pass though if not java primitive
      Parameters:
      primitiveFieldType - java field type like "int" etc
      Returns:
      java object wrapper type like "Integer" or pass though
    • getFieldsHashCode

      public static String getFieldsHashCode(List<Field> fields, String generatedCodeSoFar)
      Recursively calculates the hashcode for a message fields.
      Parameters:
      fields - The fields of this object.
      generatedCodeSoFar - The accumulated hash code so far.
      Returns:
      The generated code for getting the hashCode value.
    • getFieldsEqualsStatements

      public static String getFieldsEqualsStatements(List<Field> fields, String generatedCodeSoFar)
      Recursively calculates `equals` statement for a message fields.
      Parameters:
      fields - The fields of this object.
      generatedCodeSoFar - The accumulated hash code so far.
      Returns:
      The generated code for getting the object equality
    • getFieldsCompareToStatements

      public static String getFieldsCompareToStatements(List<Field> fields, String generatedCodeSoFar, File destinationSrcDir)
      Generate the compareTo method content for the provided fields
      Parameters:
      fields - The fields of this object.
      generatedCodeSoFar - the generated code so far (non-empty in case of nested objects)
      destinationSrcDir - a directory where the previously generated code is saved
      Returns:
      The generated code for compareTo method body
    • removingLeadingDot

      public static String removingLeadingDot(String text)
      Remove leading dot from a string so ".a.b.c" becomes "a.b.c"
      Parameters:
      text - text to remove leading dot from
      Returns:
      text without a leading dot
    • getJavaFile

      public static File getJavaFile(File srcDir, String javaPackage, String className)
      Get the java file for a src directory, package and classname with optional suffix. All parent directories will also be created.
      Parameters:
      srcDir - The src dir root of all java src
      javaPackage - the java package with '.' deliminators
      className - the camel case class name
      Returns:
      File object for java file