Search in sources :

Example 6 with MethodKey

use of org.codehaus.groovy.runtime.MethodKey in project groovy by apache.

the class ExpandoMetaClass method registerInstanceMethod.

/**
     * Registers a new instance method for the given method name and closure on this MetaClass
     *
     * @param metaMethod
     */
public void registerInstanceMethod(final MetaMethod metaMethod) {
    final boolean inited = this.initCalled;
    performOperationOnMetaClass(new Callable() {

        public void call() {
            String methodName = metaMethod.getName();
            checkIfGroovyObjectMethod(metaMethod);
            MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
            if (isInitialized()) {
                throw new RuntimeException("Already initialized, cannot add new method: " + metaMethod);
            }
            // we always adds meta methods to class itself
            addMetaMethodToIndex(metaMethod, metaMethodIndex.getHeader(theClass));
            dropMethodCache(methodName);
            expandoMethods.put(key, metaMethod);
            if (inited && isGetter(methodName, metaMethod.getParameterTypes())) {
                String propertyName = getPropertyForGetter(methodName);
                registerBeanPropertyForMethod(metaMethod, propertyName, true, false);
            } else if (inited && isSetter(methodName, metaMethod.getParameterTypes())) {
                String propertyName = getPropertyForSetter(methodName);
                registerBeanPropertyForMethod(metaMethod, propertyName, false, false);
            }
            performRegistryCallbacks();
        }
    });
}
Also used : DefaultCachedMethodKey(org.codehaus.groovy.runtime.DefaultCachedMethodKey) MethodKey(org.codehaus.groovy.runtime.MethodKey) DefaultCachedMethodKey(org.codehaus.groovy.runtime.DefaultCachedMethodKey)

Aggregations

DefaultCachedMethodKey (org.codehaus.groovy.runtime.DefaultCachedMethodKey)6 MethodKey (org.codehaus.groovy.runtime.MethodKey)6 ClosureStaticMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod)4 CachedClass (org.codehaus.groovy.reflection.CachedClass)2 MixinInMetaClass (org.codehaus.groovy.reflection.MixinInMetaClass)2 ClosureMetaMethod (org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod)2 MixedInMetaClass (org.codehaus.groovy.runtime.metaclass.MixedInMetaClass)2 MixinInstanceMetaMethod (org.codehaus.groovy.runtime.metaclass.MixinInstanceMetaMethod)2 OwnedMetaClass (org.codehaus.groovy.runtime.metaclass.OwnedMetaClass)2