org.jboss.lang
Class ClassRedirects

java.lang.Object
  extended by org.jboss.lang.ClassRedirects

public class ClassRedirects
extends java.lang.Object

Implementations of java.lang.Class methods added in jdk5


Method Summary
static
<T> java.lang.Class<? extends T>
asSubclass(java.lang.Class<T> clazz, java.lang.Class thisClazz)
           
static
<T> T
cast(java.lang.Class<T> clazz, java.lang.Object o)
          Cast an object
static boolean contains(java.lang.String string, java.lang.CharSequence s)
          Whether the string contains the character sequence
static java.lang.String getCanonicalName(java.lang.Class clazz)
          Returns the canonical name of the the underlying class as defined by the Java Language Specification.
static java.lang.Class<?> getEnclosingClass(java.lang.Class clazz)
          This method cannot be implemented as it relies on native method info.
static java.lang.reflect.Constructor<?> getEnclosingConstructor(java.lang.Class clazz)
          This method cannot be implemented as it relies on native method info.
static java.lang.reflect.Method getEnclosingMethod(java.lang.Class clazz)
          This method cannot be implemented as it relies on native method info.
static
<T extends EnumImpl<T>>
T[]
getEnumConstants(java.lang.Class<T> enumType)
          Get the enumeration constants
static java.lang.reflect.Type[] getGenericInterfaces(java.lang.Class clazz)
           
static java.lang.reflect.Type getGenericSuperclass(java.lang.Class clazz)
           
static java.lang.String getSimpleName(java.lang.Class clazz)
          Implementation of the jdk5 Class.getSimpleName() method.
static
<T> java.lang.reflect.TypeVariable<java.lang.Class<T>>[]
getTypeParameters(java.lang.Class clazz)
           
static boolean isAnonymousClass(java.lang.Class clazz)
          Returns true if and only if the underlying class is an anonymous class.
static boolean isEnum(java.lang.Class clazz)
          Whether the class is an enum
static boolean isLocalClass(java.lang.Class clazz)
           
static boolean isMemberClass(java.lang.Class clazz)
           
static boolean isSynthetic(java.lang.Class clazz)
           
static java.lang.String quoteReplacement(java.lang.String string)
          Quote the replacement string
static java.lang.String replace(java.lang.String string, java.lang.CharSequence target, java.lang.CharSequence replacement)
          Replace a character sequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEnum

public static boolean isEnum(java.lang.Class clazz)
Whether the class is an enum

Parameters:
clazz - the class
Returns:
true when it is an enum

getEnumConstants

public static <T extends EnumImpl<T>> T[] getEnumConstants(java.lang.Class<T> enumType)
Get the enumeration constants

Type Parameters:
T - the enum type
Parameters:
enumType - the enum type
Returns:
the constants

cast

public static <T> T cast(java.lang.Class<T> clazz,
                         java.lang.Object o)
Cast an object

Type Parameters:
T - the expected type
Parameters:
clazz - the expected class
o - the object
Returns:
the cast object

asSubclass

public static <T> java.lang.Class<? extends T> asSubclass(java.lang.Class<T> clazz,
                                                          java.lang.Class thisClazz)
Parameters:
clazz -
thisClazz -
Returns:
thisClazz object, cast to represent a subclass of the specified class object.
Throws:
java.lang.ClassCastException - if thisClazz object does not represent a subclass of the specified class (here "subclass" includes the class itself).

replace

public static java.lang.String replace(java.lang.String string,
                                       java.lang.CharSequence target,
                                       java.lang.CharSequence replacement)
Replace a character sequence

Parameters:
string - the string
target - the string to replace
replacement - the replacement text
Returns:
the result

contains

public static boolean contains(java.lang.String string,
                               java.lang.CharSequence s)
Whether the string contains the character sequence

Parameters:
string - the string
s - the character sequence
Returns:
true when it contains the sequence

quoteReplacement

public static java.lang.String quoteReplacement(java.lang.String string)
Quote the replacement string

Parameters:
string - the quoted string

getSimpleName

public static java.lang.String getSimpleName(java.lang.Class clazz)
Implementation of the jdk5 Class.getSimpleName() method. Returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous.

The simple name of an array is the simple name of the component type with "[]" appended. In particular the simple name of an array whose component type is anonymous is "[]".

Parameters:
clazz - the Class instance
Returns:
the simple name of the underlying class

getCanonicalName

public static java.lang.String getCanonicalName(java.lang.Class clazz)
Returns the canonical name of the the underlying class as defined by the Java Language Specification. Returns null if the underlying class does not have a canonical name (i.e., if it is a local or anonymous class or an array whose component type does not have a canonical name). The difference between a fully qualified name and a canonical name can be seen in examples such as: package p; class O1 { class I{}} class O2 extends O1{}; In this example both p.O1.I and p.O2.I are fully qualified names that denote the same class, but only p.O1.I is its canonical name.

Parameters:
clazz - the Class instance
Returns:
the canonical name of the underlying class if it exists, and null otherwise.

isAnonymousClass

public static boolean isAnonymousClass(java.lang.Class clazz)
Returns true if and only if the underlying class is an anonymous class.

Parameters:
clazz - the Class instance
Returns:
true if clazz is an anonymous class.
Since:
1.5

isSynthetic

public static boolean isSynthetic(java.lang.Class clazz)
Parameters:
clazz -
Returns:
true if (clazz.getModifiers() & SYNTHETIC) != 0

isLocalClass

public static boolean isLocalClass(java.lang.Class clazz)
Parameters:
clazz - the Class instance
Returns:
true if and only if this class is a local class.
Since:
1.5

isMemberClass

public static boolean isMemberClass(java.lang.Class clazz)
Parameters:
clazz - the Class instance
Returns:
true if and only if this class is a member class.
Since:
1.5

getTypeParameters

public static <T> java.lang.reflect.TypeVariable<java.lang.Class<T>>[] getTypeParameters(java.lang.Class clazz)
Parameters:
clazz -
Returns:
an array of TypeVariable objects that represent the type variables declared by this generic declaration

getGenericSuperclass

public static java.lang.reflect.Type getGenericSuperclass(java.lang.Class clazz)
Parameters:
clazz -
Returns:
the superclass of the class represented by this object

getGenericInterfaces

public static java.lang.reflect.Type[] getGenericInterfaces(java.lang.Class clazz)
Parameters:
clazz -
Returns:
an array of interfaces implemented by this class

getEnclosingMethod

public static java.lang.reflect.Method getEnclosingMethod(java.lang.Class clazz)
This method cannot be implemented as it relies on native method info.

Parameters:
clazz -
Returns:
null

getEnclosingConstructor

public static java.lang.reflect.Constructor<?> getEnclosingConstructor(java.lang.Class clazz)
This method cannot be implemented as it relies on native method info.

Parameters:
clazz -
Returns:
null

getEnclosingClass

public static java.lang.Class<?> getEnclosingClass(java.lang.Class clazz)
This method cannot be implemented as it relies on native method info.

Parameters:
clazz -
Returns:
null