jfun.yan.util
Class ClassDescriptor<T>

java.lang.Object
  extended by jfun.yan.util.ClassDescriptor<T>

public class ClassDescriptor<T>
extends java.lang.Object

A descriptor class for all methods/fields/contructors of a class. Hash table is pre-built to speed up query.

throughout this class, public members are defined as members defined with "public" keyword and declared in a public type. public members declared by a non-public class is considered non-public because access to it from outside is prohibited by the java access control anyway.

public members defined in public classes are always prefered even when we allow private/protected members and types to be visible. So if a non-public subtype and a public super type both have a field with the same name, the field in the public super type is always used.

Author:
Ben Yu Nov 14, 2005 9:10:41 PM

Method Summary
 java.lang.reflect.Method filterMethod(java.lang.String name, MethodPredicate pred)
          Get a public Method with a certain name and satisfies a certain predicate.
 java.lang.reflect.Method filterMethod(java.lang.String name, MethodPredicate pred, boolean suppress_security)
          Get a Method with a certain name and satisfies a certain predicate.
 java.lang.reflect.Constructor<T> getConstructor()
          Get the only one public constructor declared in the type.
 java.lang.reflect.Constructor<T> getConstructor(boolean suppress_security)
          Get the only one constructor declared in the type.
 java.lang.reflect.Constructor<T> getConstructor(java.lang.Class[] param_types)
          Get the public Constructor object identified by an array of parameter types.
 java.lang.reflect.Constructor<T> getConstructor(java.lang.Class[] param_types, boolean suppress_security)
          Get the Constructor object identified by an array of parameter types.
 java.lang.reflect.Constructor<T> getConstructor(int param_count)
          Get the only one public constructor declared in the type.
 java.lang.reflect.Constructor<T> getConstructor(int param_count, boolean suppress_security)
          Get the only one constructor declared in the type.
 java.lang.reflect.Field getField(java.lang.String name)
          Get the public Field object identified by name.
 java.lang.reflect.Field getField(java.lang.String name, boolean suppress_security)
          Get the Field object identified by name.
 java.lang.reflect.Method getMethod(java.lang.String name)
          Get the public method with a certain name.
 java.lang.reflect.Method getMethod(java.lang.String name, boolean suppress_security)
          Get the method with a certain name.
 java.lang.reflect.Method getMethod(java.lang.String name, java.lang.Class[] param_types)
          Get the public method identified by a signature.
 java.lang.reflect.Method getMethod(java.lang.String name, java.lang.Class[] param_types, boolean suppress_security)
          Get the method identified by a signature.
 java.lang.Class<T> getType()
          Get the class object that this descriptor describes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getConstructor

public java.lang.reflect.Constructor<T> getConstructor(java.lang.Class[] param_types,
                                                       boolean suppress_security)
Get the Constructor object identified by an array of parameter types.

Parameters:
param_types - the parameter types.
suppress_security - whether access to non-public constructor is allowed.
Returns:
the Constructor. or null if not found.

getConstructor

public java.lang.reflect.Constructor<T> getConstructor(java.lang.Class[] param_types)
Get the public Constructor object identified by an array of parameter types.

Parameters:
param_types - the parameter types.
Returns:
the Constructor. or null if not found.

getConstructor

public java.lang.reflect.Constructor<T> getConstructor(boolean suppress_security)
                                                throws AmbiguityException
Get the only one constructor declared in the type.

Parameters:
suppress_security - whether access to non-public constructor is allowed.
Returns:
the Constructor object. or null if not found.
Throws:
AmbiguityException - if more than one constructor is found.

getConstructor

public java.lang.reflect.Constructor<T> getConstructor()
                                                throws AmbiguityException
Get the only one public constructor declared in the type.

Returns:
the Constructor object. or null if not found.
Throws:
AmbiguityException - if more than one constructor is found.

getConstructor

public java.lang.reflect.Constructor<T> getConstructor(int param_count,
                                                       boolean suppress_security)
                                                throws AmbiguityException
Get the only one constructor declared in the type.

Parameters:
param_count - the number of formal parameters.
suppress_security - whether access to non-public constructor is allowed.
Returns:
the Constructor object. or null if not found.
Throws:
AmbiguityException - if more than one constructor is found.

getConstructor

public java.lang.reflect.Constructor<T> getConstructor(int param_count)
                                                throws AmbiguityException
Get the only one public constructor declared in the type.

Parameters:
param_count - the number of formal parameters.
Returns:
the Constructor object. or null if not found.
Throws:
AmbiguityException - if more than one constructor is found.

getMethod

public java.lang.reflect.Method getMethod(java.lang.String name,
                                          boolean suppress_security)
                                   throws AmbiguityException
Get the method with a certain name.

Parameters:
name - the method name.
suppress_security - whether to look at non-public ones.
Returns:
the Method object. or null if not found.
Throws:
AmbiguityException - when more than one are found.

getMethod

public java.lang.reflect.Method getMethod(java.lang.String name)
                                   throws AmbiguityException
Get the public method with a certain name.

Parameters:
name - the method name.
Returns:
the Method object. or null if not found.
Throws:
AmbiguityException - when more than one are found.

filterMethod

public java.lang.reflect.Method filterMethod(java.lang.String name,
                                             MethodPredicate pred)
                                      throws AmbiguityException
Get a public Method with a certain name and satisfies a certain predicate.

Parameters:
name - the method name. the method name.
pred - the predicate. pred.toString() is used in the ambiguity exception error message.
Returns:
the Method object, or null if not found.
Throws:
AmbiguityException - when more than one qualified methods are found.

filterMethod

public java.lang.reflect.Method filterMethod(java.lang.String name,
                                             MethodPredicate pred,
                                             boolean suppress_security)
                                      throws AmbiguityException
Get a Method with a certain name and satisfies a certain predicate. Because public methods are prefered, private methods are searched only when no qualified public method is found.

Parameters:
name - the method name. the method name.
pred - the predicate. pred.toString() is used in the ambiguity exception error message.
suppress_security - whether to look at non-public ones.
Returns:
the Method object, or null if not found.
Throws:
AmbiguityException - when more than one qualified methods are found.

getMethod

public java.lang.reflect.Method getMethod(java.lang.String name,
                                          java.lang.Class[] param_types,
                                          boolean suppress_security)
Get the method identified by a signature.

Parameters:
name - the method name.
param_types - the formal parameter types.
suppress_security - whether to look at non-public ones.
Returns:
the Method object. or null if not found.

getMethod

public java.lang.reflect.Method getMethod(java.lang.String name,
                                          java.lang.Class[] param_types)
Get the public method identified by a signature.

Parameters:
name - the method name.
param_types - the formal parameter types.
Returns:
the Method object. or null if not found.

getField

public java.lang.reflect.Field getField(java.lang.String name,
                                        boolean suppress_security)
Get the Field object identified by name.

Parameters:
name - the field name.
suppress_security - whether to look at non-public ones.
Returns:
the Field object. or null if not found.

getField

public java.lang.reflect.Field getField(java.lang.String name)
Get the public Field object identified by name.

Parameters:
name - the field name.
Returns:
the Field object. or null if not found.

getType

public java.lang.Class<T> getType()
Get the class object that this descriptor describes.