Class JavaUtil
java.lang.Object
uk.co.real_logic.sbe.generation.java.JavaUtil
Utilities for mapping between
Ir and the Java language.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappend(StringBuilder builder, String indent, String line) Shortcut to append a line of generated codestatic StringCode to fetch an instance ofCharsetcorresponding to the given encoding.static StringcharsetName(String encoding) Code to fetch the name of theCharsetgiven the encoding.static StringformatClassName(String className) Format a class name for the generated code.static StringformatForJavaKeyword(String value) Format a name for generated code.static StringformatGetterName(String propertyName) Format a Getter name for generated code.static StringformatPropertyName(String value) Format a property name for generated code.static voidgenerateFlyweightPropertyJavadoc(StringBuilder sb, String indent, Token propertyToken, String typeName) Generate the Javadoc comment header for flyweight property.static voidgenerateGroupEncodePropertyJavadoc(StringBuilder sb, String indent, Token propertyToken, String typeName) Generate the Javadoc comment header for group encode property.static StringgenerateLiteral(PrimitiveType type, String value) Generate a literal value to be used in code generation.static voidgenerateOptionDecodeJavadoc(Appendable out, String indent, Token optionToken) Generate the Javadoc comment header for a bitset choice option decode method.static voidgenerateOptionEncodeJavadoc(Appendable out, String indent, Token optionToken) Generate the Javadoc comment header for a bitset choice option encode method.static voidgenerateTypeJavadoc(StringBuilder sb, String indent, Token typeToken) Generate the Javadoc comment header for a type.static booleanisAsciiEncoding(String encoding) Checks if the given encoding represents an ASCII charset.static booleanisUtf8Encoding(String encoding) Checks if the given encoding represents a UTF-8 charset.static StringjavaTypeName(PrimitiveType primitiveType) Map the name of aPrimitiveTypeto a Java primitive type name.
-
Constructor Details
-
JavaUtil
public JavaUtil()
-
-
Method Details
-
javaTypeName
Map the name of aPrimitiveTypeto a Java primitive type name.- Parameters:
primitiveType- to map.- Returns:
- the name of the Java primitive that most closely maps.
-
formatPropertyName
Format a property name for generated code.If the formatted property name is a keyword then
SbeTool.KEYWORD_APPEND_TOKENis appended if set.- Parameters:
value- to be formatted.- Returns:
- the string formatted as a property name.
- Throws:
IllegalStateException- if a keyword andSbeTool.KEYWORD_APPEND_TOKENis not set.
-
formatForJavaKeyword
Format a name for generated code.If the formatted name is a keyword then
SbeTool.KEYWORD_APPEND_TOKENis appended if set.- Parameters:
value- to be formatted.- Returns:
- the string formatted as a valid name.
- Throws:
IllegalStateException- if a keyword andSbeTool.KEYWORD_APPEND_TOKENis not set.
-
formatGetterName
Format a Getter name for generated code.- Parameters:
propertyName- to be formatted.- Returns:
- the property name formatted as a getter name.
-
formatClassName
Format a class name for the generated code.- Parameters:
className- to be formatted.- Returns:
- the formatted class name.
-
append
Shortcut to append a line of generated code- Parameters:
builder- string builder to which to append the lineindent- current text indentationline- line to be appended
-
charset
Code to fetch an instance ofCharsetcorresponding to the given encoding.- Parameters:
encoding- as a string name (eg. UTF-8).- Returns:
- the code to fetch the associated Charset.
-
charsetName
Code to fetch the name of theCharsetgiven the encoding.- Parameters:
encoding- as a string name (eg. UTF-8).- Returns:
- the code to fetch the associated Charset name.
-
isAsciiEncoding
Checks if the given encoding represents an ASCII charset.- Parameters:
encoding- as a string name (e.g. ASCII).- Returns:
trueif the encoding denotes an ASCII charset.
-
isUtf8Encoding
Checks if the given encoding represents a UTF-8 charset.- Parameters:
encoding- as a string name (e.g. unicode-1-1-utf-8).- Returns:
trueif the encoding denotes a UTF-8 charset.
-
generateLiteral
Generate a literal value to be used in code generation.- Parameters:
type- of the lateral value.value- of the lateral.- Returns:
- a String representation of the Java literal.
-
generateTypeJavadoc
Generate the Javadoc comment header for a type.- Parameters:
sb- to append to.indent- level for the comment.typeToken- for the type.
-
generateOptionDecodeJavadoc
public static void generateOptionDecodeJavadoc(Appendable out, String indent, Token optionToken) throws IOException Generate the Javadoc comment header for a bitset choice option decode method.- Parameters:
out- to append to.indent- level for the comment.optionToken- for the type.- Throws:
IOException- on failing to write to output.
-
generateOptionEncodeJavadoc
public static void generateOptionEncodeJavadoc(Appendable out, String indent, Token optionToken) throws IOException Generate the Javadoc comment header for a bitset choice option encode method.- Parameters:
out- to append to.indent- level for the comment.optionToken- for the type.- Throws:
IOException- on failing to write to output.
-
generateFlyweightPropertyJavadoc
public static void generateFlyweightPropertyJavadoc(StringBuilder sb, String indent, Token propertyToken, String typeName) Generate the Javadoc comment header for flyweight property.- Parameters:
sb- to append to.indent- level for the comment.propertyToken- for the property name.typeName- for the property type.
-
generateGroupEncodePropertyJavadoc
public static void generateGroupEncodePropertyJavadoc(StringBuilder sb, String indent, Token propertyToken, String typeName) Generate the Javadoc comment header for group encode property.- Parameters:
sb- to append to.indent- level for the comment.propertyToken- for the property name.typeName- for the property type.
-