Class Common
java.lang.Object
com.hedera.pbj.compiler.impl.Common
Common functions and constants for code generation
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final StringThe indent for fields, default 4 spaces(package private) static final intNumber of bits used to represent the tag typestatic final intWire format code for fixed 32bit numberstatic final intWire format code for fixed 64bit numberstatic final intWire format code for length delimited, all the complex typesstatic final intWire format code for var int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbuildCleanFieldJavaDoc(int fieldNumber, Protobuf3Parser.DocCommentContext docContext) Build a clean java doc comment for a fieldstatic StringbuildCleanFieldJavaDoc(List<Integer> fieldNumbers, Protobuf3Parser.DocCommentContext docContext) Build a clean java doc comment for an oneof fieldstatic StringcamelToUpperSnake(String name) Convert a camel case name to upper case snake casestatic StringcapitalizeFirstLetter(String name) Make sure first character of a string is upper casestatic StringcleanDocStr(String docStr) Clean a string so that it can be included in JavaDoc.static StringcleanJavaDocComment(String fieldComment) Clean up a java doc style comment removing all the "*" etc.static StringgetFieldsCompareToStatements(List<Field> fields, String generatedCodeSoFar) Generate the compareTo method content for the provided fieldsstatic StringgetFieldsEqualsStatements(List<Field> fields, String generatedCodeSoFar, String prefixFieldName) Recursively calculates `equals` statement for a message fields.static StringgetFieldsHashCode(String modelClassName, List<Field> fields, String fieldNamePrefix, String generatedCodeSoFar) Recursively calculates the hashcode for a message fields.static FilegetJavaFile(File srcDir, String javaPackage, String className) Get the java file for a src directory, package and classname with optional suffix.static intgetTag(int wireType, int fieldNumber) Makes a tag value given a field number and wire type.static StringjavaPrimitiveToObjectType(String primitiveFieldType) Convert a field type like "long" to the Java object wrapper type "Long", or pass though if not java primitivestatic StringremovingLeadingDot(String text) Remove leading dot from a string so ".a.b.c" becomes "a.b.c"static StringsnakeToCamel(String name, boolean firstUpper) Convert names like "hello_world" to "HelloWorld" or "helloWorld" depending on firstUpper.
-
Field Details
-
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_VARINTWire format code for var int- See Also:
-
TYPE_FIXED64
public static final int TYPE_FIXED64Wire format code for fixed 64bit number- See Also:
-
TYPE_LENGTH_DELIMITED
public static final int TYPE_LENGTH_DELIMITEDWire format code for length delimited, all the complex types- See Also:
-
TYPE_FIXED32
public static final int TYPE_FIXED32Wire format code for fixed 32bit number- See Also:
-
TAG_TYPE_BITS
static final int TAG_TYPE_BITSNumber of bits used to represent the tag type- 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 tagfieldNumber- the field number part of tag- Returns:
- packed encoded tag
-
capitalizeFirstLetter
-
snakeToCamel
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 casefirstUpper- if true then first char is upper case otherwise it is lower- Returns:
- out name in camel case
-
camelToUpperSnake
-
buildCleanFieldJavaDoc
public static String buildCleanFieldJavaDoc(int fieldNumber, Protobuf3Parser.DocCommentContext docContext) Build a clean java doc comment for a field- Parameters:
fieldNumber- The field proto numberdocContext- 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 oneofdocContext- The parsed field comment contact- Returns:
- clean comment
-
cleanJavaDocComment
-
cleanDocStr
-
javaPrimitiveToObjectType
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(String modelClassName, List<Field> fields, String fieldNamePrefix, 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, String prefixFieldName) 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
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)- Returns:
- The generated code for compareTo method body
-
removingLeadingDot
-
getJavaFile
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 srcjavaPackage- the java package with '.' deliminatorsclassName- the camel case class name- Returns:
- File object for java file
-