public final class Accessors
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Accessors.SynchronizedFieldAccessor
Represents a field accessor that synchronizes access to the underlying field.
|
Modifier and Type | Method and Description |
---|---|
static FieldAccessor |
getCached(FieldAccessor inner)
Retrieve a field accessor that will cache the content of the field.
|
static ConstructorAccessor |
getConstructorAccessor(java.lang.Class<?> instanceClass,
java.lang.Class<?>... parameters)
Retrieve a constructor accessor for a constructor with the given signature.
|
static ConstructorAccessor |
getConstructorAccessor(java.lang.reflect.Constructor<?> constructor)
Retrieve a constructor accessor for a particular constructor, avoding checked exceptions.
|
static ConstructorAccessor |
getConstructorAccessorOrNull(java.lang.Class<?> clazz,
java.lang.Class<?>... parameters)
Find a specific constructor in a class.
|
static FieldAccessor |
getFieldAcccessorOrNull(java.lang.Class<?> clazz,
java.lang.String fieldName,
java.lang.Class<?> fieldType)
Retrieve a field accessor for a field with the given name and equivalent type, or NULL.
|
static FieldAccessor |
getFieldAccessor(java.lang.Class<?> instanceClass,
java.lang.Class<?> fieldClass,
boolean forceAccess)
Retrieve an accessor for the first field of the given type.
|
static FieldAccessor |
getFieldAccessor(java.lang.Class<?> instanceClass,
java.lang.String fieldName,
boolean forceAccess)
Retrieve an accessor for the first field of the given type.
|
static FieldAccessor |
getFieldAccessor(java.lang.reflect.Field field)
Retrieve a field accessor from a given field that uses unchecked exceptions.
|
static FieldAccessor |
getFieldAccessor(java.lang.reflect.Field field,
boolean forceAccess)
Retrieve a field accessor from a given field that uses unchecked exceptions.
|
static FieldAccessor[] |
getFieldAccessorArray(java.lang.Class<?> instanceClass,
java.lang.Class<?> fieldClass,
boolean forceAccess)
Retrieve an accessor (in declared order) for every field of the givne type.
|
static MethodAccessor |
getMethodAccessor(java.lang.Class<?> instanceClass,
java.lang.String methodName,
java.lang.Class<?>... parameters)
Retrieve a method accessor for a method with the given name and signature.
|
static MethodAccessor |
getMethodAccessor(java.lang.reflect.Method method)
Retrieve a method accessor for a particular method, avoding checked exceptions.
|
static MethodAccessor |
getMethodAccessor(java.lang.reflect.Method method,
boolean forceAccess)
Retrieve a method accessor for a particular method, avoding checked exceptions.
|
static FieldAccessor |
getSynchronized(FieldAccessor accessor)
Retrieve a field accessor where the write operation is synchronized on the current field value.
|
public static FieldAccessor getFieldAccessor(java.lang.Class<?> instanceClass, java.lang.Class<?> fieldClass, boolean forceAccess)
instanceClass
- - the type of the instance to retrieve.fieldClass
- - type of the field to retrieve.forceAccess
- - whether or not to look for private and protected fields.java.lang.IllegalArgumentException
- If the field cannot be found.public static FieldAccessor[] getFieldAccessorArray(java.lang.Class<?> instanceClass, java.lang.Class<?> fieldClass, boolean forceAccess)
instanceClass
- - the type of the instance to retrieve.fieldClass
- - type of the field(s) to retrieve.forceAccess
- - whether or not to look for private and protected fields.public static FieldAccessor getFieldAccessor(java.lang.Class<?> instanceClass, java.lang.String fieldName, boolean forceAccess)
instanceClass
- - the type of the instance to retrieve.fieldClass
- - type of the field to retrieve.forceAccess
- - whether or not to look for private and protected fields.java.lang.IllegalArgumentException
- If the field cannot be found.public static FieldAccessor getFieldAccessor(java.lang.reflect.Field field)
field
- - the field.public static FieldAccessor getFieldAccessor(java.lang.reflect.Field field, boolean forceAccess)
field
- - the field.forceAccess
- - whether or not to skip Java access checking.public static FieldAccessor getFieldAcccessorOrNull(java.lang.Class<?> clazz, java.lang.String fieldName, java.lang.Class<?> fieldType)
clazz
- - the declaration class.fieldName
- - the field name.fieldType
- - assignable field type.public static ConstructorAccessor getConstructorAccessorOrNull(java.lang.Class<?> clazz, java.lang.Class<?>... parameters)
clazz
- - the class.parameters
- - the signature of the constructor to find.public static FieldAccessor getCached(FieldAccessor inner)
Note that we don't check if the underlying field has changed after the value has been cached, so it's best to use this on final fields.
inner
- - the accessor.public static FieldAccessor getSynchronized(FieldAccessor accessor)
accessor
- - the accessor.public static MethodAccessor getMethodAccessor(java.lang.Class<?> instanceClass, java.lang.String methodName, java.lang.Class<?>... parameters)
instanceClass
- - the parent class.methodName
- - the method name.parameters
- - the parameters.public static MethodAccessor getMethodAccessor(java.lang.reflect.Method method)
method
- - the method to access.public static MethodAccessor getMethodAccessor(java.lang.reflect.Method method, boolean forceAccess)
method
- - the method to access.forceAccess
- - whether or not to skip Java access checking.public static ConstructorAccessor getConstructorAccessor(java.lang.Class<?> instanceClass, java.lang.Class<?>... parameters)
instanceClass
- - the parent class.parameters
- - the parameters.java.lang.IllegalArgumentException
- If we cannot find this constructor.java.lang.IllegalStateException
- If we cannot access reflection.public static ConstructorAccessor getConstructorAccessor(java.lang.reflect.Constructor<?> constructor)
constructor
- - the constructor to access.