nl.tudelft.simulation.language.reflection
Class ClassUtil

java.lang.Object
  extended by nl.tudelft.simulation.language.reflection.ClassUtil

public final class ClassUtil
extends Object

ClassUtil is a utility class providing assistance for Java Classes.

(c) copyright 2002-2005 Delft University of Technology , the Netherlands.

See for project information www.simulation.tudelft.nl/language
License of use: Lesser General Public License (LGPL) , no warranty

Since:
1.3
Version:
$Revision: 1.1 $ $Date: 2007/01/06 13:25:54 $
Author:
Peter Jacobs , Niels Lang Alexander Verbraeck

Method Summary
static Constructor[] getAllConstructors(Class clazz, Constructor[] result)
          gets all the constructors of a class and adds the result to result
static Method[] getAllMethods(Class clazz, String name, Method[] result)
          gets all the methods of a class and adds the result to result
static Class[] getClass(Object[] array)
          converts an array of objects to their corresponding classes
static boolean isMoreSpecific(Class[] a, Class[] b)
          Determines & returns whether constructor 'a' is more specific than constructor 'b', as defined in the Java Language Specification §15.12.
static boolean isMoreSpecific(Constructor a, Constructor b)
          Determines & returns whether constructor 'a' is more specific than constructor 'b', as defined in the Java Language Specification §15.12.
static boolean isMoreSpecific(Method a, Method b)
          Determines & returns whether constructor 'a' is more specific than constructor 'b', as defined in the Java Language Specification §15.12.
static boolean isVisible(Constructor constructor, Class caller)
          Returns whether a constructor is visible for a caller.
static boolean isVisible(Field field, Class caller)
          Returns whether a field is visible for a caller.
static boolean isVisible(int modifiers, Class declaringClass, Class caller)
          Returns whether a declaringClass is accessible according to the modifiers
static boolean isVisible(Method method, Class caller)
          Returns whether a method is visible for a caller.
