Package org.apache.tapestry5.plastic

# Class PlasticUtils

java.lang.Object
org.apache.tapestry5.plastic.PlasticUtils

public class PlasticUtils extends Object
Utilities for user code making use of Plastic.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `PlasticUtils.FieldInfo`
  Class used to represent a field name and its type for implementFieldValueProvider(PlasticClass, Set).

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final Method`
  `TO_STRING`
  The `toString()` method inherited from Object.
  `static final MethodDescription`
  `TO_STRING_DESCRIPTION`
  The MethodDescription version of `toString()`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PlasticUtils()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `getEnclosingClassName(String className)`
  If the given class is an inner class, returns the enclosing class.
  `static Method`
  `getMethod(Class declaringClass, String name, Class... parameterTypes)`
  Convenience for getting a method from a class.
  `static MethodDescription`
  `getMethodDescription(Class declaringClass, String name, Class... parameterTypes)`
  Uses `getMethod(Class, String, Class...)` and wraps the result as a `MethodDescription`.
  `static void`
  `implementFieldValueProvider(PlasticClass plasticClass, Set<PlasticUtils.FieldInfo> fieldInfos)`
  Transforms this PlasticClass so it implements FieldValueProvider for the given set of field names.
  `static void`
  `implementPropertyValueProvider(PlasticClass plasticClass, Set<PlasticUtils.FieldInfo> fieldInfos)`
  Transforms this PlasticClass so it implements PropertyValueProvider for the given set of field names.
  `static boolean`
  `isPrimitive(String typeName)`
  Determines if the provided type name is a primitive type.
  `static String`
  `nextUID()`
  Returns a string that can be used as part of a Java identifier and is unique for this JVM.
  `static PlasticUtils.FieldInfo`
  `toFieldInfo(PlasticField field)`
  Utility method for creating PlasticUtils.FieldInfo instances.
  `static String`
  `toTypeName(Class type)`
  Converts a type (including array and primitive types) to their type name (the way they are represented in Java source files).
  `static String[]`
  `toTypeNames(Class[] types)`
  Converts a number of types (usually, arguments to a method or constructor) into their type names.
  `static Class`
  `toWrapperType(Class type)`
  Gets the wrapper type for a given type (if primitive)

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### TO_STRING

    public static final Method TO_STRING
    The `toString()` method inherited from Object.

  - ### TO_STRING_DESCRIPTION

    public static final MethodDescription TO_STRING_DESCRIPTION
    The MethodDescription version of `toString()`.

- ## Constructor Details

  - ### PlasticUtils

    public PlasticUtils()

- ## Method Details

  - ### nextUID

    public static String nextUID()
    Returns a string that can be used as part of a Java identifier and is unique for this JVM. Currently returns a hexadecimal string and initialized by System.nanoTime() (but both those details may change in the future). Note that the returned value may start with a numeric digit, so it should be used as a suffix, not prefix of a Java identifier.
    Returns:
      unique id that can be used as part of a Java identifier

  - ### toTypeName

    public static String toTypeName(Class type)
    Converts a type (including array and primitive types) to their type name (the way they are represented in Java source files).

  - ### toTypeNames

    public static String[] toTypeNames(Class[] types)
    Converts a number of types (usually, arguments to a method or constructor) into their type names.

  - ### toWrapperType

    public static Class toWrapperType(Class type)
    Gets the wrapper type for a given type (if primitive)
    Parameters:
      `type` - type to look up
    Returns:
      the input type for non-primitive type, or corresponding wrapper type (Boolean.class for boolean.class, etc.)

  - ### getMethod

    public static Method getMethod(Class declaringClass, String name, Class... parameterTypes)
    Convenience for getting a method from a class.
    Parameters:
      `declaringClass` - containing class
      `name` - name of method
      `parameterTypes` - types of parameters
    Returns:
      the Method
    Throws:
      `RuntimeException` - if any error (such as method not found)

  - ### getMethodDescription

    public static MethodDescription getMethodDescription(Class declaringClass, String name, Class... parameterTypes)
    Uses `getMethod(Class, String, Class...)` and wraps the result as a `MethodDescription`.
    Parameters:
      `declaringClass` - containing class
      `name` - name of method
      `parameterTypes` - types of parameters
    Returns:
      description for method
    Throws:
      `RuntimeException` - if any error (such as method not found)

  - ### isPrimitive

    public static boolean isPrimitive(String typeName)
    Determines if the provided type name is a primitive type.
    Parameters:
      `typeName` - Java type name, such as "boolean" or "java.lang.String"
    Returns:
      true if primitive

  - ### getEnclosingClassName

    public static String getEnclosingClassName(String className)
    If the given class is an inner class, returns the enclosing class. Otherwise, returns the class name unchanged.

  - ### toFieldInfo

    public static PlasticUtils.FieldInfo toFieldInfo(PlasticField field)
    Utility method for creating PlasticUtils.FieldInfo instances.
    Parameters:
      `field` - a PlasticField.
    Returns:
      a corresponding PlasticUtils.FieldInfo.
    Since:
      5.8.4

  - ### implementFieldValueProvider

    public static void implementFieldValueProvider(PlasticClass plasticClass, Set<PlasticUtils.FieldInfo> fieldInfos)
    Transforms this PlasticClass so it implements FieldValueProvider for the given set of field names. Notice attempts to read a superclass' private field will result in an IllegalAccessError.
    Parameters:
      `plasticClass` - a PlasticClass instance.
      `fieldInfos` - a Set of Strings containing the field names.
    Since:
      5.8.4

  - ### implementPropertyValueProvider

    public static void implementPropertyValueProvider(PlasticClass plasticClass, Set<PlasticUtils.FieldInfo> fieldInfos)
    Transforms this PlasticClass so it implements PropertyValueProvider for the given set of field names. The implementation will use the fields' corresponding getters instead of direct fields access.
    Parameters:
      `plasticClass` - a PlasticClass instance.
      `fieldInfos` - a Set of Strings containing the filed (i.e. property) names.
    Since:
      5.8.4