Package org.codehaus.groovy.runtime
Class HandleMetaClass
java.lang.Object
groovy.lang.DelegatingMetaClass
org.codehaus.groovy.runtime.HandleMetaClass
- All Implemented Interfaces:
GroovyObject,MetaClass,MetaObjectProtocol,MutableMetaClass
A delegating meta-class that can replace the meta-class of one instance on demand.
-
Field Summary
Fields inherited from class groovy.lang.DelegatingMetaClass
delegate -
Constructor Summary
ConstructorsConstructorDescriptionDelegates tomcwith no instance attached.HandleMetaClass(MetaClass mc, Object obj) Delegates tomcand records whetherobjstill needs a per-instance meta class. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMetaBeanProperty(MetaBeanProperty metaBeanProperty) Adds a new MetaBeanProperty to the MetaClass.voidaddMetaMethod(MetaMethod metaMethod) Adds a new MetaMethod to the MetaClass.voidaddNewInstanceMethod(Method method) adds a new instance method to this MetaClass.voidaddNewStaticMethod(Method method) adds a new static method to this MetaClass.booleangetProperty(String property) Retrieves a property value.voidComplete the initialisation process.invokeMethod(String name, Object args) Invokes the given method.Ensures the delegate is anExpandoMetaClasswhen a replacement is still pending, then returns that delegate.voidsetProperty(String property, Object newValue) Sets the given property to the new value.Methods inherited from class groovy.lang.DelegatingMetaClass
getAdaptee, getAttribute, getAttribute, getClassNode, getMetaClass, getMetaMethod, getMetaMethods, getMetaProperty, getMethods, getProperties, getProperty, getProperty, getStaticMetaMethod, getStaticMetaMethod, getTheClass, hashCode, hasProperty, invokeConstructor, invokeMethod, invokeMethod, invokeMethod, invokeMissingMethod, invokeMissingProperty, invokeStaticMethod, isGroovyObject, isModified, pickMethod, respondsTo, respondsTo, selectConstructorAndTransformArguments, setAdaptee, setAttribute, setAttribute, setMetaClass, setProperty, setProperty, toString
-
Constructor Details
-
HandleMetaClass
Delegates tomcwith no instance attached.replaceDelegate()then installs anExpandoMetaClasson the class. Equivalent toHandleMetaClass(mc, null).- Parameters:
mc- the meta class to delegate to
-
HandleMetaClass
Delegates tomcand records whetherobjstill needs a per-instance meta class. A nullobjleaves replacement to the class, asHandleMetaClass(MetaClass)does. A non-nullobjis remembered when the meta class ofobj's class ismc, or whenmcis not anExpandoMetaClass. Otherwise the instance is treated as already having its own meta class andreplaceDelegate()leaves it alone.- Parameters:
mc- the meta class to delegate toobj- the instance whose meta class may be replaced, ornullfor the class
-
-
Method Details
-
initialize
public void initialize()Description copied from class:DelegatingMetaClassComplete 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- Overrides:
initializein classDelegatingMetaClass
-
replaceDelegate
Ensures the delegate is anExpandoMetaClasswhen a replacement is still pending, then returns that delegate. With no instance, a delegate that is not already an expando meta class is replaced bynew ExpandoMetaClass(theClass, true, true), initialized, and registered on the class; an existing expando delegate is registered again. With a pending instance, a newExpandoMetaClass(theClass, false, true)is created, expando methods are copied when the previous delegate is anExpandoMetaClass, and the new meta class is set on that instance. After an instance replacement, further calls do not replace again. The delegate is cast toGroovyObject.- Returns:
- the delegate after any replacement
-
invokeMethod
Description copied from class:DelegatingMetaClassInvokes the given method.- Specified by:
invokeMethodin interfaceGroovyObject- Overrides:
invokeMethodin classDelegatingMetaClass- Parameters:
name- the name of the method to callargs- the arguments to use for the method call- Returns:
- the result of invoking the method
-
getProperty
Description copied from class:DelegatingMetaClassRetrieves a property value.- Specified by:
getPropertyin interfaceGroovyObject- Overrides:
getPropertyin classDelegatingMetaClass- Parameters:
property- the name of the property of interest- Returns:
- the given property
-
setProperty
Description copied from class:DelegatingMetaClassSets the given property to the new value.- Specified by:
setPropertyin interfaceGroovyObject- Overrides:
setPropertyin classDelegatingMetaClass- Parameters:
property- the name of the property of interestnewValue- the new value for the property
-
addNewInstanceMethod
Description copied from class:DelegatingMetaClassadds a new instance method to this MetaClass. Instance methods are able to overwrite the original methods of the class. Calling this method should not be done after initialise was called.- Specified by:
addNewInstanceMethodin interfaceMutableMetaClass- Overrides:
addNewInstanceMethodin classDelegatingMetaClass- Parameters:
method- the method to be added
-
addNewStaticMethod
Description copied from class:DelegatingMetaClassadds a new static method to this MetaClass. This is only possible as long as initialise was not called.- Specified by:
addNewStaticMethodin interfaceMutableMetaClass- Overrides:
addNewStaticMethodin classDelegatingMetaClass- Parameters:
method- the method to be added
-
addMetaMethod
Description copied from class:DelegatingMetaClassAdds a new MetaMethod to the MetaClass. This is only possible as long as initialise was not called.- Specified by:
addMetaMethodin interfaceMutableMetaClass- Overrides:
addMetaMethodin classDelegatingMetaClass- Parameters:
metaMethod- The MetaMethod to add
-
addMetaBeanProperty
Description copied from class:DelegatingMetaClassAdds a new MetaBeanProperty to the MetaClass. This is only possible as long as initialise was not called.- Specified by:
addMetaBeanPropertyin interfaceMutableMetaClass- Overrides:
addMetaBeanPropertyin classDelegatingMetaClass- Parameters:
metaBeanProperty- The MetaBeanProperty instance
-
equals
Description copied from class:DelegatingMetaClass- Overrides:
equalsin classDelegatingMetaClass
-