public final class ClassUtil extends Object
Copyright (c) 2002-2009 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
See for project information www.simulation.tudelft.nl.
The DSOL project is distributed under the following BSD-style license:
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
conditions are met:
Modifier and Type | Method and Description |
---|---|
static Constructor<?>[] |
getAllConstructors(Class<?> clazz,
Constructor<?>[] result)
gets all the constructors of a class and adds the result to result.
|
static Set<Field> |
getAllFields(Class<?> clazz)
gets all the fields of a class (public, protected, package, and private).
|
static Set<Field> |
getAllFields(Class<?> clazz,
Set<Field> result)
gets all the fields of a class (public, protected, package, and private) and adds the result to the return value.
|
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.
|
public static Constructor<?>[] getAllConstructors(Class<?> clazz, Constructor<?>[] result)
clazz
- the classresult
- the resulting setpublic static Constructor<?> resolveConstructor(Class<?> clazz, Class<?> callerClass, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- the class to start withcallerClass
- the calling classparameterTypes
- the parameterTypesNoSuchMethodException
- if the method cannot be resolvedpublic static Constructor<?> resolveConstructor(Class<?> clazz, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- the class to start withparameterTypes
- the parameterTypesNoSuchMethodException
- if the method cannot be resolvedpublic static Constructor<?> resolveConstructor(Class<?> clazz, Object[] arguments) throws NoSuchMethodException
clazz
- the clazz to start witharguments
- the argumentsNoSuchMethodException
- on lookup failurepublic static Set<Field> getAllFields(Class<?> clazz, Set<Field> result)
clazz
- the classresult
- the resulting setpublic static Set<Field> getAllFields(Class<?> clazz)
clazz
- the classpublic static Field resolveField(Class<?> clazz, String fieldName) throws NoSuchFieldException
clazz
- the class to resolve the field for, including inner classesfieldName
- name of the fieldNoSuchFieldException
- on no such fieldpublic static Field resolveField(Class<?> clazz, Class<?> callerClass, String name) throws NoSuchFieldException
clazz
- the class to start withcallerClass
- the calling classname
- the fieldNameNoSuchFieldException
- if the method cannot be resolvedpublic static Field resolveField(Object object, String fieldName) throws NoSuchFieldException
object
- the object to resolve the field forfieldName
- name of the field to resolveNoSuchFieldException
- if the field cannot be resolvedpublic static Method[] getAllMethods(Class<?> clazz, String name, Method[] result)
clazz
- the classname
- the name of the methodresult
- the resulting setpublic static Method resolveMethod(Class<?> clazz, Class<?> callerClass, String name, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- the class to start withcallerClass
- the caller classname
- the name of the methodparameterTypes
- the parameterTypesNoSuchMethodException
- on lookup failurepublic static Method resolveMethod(Class<?> clazz, String name, Class<?>... parameterTypes) throws NoSuchMethodException
clazz
- the class to start withname
- the name of the methodparameterTypes
- the parameterTypesNoSuchMethodException
- on lookup failurepublic static Method resolveMethod(Object object, String name, Class<?>... parameterTypes) throws NoSuchMethodException
object
- the object to start withname
- the name of the methodparameterTypes
- the parameterTypesNoSuchMethodException
- on lookup failurepublic static Method resolveMethod(Object object, String name, Object[] arguments) throws NoSuchMethodException
object
- the object to start withname
- the name of the methodarguments
- the argumentsNoSuchMethodException
- on lookup failurepublic static boolean isVisible(int modifiers, Class<?> declaringClass, Class<?> caller)
modifiers
- the modifiersdeclaringClass
- the declaringClasscaller
- the callerpublic static boolean isMoreSpecific(Class<?>[] a, Class<?>[] b)
a
- reflects the first constructorb
- reflects the second constructorpublic static boolean isMoreSpecific(Constructor<?> a, Constructor<?> b)
a
- reflects the first constructorb
- reflects the second constructorpublic static boolean isMoreSpecific(Method a, Method b)
a
- reflects the first methodb
- reflects the second methodpublic static boolean isVisible(Field field, Class<?> caller)
field
- The fieldcaller
- The class of the caller for whom invocation visibility is checked.public static boolean isVisible(Constructor<?> constructor, Class<?> caller)
constructor
- The constructorcaller
- The class of the caller for whom invocation visibility is checked.public static boolean isVisible(Method method, Class<?> caller)
method
- The methodcaller
- The class of the caller for whom invocation visibility is checked.public static Method[] matchSignature(Method[] methods, String name, Class<?>... argTypes)
methods
- which are methods to be filtered.name
- reflects the method's name, part of the signatureargTypes
- are the method's argument typespublic static boolean matchSignature(Method method, String name, Class<?>... argTypes)
method
- The method to be filtered.name
- reflects the method's name, part of the signatureargTypes
- are the method's argument typespublic static boolean matchSignature(Constructor<?> constructor, Class<?>... argTypes)
constructor
- which are constructors to be filtered.argTypes
- are the constructor's argument typespublic static Constructor<?>[] matchSignature(Constructor<?>[] constructors, Class<?>... argTypes)
constructors
- which are constructors to be filtered.argTypes
- are the constructor's argument typesCopyright © 2015–2019 Delft University of Technology. All rights reserved.