Package com.palantir.ptoss.util
Class Reflections
java.lang.Object
com.palantir.ptoss.util.Reflections
A collection of utility methods and classes to handle all the of the Java Reflection calls
 need to wire and fire bindings.
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic ObjectgetAnnotatedFields(Class<?> klass, Class<? extends Annotation> annotation) Returns the list of fields on this class annotated with the passedAnnotationgetAnnotatedFieldsForClassHierarchy(Class<?> klass, Class<? extends Annotation> annotation) Returns the list of fields on this class or any of its ancestors annotated with the passedAnnotation.static FieldgetFieldByName(Class<?> klass, String fieldName) Find aFieldbased on the field name.static <T> TgetFieldObject(Object object, Field field, Class<T> klass) getFieldsOfType(Class<?> klass, Class<?> targetClass) Gets all fields from a given class that are assignable from the target class.getFieldsOfTypeForClassHierarchy(Class<?> klass, Class<?> targetClass) Gets all fields assignable fromtargetClassin the passed class's type hierarchy.static List<ObjectFieldMethod>Returns all methods in the passed object's class hierarchy that do no not take parametersstatic <F,T> com.google.common.base.Function<F, T> getterFunction(Class<F> klass, Class<T> returnType, String getter) Returns aFunctionthat will read values from the named field from a passed object.getTypesOfType(Class<?> klass, Class<?> targetClass) Gets all inner classes from a given class that are assignable from the target class.getTypesOfTypeForClassHierarchy(Class<?> klass, Class<?> targetClass) Gets all inner classes assignable fromtargetClassin the passed class's type hierarchy.static booleanisClassAnnotatedForClassHierarchy(Object object, Class<? extends Annotation> annotation) Checks whether or not the specifiedAnnotationexists in the passedObject's class hierarchy.static booleanisFieldFinal(Field field) Returns whether or not the givenFieldis final.static booleanisFieldStatic(Field field) Returns whether or not the givenFieldis static.static booleanisMethodPublic(Method method) Returns whether or not the givenMethodis public.static voidvisitClassHierarchy(Class<?> klass, Visitor<Class<?>> visitor) Starting at the bottom of a class hierarchy, visit all classes (ancestors) in the hierarchy.
- 
Field Details
- 
Constructor Details- 
Reflectionspublic Reflections()
 
- 
- 
Method Details- 
visitClassHierarchyStarting at the bottom of a class hierarchy, visit all classes (ancestors) in the hierarchy. Does not visit interfaces.- Parameters:
- klass- Class to use as the bottom of the class hierarchy
- visitor- Visitor object
 
- 
getFieldObject
- 
isFieldFinalReturns whether or not the givenFieldis final.
- 
isFieldStaticReturns whether or not the givenFieldis static.
- 
isMethodPublicReturns whether or not the givenMethodis public.
- 
getFieldByNameFind aFieldbased on the field name. Will return private fields but will not look in superclasses.- Returns:
- null if there is no field found
 
- 
getTypesOfTypeGets all inner classes from a given class that are assignable from the target class.- Parameters:
- klass- type to query for inner-classes.
- targetClass- interface or class that inner classes must be assignable from to be returned.
- Returns:
- all inner classes in klassthat are assignable fromtargetClass
- See Also:
 
- 
getTypesOfTypeForClassHierarchyGets all inner classes assignable fromtargetClassin the passed class's type hierarchy.- Parameters:
- klass- starting point in the type stack to query for inner classes.
- targetClass- looks for inner classes that are assignable from this type.
- Returns:
- all inner classes in klass's type hierarchy assignable fromtargetclass
- See Also:
 
- 
getFieldsOfTypeGets all fields from a given class that are assignable from the target class.- Parameters:
- klass- type to query for fields.
- targetClass- interface or class that fields must be assignable from to be returned.
- Returns:
- all fields in klassthat are assignable fromtargetClass
- See Also:
 
- 
getFieldsOfTypeForClassHierarchyGets all fields assignable fromtargetClassin the passed class's type hierarchy.- Parameters:
- klass- starting point in the type stack to query for fields of the specified type.
- targetClass- looks for fields that are assignable from this type.
- Returns:
- all fields declared by classes in klass's type hierarchy assignable fromtargetclass
- See Also:
 
- 
evalEnum
- 
isClassAnnotatedForClassHierarchypublic static boolean isClassAnnotatedForClassHierarchy(Object object, Class<? extends Annotation> annotation) Checks whether or not the specifiedAnnotationexists in the passedObject's class hierarchy.- Parameters:
- object- object to check
- annotation- annotation to look for
- Returns:
- true is a class in this passed object's type hierarchy is annotated with the
 passed Annotation
 
- 
getAnnotatedFieldspublic static List<Field> getAnnotatedFields(Class<?> klass, Class<? extends Annotation> annotation) Returns the list of fields on this class annotated with the passedAnnotation- Parameters:
- klass- checks the- Fields on this class
- annotation- looks for this- Annotation
- Returns:
- list of all Fields that are annotated with the specifiedAnnotation
 
- 
getAnnotatedFieldsForClassHierarchypublic static List<Field> getAnnotatedFieldsForClassHierarchy(Class<?> klass, Class<? extends Annotation> annotation) Returns the list of fields on this class or any of its ancestors annotated with the passedAnnotation.- Parameters:
- klass- checks the- Fields on this class and its ancestors
- annotation- looks for this- Annotation
- Returns:
- list of all Fields that are annotated with the specifiedAnnotation
 
- 
getParameterlessMethodsForClassHierarchyReturns all methods in the passed object's class hierarchy that do no not take parameters- Parameters:
- object- object to query for parameterless methods
- Returns:
- a list ObjectFieldMethodtuples mapping the parameterless methods to the passed object.
 
- 
getterFunctionpublic static <F,T> com.google.common.base.Function<F,T> getterFunction(Class<F> klass, Class<T> returnType, String getter) Returns aFunctionthat will read values from the named field from a passed object.- Parameters:
- klass- type to read values from
- returnType- return type of read field
- getter- name of the field
- Returns:
- a Functionobject that, when applied to an instance ofklass, returns the of typereturnTypethat resides in fieldgetter
 
 
-