public final class ClassUtil extends Object
Copyright (c) 2002-2019 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djutils.org. The DJUTILS project is distributed under a three-clause BSD-style license, which can be found at https://djutils.org/docs/license.html.
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
- Class<?>; the classresult
- Constructor<?>[]; the resulting setpublic static Constructor<?> resolveConstructor(Class<?> clazz, Class<?> callerClass, Class<?>[] parameterTypes) throws NoSuchMethodException
clazz
- Class<?>; the class to start withcallerClass
- Class<?>; the calling classparameterTypes
- Class<?>[]; the parameterTypesNoSuchMethodException
- if the method cannot be resolvedpublic static Constructor<?> resolveConstructor(Class<?> clazz, Class<?>[] parameterTypes) throws NoSuchMethodException
clazz
- Class<?>; the class to start withparameterTypes
- Class<?>[]; the parameterTypesNoSuchMethodException
- if the method cannot be resolvedpublic static Constructor<?> resolveConstructor(Class<?> clazz, Object[] arguments) throws NoSuchMethodException
clazz
- Class<?>; the clazz to start witharguments
- Object[]; the argumentsNoSuchMethodException
- on lookup failurepublic static Set<Field> getAllFields(Class<?> clazz, Set<Field> result)
clazz
- Class<?>; the classresult
- Set<Field>; the resulting setpublic static Set<Field> getAllFields(Class<?> clazz)
clazz
- Class<?>; 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
- Class<?>; the class to start withcallerClass
- Class<?>; the calling classname
- String; the fieldNameNoSuchFieldException
- if the method cannot be resolvedpublic static Field resolveField(Object object, String fieldName) throws NoSuchFieldException
object
- Object; the object to resolve the field forfieldName
- String; name of the field to resolveNoSuchFieldException
- if the field cannot be resolvedpublic static Method[] getAllMethods(Class<?> clazz, String name, Method[] result)
clazz
- Class<?>; the classname
- String; the name of the methodresult
- Method[]; the resulting setpublic static Method resolveMethod(Class<?> clazz, Class<?> callerClass, String name, Class<?>[] parameterTypes) throws NoSuchMethodException
clazz
- Class<?>; the class to start withcallerClass
- Class<?>; the caller classname
- String; the name of the methodparameterTypes
- Class<?>[]; the parameterTypesNoSuchMethodException
- on lookup failurepublic static Method resolveMethod(Class<?> clazz, String name, Class<?>[] parameterTypes) throws NoSuchMethodException
clazz
- Class<?>; the class to start withname
- String; the name of the methodparameterTypes
- Class<?>[]; the parameterTypesNoSuchMethodException
- on lookup failurepublic static Method resolveMethod(Object object, String name, Class<?>[] parameterTypes) throws NoSuchMethodException
object
- Object; the object to start withname
- String; the name of the methodparameterTypes
- Class<?>[]; the parameterTypesNoSuchMethodException
- on lookup failurepublic static Method resolveMethod(Object object, String name, Object[] arguments) throws NoSuchMethodException
object
- Object; the object to start withname
- String; the name of the methodarguments
- Object[]; the argumentsNoSuchMethodException
- on lookup failurepublic static boolean isVisible(int modifiers, Class<?> declaringClass, Class<?> caller)
modifiers
- int; the modifiersdeclaringClass
- Class<?>; the declaringClasscaller
- Class<?>; the callerpublic static boolean isMoreSpecific(Class<?>[] a, Class<?>[] b)
a
- Class<?>[]; reflects the first constructorb
- Class<?>[]; reflects the second constructorpublic static boolean isMoreSpecific(Constructor<?> a, Constructor<?> b)
a
- Constructor<?>; reflects the first constructorb
- Constructor<?>; reflects the second constructorpublic static boolean isMoreSpecific(Method a, Method b)
a
- Method; reflects the first methodb
- Method; reflects the second methodpublic static boolean isVisible(Field field, Class<?> caller)
field
- Field; The fieldcaller
- Class<?>; The class of the caller for whom invocation visibility is checked.public static boolean isVisible(Constructor<?> constructor, Class<?> caller)
constructor
- Constructor<?>; The constructorcaller
- Class<?>; The class of the caller for whom invocation visibility is checked.public static boolean isVisible(Method method, Class<?> caller)
method
- Method; The methodcaller
- Class<?>; The class of the caller for whom invocation visibility is checked.public static Method[] matchSignature(Method[] methods, String name, Class<?>[] argTypes)
methods
- Method[]; which are methods to be filtered.name
- String; reflects the method's name, part of the signatureargTypes
- Class<?>[]; are the method's argument typespublic static boolean matchSignature(Method method, String name, Class<?>[] argTypes)
method
- Method; The method to be filtered.name
- String; reflects the method's name, part of the signatureargTypes
- Class<?>[]; are the method's argument typespublic static boolean matchSignature(Constructor<?> constructor, Class<?>[] argTypes)
constructor
- Constructor<?>; which are constructors to be filtered.argTypes
- Class<?>[]; are the constructor's argument typespublic static Constructor<?>[] matchSignature(Constructor<?>[] constructors, Class<?>[] argTypes)
constructors
- Constructor<?>[]; which are constructors to be filtered.argTypes
- Class<?>[]; are the constructor's argument typesCopyright © 2018–2019 Delft University of Technology. All rights reserved.