Class JavaUtil

java.lang.Object
uk.co.real_logic.sbe.generation.java.JavaUtil

public class JavaUtil extends Object
Utilities for mapping between Ir and the Java language.
  • Constructor Details

    • JavaUtil

      public JavaUtil()
  • Method Details

    • javaTypeName

      public static String javaTypeName(PrimitiveType primitiveType)
      Map the name of a PrimitiveType to a Java primitive type name.
      Parameters:
      primitiveType - to map.
      Returns:
      the name of the Java primitive that most closely maps.
    • formatPropertyName

      public static String formatPropertyName(String value)
      Format a property name for generated code.

      If the formatted property name is a keyword then SbeTool.KEYWORD_APPEND_TOKEN is appended if set.

      Parameters:
      value - to be formatted.
      Returns:
      the string formatted as a property name.
      Throws:
      IllegalStateException - if a keyword and SbeTool.KEYWORD_APPEND_TOKEN is not set.
    • formatForJavaKeyword

      public static String formatForJavaKeyword(String value)
      Format a name for generated code.

      If the formatted name is a keyword then SbeTool.KEYWORD_APPEND_TOKEN is appended if set.

      Parameters:
      value - to be formatted.
      Returns:
      the string formatted as a valid name.
      Throws:
      IllegalStateException - if a keyword and SbeTool.KEYWORD_APPEND_TOKEN is not set.
    • formatGetterName

      public static String formatGetterName(String propertyName)
      Format a Getter name for generated code.
      Parameters:
      propertyName - to be formatted.
      Returns:
      the property name formatted as a getter name.
    • formatClassName

      public static String formatClassName(String className)
      Format a class name for the generated code.
      Parameters:
      className - to be formatted.
      Returns:
      the formatted class name.
    • append

      public static void append(StringBuilder builder, String indent, String line)
      Shortcut to append a line of generated code
      Parameters:
      builder - string builder to which to append the line
      indent - current text indentation
      line - line to be appended
    • charset

      public static String charset(String encoding)
      Code to fetch an instance of Charset corresponding to the given encoding.
      Parameters:
      encoding - as a string name (eg. UTF-8).
      Returns:
      the code to fetch the associated Charset.
    • charsetName

      public static String charsetName(String encoding)
      Code to fetch the name of the Charset given the encoding.
      Parameters:
      encoding - as a string name (eg. UTF-8).
      Returns:
      the code to fetch the associated Charset name.
    • isAsciiEncoding

      public static boolean isAsciiEncoding(String encoding)
      Checks if the given encoding represents an ASCII charset.
      Parameters:
      encoding - as a string name (e.g. ASCII).
      Returns:
      true if the encoding denotes an ASCII charset.
    • isUtf8Encoding

      public static boolean isUtf8Encoding(String encoding)
      Checks if the given encoding represents a UTF-8 charset.
      Parameters:
      encoding - as a string name (e.g. unicode-1-1-utf-8).
      Returns:
      true if the encoding denotes a UTF-8 charset.
    • generateLiteral

      public static String generateLiteral(PrimitiveType type, String value)
      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

      public static void generateTypeJavadoc(StringBuilder sb, String indent, Token typeToken)
      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.