net.craftforge.reflection.managers
Class ClassManager

java.lang.Object
  extended by net.craftforge.reflection.managers.ClassManager

public class ClassManager
extends Object

Manages a class by caching all reflection actions provided by the manager.

Since:
14.03.2011
Author:
Christian Bick

Method Summary
 List<Field> getActualReferences()
          Gets all actual reference fields of a class.
 ConcurrentMap<String,List<Method>> getAllGetterMethods()
          Gets all getter methods of a class and groups them by their corresponding field names.
 List<Method> getAllMethodsAnnotatedWith(Class<? extends Annotation> annotationClass)
          Gets all methods being annotated with an annotation of the given annotation class.
 List<Field> getAllPropertiesAnnotatedWith(Class<? extends Annotation> annotationClass)
          Gets all fields which are annotated themselves or whose corresponding getters or setters are annotated with an annotation of the given annotation class.
 ConcurrentMap<String,List<Method>> getAllSetterMethods()
          Gets all setter methods of a class and groups them by their corresponding field names.
 List<Class<?>> getClassHierarchy()
          Gets a class hierarchy of the class as a list containing the class itself and all its super classes except of java.lang.Object.
 List<Class<?>> getCompleteClassHierarchy()
          Gets a class hierarchy of the class as a list containing the class itself and all its super classes as well as all implemented interfaces within the class hierarchy and their super interfaces.
 List<Method> getCompleteClassHierarchyMethods()
          Gets all declared methods.
static ClassManager getInstance(Class<?> clazz)
          Gets the class manager corresponding to the class.
static ClassManager getInstance(Field field)
          Gets the class manager corresponding to the field's declaring class
static ClassManager getInstance(Method method)
          Gets the class manager corresponding to the method's declaring class
 List<Class<?>> getInterfaceHierarchy()
          Gets a interface hierarchy of the class as a list containing the class's implemented interfaces and all their super interfaces.
 Annotation getMethodLevelAnnotation(Method method, Class<? extends Annotation> annotationClass)
          Gets the first occurrence of an annotation of the given annotation class at method level.
 Annotation getMethodOrTypeLevelAnnotation(Method method, Class<? extends Annotation> annotationClass)
          Gets the first annotation of an annotation class on the given method's or type level.
 Annotation[][] getMethodParameterAnnotations(Method method, Class<? extends Annotation> annotationClass)
          Gets all parameter annotations of a method.
 Annotation getPropertyLevelAnnotation(Field field, Class<? extends Annotation> annotationClass)
          Gets the first occurrence of an annotation of the given annotation class at field level or at method level of the corresponding setter and getter methods.
 Annotation getTypeLevelAnnotation(Class<? extends Annotation> annotationClass)
          Gets the first occurrence of an annotation of the given annotation class at type level.
 List<Field> getVirtualPrimitives()
          Gets all virtual primitives of a class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static ClassManager getInstance(Field field)
Gets the class manager corresponding to the field's declaring class

Parameters:
field - The field
Returns:
The corresponding ClassManager

getInstance

public static ClassManager getInstance(Method method)
Gets the class manager corresponding to the method's declaring class

Parameters:
method - The method
Returns:
The corresponding class manager

getInstance

public static ClassManager getInstance(Class<?> clazz)
Gets the class manager corresponding to the class.

Parameters:
clazz - The class
Returns:
The corresponding class manager

getTypeLevelAnnotation

public Annotation getTypeLevelAnnotation(Class<? extends Annotation> annotationClass)
Gets the first occurrence of an annotation of the given annotation class at type level. Searches within the complete class and interface hierarchy.

Parameters:
annotationClass - The annotation class
Returns:
First occurrence of the searched annotation, null if not found

getPropertyLevelAnnotation

public Annotation getPropertyLevelAnnotation(Field field,
                                             Class<? extends Annotation> annotationClass)
Gets the first occurrence of an annotation of the given annotation class at field level or at method level of the corresponding setter and getter methods. Searches within the complete class and interface hierarchy of the field's declaring class.

Parameters:
field - The field
annotationClass - The annotation class
Returns:
First occurrence of the searched annotation, null if not found