static Constructor[] matchSignature(Constructor[] constructors, Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static boolean matchSignature(Constructor constructor, Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static Method[] matchSignature(Method[] methods, String name, Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static boolean matchSignature(Method method, String name, Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static Constructor resolveConstructor(Class clazz, Class[] parameterTypes)
          returns the interface method
static Constructor resolveConstructor(Class clazz, Class callerClass, Class[] parameterTypes)
          returns the interface method
static Constructor resolveConstructor(Class clazz, Object[] arguments)
          returns the constructor
static Field resolveField(Class clazz, Class callerClass, String name)
          returns the field
static Field resolveField(Class clazz, String fieldName)
          resolves the field for a class, taking into account inner classes
static Field resolveField(Object object, String fieldName)
          resolves the field for a given object instance
static Method resolveMethod(Class clazz, Class callerClass, String name, Class[] parameterTypes)
          returns the interface method
static Method resolveMethod(Class clazz, String name, Class[] parameterTypes)
          returns the interface method
static Method resolveMethod(Object object, String name, Class[] parameterTypes)
          resolves a method the method
static Method resolveMethod(Object object, String name, Object[] arguments)
          returns the method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAllConstructors

public static Constructor[] getAllConstructors(Class clazz,
                                               Constructor[] result)
gets all the constructors of a class and adds the result to result

Parameters:
clazz - the class
result - the resulting set
Returns:
result

resolveConstructor

public static Constructor resolveConstructor(Class clazz,
                                             Class callerClass,
                                             Class[] parameterTypes)
                                      throws NoSuchMethodException
returns the interface method

Parameters:
clazz - the class to start with
callerClass - the calling class
parameterTypes - the parameterTypes
Returns:
Constructor
Throws:
NoSuchMethodException - if the method cannot be resolved

resolveConstructor

public static Constructor resolveConstructor(Class clazz,
                                             Class[] parameterTypes)
                                      throws NoSuchMethodException
returns the interface method

Parameters:
clazz - the class to start with
parameterTypes - the parameterTypes
Returns:
Constructor
Throws:
NoSuchMethodException - if the method cannot be resolved

resolveConstructor

public static Constructor resolveConstructor(Class clazz,
                                             Object[] arguments)
                                      throws NoSuchMethodException
returns the constructor

Parameters:
clazz - the clazz to start with
arguments - the arguments
Returns:
Constructor
Throws:
NoSuchMethodException - on lookup failure

resolveField

public static Field resolveField(Class clazz,
                                 String fieldName)
                          throws NoSuchFieldException
resolves the field for a class, taking into account inner classes

Parameters:
clazz - the class to resolve the field for, including inner classes
fieldName - name of the field
Returns:
Field the field
Throws:
NoSuchFieldException - on no such field

resolveField

public static Field resolveField(Class clazz,
                                 Class callerClass,
                                 String name)
                          throws NoSuchFieldException
returns the field

Parameters:
clazz - the class to start with
callerClass - the calling class
name - the fieldName
Returns:
Constructor
Throws:
NoSuchFieldException - if the method cannot be resolved

resolveField

public static Field resolveField(Object object,
                                 String fieldName)
                          throws NoSuchFieldException
resolves the field for a given object instance

Parameters:
object - the object to resolve the field for
fieldName - name of the field to resolve
Returns:
the field (if found)
Throws:
NoSuchFieldException - if the field cannot be resolved

getAllMethods

public static Method[] getAllMethods(Class clazz,
                                     String name,
                                     Method[] result)
gets all the methods of a class and adds the result to result

Parameters:
clazz - the class
name - the name of the method
result - the resulting set
Returns:
result

resolveMethod

public static Method resolveMethod(Class clazz,
                                   Class callerClass,
                                   String name,
                                   Class[] parameterTypes)
                            throws NoSuchMethodException
returns the interface method

Parameters:
clazz - the class to start with
callerClass - the caller class
name - the name of the method
parameterTypes - the parameterTypes
Returns:
Method
Throws:
NoSuchMethodException - on lookup failure

resolveMethod

public static Method resolveMethod(Class clazz,
                                   String name,
                                   Class[] parameterTypes)
                            throws NoSuchMethodException
returns the interface method

Parameters:
clazz - the class to start with
name - the name of the method
parameterTypes - the parameterTypes
Returns:
Method
Throws:
NoSuchMethodException - on lookup failure

resolveMethod

public static Method resolveMethod(Object object,
                                   String name,
                                   Class[] parameterTypes)
                            throws NoSuchMethodException
resolves a method the method

Parameters:
object - the object to start with
name - the name of the method
parameterTypes - the parameterTypes
Returns:
Method
Throws:
NoSuchMethodException - on lookup failure

resolveMethod

public static Method resolveMethod(Object object,
                                   String name,
                                   Object[] arguments)
                            throws NoSuchMethodException
returns the method

Parameters:
object - the object to start with
name - the name of the method
arguments - the arguments
Returns:
Method
Throws:
NoSuchMethodException - on lookup failure

isVisible

public static boolean isVisible(int modifiers,
                                Class declaringClass,
                                Class caller)
Returns whether a declaringClass is accessible according to the modifiers

Parameters:
modifiers - the modifiers
declaringClass - the declaringClass
caller - the caller
Returns:
boolean isVisible

isMoreSpecific

public static boolean isMoreSpecific(Class[] a,
                                     Class[] b)
Determines & returns whether constructor 'a' is more specific than constructor 'b', as defined in the Java Language Specification §15.12.

Parameters:
a - reflects the first constructor
b - reflects the second constructor
Returns:
true if 'a' is more specific than b, false otherwise. 'false' is also returned when constructors are incompatible, e.g. have different names or a different number of parameters.

isMoreSpecific

public static boolean isMoreSpecific(Constructor a,
                                     Constructor b)
Determines & returns whether constructor 'a' is more specific than constructor 'b', as defined in the Java Language Specification §15.12.

Parameters:
a - reflects the first constructor
b - reflects the second constructor
Returns:
true if 'a' is more specific than b, false otherwise. 'false' is also returned when constructors are incompatible, e.g. have different names or a different number of parameters.

isMoreSpecific

public static boolean isMoreSpecific(Method a,
                                     Method b)
Determines & returns whether constructor 'a' is more specific than constructor 'b', as defined in the Java Language Specification §15.12.

Parameters:
a - reflects the first method
b - reflects the second method
Returns:
true if 'a' is more specific than b, false otherwise. 'false' is also returned when constructors are incompatible, e.g. have different names or a different number of parameters.

isVisible

public static boolean isVisible(Field field,
                                Class caller)
Returns whether a field is visible for a caller.

Parameters:
field - The field
caller - The class of the caller for whom invocation visibility is checked.
Returns:
boolean yes or no

isVisible

public static boolean isVisible(Constructor constructor,
                                Class caller)
Returns whether a constructor is visible for a caller.

Parameters:
constructor - The constructor
caller - The class of the caller for whom invocation visibility is checked.
Returns:
boolean yes or no

isVisible

public static boolean isVisible(Method method,
                                Class caller)
Returns whether a method is visible for a caller.

Parameters:
method - The method
caller - The class of the caller for whom invocation visibility is checked.
Returns:
boolean yes or no

matchSignature

public static Method[] matchSignature(Method[] methods,
                                      String name,
                                      Class[] argTypes)
Filters an array methods for signatures that are compatible with a given signature.

Parameters:
methods - which are methods to be filtered.
name - reflects the method's name, part of the signature
argTypes - are the method's argument types
Returns:
Method[] An unordered Method-array consisting of the elements of 'methods' that match with the given signature. An array with 0 elements is returned when no matching Method objects are found.

matchSignature

public static boolean matchSignature(Method method,
                                     String name,
                                     Class[] argTypes)
Filters an array methods for signatures that are compatible with a given signature.

Parameters:
method - The method to be filtered.
name - reflects the method's name, part of the signature
argTypes - are the method's argument types
Returns:
boolean if methodParameters assignable from argTypes

matchSignature

public static boolean matchSignature(Constructor constructor,
                                     Class[] argTypes)
Filters an array methods for signatures that are compatible with a given signature.

Parameters:
constructor - which are constructors to be filtered.
argTypes - are the constructor's argument types
Returns:
boolean if methodParameters assignable from argTypes

matchSignature

public static Constructor[] matchSignature(Constructor[] constructors,
                                           Class[] argTypes)
Filters an array methods for signatures that are compatible with a given signature.

Parameters:
constructors - which are constructors to be filtered.
argTypes - are the constructor's argument types
Returns:
Constructor[] An unordered Constructor-array consisting of the elements of 'constructors' that match with the given signature. An array with 0 elements is returned when no matching Method objects are found.

getClass

public static Class[] getClass(Object[] array)
converts an array of objects to their corresponding classes

Parameters:
array - the array to invoke
Returns:
Class[] the result;


Copyright © 2002-2011 Delft University of Technology, the Netherlands. All Rights Reserved.