Package repast.simphony.util
Class ClassUtilities
java.lang.Object
repast.simphony.util.ClassUtilities
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Annotation>
TdeepAnnotationCheck
(Method method, Class<T> annotationClass) Checks a method for an annotation by checking the method itself and then any interfaces the method's class implements.static Field
deepFindField
(Class clazz, String name) Search for and return the named field in the current class and in its super classes.static Field[]
findFields
(Class<?> clazz, Class<? extends Annotation>... annotationsToLookFor) Inspects a class looking for fields marked with the specified annotation and returns all those fields that are marked.static Method
findFirstMethodWithArgs
(Class clazz, String name, int argCount) static Method
findGetter
(Class<?> clazz, String propertyName, Class<?>... args) static Method
findMethod
(Class<?> clazz, String methodName, Class<?>... params) Finds the named method with the specified parameters in the specified class.static Method[]
findMethods
(Class<?> clazz, Class<? extends Annotation>... annotationsToLookFor) Inspects a class looking for methods marked with the specified annotation and returns all those methods that are marked.static Method
findSetter
(Class<?> clazz, String propertyName, Class<?>... args) getClasses
(String classpath) Gets a list of classes on the specified classpath.static String
getPropertyName
(String name) static Object
static boolean
isNumericType
(Class clazz) static boolean
-
Field Details
-
doWarn
public static boolean doWarn
-
-
Constructor Details
-
ClassUtilities
public ClassUtilities()
-
-
Method Details
-
deepFindField
Search for and return the named field in the current class and in its super classes. If the field is not found, this throws a NoSuchFieldException- Parameters:
clazz
- the clazz to begin the search for the field in.name
- the name of the field to find- Returns:
- the found field
- Throws:
NoSuchFieldException
- is the field is not found
-
isNumericType
- Parameters:
clazz
- the type to test- Returns:
- true if the type is numeric, otherwise false
-
findMethods
public static Method[] findMethods(Class<?> clazz, Class<? extends Annotation>... annotationsToLookFor) Inspects a class looking for methods marked with the specified annotation and returns all those methods that are marked.- Parameters:
clazz
- the class to look intoannotationsToLookFor
- the annotation to check for on the class's methods- Returns:
- an array of the methods with the specified annotation
-
findFields
public static Field[] findFields(Class<?> clazz, Class<? extends Annotation>... annotationsToLookFor) Inspects a class looking for fields marked with the specified annotation and returns all those fields that are marked.- Parameters:
clazz
- the class to look intoannotationsToLookFor
- the annotation to check for on the class's fields- Returns:
- an array of the fields with the specified annotation
-
findMethod
Finds the named method with the specified parameters in the specified class. This will search in superclasses and attempt to match parameters using Class.isAssignable. If this fails to find any matches then it will try to convert all the Object primitives in params, if any, to their primitive representations and then redo the search.- Parameters:
clazz
- the class to find the method inmethodName
- the name of the methodparams
- the parameters types of the method, if null then it is assumed the method takes no arguments- Returns:
- the found method, or null if the method is not found.
-
findFirstMethodWithArgs
-
getPropertyName
-
findSetter
-
setValue
-
getValue
-
findGetter
-
deepAnnotationCheck
public static <T extends Annotation> T deepAnnotationCheck(Method method, Class<T> annotationClass) throws SecurityException Checks a method for an annotation by checking the method itself and then any interfaces the method's class implements. This allows for finding annotations set on methods in an interface, as these annotations do not carry over to the classes that implement the interface. This works by grabbing the passed in method's declaring class and searching its declared interfaces for the method with the same name and parameters. It then will repeat this process on the class's superclass until the current class has no super class. An example of what this will find annotations (deeply) on is:interface InterfaceWithAnnotation {
- Parameters:
method
- the method to check for annotationsannotationClass
-- Returns:
- Throws:
SecurityException
- } class ClassImplementingInterface implements InterfaceWithAnnotation { public void methodWithAnnotation() { } } Note: this checking only works on public methods.
-
getClasses
Gets a list of classes on the specified classpath.- Parameters:
classpath
- the class path- Returns:
- a list of classes on the specified classpath.
- Throws:
IOException
ClassNotFoundException
-