Package org.codehaus.groovy.reflection
Class CachedField
java.lang.Object
groovy.lang.MetaProperty
org.codehaus.groovy.reflection.CachedField
- All Implemented Interfaces:
MetaMember
Caches reflection information about a single field for efficient access and modification.
Extends MetaProperty to integrate with the meta-programming framework.
Handles lazy field accessibility and provides property-like access to field values.
-
Field Summary
Fields inherited from class groovy.lang.MetaProperty
name, PROPERTY_SET_PREFIX, type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasAccessMethod(MethodHandles.Lookup lookup) Creates a method handle that provides getter access to this field via MethodHandles API.Returns the underlying JavaFieldobject, making it accessible if necessary.Returns the class that declares this field.intReturns the access modifiers.getProperty(Object object) booleanisAnnotationPresent(Class<? extends Annotation> annotationType) Checks whether the underlying field has the specified annotation.voidsetProperty(Object object, Object newValue) Sets the property on the given object to the new value.Methods inherited from class groovy.lang.MetaProperty
getGetterName, getName, getSetterName, getTypeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface groovy.lang.MetaMember
isFinal, isPackagePrivate, isPrivate, isProtected, isPublic, isStatic, isSynthetic
-
Constructor Details
-
CachedField
Constructs aCachedFieldfor the given Java field.- Parameters:
field- the field to cache reflection information for
-
-
Method Details
-
getCachedField
Returns the underlying JavaFieldobject, making it accessible if necessary.- Returns:
- the cached field with accessibility ensured
-
getDeclaringClass
Returns the class that declares this field.- Returns:
- the declaring class
-
isAnnotationPresent
Checks whether the underlying field has the specified annotation. UnlikegetCachedField(), this does not trigger accessibility changes.- Since:
- 6.0.0
-
getModifiers
public int getModifiers()Returns the access modifiers.- Specified by:
getModifiersin interfaceMetaMember- Overrides:
getModifiersin classMetaProperty- Returns:
Modifier.PUBLIC
-
getProperty
- Specified by:
getPropertyin classMetaProperty- Returns:
- the property of the given object
-
setProperty
Sets the property on the given object to the new value.- Specified by:
setPropertyin classMetaProperty- Parameters:
object- on which to set the propertynewValue- the new value of the property
-
asAccessMethod
Creates a method handle that provides getter access to this field via MethodHandles API. Attempts to unreflect the field, automatically making it accessible if needed.- Parameters:
lookup- the method handles lookup context- Returns:
- a method handle providing getter access to this field
- Throws:
IllegalAccessException- if the field cannot be accessed even with accessibility adjustments
-