Class MetaClassImpl
- All Implemented Interfaces:
MetaClass,MetaObjectProtocol,MutableMetaClass
- Direct Known Subclasses:
ClosureMetaClass,ExpandoMetaClass,ProxyMetaClass
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThis is a helper class which is used only by indy. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Object[]Shared empty argument array used by MOP dispatch helpers.protected MetaMethodEffectivegetPropertyhandler discovered for this meta class.protected static final StringConventional Groovy instanceinvokeMethodhook name.protected MetaMethodEffectiveinvokeMethodhandler discovered for this meta class.protected final booleanIndicates whethertheClassimplementsGroovyObject.protected final booleanprotected final MetaMethodIndexMethod index used for Groovy method selection and caching.protected static final StringConventional Groovy instancemethodMissinghook name.protected static final StringConventional Groovy instancepropertyMissinghook name.protected MetaClassRegistryRegistry that owns this meta class.protected MetaMethodEffectivesetPropertyhandler discovered for this meta class.protected static final StringSynthetic method name used for staticmethodMissingdispatch.protected static final StringSynthetic method name used for staticpropertyMissingdispatch.protected final CachedClassCached reflection view fortheClass.protected final ClassJava class represented by this meta class. -
Constructor Summary
ConstructorsConstructorDescriptionMetaClassImpl(MetaClassRegistry registry, Class theClass) Constructor with registry setting methods to nullMetaClassImpl(MetaClassRegistry registry, Class theClass, MetaMethod[] add) Constructor with registryMetaClassImpl(Class theClass) Constructor that sets the methods to nullMetaClassImpl(Class theClass, MetaMethod[] add) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new MetaBeanProperty to this MetaClassvoidaddMetaMethod(MetaMethod method) Adds a MetaMethod to this class.protected voidaddMetaMethodToIndex(MetaMethod method, Map<String, MetaMethodIndex.Cache> cacheIndex) Adds a meta method to the supplied method index after standard-hook bookkeeping.voidaddNewInstanceMethod(Method method) Adds an instance method to this metaclass.voidaddNewStaticMethod(Method method) Adds a static method to this metaclass.protected voidapplyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors) Turns JavaBeans property descriptors into Groovy meta properties.protected final voidcheckIfGroovyObjectMethod(MetaMethod metaMethod) Checks if the metaMethod is getProperty, setProperty, or invokeMethod.protected voidchecks if the initialisation of the class id complete.protected ObjectchooseMethod(String methodName, Object methodOrList, Class[] arguments) Chooses the correct method to use from a list of methods which match by name.protected voidremove all method call cache entries.createConstructorSite(CallSite site, Object[] args) Create a CallSiteprotected static StringcreateErrorMessageForAmbiguity(String theClassName, String name, Class[] arguments, LinkedList matches) Creates the diagnostic message for an ambiguous overload selection.createPogoCallCurrentSite(CallSite site, Class sender, Object[] args) Create a CallSitecreatePogoCallSite(CallSite site, Object[] args) Create a CallSitecreatePojoCallSite(CallSite site, Object receiver, Object[] args) Create a CallSitecreateStaticSite(CallSite site, Object[] args) Create a CallSiteprotected MetaMethodcreateTransformMetaMethod(MetaMethod method) Wraps a meta method so single-list arguments are expanded before invocation.protected static ObjectdoChooseMostSpecificParams(String theClassName, String name, List matchingMethods, Class[] arguments, boolean checkParameterCompatibility) Chooses the most specific overload among matching parameter type candidates.protected voiddropMethodCache(String name) Clears cached instance method selections for the supplied method name.protected voiddropStaticMethodCache(String name) Clears cached static method selections for the supplied method name.protected static MetaMethodfindMethodInClassHierarchy(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass) Searches a meta-class hierarchy for the most specific visible method.protected MetaMethodfindMixinMethod(String methodName, Class[] arguments) Searches for a matching mixin method.protected static MetaMethodfindOwnMethod(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass, MetaMethod method) Chooses the best method declared directly on the supplied meta class.protected MetaBeanPropertyfindPropertyInClassHierarchy(String propertyName, CachedClass theClass) Searches the class hierarchy for a mutable meta-class bean property.Retrieves a list of additional MetaMethods held by this classgetAttribute(Class sender, Object object, String attribute, boolean useSuper) Retrieves the value of an attribute (field).getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass) Retrieves the value of an attribute (field).getAttribute(Object object, String attribute) Retrieves the value of an attribute (field).Returns the ClassInfo for the contained ClassObtains a reference to the original AST for the MetaClass if it is available at runtimegetEffectiveGetMetaProperty(Class sender, Object object, String name, boolean useSuper) Returns the effective readable meta property for a property access.getMetaMethod(String name, Object[] argTypes) Retrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethodRetrieves the list of MetaMethods held by this class.getMetaProperty(String name) Returns a MetaProperty for the given name or null if it doesn't existRetrieves the list of MetaMethods held by the class.getMethodWithCaching(Class sender, String methodName, Object[] arguments, boolean isCallToSuper) Resolves a method and caches the selection for the supplied argument types.getMethodWithoutCaching(Class sender, String methodName, Class[] arguments, boolean isCallToSuper) Resolves a method without populating the method cache.protected static Class<?>getNonClosureOuter(Class<?> c) Returns the available properties for this type.getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass) Retrieves a property on the given receiver for the specified arguments.getProperty(Object object, String property) Retrieves a property on the given object for the specified arguments.Returns the registry for this metaclassgetStaticMetaMethod(String name, Object[] argTypes) Retrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethodprotected ObjectgetSubclassMetaMethods(String methodName) Returns subclass-scoped meta methods contributed by specialized meta classes.protected LinkedList<CachedClass>Returns the cached super-class chain used while building method and property indexes.final CachedClassReturns the cached class for this metaclassReturns the class this metaclass represents.intReturns version of the contained Classprotected static longhandleMatches(long matchesDistance, LinkedList matches, Object method, long dist) Updates the current best-match set using the supplied distance metric.booleanindicates is the metaclass method invocation for non-static methods is done through a custom invoker object.booleanindicates is the metaclass method invocation for static methods is done through a custom invoker object.hasProperty(Object obj, String name) Returns true of the implementing MetaClass has a property of the given namevoidIncrements version of the contained ClassvoidComplete the initialisation process.invokeConstructor(Object[] arguments) Invokes a constructor for the given arguments.invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass) Invokes a method on the given receiver for the specified arguments.invokeMethod(Object object, String methodName, Object arguments) Invoke a method on the given object with the given arguments.invokeMethod(Object object, String methodName, Object[] arguments) Invokes a method on the given receiver for the specified arguments.invokeMissingMethod(Object instance, String methodName, Object[] arguments) Invoke a missing method on the given object with the given arguments.invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Invoke a missing property on the given object with the given arguments.invokeStaticMethod(Object object, String methodName, Object[] arguments) Invokes a static method on the given Object with the given name and arguments.protected ObjectinvokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Hook to deal with the case of missing property for static properties.booleanIndicates if the represented class is an instance of theGroovyObjectclass.protected booleanIndicates whether this meta class finished initialization.booleanReturns whether this MetaClassImpl has been modified.booleanIndicates whether permissive property access semantics are enabled.protected voidCallback invoked when agetPropertyimplementation is discovered.protected voidCallback invoked when aninvokeMethodimplementation is discovered.protected voidonMixinMethodFound(MetaMethod method) Callback invoked when a mixin method is discovered during initialization.protected voidCallback invoked when asetPropertyimplementation is discovered.protected voidCallback invoked when a super-class method is discovered during initialization.protected voidCallback invoked when a super-class bean property is discovered during initialization.pickMethod(String methodName, Class[] arguments) Selects a method by name and argument classes.protected voidRebuilds method, property and call-site state for this meta class.respondsTo(Object obj, String name) Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments.respondsTo(Object obj, String name, Object[] argTypes) Returns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.retrieveConstructor(Class[] arguments) Resolves a constructor by parameter types.retrieveConstructor(Object[] arguments) This is a helper method which is used only by indy.retrieveStaticMethod(String methodName, Object[] arguments) Resolves a static method and caches the selection when possible.intselectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments) Internal method to support Groovy runtime.voidsetAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass) Sets an attribute on the given receiver for the specified arguments.voidsetAttribute(Object object, String attribute, Object newValue) Sets the value of an attribute (field).protected voidsetInitialized(boolean initialized) Updates the initialization flag for this meta class.voidsetPermissivePropertyAccess(boolean permissivePropertyAccess) Enables or disables permissive property access semantics.voidsetProperties(Object bean, Map map) Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to setvoidsetProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) Writes a property on the given receiver for the specified arguments.voidsetProperty(Object object, String property, Object newValue) Sets a property on the given object for the specified arguments.toString()Returns a string representation of this metaclass
-
Field Details
-
EMPTY_ARGUMENTS
Shared empty argument array used by MOP dispatch helpers. -
STATIC_METHOD_MISSING
Synthetic method name used for staticmethodMissingdispatch.- See Also:
-
STATIC_PROPERTY_MISSING
Synthetic method name used for staticpropertyMissingdispatch.- See Also:
-
METHOD_MISSING
Conventional Groovy instancemethodMissinghook name.- See Also:
-
PROPERTY_MISSING
Conventional Groovy instancepropertyMissinghook name.- See Also:
-
INVOKE_METHOD_METHOD
Conventional Groovy instanceinvokeMethodhook name.- See Also:
-
theClass
Java class represented by this meta class. -
theCachedClass
Cached reflection view fortheClass. -
isGroovyObject
protected final boolean isGroovyObjectIndicates whethertheClassimplementsGroovyObject. -
isMap
protected final boolean isMap -
metaMethodIndex
Method index used for Groovy method selection and caching. -
getPropertyMethod
EffectivegetPropertyhandler discovered for this meta class. -
invokeMethodMethod
EffectiveinvokeMethodhandler discovered for this meta class. -
setPropertyMethod
EffectivesetPropertyhandler discovered for this meta class. -
registry
Registry that owns this meta class.
-
-
Constructor Details
-
MetaClassImpl
Constructor- Parameters:
theClass- The class this is the metaclass foradd- The methods for this class
-
MetaClassImpl
Constructor that sets the methods to null- Parameters:
theClass- The class this is the metaclass for
-
MetaClassImpl
Constructor with registry- Parameters:
registry- The metaclass registry for this MetaClasstheClass- The classadd- The methods
-
MetaClassImpl
Constructor with registry setting methods to null- Parameters:
registry- The metaclass registry for this MetaClasstheClass- The class
-
-
Method Details
-
getTheCachedClass
Returns the cached class for this metaclass- Returns:
- The cached class.
-
getRegistry
Returns the registry for this metaclass- Returns:
- The registry
-
respondsTo
Description copied from interface:MetaObjectProtocolReturns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name and arguments types.
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
- Specified by:
respondsToin interfaceMetaObjectProtocol- Parameters:
obj- The object to inspectname- The name of the method of interestargTypes- The argument types to match against- Returns:
- A List of MetaMethods matching the argument types which will be empty if no matching methods exist
- See Also:
-
respondsTo
Description copied from interface:MetaObjectProtocolReturns an object satisfying Groovy truth if the implementing MetaClass responds to a method with the given name regardless of arguments. In other words this method will return for foo() and foo(String).
Note that this method's return value is based on realised methods and does not take into account objects or classes that implement invokeMethod or methodMissing
This method is "safe" in that it will always return a value and never throw an exception
- Specified by:
respondsToin interfaceMetaObjectProtocol- Parameters:
obj- The object to inspectname- The name of the method of interest- Returns:
- A List of MetaMethods which will be empty if no methods with the given name exist
- See Also:
-
hasProperty
Description copied from interface:MetaObjectProtocolReturns true of the implementing MetaClass has a property of the given name
Note that this method will only return true for realised properties and does not take into account implementation of getProperty or propertyMissing
- Specified by:
hasPropertyin interfaceMetaObjectProtocol- Parameters:
obj- The object to inspectname- The name of the property- Returns:
- The MetaProperty or null if it doesn't exist
- See Also:
-
getMetaProperty
Description copied from interface:MetaObjectProtocolReturns a MetaProperty for the given name or null if it doesn't exist- Specified by:
getMetaPropertyin interfaceMetaObjectProtocol- Parameters:
name- The name of the MetaProperty- Returns:
- A MetaProperty or null
- See Also:
-
getStaticMetaMethod
Description copied from interface:MetaObjectProtocolRetrieves a static MetaMethod for the given name and argument values, using the types of the arguments to establish the chosen MetaMethod- Specified by:
getStaticMetaMethodin interfaceMetaObjectProtocol- Parameters:
name- The name of the MetaMethodargTypes- The argument types- Returns:
- A MetaMethod or null if it doesn't exist
- See Also:
-
getMetaMethod
Description copied from interface:MetaObjectProtocolRetrieves an instance MetaMethod for the given name and argument values, using the types of the argument values to establish the chosen MetaMethod- Specified by:
getMetaMethodin interfaceMetaObjectProtocol- Parameters:
name- The name of the MetaMethodargTypes- Array containing - 1) the argument values (using which their types are then inferred), or 2) the corresponding argument types- Returns:
- A MetaMethod or null if it doesn't exist
- See Also:
-
getTheClass
Returns the class this metaclass represents.- Specified by:
getTheClassin interfaceMetaObjectProtocol- Returns:
- The java.lang.Class instance
-
isGroovyObject
public boolean isGroovyObject()Indicates if the represented class is an instance of theGroovyObjectclass. -
getSuperClasses
Returns the cached super-class chain used while building method and property indexes.- Returns:
- the cached super classes in lookup order
-
isModified
public boolean isModified()Returns whether this MetaClassImpl has been modified. Since MetaClassImpl is not designed for modification this method always returns false- Specified by:
isModifiedin interfaceMutableMetaClass- Returns:
- false
-
addNewInstanceMethod
Adds an instance method to this metaclass.- Specified by:
addNewInstanceMethodin interfaceMutableMetaClass- Parameters:
method- The method to be added
-
addNewStaticMethod
Adds a static method to this metaclass.- Specified by:
addNewStaticMethodin interfaceMutableMetaClass- Parameters:
method- The method to be added
-
invokeMethod
Invoke a method on the given object with the given arguments.- Specified by:
invokeMethodin interfaceMetaObjectProtocol- Parameters:
object- The object the method should be invoked on.methodName- The name of the method to invoke.arguments- The arguments to the invoked method as null, a Tuple, an array or a single argument of any type.- Returns:
- The result of the method invocation.
- See Also:
-
invokeMissingMethod
Invoke a missing method on the given object with the given arguments.- Specified by:
invokeMissingMethodin interfaceMetaClass- Parameters:
instance- The object the method should be invoked on.methodName- The name of the method to invoke.arguments- The arguments to the invoked method.- Returns:
- The result of the method invocation.
- See Also:
-
invokeMissingProperty
public Object invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Invoke a missing property on the given object with the given arguments.- Specified by:
invokeMissingPropertyin interfaceMetaClass- Parameters:
instance- The object the method should be invoked on.propertyName- The name of the property to invoke.optionalValue- The (optional) new value for the propertyisGetter- Whether the method is a getter- Returns:
- The result of the method invocation.
-
onSuperPropertyFoundInHierarchy
Callback invoked when a super-class bean property is discovered during initialization.- Parameters:
property- the inherited property
-
onMixinMethodFound
Callback invoked when a mixin method is discovered during initialization.- Parameters:
method- the discovered mixin method
-
onSuperMethodFoundInHierarchy
Callback invoked when a super-class method is discovered during initialization.- Parameters:
method- the inherited method
-
onInvokeMethodFoundInHierarchy
Callback invoked when aninvokeMethodimplementation is discovered.- Parameters:
method- the discovered handler
-
onSetPropertyFoundInHierarchy
Callback invoked when asetPropertyimplementation is discovered.- Parameters:
method- the discovered handler
-
onGetPropertyFoundInHierarchy
Callback invoked when agetPropertyimplementation is discovered.- Parameters:
method- the discovered handler
-
invokeStaticMissingProperty
protected Object invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter) Hook to deal with the case of missing property for static properties. The method attempts to look up "$static_propertyMissing" handlers and invoke them otherwise throws a MissingPropertyException.- Parameters:
instance- the class instancepropertyName- the name of the propertyoptionalValue- the value in the case of a setterisGetter- true for property read, false for property write- Returns:
- The value in the case of a getter or null in the case of a setter.
- Throws:
MissingPropertyException
-
invokeMethod
Invokes a method on the given receiver for the specified arguments. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.- Specified by:
invokeMethodin interfaceMetaObjectProtocol- Parameters:
object- The object which the method was invoked onmethodName- The name of the methodarguments- The arguments to the method- Returns:
- The return value of the method
- See Also:
-
invokeMethod
public Object invokeMethod(Class sender, Object object, String methodName, Object[] originalArguments, boolean isCallToSuper, boolean fromInsideClass) Invokes a method on the given receiver for the specified arguments. The sender is the class that invoked the method on the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
invokeMethodin interfaceMetaClass- Parameters:
sender- The java.lang.Class instance that invoked the methodobject- The object which the method was invoked onmethodName- The name of the methodoriginalArguments- The arguments to the methodisCallToSuper- Whether the method is a call to a super class methodfromInsideClass- Whether the call was invoked from the inside or the outside of the class- Returns:
- The return value of the method.
- See Also:
-
getNonClosureOuter
- Since:
- 6.0.0
-
createTransformMetaMethod
Wraps a meta method so single-list arguments are expanded before invocation.- Parameters:
method- the method to wrap- Returns:
- the transforming method, or
nullif the input method isnull
-
getMethodWithCaching
public MetaMethod getMethodWithCaching(Class sender, String methodName, Object[] arguments, boolean isCallToSuper) Resolves a method and caches the selection for the supplied argument types.- Parameters:
sender- the calling classmethodName- the method namearguments- the runtime argumentsisCallToSuper- whether the dispatch originated fromsuper- Returns:
- the selected meta method, or
nullif none matches
-
retrieveConstructor
Resolves a constructor by parameter types.- Parameters:
arguments- the constructor parameter types- Returns:
- the matching constructor, or
nullif none matches
-
getMethodWithoutCaching
public MetaMethod getMethodWithoutCaching(Class sender, String methodName, Class[] arguments, boolean isCallToSuper) Resolves a method without populating the method cache.- Parameters:
sender- the calling classmethodName- the method namearguments- the parameter typesisCallToSuper- whether the dispatch originated fromsuper- Returns:
- the selected meta method, or
nullif none matches
-
retrieveStaticMethod
Resolves a static method and caches the selection when possible.- Parameters:
methodName- the method namearguments- the runtime arguments- Returns:
- the selected static meta method, or
nullif none matches
-
invokeStaticMethod
Invokes a static method on the given Object with the given name and arguments.The Object can either be an instance of the class that this MetaObjectProtocol instance applies to or the java.lang.Class instance itself. If a method cannot be invoked a MissingMethodException is will be thrown
- Specified by:
invokeStaticMethodin interfaceMetaObjectProtocol- Parameters:
object- An instance of the class returned by the getTheClass() method or the class itselfmethodName- The name of the methodarguments- The arguments to the method- Returns:
- The return value of the method which is null if the return type is void
- See Also:
-
invokeConstructor
Invokes a constructor for the given arguments. The MetaClass will attempt to pick the best argument which matches the types of the objects passed within the arguments array- Specified by:
invokeConstructorin interfaceMetaObjectProtocol- Parameters:
arguments- The arguments to the constructor- Returns:
- An instance of the java.lang.Class that this MetaObjectProtocol object applies to
-
selectConstructorAndTransformArguments
Internal method to support Groovy runtime. Not for client usage.- Specified by:
selectConstructorAndTransformArgumentsin interfaceMetaClass- Parameters:
numberOfConstructors- The number of constructorsarguments- The arguments- Returns:
- selected index
-
checkInitalised
protected void checkInitalised()checks if the initialisation of the class id complete. This method should be called as a form of assert, it is no way to test if there is still initialisation work to be done. Such logic must be implemented in a different way.- Throws:
IllegalStateException- if the initialisation is incomplete yet
-
retrieveConstructor
This is a helper method which is used only by indy. It is for internal use.- Since:
- 2.1.0
-
setProperties
Sets a number of bean properties from the given Map where the keys are the String names of properties and the values are the values of the properties to set -
getProperty
public Object getProperty(Class sender, Object object, String name, boolean useSuper, boolean fromInsideClass) Retrieves a property on the given receiver for the specified arguments. The sender is the class that is requesting the property from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
getPropertyin interfaceMetaClass- Parameters:
sender- The java.lang.Class instance that requested the propertyobject- The Object which the property is being retrieved fromname- The name of the propertyuseSuper- Whether the call is to a super class propertyfromInsideClass- ??- Returns:
- The property's value.
-
getEffectiveGetMetaProperty
public MetaProperty getEffectiveGetMetaProperty(Class sender, Object object, String name, boolean useSuper) Returns the effective readable meta property for a property access.- Parameters:
sender- the calling classobject- the receiver object or classname- the property nameuseSuper- whether the lookup should start at the super class- Returns:
- the effective readable meta property
-
getProperties
Returns the available properties for this type.- Specified by:
getPropertiesin interfaceMetaClass- Specified by:
getPropertiesin interfaceMetaObjectProtocol- Returns:
- a list of
MetaPropertyobjects - See Also:
-
applyPropertyDescriptors
Turns JavaBeans property descriptors into Groovy meta properties.- Parameters:
propertyDescriptors- the descriptors to apply
-
addMetaBeanProperty
Adds a new MetaBeanProperty to this MetaClass- Specified by:
addMetaBeanPropertyin interfaceMutableMetaClass- Parameters:
mp- The MetaBeanProperty
-
setProperty
public void setProperty(Class sender, Object object, String name, Object newValue, boolean useSuper, boolean fromInsideClass) Writes a property on the given receiver for the specified arguments. The sender is the class that is requesting the property from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.The useSuper and fromInsideClass help the runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
setPropertyin interfaceMetaClass- Parameters:
sender- The java.lang.Class instance that is mutating the propertyobject- The Object which the property is being set onname- The name of the propertynewValue- The new value of the property to setuseSuper- Whether the call is to a super class propertyfromInsideClass- Whether the call was invoked from the inside or the outside of the class.
-
getAttribute
Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Specified by:
getAttributein interfaceMetaClass- Parameters:
sender- The class of the object that requested the attributeobject- The instanceattribute- The name of the attributeuseSuper- Whether to look-up on the super class or not- Returns:
- The attribute value
-
getAttribute
public Object getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass) Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Parameters:
sender- The class of the object that requested the attributeobject- The instance the attribute is to be retrieved fromattribute- The name of the attributeuseSuper- Whether to look-up on the super class or notfromInsideClass- Whether the call was invoked from the inside or the outside of the class.- Returns:
- The attribute value
-
setAttribute
public void setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass) Sets an attribute on the given receiver for the specified arguments. The sender is the class that is setting the attribute from the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
- Specified by:
setAttributein interfaceMetaClass- Parameters:
sender- The java.lang.Class instance that is mutating the propertyobject- The Object which the property is being set onattribute- The name of the attribute,newValue- The new value of the attribute to setuseSuper- Whether the call is to a super class propertyfromInsideClass- Whether the call was invoked from the inside or the outside of the class
-
getClassNode
Obtains a reference to the original AST for the MetaClass if it is available at runtime- Specified by:
getClassNodein interfaceMetaClass- Returns:
- The original AST or null if it cannot be returned
-
toString
Returns a string representation of this metaclass -
addMetaMethod
Adds a MetaMethod to this class. WARNING: this method will not do the necessary steps for multimethod logic and using this method doesn't mean, that a method added here is replacing another method from a parent class completely. These steps are usually done by initialize, which means if you need these steps, you have to add the method before running initialize the first time.- Specified by:
addMetaMethodin interfaceMutableMetaClass- Parameters:
method- The MetaMethod to add- See Also:
-
addMetaMethodToIndex
protected void addMetaMethodToIndex(MetaMethod method, Map<String, MetaMethodIndex.Cache> cacheIndex) Adds a meta method to the supplied method index after standard-hook bookkeeping.- Parameters:
method- the method to indexcacheIndex- the target index bucket
-
checkIfGroovyObjectMethod
Checks if the metaMethod is getProperty, setProperty, or invokeMethod.- See Also:
-
isInitialized
protected boolean isInitialized()Indicates whether this meta class finished initialization.- Returns:
trueonce initialization completed
-
setInitialized
protected void setInitialized(boolean initialized) Updates the initialization flag for this meta class.- Parameters:
initialized- the new initialization state
-
chooseMethod
protected Object chooseMethod(String methodName, Object methodOrList, Class[] arguments) throws MethodSelectionException Chooses the correct method to use from a list of methods which match by name.- Parameters:
methodOrList- the possible methods to choose fromarguments- the arguments- Throws:
MethodSelectionException
-
doChooseMostSpecificParams
protected static Object doChooseMostSpecificParams(String theClassName, String name, List matchingMethods, Class[] arguments, boolean checkParameterCompatibility) Chooses the most specific overload among matching parameter type candidates.- Parameters:
theClassName- the receiver class name used in diagnosticsname- the method namematchingMethods- the candidate methodsarguments- the runtime argument typescheckParameterCompatibility- whether candidates should be filtered for compatibility first- Returns:
- the selected candidate, or
nullif none matches
-
createErrorMessageForAmbiguity
protected static String createErrorMessageForAmbiguity(String theClassName, String name, Class[] arguments, LinkedList matches) Creates the diagnostic message for an ambiguous overload selection.- Parameters:
theClassName- the receiver class namename- the method namearguments- the runtime argument typesmatches- the ambiguous candidates- Returns:
- the ambiguity message
-
handleMatches
protected static long handleMatches(long matchesDistance, LinkedList matches, Object method, long dist) Updates the current best-match set using the supplied distance metric.- Parameters:
matchesDistance- the best distance seen so farmatches- the current best candidatesmethod- the candidate methoddist- the candidate distance- Returns:
- the updated best distance
-
initialize
public void initialize()Complete the initialisation process. After this method is called no methods should be added to the metaclass. Invocation of methods or access to fields/properties is forbidden unless this method is called. This method should contain any initialisation code, taking a longer time to complete. An example is the creation of the Reflector. It is suggested to synchronize this method.- Specified by:
initializein interfaceMetaClass
-
reinitialize
protected void reinitialize()Rebuilds method, property and call-site state for this meta class. -
getMethods
Retrieves the list of MetaMethods held by the class. This list does not include MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMethodsin interfaceMetaClass- Specified by:
getMethodsin interfaceMetaObjectProtocol- Returns:
- A list of MetaMethods
- See Also:
-
getMetaMethods
Retrieves the list of MetaMethods held by this class. This list includes MetaMethods added by groovy.lang.ExpandoMetaClass.- Specified by:
getMetaMethodsin interfaceMetaClass- Returns:
- A list of MetaMethods
-
dropStaticMethodCache
Clears cached static method selections for the supplied method name.- Parameters:
name- the method name whose cache entries should be cleared
-
dropMethodCache
Clears cached instance method selections for the supplied method name.- Parameters:
name- the method name whose cache entries should be cleared
-
createPojoCallSite
Create a CallSite -
createStaticSite
Create a CallSite -
createPogoCallSite
Create a CallSite -
createPogoCallCurrentSite
Create a CallSite -
createConstructorSite
Create a CallSite -
getClassInfo
Returns the ClassInfo for the contained Class- Returns:
- The ClassInfo for the contained class.
-
getVersion
public int getVersion()Returns version of the contained Class- Returns:
- The version of the contained class.
-
incVersion
public void incVersion()Increments version of the contained Class -
getAdditionalMetaMethods
Retrieves a list of additional MetaMethods held by this class- Returns:
- A list of MetaMethods
-
findPropertyInClassHierarchy
Searches the class hierarchy for a mutable meta-class bean property.- Parameters:
propertyName- the property nametheClass- the class to start searching from- Returns:
- the matching bean property, or
nullif none is found
-
findMixinMethod
Searches for a matching mixin method.- Parameters:
methodName- the method namearguments- the parameter types- Returns:
- the matching mixin method, or
nullif none is found
-
findMethodInClassHierarchy
protected static MetaMethod findMethodInClassHierarchy(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass) Searches a meta-class hierarchy for the most specific visible method.- Parameters:
instanceKlazz- the runtime receiver classmethodName- the method namearguments- the parameter typesmetaClass- the starting meta class- Returns:
- the selected method, or
nullif none matches
-
findOwnMethod
protected static MetaMethod findOwnMethod(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass, MetaMethod method) Chooses the best method declared directly on the supplied meta class.- Parameters:
instanceKlazz- the runtime receiver classmethodName- the method namearguments- the parameter typesmetaClass- the meta class being inspectedmethod- the current best method candidate- Returns:
- the updated best method candidate
-
getSubclassMetaMethods
Returns subclass-scoped meta methods contributed by specialized meta classes.- Parameters:
methodName- the method name- Returns:
- subclass methods for the name, or
nullif none are registered
-
getProperty
Retrieves a property on the given object for the specified arguments.
- Specified by:
getPropertyin interfaceMetaObjectProtocol- Parameters:
object- The Object which the property is being retrieved fromproperty- The name of the property- Returns:
- The properties value
- See Also:
-
setProperty
Sets a property on the given object for the specified arguments.
- Specified by:
setPropertyin interfaceMetaObjectProtocol- Parameters:
object- The Object which the property is being retrieved fromproperty- The name of the propertynewValue- The new value- See Also:
-
getAttribute
Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Specified by:
getAttributein interfaceMetaObjectProtocol- Parameters:
object- The object to get the attribute fromattribute- The name of the attribute- Returns:
- The attribute value
- See Also:
-
setAttribute
Sets the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.- Specified by:
setAttributein interfaceMetaObjectProtocol- Parameters:
object- The object to get the attribute fromattribute- The name of the attributenewValue- The new value of the attribute- See Also:
-
pickMethod
Selects a method by name and argument classes. This method does not search for an exact match, it searches for a compatible method. For this the method selection mechanism is used as provided by the implementation of this MetaClass. pickMethod may or may not be used during the method selection process when invoking a method. There is no warranty for that.- Specified by:
pickMethodin interfaceMetaClass- Parameters:
methodName- the name of the method to pickarguments- the method arguments- Returns:
- a matching MetaMethod or null
- Throws:
GroovyRuntimeException- if there is more than one matching method
-
hasCustomInvokeMethod
public boolean hasCustomInvokeMethod()indicates is the metaclass method invocation for non-static methods is done through a custom invoker object.- Returns:
- true - if the method invocation is not done by the metaclass itself
-
hasCustomStaticInvokeMethod
public boolean hasCustomStaticInvokeMethod()indicates is the metaclass method invocation for static methods is done through a custom invoker object.- Returns:
- true - if the method invocation is not done by the metaclass itself
-
clearInvocationCaches
protected void clearInvocationCaches()remove all method call cache entries. This should be done if a method is added during runtime, but not by using a category. -
isPermissivePropertyAccess
public boolean isPermissivePropertyAccess()Indicates whether permissive property access semantics are enabled.- Returns:
trueif missing getters may still resolve fields or map entries
-
setPermissivePropertyAccess
public void setPermissivePropertyAccess(boolean permissivePropertyAccess) Enables or disables permissive property access semantics.- Parameters:
permissivePropertyAccess- the new permissive-property-access flag
-