public class MetaClassImpl
extends Object
implements MetaClass, MutableMetaClass
Allows methods to be dynamically added to existing classes at runtime
| Modifiers | Name | Description |
|---|---|---|
static class |
MetaClassImpl.MetaConstructor |
This is a helper class which is used only by indy. |
| Modifiers | Name | Description |
|---|---|---|
static Object[] |
EMPTY_ARGUMENTS |
Shared empty argument array used by MOP dispatch helpers. |
protected static String |
INVOKE_METHOD_METHOD |
Conventional Groovy instance invokeMethod hook name. |
protected static String |
METHOD_MISSING |
Conventional Groovy instance methodMissing hook name. |
protected static String |
PROPERTY_MISSING |
Conventional Groovy instance propertyMissing hook name. |
protected static String |
STATIC_METHOD_MISSING |
Synthetic method name used for static methodMissing dispatch. |
protected static String |
STATIC_PROPERTY_MISSING |
Synthetic method name used for static propertyMissing dispatch. |
protected MetaMethod |
getPropertyMethod |
Effective getProperty handler discovered for this meta class. |
protected MetaMethod |
invokeMethodMethod |
Effective invokeMethod handler discovered for this meta class. |
protected boolean |
isGroovyObject |
Indicates whether theClass implements GroovyObject. |
protected boolean |
isMap |
Indicates whether theClass is assignable from Map. |
protected MetaMethodIndex |
metaMethodIndex |
Method index used for Groovy method selection and caching. |
protected MetaClassRegistry |
registry |
Registry that owns this meta class. |
protected MetaMethod |
setPropertyMethod |
Effective setProperty handler discovered for this meta class. |
protected CachedClass |
theCachedClass |
Cached reflection view for theClass. |
protected Class |
theClass |
Java class represented by this meta class. |
| Constructor and description |
|---|
MetaClassImpl(Class theClass, MetaMethod[] add)Constructor |
MetaClassImpl(Class theClass)Constructor that sets the methods to null |
MetaClassImpl(MetaClassRegistry registry, Class theClass, MetaMethod[] add)Constructor with registry |
MetaClassImpl(MetaClassRegistry registry, Class theClass)Constructor with registry setting methods to null |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
addMetaBeanProperty(MetaBeanProperty mp)Adds a new MetaBeanProperty to this MetaClass |
|
public void |
addMetaMethod(MetaMethod method)Adds a MetaMethod to this class. |
|
protected void |
addMetaMethodToIndex(MetaMethod method, Map<String, MetaMethodIndex.Cache> cacheIndex)Adds a meta method to the supplied method index after standard-hook bookkeeping. |
|
public void |
addNewInstanceMethod(Method method)Adds an instance method to this metaclass. |
|
public void |
addNewStaticMethod(Method method)Adds a static method to this metaclass. |
|
protected void |
applyPropertyDescriptors(PropertyDescriptor[] propertyDescriptors)Turns JavaBeans property descriptors into Groovy meta properties. |
|
protected final void |
checkIfGroovyObjectMethod(MetaMethod metaMethod)Checks if the metaMethod is getProperty, setProperty, or invokeMethod. |
|
protected void |
checkInitalised()checks if the initialisation of the class id complete. |
|
protected Object |
chooseMethod(String methodName, Object methodOrList, Class[] arguments)Chooses the correct method to use from a list of methods which match by name. |
|
protected void |
clearInvocationCaches()remove all method call cache entries. |
|
public CallSite |
createConstructorSite(CallSite site, Object[] args)Create a CallSite |
|
protected static String |
createErrorMessageForAmbiguity(String theClassName, String name, Class[] arguments, LinkedList matches)Creates the diagnostic message for an ambiguous overload selection. |
|
public CallSite |
createPogoCallCurrentSite(CallSite site, Class sender, Object[] args)Create a CallSite |
|
public CallSite |
createPogoCallSite(CallSite site, Object[] args)Create a CallSite |
|
public CallSite |
createPojoCallSite(CallSite site, Object receiver, Object[] args)Create a CallSite |
|
public CallSite |
createStaticSite(CallSite site, Object[] args)Create a CallSite |
|
protected MetaMethod |
createTransformMetaMethod(MetaMethod method)Wraps a meta method so single-list arguments are expanded before invocation. |
|
protected static Object |
doChooseMostSpecificParams(String theClassName, String name, List matchingMethods, Class[] arguments, boolean checkParameterCompatibility)Chooses the most specific overload among matching parameter type candidates. |
|
protected void |
dropMethodCache(String name)Clears cached instance method selections for the supplied method name. |
|
protected void |
dropStaticMethodCache(String name)Clears cached static method selections for the supplied method name. |
|
protected static MetaMethod |
findMethodInClassHierarchy(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass)Searches a meta-class hierarchy for the most specific visible method. |
|
protected MetaMethod |
findMixinMethod(String methodName, Class[] arguments)Searches for a matching mixin method. |
|
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. |
|
protected MetaBeanProperty |
findPropertyInClassHierarchy(String propertyName, CachedClass theClass)Searches the class hierarchy for a mutable meta-class bean property. |
|
public MetaMethod[] |
getAdditionalMetaMethods()Retrieves a list of additional MetaMethods held by this class |
|
public Object |
getAttribute(Class sender, Object object, String attribute, boolean useSuper)Retrieves the value of an attribute (field). |
|
public Object |
getAttribute(Class sender, Object object, String attribute, boolean useSuper, boolean fromInsideClass)Retrieves the value of an attribute (field). |
|
public Object |
getAttribute(Object object, String attribute)Retrieves the value of an attribute (field). |
|
public ClassInfo |
getClassInfo()Returns the ClassInfo for the contained Class |
|
public ClassNode |
getClassNode()Obtains a reference to the original AST for the MetaClass if it is available at runtime |
|
public MetaProperty |
getEffectiveGetMetaProperty(Class sender, Object object, String name, boolean useSuper)Returns the effective readable meta property for a property access. |
|
public MetaMethod |
getMetaMethod(String name, Object[] argTypes)
|
|
public List<MetaMethod> |
getMetaMethods()Retrieves the list of MetaMethods held by this class. |
|
public MetaProperty |
getMetaProperty(String name)
|
|
public MetaMethod |
getMethodWithCaching(Class sender, String methodName, Object[] arguments, boolean isCallToSuper)Resolves a method and caches the selection for the supplied argument types. |
|
public MetaMethod |
getMethodWithoutCaching(Class sender, String methodName, Class[] arguments, boolean isCallToSuper)Resolves a method without populating the method cache. |
|
public List<MetaMethod> |
getMethods()Retrieves the list of MetaMethods held by the class. |
|
protected static Class<?> |
getNonClosureOuter(Class<?> c)
|
|
public List<MetaProperty> |
getProperties()Returns the available properties for this type. |
|
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
|
|
public Object |
getProperty(Object object, String property) |
|
public MetaClassRegistry |
getRegistry()Returns the registry for this metaclass |
|
public MetaMethod |
getStaticMetaMethod(String name, Object[] argTypes) |
|
protected Object |
getSubclassMetaMethods(String methodName)Returns subclass-scoped meta methods contributed by specialized meta classes. |
|
protected LinkedList<CachedClass> |
getSuperClasses()Returns the cached super-class chain used while building method and property indexes. |
|
public final CachedClass |
getTheCachedClass()Returns the cached class for this metaclass |
|
public Class |
getTheClass()Returns the class this metaclass represents. |
|
public int |
getVersion()Returns version of the contained Class |
|
protected static long |
handleMatches(long matchesDistance, LinkedList matches, Object method, long dist)Updates the current best-match set using the supplied distance metric. |
|
public boolean |
hasCustomInvokeMethod()indicates is the metaclass method invocation for non-static methods is done through a custom invoker object. |
|
public boolean |
hasCustomStaticInvokeMethod()indicates is the metaclass method invocation for static methods is done through a custom invoker object. |
|
public MetaProperty |
hasProperty(Object obj, String name)
|
|
public void |
incVersion()Increments version of the contained Class |
|
public void |
initialize()Complete the initialisation process. |
|
public Object |
invokeConstructor(Object[] arguments)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
|
|
public Object |
invokeMethod(Object object, String methodName, Object arguments)Invoke a method on the given object with the given arguments. |
|
public Object |
invokeMethod(Object object, String methodName, Object[] arguments)Invokes a method on the given receiver for the specified arguments. |
|
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. |
|
public Object |
invokeMissingMethod(Object instance, String methodName, Object[] arguments)Invoke a missing method on the given object with the given arguments. |
|
public Object |
invokeMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)Invoke a missing property on the given object with the given arguments. |
|
public Object |
invokeStaticMethod(Object object, String methodName, Object[] arguments)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
|
|
protected Object |
invokeStaticMissingProperty(Object instance, String propertyName, Object optionalValue, boolean isGetter)Hook to deal with the case of missing property for static properties. |
|
public boolean |
isGroovyObject()Indicates if the represented class is an instance of the GroovyObject class. |
|
protected boolean |
isInitialized()Indicates whether this meta class finished initialization. |
|
public boolean |
isModified()Returns whether this MetaClassImpl has been modified. |
|
public boolean |
isPermissivePropertyAccess()Indicates whether permissive property access semantics are enabled. |
|
protected void |
onGetPropertyFoundInHierarchy(MetaMethod method)Callback invoked when a getProperty implementation is discovered. |
|
protected void |
onInvokeMethodFoundInHierarchy(MetaMethod method)Callback invoked when an invokeMethod implementation is discovered. |
|
protected void |
onMixinMethodFound(MetaMethod method)Callback invoked when a mixin method is discovered during initialization. |
|
protected void |
onSetPropertyFoundInHierarchy(MetaMethod method)Callback invoked when a setProperty implementation is discovered. |
|
protected void |
onSuperMethodFoundInHierarchy(MetaMethod method)Callback invoked when a super-class method is discovered during initialization. |
|
protected void |
onSuperPropertyFoundInHierarchy(MetaBeanProperty property)Callback invoked when a super-class bean property is discovered during initialization. |
|
public MetaMethod |
pickMethod(String methodName, Class[] arguments)Selects a method by name and argument classes. |
|
protected void |
reinitialize()Rebuilds method, property and call-site state for this meta class. |
|
public List<MetaMethod> |
respondsTo(Object obj, String name, Object[] argTypes)
|
|
public List<MetaMethod> |
respondsTo(Object obj, String name)
|
|
public Constructor |
retrieveConstructor(Class[] arguments)Resolves a constructor by parameter types. |
|
public MetaMethod |
retrieveStaticMethod(String methodName, Object[] arguments)Resolves a static method and caches the selection when possible. |
|
public int |
selectConstructorAndTransformArguments(int numberOfConstructors, Object[] arguments)Internal method to support Groovy runtime. Not for client usage.
|
|
public void |
setAttribute(Class sender, Object object, String attribute, Object newValue, boolean useSuper, boolean fromInsideClass) |
|
public void |
setAttribute(Object object, String attribute, Object newValue)Sets the value of an attribute (field). |
|
protected void |
setInitialized(boolean initialized)Updates the initialization flag for this meta class. |
|
public void |
setPermissivePropertyAccess(boolean permissivePropertyAccess)Enables or disables permissive property access semantics. |
|
public void |
setProperties(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 set |
|
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. |
|
public void |
setProperty(Object object, String property, Object newValue) |
|
public String |
toString()Returns a string representation of this metaclass |
Shared empty argument array used by MOP dispatch helpers.
Conventional Groovy instance invokeMethod hook name.
Conventional Groovy instance methodMissing hook name.
Conventional Groovy instance propertyMissing hook name.
Synthetic method name used for static methodMissing dispatch.
Synthetic method name used for static propertyMissing dispatch.
Effective getProperty handler discovered for this meta class.
Effective invokeMethod handler discovered for this meta class.
Indicates whether theClass implements GroovyObject.
Method index used for Groovy method selection and caching.
Registry that owns this meta class.
Effective setProperty handler discovered for this meta class.
Cached reflection view for theClass.
Java class represented by this meta class.
Constructor
theClass - The class this is the metaclass foradd - The methods for this classConstructor that sets the methods to null
theClass - The class this is the metaclass forConstructor with registry
registry - The metaclass registry for this MetaClasstheClass - The classadd - The methodsConstructor with registry setting methods to null
registry - The metaclass registry for this MetaClasstheClass - The classAdds a new MetaBeanProperty to this MetaClass
mp - The MetaBeanPropertyAdds 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.
Adds a meta method to the supplied method index after standard-hook bookkeeping.
method - the method to indexcacheIndex - the target index bucketAdds an instance method to this metaclass.
method - The method to be addedAdds a static method to this metaclass.
method - The method to be addedTurns JavaBeans property descriptors into Groovy meta properties.
propertyDescriptors - the descriptors to applyChecks if the metaMethod is getProperty, setProperty, or invokeMethod.
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.
Chooses the correct method to use from a list of methods which match by name.
methodOrList - the possible methods to choose fromarguments - the argumentsremove all method call cache entries. This should be done if a method is added during runtime, but not by using a category.
Creates the diagnostic message for an ambiguous overload selection.
theClassName - the receiver class namename - the method namearguments - the runtime argument typesmatches - the ambiguous candidatesCreate a CallSite
Wraps a meta method so single-list arguments are expanded before invocation.
method - the method to wrapnull if the input method is nullChooses the most specific overload among matching parameter type candidates.
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 firstnull if none matchesClears cached instance method selections for the supplied method name.
name - the method name whose cache entries should be clearedClears cached static method selections for the supplied method name.
name - the method name whose cache entries should be clearedSearches a meta-class hierarchy for the most specific visible method.
instanceKlazz - the runtime receiver classmethodName - the method namearguments - the parameter typesmetaClass - the starting meta classnull if none matchesSearches for a matching mixin method.
methodName - the method namearguments - the parameter typesnull if none is foundChooses the best method declared directly on the supplied meta class.
instanceKlazz - the runtime receiver classmethodName - the method namearguments - the parameter typesmetaClass - the meta class being inspectedmethod - the current best method candidateSearches the class hierarchy for a mutable meta-class bean property.
propertyName - the property nametheClass - the class to start searching fromnull if none is foundRetrieves a list of additional MetaMethods held by this class
Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.
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 notRetrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.
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.Retrieves the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.
object - The object to get the attribute fromattribute - The name of the attributeReturns the ClassInfo for the contained Class
Obtains a reference to the original AST for the MetaClass if it is available at runtime
Returns the effective readable meta property for a property access.
sender - the calling classobject - the receiver object or classname - the property nameuseSuper - whether the lookup should start at the super class
Retrieves the list of MetaMethods held by this class. This list includes MetaMethods added by groovy.lang.ExpandoMetaClass.
Resolves a method and caches the selection for the supplied argument types.
sender - the calling classmethodName - the method namearguments - the runtime argumentsisCallToSuper - whether the dispatch originated from supernull if none matchesResolves a method without populating the method cache.
sender - the calling classmethodName - the method namearguments - the parameter typesisCallToSuper - whether the dispatch originated from supernull if none matchesRetrieves the list of MetaMethods held by the class. This list does not include MetaMethods added by groovy.lang.ExpandoMetaClass.
Returns the available properties for this type.
MetaProperty objects
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
sender - The java.lang.Class instance that requested the propertyreceiver - The Object which the property is being retrieved fromproperty - The name of the propertyisCallToSuper - Whether the call is to a super class propertyfromInsideClass - ??
Retrieves a property on the given object for the specified arguments.
object - The Object which the property is being retrieved fromproperty - The name of the propertyReturns the registry for this metaclass
Returns subclass-scoped meta methods contributed by specialized meta classes.
methodName - the method namenull if none are registeredReturns the cached super-class chain used while building method and property indexes.
Returns the cached class for this metaclass
Returns the class this metaclass represents.
Returns version of the contained Class
Updates the current best-match set using the supplied distance metric.
matchesDistance - the best distance seen so farmatches - the current best candidatesmethod - the candidate methoddist - the candidate distanceindicates is the metaclass method invocation for non-static methods is done through a custom invoker object.
indicates is the metaclass method invocation for static methods is done through a custom invoker object.
Increments version of the contained Class
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.
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
arguments - The arguments to the constructorInvoke a method on the given object with the given arguments.
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.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.
object - The object which the method was invoked onmethodName - The name of the methodarguments - The arguments to the methodInvokes 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
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 classInvoke a missing method on the given object with the given arguments.
instance - The object the method should be invoked on.methodName - The name of the method to invoke.arguments - The arguments to the invoked method.Invoke a missing property on the given object with the given arguments.
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 getterInvokes 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
object - An instance of the class returned by the getTheClass() method or the class itselfmethodName - The name of the methodarguments - The arguments to the methodHook 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.
instance - the class instancepropertyName - the name of the propertyoptionalValue - the value in the case of a setterisGetter - true for property read, false for property writeIndicates if the represented class is an instance of the GroovyObject class.
Indicates whether this meta class finished initialization.
true once initialization completedReturns whether this MetaClassImpl has been modified. Since MetaClassImpl is not designed for modification this method always returns false
Indicates whether permissive property access semantics are enabled.
true if missing getters may still resolve fields or map entries Callback invoked when a getProperty implementation is discovered.
method - the discovered handler Callback invoked when an invokeMethod implementation is discovered.
method - the discovered handlerCallback invoked when a mixin method is discovered during initialization.
method - the discovered mixin method Callback invoked when a setProperty implementation is discovered.
method - the discovered handlerCallback invoked when a super-class method is discovered during initialization.
method - the inherited methodCallback invoked when a super-class bean property is discovered during initialization.
property - the inherited propertySelects 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.
methodName - the name of the method to pickarguments - the method argumentsRebuilds method, property and call-site state for this meta class.
Resolves a constructor by parameter types.
arguments - the constructor parameter typesnull if none matchesResolves a static method and caches the selection when possible.
methodName - the method namearguments - the runtime argumentsnull if none matchesInternal method to support Groovy runtime. Not for client usage.
numberOfConstructors - The number of constructorsarguments - The arguments
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
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 classSets the value of an attribute (field). This method is to support the Groovy runtime and not for general client API usage.
object - The object to get the attribute fromattribute - The name of the attributenewValue - The new value of the attributeUpdates the initialization flag for this meta class.
initialized - the new initialization stateEnables or disables permissive property access semantics.
permissivePropertyAccess - the new permissive-property-access flagSets 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
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
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.
Sets a property on the given object for the specified arguments.
object - The Object which the property is being retrieved fromproperty - The name of the propertynewValue - The new valueReturns a string representation of this metaclass
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.