public class ClassUtil extends Object
Modifier and Type | Field and Description |
---|---|
static Class<?>[] |
BOOLEAN |
static Class<?>[] |
BYTE |
static Class<?>[] |
CHAR |
static Class<?>[] |
DOUBLE |
static Class<?>[] |
FLOAT |
static Class<?>[] |
INT |
static Class<?>[] |
INTEGER |
static Class<?>[] |
LONG |
static Class<?>[] |
NUMBER |
static Class<?>[] |
SHORT |
static Class<?>[] |
STRING |
Constructor and Description |
---|
ClassUtil() |
Modifier and Type | Method and Description |
---|---|
static boolean |
doesImplement(Class<?> testMe,
Class<?> aInterface)
Determines if the supplied testMe class implements the supplied interface.
|
static List<Field> |
getAllDeclaredFields(Class<?> aClass)
Retrieves all of the fields defined in the supplied
Class . |
static List<Method> |
getAllDeclaredMethods(Class<?> aClass)
Retrieves all of the methods defined in the supplied
Class . |
static <T extends Annotation> |
getAnnotation(Class<T> annotation,
Class<?> ownerClass,
Method method)
Retrieves the annotation from the method, if it is not on the method, the parent
is checked.
|
static Object |
getFieldValue(Object instance,
String fieldName)
Retrieve a data members value.
|
static Field |
getInheritedField(Class<?> aClass,
String fieldName)
Get the data member by name.
|
static Method |
getInheritedMethodByName(Class<?> aClass,
String name,
Class<?>[] parameterTypes)
Get the method by name and parameter types.
|
static Method |
getMethodByAnnotationAlias(Class<?> aClass,
String methodName)
|
static Method |
getMethodByName(Class<?> aClass,
String methodName,
Class<?>... params)
Retrieves a method by name (grabs the first if overloaded).
|
static List<Method> |
getMethodsByAnnotationAlias(Class<?> aClass,
String methodName)
Retrieves the method names in which have the
LeolaMethod annotation with the LeolaMethod.alias() of
the supplied 'methodName' |
static List<Method> |
getMethodsByName(Class<?> aClass,
String methodName)
Retrieves all the overloaded methods by the supplied name
|
static Object |
getStaticFieldValue(Class<?> aClass,
String fieldName)
Retrieve a class members value.
|
static boolean |
inheritsFrom(Class<?> child,
Class<?> parent)
Determines if the supplied child class inherits from the supplied parent class.
|
static Object |
invokeMethod(List<Method> overloads,
Object instance,
LeoObject[] args)
Attempts to find the best matching overloaded
Method . |
static Object |
invokeMethod(Method method,
Object owner,
LeoObject[] params)
Invokes the supplied method.
|
static Object |
invokeMethod(Method method,
Object owner,
Object[] params)
Invokes a method reflectively.
|
static boolean |
isNativeClass(String className)
Determines if the supplied class name is a native class.
|
static boolean |
isType(Class<?> type,
Class<?>... classes)
|
static LeoNativeClass |
newNativeInstance(String className,
LeoObject... params)
Creates a new
LeoNativeClass based off of the Java fully qualified name and supplied parameters. |
static Class<?> |
primitiveToWrapper(Class<?> cls) |
static Class<?> |
wrapperToPrimitive(Class<?> cls) |
public static final Class<?>[] STRING
public static final Class<?>[] BOOLEAN
public static final Class<?>[] BYTE
public static final Class<?>[] CHAR
public static final Class<?>[] SHORT
public static final Class<?>[] INT
public static final Class<?>[] LONG
public static final Class<?>[] FLOAT
public static final Class<?>[] DOUBLE
public static final Class<?>[] INTEGER
public static final Class<?>[] NUMBER
public static Method getMethodByName(Class<?> aClass, String methodName, Class<?>... params)
methodName
- public static List<Method> getMethodsByName(Class<?> aClass, String methodName)
aClass
- methodName
- public static List<Method> getMethodsByAnnotationAlias(Class<?> aClass, String methodName)
LeolaMethod
annotation with the LeolaMethod.alias()
of
the supplied 'methodName'aClass
- methodName
- LeolaMethod
annotation with the matching alias namepublic static Method getMethodByAnnotationAlias(Class<?> aClass, String methodName)
aClass
- methodName
- Method
if found, otherwise null
public static Object invokeMethod(List<Method> overloads, Object instance, LeoObject[] args)
overloads
- instance
- args
- public static Object invokeMethod(Method method, Object owner, LeoObject[] params) throws LeolaRuntimeException
method
- the method to be executedowner
- the instance owner of the methodparams
- the parameters to be usedLeolaRuntimeException
public static Object invokeMethod(Method method, Object owner, Object[] params) throws LeolaRuntimeException
method
- the method to be executedowner
- the instance owner of the methodparams
- the parameters to be usedLeolaRuntimeException
public static Object getFieldValue(Object instance, String fieldName)
instance
- the instance of a classfieldName
- the data member name, in which to retrieve its valuepublic static Object getStaticFieldValue(Class<?> aClass, String fieldName)
aClass
- the class in which to retrieve a fieldfieldName
- the class member name, in which to retrieve its valuepublic static boolean isNativeClass(String className)
className
- the fully qualified Java class namepublic static boolean isType(Class<?> type, Class<?>... classes)
type
- the type to checkclasses
- the classes to compare type againstpublic static boolean inheritsFrom(Class<?> child, Class<?> parent)
child
- parent
- public static boolean doesImplement(Class<?> testMe, Class<?> aInterface)
testMe
- aInterface
- public static List<Method> getAllDeclaredMethods(Class<?> aClass)
Class
. This will navigate up the class
hierarchy up until the Object class is reached.
This will not grab any methods annotated with LeolaIgnore
.
public static List<Field> getAllDeclaredFields(Class<?> aClass)
Class
. This will navigate up the class
hierarchy up until the Object class is reached.
This will not grab any fields annotated with LeolaIgnore
.
public static Method getInheritedMethodByName(Class<?> aClass, String name, Class<?>[] parameterTypes)
Class.getMethod(String, Class...)
.aClass
- the class to checkmethodName
- the methods nameparameterTypes
- the parameter types.Method
if found; otherwise null.public static Field getInheritedField(Class<?> aClass, String fieldName)
aClass
- the class to checkfieldName
- the data member nameField
if found; otherwise null.public static <T extends Annotation> T getAnnotation(Class<T> annotation, Class<?> ownerClass, Method method)
annotation
- the annotation to look forownerClass
- the class in which this method belongs tomethod
- the method which should be probed for annotationspublic static LeoNativeClass newNativeInstance(String className, LeoObject... params) throws LeolaRuntimeException
LeoNativeClass
based off of the Java fully qualified name and supplied parameters.className
- the fully qualified Java class nameparams
- the parameters used to construct the instanceLeoNativeClass
LeolaRuntimeException
Copyright © 2010–2015. All rights reserved.