Class TypeHandling


  • public final class TypeHandling
    extends Object
    Helper class to provide some formatting of type names.
    • Method Detail

      • simplifyType

        public static String simplifyType​(String typeName)
        Returns a simplified description of a type name. This involves transforming type names from their formal descriptors to more human friendly forms, removing package names from certain well-known classes, transforming formal array specified to square brackets etc.
        Parameters:
        typeName - a type name
        Returns:
        a simplified description of the type name
      • getValueString

        public static String getValueString​(Object value)
        Returns the value in possible augmented way. It could be viewed as an override of toString().
        Parameters:
        value - the value to textualize
        Returns:
        the value as a string
      • getVerboseString

        public static String getVerboseString​(Object value)
        Returns a possibly more verbose description of an object. This is similar to getValueString(Object), but can return longer texts.
        Parameters:
        value - the value to textualize
        Returns:
        the value as a string
      • getNumericString

        public static String getNumericString​(Number value)
        Check for missing values, and return the numeric value in string format.

        JMC-6256: JMC doesn't respect Long.MIN_VALUE as a missing value.

        As per the bug report, the following values should be considered "missing"

        • Integer.MIN_VALUE
        • Long.MIN_VALUE
        • Double.NaN
        • Double.NEGATIVE_INFINITY
        • Float.NaN
        • Float.NEGATIVE_INFINITY

        Parameters:
        value - the numeric value to be converted to a string
        Returns:
        a string with the numeric value, or a N/A message
      • getClassWithName

        public static Class<?> getClassWithName​(String name)
                                         throws ClassNotFoundException
        Return the class object for given type name.
        Parameters:
        name - the name of the type
        Returns:
        the class object of the type
        Throws:
        ClassNotFoundException - if name is an invalid class name
      • toNonPrimitiveClass

        public static Class<?> toNonPrimitiveClass​(Class<?> primitiveClass)
        Return the non-primitive class corresponding to argument class (int -> Integer).
        Parameters:
        primitiveClass - the class to convert
        Returns:
        the non-primitive class or the argument class if non-primitive
      • isPrimitive

        public static boolean isPrimitive​(String className)
        Check if a class name represents a primitive type or not.
        Parameters:
        className - the name to check
        Returns:
        true if the class name represents a primitive type, false otherwise
      • cast

        public static <T> T cast​(Object o,
                                 Class<T> type)
        Check if an object is of a specified type and cast it to that if possible.
        Parameters:
        o - object to cast
        type - type to cast the object to
        Returns:
        the object cast to the specified type if possible, null if not