use of org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod in project groovy-core by groovy.
the class ExpandoMetaClass method registerStaticMethod.
/**
* Registers a new static method for the given method name and closure on this MetaClass
*
* @param name The method name
* @param callable The callable Closure
*/
protected void registerStaticMethod(final String name, final Closure callable, final Class[] paramTypes) {
performOperationOnMetaClass(new Callable() {
public void call() {
String methodName;
if (name.equals(METHOD_MISSING))
methodName = STATIC_METHOD_MISSING;
else if (name.equals(PROPERTY_MISSING))
methodName = STATIC_PROPERTY_MISSING;
else
methodName = name;
ClosureStaticMetaMethod metaMethod = null;
if (paramTypes != null) {
metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable, paramTypes);
} else {
metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable);
}
if (methodName.equals(INVOKE_METHOD_METHOD) && callable.getParameterTypes().length == 2) {
invokeStaticMethodMethod = metaMethod;
} else {
if (methodName.equals(METHOD_MISSING)) {
methodName = STATIC_METHOD_MISSING;
}
MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
addMetaMethod(metaMethod);
dropStaticMethodCache(methodName);
if (isGetter(methodName, metaMethod.getParameterTypes())) {
String propertyName = getPropertyForGetter(methodName);
registerBeanPropertyForMethod(metaMethod, propertyName, true, true);
} else if (isSetter(methodName, metaMethod.getParameterTypes())) {
String propertyName = getPropertyForSetter(methodName);
registerBeanPropertyForMethod(metaMethod, propertyName, false, true);
}
performRegistryCallbacks();
expandoMethods.put(key, metaMethod);
}
}
});
}
use of org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod in project groovy-core by groovy.
the class ExpandoMetaClass method refreshInheritedMethods.
private void refreshInheritedMethods(ExpandoMetaClass superExpando) {
List<MetaMethod> metaMethods = superExpando.getExpandoMethods();
for (MetaMethod metaMethod : metaMethods) {
if (metaMethod.isStatic()) {
if (superExpando.getTheClass() != getTheClass())
// don't inherit static methods except our own
continue;
registerStaticMethod(metaMethod.getName(), (Closure) ((ClosureStaticMetaMethod) metaMethod).getClosure().clone());
} else
addSuperMethodIfNotOverridden(metaMethod);
}
Collection<MetaProperty> metaProperties = superExpando.getExpandoProperties();
for (Object metaProperty : metaProperties) {
MetaBeanProperty property = (MetaBeanProperty) metaProperty;
expandoProperties.put(property.getName(), property);
addMetaBeanProperty(property);
}
}
use of org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod in project groovy by apache.
the class ExpandoMetaClass method refreshInheritedMethods.
private void refreshInheritedMethods(ExpandoMetaClass superExpando) {
List<MetaMethod> metaMethods = superExpando.getExpandoMethods();
for (MetaMethod metaMethod : metaMethods) {
if (metaMethod.isStatic()) {
if (superExpando.getTheClass() != getTheClass())
// don't inherit static methods except our own
continue;
registerStaticMethod(metaMethod.getName(), (Closure) ((ClosureStaticMetaMethod) metaMethod).getClosure().clone());
} else
addSuperMethodIfNotOverridden(metaMethod);
}
Collection<MetaProperty> metaProperties = superExpando.getExpandoProperties();
for (Object metaProperty : metaProperties) {
MetaBeanProperty property = (MetaBeanProperty) metaProperty;
expandoProperties.put(property.getName(), property);
addMetaBeanProperty(property);
}
}
use of org.codehaus.groovy.runtime.metaclass.ClosureStaticMetaMethod in project groovy by apache.
the class ExpandoMetaClass method registerStaticMethod.
/**
* Registers a new static method for the given method name and closure on this MetaClass
*
* @param name The method name
* @param callable The callable Closure
*/
protected void registerStaticMethod(final String name, final Closure callable, final Class[] paramTypes) {
performOperationOnMetaClass(new Callable() {
public void call() {
String methodName;
if (name.equals(METHOD_MISSING))
methodName = STATIC_METHOD_MISSING;
else if (name.equals(PROPERTY_MISSING))
methodName = STATIC_PROPERTY_MISSING;
else
methodName = name;
ClosureStaticMetaMethod metaMethod = null;
if (paramTypes != null) {
metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable, paramTypes);
} else {
metaMethod = new ClosureStaticMetaMethod(methodName, theClass, callable);
}
if (methodName.equals(INVOKE_METHOD_METHOD) && callable.getParameterTypes().length == 2) {
invokeStaticMethodMethod = metaMethod;
} else {
if (methodName.equals(METHOD_MISSING)) {
methodName = STATIC_METHOD_MISSING;
}
MethodKey key = new DefaultCachedMethodKey(theClass, methodName, metaMethod.getParameterTypes(), false);
addMetaMethod(metaMethod);
dropStaticMethodCache(methodName);
if (isGetter(methodName, metaMethod.getParameterTypes())) {
String propertyName = getPropertyForGetter(methodName);
registerBeanPropertyForMethod(metaMethod, propertyName, true, true);
} else if (isSetter(methodName, metaMethod.getParameterTypes())) {
String propertyName = getPropertyForSetter(methodName);
registerBeanPropertyForMethod(metaMethod, propertyName, false, true);
}
performRegistryCallbacks();
expandoMethods.put(key, metaMethod);
}
}
});
}
Aggregations