Class JavaClassWriterHelper

java.lang.Object
com.sun.jdo.spi.persistence.utility.JavaTypeHelper
com.sun.jdo.spi.persistence.utility.generator.JavaClassWriterHelper

public class JavaClassWriterHelper extends JavaTypeHelper
  • Field Details

  • Constructor Details

    • JavaClassWriterHelper

      public JavaClassWriterHelper()
  • Method Details

    • getBodyAsStrings

      public static String[] getBodyAsStrings(String body)
      Converts method body into String array.
      Parameters:
      body - as String with each substring separated by "\n"
      Returns:
      method body as String array.
    • getWrapperType

      public static Class getWrapperType(Class cls)
      Returns java Object wrapper Class corresponding to the primitive Class if the passed class represents a primitive. If the parameter is of Object type, it is returned.
      Parameters:
      cls - the primitive Class to find Object wrapper for.
      Returns:
      Object type Class.
    • getWrapperExpr

      public static String getWrapperExpr(Class exprType, String expr)
      A helper method which generates an expression to wrap a primitive datatype to its corresponding wrapper class.
      Parameters:
      exprType - The class of the primitive type
      expr - The expression representing a primtive typevalue
      Returns:
      A String containing the expression for wrapping the primitive datatype in its corresponding wrapperclass
    • getUnwrapMethodName

      public static String getUnwrapMethodName(Class primitiveType)
      Returns the name of the method to access the value of the primitive type of the wrapper class. example: boolean.class is mapped to "booleanValue()".
      Parameters:
      primitiveType - the class object of the primitive type.
      Returns:
      the name of the method to access the primitive value of the wrapper
    • getPrimitiveType

      public static String getPrimitiveType(Class cls)
      Returns name of the primitive type corresponding to the Object wrapper Class passed as a parameter. If the parameter is of primitive type, its name is returned.
      Parameters:
      cls - the Object wrapper Class to find name of the primitive type for.
      Returns:
      name of the primitive type as String.
    • getExceptionNames

      public static String[] getExceptionNames(Method m)
      Returns exception type names as String[].
      Parameters:
      m - the Method to identify exception types for.
      Returns:
      exception type names as String[].
    • getParameterTypesList

      public static String getParameterTypesList(Method m)
      Returns list of method parameter types in format type0[,type1[,...]]
      Parameters:
      m - the Method to identify list of method parameters for.
      Returns:
      list of method parameter types as String
    • getParametersList

      public static String getParametersList(Method m)
      Returns list of method parameters in format param0[, param1[,...]]
      Parameters:
      m - the Method to identify list of method parameters for.
      Returns:
      list of method parameters as String
    • getParametersListWithSeparator

      public static String getParametersListWithSeparator(Method m, String sep)
      Returns list of method parameters delimited by specified separator
      Parameters:
      m - the Method to identify list of method parameters for.
      sep - the separator to be used to delimit the parameter names
      Returns:
      list of method parameters as String
    • addFields

      public static void addFields(String prop, int modifiers, JavaClassWriter writer) throws IOException
      Adds fields to a class parsing the multi-String property.
      Parameters:
      prop - String to use for field generation.
      modifiers - other field modifiers for these fields.
      writer - the Class writer.
      Throws:
      IOException - if writer fails to add a field.
    • addPrivateField

      public static void addPrivateField(String prop, int modifiers, JavaClassWriter writer) throws IOException
      Adds private fields to a class parsing the multi-String property.
      Parameters:
      prop - String to use for field generation.
      modifiers - field modifiers for these fields.
      Throws:
      IOException - if writer fails to add a field.
    • addGenericMethod

      public static void addGenericMethod(String mname, String[] body, JavaClassWriter writer) throws IOException
      Adds a private void no-args method to a class with this method body.
      Parameters:
      mname - method name
      body - the method body as String[]
      Throws:
      IOException - if writer fails to add a field.
    • addGenericMethod

      public static void addGenericMethod(String mname, String type, String[] body, JavaClassWriter writer) throws IOException
      Adds a private no-args method to a class with this method body and return type.
      Parameters:
      mname - method name
      type - return type of the method
      body - the method body as String[]
      Throws:
      IOException - if writer fails to add a field.
    • addGenericMethod

      public static void addGenericMethod(String mname, int modifiers, String[] body, JavaClassWriter writer) throws IOException
      Adds a private void no-args method to a class with this method body and modifiers.
      Parameters:
      mname - method name
      modifiers - the method modifiers
      body - the method body as String[]
      Throws:
      IOException - if writer fails to add a field.
    • addGenericMethod

      public static void addGenericMethod(String mname, int modifiers, String type, String[] body, JavaClassWriter writer) throws IOException
      Adds a private void no-args method to a class with this method body, modifiers, and return type.
      Parameters:
      mname - method name
      modifiers - the method modifiers
      type - return type of the method
      body - the method body as String[]
      Throws:
      IOException - if writer fails to add a field.
    • addGenericMethod

      public static void addGenericMethod(Method m, String mname, String mtype, String body, JavaClassWriter writer) throws IOException
      Adds a method to a class parsing the multi-String property.
      Parameters:
      m - Method that describes one to be added to the bean.
      mname - method name if different from Method#getName(). This will be true for finder/selector/create methods.
      mtype - return type of the method, that can differ from the bean's local or remote interface.
      body - String to use for method body generation.
      Throws:
      IOException - if writer fails to add a field.
    • getTypeRepr

      public static String getTypeRepr(Class clazz)
      Returns the String representation of the specified class instance. An array is represented as the name of the element type followed by [].