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();
}
});
}
Aggregations