getMethodLevelAnnotation

public Annotation getMethodLevelAnnotation(Method method,
                                           Class<? extends Annotation> annotationClass)
Gets the first occurrence of an annotation of the given annotation class at method level. Searches within the complete class and interface hierarchy of the method's declaring class.

Parameters:
method - The method
annotationClass - The annotation class
Returns:
First occurrence of the searched annotation, null if not found

getMethodParameterAnnotations

public Annotation[][] getMethodParameterAnnotations(Method method,
                                                    Class<? extends Annotation> annotationClass)
Gets all parameter annotations of a method. Searches for a signature using the annotation of type annotation class within the complete class and interface hierarchy of the method's declaring class.

Parameters:
method - The method
annotationClass - The annotation class
Returns:
Two dimensional array - first dimension for the parameters, the second one for each parameter's annotation.

getMethodOrTypeLevelAnnotation

public Annotation getMethodOrTypeLevelAnnotation(Method method,
                                                 Class<? extends Annotation> annotationClass)
Gets the first annotation of an annotation class on the given method's or type level. Makes use of the complete class hierarchy. Prefers method annotations about type annotations.

Parameters:
method - The method
annotationClass - The annotation class
Returns:
The first found annotation

getAllMethodsAnnotatedWith

public List<Method> getAllMethodsAnnotatedWith(Class<? extends Annotation> annotationClass)
Gets all methods being annotated with an annotation of the given annotation class. Makes use of the complete class hierarchy.

Parameters:
annotationClass - The annotation class
Returns:
List of all annotated methods

getAllPropertiesAnnotatedWith

public List<Field> getAllPropertiesAnnotatedWith(Class<? extends Annotation> annotationClass)
Gets all fields which are annotated themselves or whose corresponding getters or setters are annotated with an annotation of the given annotation class. Makes use of the complete class hierarchy.

Parameters:
annotationClass - The annotation class
Returns:
List of all annotated properties

getClassHierarchy

public List<Class<?>> getClassHierarchy()
Gets a class hierarchy of the class as a list containing the class itself and all its super classes except of java.lang.Object. (bottom up)

Returns:
List containing the class and all its super classes except of java.lang.Object

getInterfaceHierarchy

public List<Class<?>> getInterfaceHierarchy()
Gets a interface hierarchy of the class as a list containing the class's implemented interfaces and all their super interfaces. (bottom up)

Returns:
List of classes that represent the interfaces

getCompleteClassHierarchy

public List<Class<?>> getCompleteClassHierarchy()
Gets a class hierarchy of the class as a list containing the class itself and all its super classes as well as all implemented interfaces within the class hierarchy and their super interfaces. (bottom up)

Returns:
List of classes - first all classes, second all interfaces

getCompleteClassHierarchyMethods

public List<Method> getCompleteClassHierarchyMethods()
Gets all declared methods. Searches within the complete class and interface hierarchy.

Returns:
List of all methods declared in the class hierarchy - first declared by classes, second declared by interfaces

getAllGetterMethods

public ConcurrentMap<String,List<Method>> getAllGetterMethods()
Gets all getter methods of a class and groups them by their corresponding field names.

Returns:
Map with keys representing the field names and values representing the corresponding getter methods

getAllSetterMethods

public ConcurrentMap<String,List<Method>> getAllSetterMethods()
Gets all setter methods of a class and groups them by their corresponding field names.

Returns:
Map with keys representing the field names and values representing the corresponding setter methods

getActualReferences

public List<Field> getActualReferences()
Gets all actual reference fields of a class. Searches within the complete class hierarchy. Actual references are represented by all classes that are not virtual primitives. So this method ignores references to primitive objects (Integer, Long, etc.) as well as to String and Date.

Returns:
List containing all actual references in the class hierarchy

getVirtualPrimitives

public List<Field> getVirtualPrimitives()
Gets all virtual primitives of a class. Searches within the complete class hierarchy. Virtual primitives are all real primitives, their object representation (Integer, Long etc.) as well as String and Date.

Returns:
List containing all virtual primitives in the class hierarchy


Copyright © 2011. All Rights Reserved.