Top Description Inners Fields Constructors Methods
org.springframework.expression.spel.support

public Class ReflectivePropertyAccessor

extends Object
implements PropertyAccessor
Class Inheritance
All Implemented Interfaces
org.springframework.expression.PropertyAccessor
Known Direct Subclasses
org.springframework.expression.spel.support.DataBindingPropertyAccessor
Imports
java.lang.reflect.Array, .Field, .Member, .Method, .Modifier, java.util.Arrays, .Collections, .Map, .Set, java.util.concurrent.ConcurrentHashMap, kotlin.jvm.JvmClassMappingKt, kotlin.reflect.KClass, kotlin.reflect.KMutableProperty, kotlin.reflect.KProperty, kotlin.reflect.full.KClasses, kotlin.reflect.jvm.ReflectJvmMapping, org.springframework.asm.MethodVisitor, org.springframework.core.KotlinDetector, .MethodParameter, org.springframework.core.convert.Property, .TypeDescriptor, org.springframework.expression.AccessException, .EvaluationContext, .EvaluationException, .PropertyAccessor, .TypedValue, org.springframework.expression.spel.CodeFlow, .CompilablePropertyAccessor, org.springframework.lang.Nullable, org.springframework.util.Assert, .ClassUtils, .ReflectionUtils, .StringUtils

A powerful PropertyAccessor that uses reflection to access properties for reading and possibly also for writing on a target instance.

A property can be referenced through a public getter method (when being read) or a public setter method (when being written), and also as a public field.

Authors
Andy Clement, Juergen Hoeller, Phillip Webb, Sam Brannen, Sebastien Deleuze
Since
3.0
See Also
StandardEvaluationContext, SimpleEvaluationContext, DataBindingPropertyAccessor

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
ReflectivePropertyAccessor.InvokerPair

Captures the member (method/field) to call reflectively to access a property value and the type descriptor for the value returned by the reflective call.

private static class
ReflectivePropertyAccessor.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

public static class
ReflectivePropertyAccessor.OptimalPropertyAccessor

An optimized form of a PropertyAccessor that will use reflection but only knows how to access a particular property on a particular class.

private static class

Field Summary

Modifier and TypeField and Description
private final boolean
private static final Set<Class<?>>
private static final Set<Class<?>>
private volatile ReflectivePropertyAccessor.InvokerPair
private final Map<ReflectivePropertyAccessor.PropertyCacheKey, ReflectivePropertyAccessor.InvokerPair>
private final Map<Class<?>, Method[]>
private final Map<ReflectivePropertyAccessor.PropertyCacheKey, TypeDescriptor>
private final Map<ReflectivePropertyAccessor.PropertyCacheKey, Member>

Constructor Summary

AccessConstructor and Description
public
ReflectivePropertyAccessor()

Create a new property accessor for reading as well writing.

public
ReflectivePropertyAccessor(boolean
whether to allow write operations on a target instance
allowWrite
)

Create a new property accessor for reading and possibly also writing.

Method Summary

Modifier and TypeMethod and Description
public boolean
canRead(EvaluationContext
the evaluation context in which the access is being attempted
context
,
Object
the target object upon which the property is being accessed
target
,
String
the name of the property being accessed
name
)

Implements org.springframework.expression.PropertyAccessor.canRead.

Called to determine if a resolver instance is able to access a specified property on a specified target object.

public boolean
canWrite(EvaluationContext
the evaluation context in which the access is being attempted
context
,
Object
the target object upon which the property is being accessed
target
,
String
the name of the property being accessed
name
)

Implements org.springframework.expression.PropertyAccessor.canWrite.

Called to determine if a resolver instance is able to write to a specified property on a specified target object.

public PropertyAccessor
createOptimalAccessor(EvaluationContext context, Object target, String name)

Attempt to create an optimized property accessor tailored for a property of a particular name on a particular class.

private Field
findField(String name, Class<?> clazz, Object target)

protected Field
findField(String name, Class<?> clazz, boolean mustBeStatic)

Find a field of a certain name on a specified class.

private Method
findGetterForProperty(String propertyName, Class<?> clazz, Object target)

protected Method
findGetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic)

Find a getter method for the specified property.

private Method
findMethodForProperty(String[] methodSuffixes, String prefix, Class<?> clazz, boolean mustBeStatic, int numberOfParams, Set<Class<?>> requiredReturnTypes)

private Method
findSetterForProperty(String propertyName, Class<?> clazz, Object target)

protected Method
findSetterForProperty(String propertyName, Class<?> clazz, boolean mustBeStatic)

Find a setter method for the specified property.

protected String
getPropertyMethodSuffix(String propertyName)

Return the method suffix for a given property name.

protected String[]
getPropertyMethodSuffixes(String propertyName)

Return the method suffixes for a given property name.

private Method[]
getSortedMethods(Class<?> clazz)

Return class methods ordered with non-bridge methods appearing higher.

public Class<?>[]
getSpecificTargetClasses()

Implements org.springframework.expression.PropertyAccessor.getSpecificTargetClasses.

Returns null which means this is a general purpose accessor.

private TypeDescriptor
protected boolean
isCandidateForProperty(Method
the Method to evaluate
method
,
Class<?>
the concrete target class that is being introspected
targetClass
)

Determine whether the given Method is a candidate for property access on an instance of the given target class.

private static boolean
isKotlinProperty(Method method, String methodSuffix)

public TypedValue
read(EvaluationContext
the evaluation context in which the access is being attempted
context
,
Object
the target object upon which the property is being accessed
target
,
String
the name of the property being accessed
name
)

Implements org.springframework.expression.PropertyAccessor.read.

Called to read a property from a specified target object.

public void
write(EvaluationContext
the evaluation context in which the access is being attempted
context
,
Object
the target object upon which the property is being accessed
target
,
String
the name of the property being accessed
name
,
Object
the new value for the property
newValue
)

Implements org.springframework.expression.PropertyAccessor.write.

Called to write to a property on a specified target object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait