nl.tudelft.simulation.language.reflection
Class ClassUtil

java.lang.Object
  extended bynl.tudelft.simulation.language.reflection.ClassUtil

public final class ClassUtil
extends java.lang.Object

ClassUtil is a utility class providing assistance for Java Classes
(c) copyright 2003 Delft University of Technology , the Netherlands.
See for project information www.simulation.tudelft.nl
License of use: General Public License (GPL) , no warranty

Since:
1.3
Version:
1.7 April 25, 2004
Author:
Peter Jacobs , Niels Lang Alexander Verbraeck

Method Summary
static java.lang.reflect.Constructor[] getAllConstructors(java.lang.Class clazz, java.lang.reflect.Constructor[] result)
          gets all the constructors of a class and adds the result to result
static java.lang.reflect.Method[] getAllMethods(java.lang.Class clazz, java.lang.String name, java.lang.reflect.Method[] result)
          gets all the methods of a class and adds the result to result
static java.lang.Class[] getClass(java.lang.Object[] array)
          converts an array of objects to their corresponding classes
static boolean isMoreSpecific(java.lang.Class[] a, java.lang.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(java.lang.reflect.Constructor a, java.lang.reflect.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(java.lang.reflect.Method a, java.lang.reflect.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(java.lang.reflect.Constructor constructor, java.lang.Class caller)
          Returns whether a constructor is visible for a caller.
static boolean isVisible(java.lang.reflect.Field field, java.lang.Class caller)
          Returns whether a field is visible for a caller.
static boolean isVisible(int modifiers, java.lang.Class declaringClass, java.lang.Class caller)
          Returns whether a declaringClass is accessible according to the modifiers
static boolean isVisible(java.lang.reflect.Method method, java.lang.Class caller)
          Returns whether a method is visible for a caller.
static java.lang.reflect.Constructor[] matchSignature(java.lang.reflect.Constructor[] constructors, java.lang.Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static boolean matchSignature(java.lang.reflect.Constructor constructor, java.lang.Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static java.lang.reflect.Method[] matchSignature(java.lang.reflect.Method[] methods, java.lang.String name, java.lang.Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static boolean matchSignature(java.lang.reflect.Method method, java.lang.String name, java.lang.Class[] argTypes)
          Filters an array methods for signatures that are compatible with a given signature.
static java.lang.reflect.Constructor resolveConstructor(java.lang.Class clazz, java.lang.Class[] parameterTypes)
          returns the interface method
static java.lang.reflect.Constructor resolveConstructor(java.lang.Class clazz, java.lang.Class callerClass, java.lang.Class[] parameterTypes)
          returns the interface method
static java.lang.reflect.Constructor resolveConstructor(java.lang.Class clazz, java.lang.Object[] arguments)
          returns the constructor
static java.lang.reflect.Field resolveField(java.lang.Class clazz, java.lang.Class callerClass, java.lang.String name)
          returns the field
static java.lang.reflect.Field resolveField(java.lang.Class clazz, java.lang.String fieldName)
          resolves the field for a class, taking into account inner classes
static java.lang.reflect.Field resolveField(java.lang.Object object, java.lang.String fieldName)
          resolves the field for a given object instance
static java.lang.reflect.Method resolveMethod(java.lang.Class clazz, java.lang.Class callerClass, java.lang.String name, java.lang.Class[] parameterTypes)
          returns the interface method
static java.lang.reflect.Method resolveMethod(java.lang.Class clazz, java.lang.String name, java.lang.Class[] parameterTypes)
          returns the interface method
static java.lang.reflect.Method resolveMethod(java.lang.Object object, java.lang.String name, java.lang.Class[] parameterTypes)
          resolves a method the method
static java.lang.reflect.Method resolveMethod(java.lang.Object object, java.lang.String name, java.lang.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 java.lang.reflect.Constructor[] getAllConstructors(java.lang.Class clazz,
                                                                 java.lang.reflect.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 java.lang.reflect.Constructor resolveConstructor(java.lang.Class clazz,
                                                               java.lang.Class callerClass,
                                                               java.lang.Class[] parameterTypes)
                                                        throws java.lang.NoSuchMethodException
returns the interface method

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

resolveConstructor

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

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

resolveConstructor

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

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

resolveField

public static java.lang.reflect.Field resolveField(java.lang.Class clazz,
                                                   java.lang.String fieldName)
                                            throws java.lang.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:
java.lang.NoSuchFieldException - on no such field

resolveField

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

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

resolveField

public static java.lang.reflect.Field resolveField(java.lang.Object object,
                                                   java.lang.String fieldName)
                                            throws java.lang.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:
java.lang.NoSuchFieldException - if the field cannot be resolved

getAllMethods

public static java.lang.reflect.Method[] getAllMethods(java.lang.Class clazz,
                                                       java.lang.String name,
                                                       java.lang.reflect.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 java.lang.reflect.Method resolveMethod(java.lang.Class clazz,
                                                     java.lang.Class callerClass,
                                                     java.lang.String name,
                                                     java.lang.Class[] parameterTypes)
                                              throws java.lang.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:
java.lang.NoSuchMethodException - on lookup failure

resolveMethod

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

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

resolveMethod

public static java.lang.reflect.Method resolveMethod(java.lang.Object object,
                                                     java.lang.String name,
                                                     java.lang.Class[] parameterTypes)
                                              throws java.lang.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:
java.lang.NoSuchMethodException - on lookup failure

resolveMethod

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

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

isVisible

public static boolean isVisible(int modifiers,
                                java.lang.Class declaringClass,
                                java.lang.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(java.lang.Class[] a,
                                     java.lang.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(java.lang.reflect.Constructor a,
                                     java.lang.reflect.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(java.lang.reflect.Method a,
                                     java.lang.reflect.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(java.lang.reflect.Field field,
                                java.lang.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(java.lang.reflect.Constructor constructor,
                                java.lang.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(java.lang.reflect.Method method,
                                java.lang.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 java.lang.reflect.Method[] matchSignature(java.lang.reflect.Method[] methods,
                                                        java.lang.String name,
                                                        java.lang.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(java.lang.reflect.Method method,
                                     java.lang.String name,
                                     java.lang.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(java.lang.reflect.Constructor constructor,
                                     java.lang.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 java.lang.reflect.Constructor[] matchSignature(java.lang.reflect.Constructor[] constructors,
                                                             java.lang.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 java.lang.Class[] getClass(java.lang.Object[] array)
converts an array of objects to their corresponding classes

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


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