Package com.hedera.pbj.compiler.impl
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 spacesstatic 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, File destinationSrcDir) Generate the compareTo method content for the provided fieldsstatic StringgetFieldsEqualsStatements(List<Field> fields, String generatedCodeSoFar) Recursively calculates `equals` statement for a message fields.static StringgetFieldsHashCode(List<Field> fields, 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:
-
-
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
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
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
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 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
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
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
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
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
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
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
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
-