|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.util.UtlReflection
public class UtlReflection
Reflection related utilities.
This class IS NOT intended to be used by end users.
Constructor Summary | |
---|---|
UtlReflection()
|
Method Summary | ||
---|---|---|
static void |
appendMethodAndCodeSource(Method method,
StringBuilder builder)
Append the method name and code source. |
|
static Collection<Field> |
collectAllFields(Class<?> clazz)
|
|
static void |
collectAllFields(Class<?> clazz,
Collection<Field> target)
Collects non public method from the given class and its supertypes. |
|
static Collection<Method> |
collectAllMethods(Class<?> clazz)
Collects public and non public method from the given class and its supertypes (excluding those methods from Object itself) |
|
static void |
collectNonPublicMethods(Class<?> clazz,
Collection<Method> target)
Collects non public method from the given class and its supertypes. |
|
static
|
getAnnotation(Method method,
Class<T> annotationClass)
Tests if an annotation is present on a method, or present on a super class or interface declaration of the method. |
|
static Set<String> |
getDecamelCasedNonObjectProperties(Class<?> type)
Gets the properties of a class excluding properties from java.lang.Object This method return the properties for the given class eliminating possible duplicates from decamelcasing. |
|
static Set<String> |
getDecamelcasedProperties(Class<?> type)
Gets the properties of a class. |
|
static Set<String> |
getDeclaredProperties(Class<?> type)
Gets the properties declared by the class (not including super type properties) |
|
static Method |
getGetter(Class<?> type,
String property)
Gets the accessor method for a given property of the type provided. |
|
static boolean |
getHasPropertyCheckerValue(Object object,
String name)
Checks if an object has a hasXXX method for the given non nested field and if so will call it and return its value. |
|
static Method |
getMethod(Class<?> type,
String name,
Class<?>... parameterTypes)
Looks up a method for a class. |
|
static Method |
getNonNestedAccessor(Class<?> type,
String field)
Gets the accessor for the given field or null if no such field accessor can be found. |
|
static Method |
getNonNestedChecker(Class<?> type,
String field)
Gets the check for the given field or null if no such field checker can be found. |
|
static
|
getNonNestedProperty(Object object,
String field)
Gets a property for the object at the given bean path. |
|
static Set<String> |
getNonObjectProperties(Class<?> type)
Gets the properties of a class excluding properties from java.lang.Object Note this method returns property names in both first letter lowercase and first letter uppercase form. |
|
static Set<String> |
getProperties(Class<?> type)
Gets the properties of a class. |
|
static
|
getProperty(Object object,
int pathOffset,
String... path)
Traverses the given bean path from the specified index to retrieve a value on the provided object. |
|
static
|
getProperty(Object object,
String path)
Gets a property for the object at the given bean path. |
|
static Class<?> |
getUnwrappedReturnType(Class<?> type,
String path)
Gets the return type of the accessor at the given bean path relative to the provided type. |
|
static boolean |
hasPath(Class<?> type,
String path)
Indicate whether the given type has the provided, possibly nested, unambiguous bean/field path. |
|
static boolean |
hasPath(Object object,
String path)
Indicate whether the given object has the provided, possibly nested, bean/field path. |
|
static boolean |
isAnnotationPresent(Method method,
Class<? extends Annotation> annotationClass)
Tests if an annotation is present on a method, or present on a super class declaration of the method. |
|
static void |
setNonNestedProperty(Object object,
String property,
Object value)
Looks for a setter method for the given property in the provided target object, and attempts to invoke the method with the supplied value. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public UtlReflection()
Method Detail |
---|
public static void collectNonPublicMethods(Class<?> clazz, Collection<Method> target)
clazz
- The class for which to collect methods.target
- The target.public static Collection<Method> collectAllMethods(Class<?> clazz)
Object
itself)
clazz
- The class for which to collect methods.public static Collection<Field> collectAllFields(Class<?> clazz)
clazz
- The class for which to collect fields.
public static void collectAllFields(Class<?> clazz, Collection<Field> target)
clazz
- The class for which to collect methods.target
- The target.public static final Class<?> getUnwrappedReturnType(Class<?> type, String path)
type
- The type at the bean path root.path
- The bean path of the field relative to the type
public static Method getGetter(Class<?> type, String property)
type
- The typeproperty
- The bean path of the property relative to the type.
public static boolean hasPath(Class<?> type, String path)
Note that a return value of false
does not mean that a concrete instance
of the class would yield false
for
hasPath(Object, String)
. For example consider:
Record.class, "attachment.zipCode"if Record.getAttachment return type Object.class, then if an instance of Record has an Address object as its attachment field, it would yield a return value of
true
for zipCode while this method would return false
.
type
- The type to check.path
- The path to check.
true
If the path exists.public static boolean hasPath(Object object, String path)
object
- The type to check.path
- The path to check.
true
If the path exists.public static <T> T getProperty(Object object, String path)
object
- The object to introspect.path
- The bean path which may be a '.' separated nested path.
public static void setNonNestedProperty(Object object, String property, Object value) throws NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
object
- The object on which to set the property.property
- The property name.value
- The value to set the property to (conversion will be attempted).
NoSuchMethodException
- if no property can be found for the given class.
InvocationTargetException
- If there is an error setting the property.
IllegalAccessException
- If the setter method is not accessible.
IllegalArgumentException
- If the arguments are of the wrong type and cannot be converted.public static <T> T getProperty(Object object, int pathOffset, String... path)
object
- The object to introspect.pathOffset
- The offset into the path to use for the bean path.path
- The bean path (potentially offset by path offset).
public static <T> T getNonNestedProperty(Object object, String field)
object
- The object to introspect.field
- The bean path which may not be a '.' separated nested path.
public static final boolean getHasPropertyCheckerValue(Object object, String name)
object
- The object.name
- The property.public static Method getNonNestedAccessor(Class<?> type, String field)
type
- The type.field
- The fields bean path name
public static Method getNonNestedChecker(Class<?> type, String field)
type
- The type.field
- The fields bean path name
public static final Set<String> getProperties(Class<?> type)
Note this method returns property names in both first letter lowercase
and first letter uppercase form. Use getDecamelcasedProperties(Class)
to avoid duplicates.
type
- The type for which to return properties.public static final Set<String> getDecamelcasedProperties(Class<?> type)
This method return the properties for the given class eliminating possible duplicates from decamelcasing.
type
- The type for which to return properties.public static final Set<String> getNonObjectProperties(Class<?> type)
Note this method returns property names in both first letter lowercase
and first letter uppercase form. Use getDecamelcasedProperties(Class)
to avoid duplicates.
type
- The type for which to return properties.public static final Set<String> getDecamelCasedNonObjectProperties(Class<?> type)
This method return the properties for the given class eliminating possible duplicates from decamelcasing.
type
- The type for which to return properties.public static Set<String> getDeclaredProperties(Class<?> type)
type
- The type for which to return properties.public static void appendMethodAndCodeSource(Method method, StringBuilder builder)
For example:
public void com.foo.Bar.someMethod(int) [/libs/myjar.jar]
method
- The method.builder
- The builder to which to append.public static Method getMethod(Class<?> type, String name, Class<?>... parameterTypes)
type
- The Type to search for the given method.name
- The method name.
public static <T extends Annotation> T getAnnotation(Method method, Class<T> annotationClass)
method
- The method.annotationClass
- The annotation.
public static boolean isAnnotationPresent(Method method, Class<? extends Annotation> annotationClass)
method
- The method.annotationClass
- The annotation.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |