use of org.codehaus.groovy.reflection.MixinInMetaClass in project groovy by apache.
the class ExpandoMetaClass method findMixinMethod.
public MetaMethod findMixinMethod(String methodName, Class[] arguments) {
for (MixinInMetaClass mixin : mixinClasses) {
final CachedClass mixinClass = mixin.getMixinClass();
MetaClass metaClass = mixinClass.classInfo.getMetaClassForClass();
if (metaClass == null) {
metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(mixinClass.getTheClass());
}
MetaMethod metaMethod = metaClass.pickMethod(methodName, arguments);
if (metaMethod == null && metaClass instanceof MetaClassImpl) {
MetaClassImpl mc = (MetaClassImpl) metaClass;
for (CachedClass cl = mc.getTheCachedClass().getCachedSuperClass(); cl != null; cl = cl.getCachedSuperClass()) {
metaMethod = mc.getMethodWithoutCaching(cl.getTheClass(), methodName, arguments, false);
if (metaMethod != null)
break;
}
}
if (metaMethod != null) {
MetaMethod method = new MixinInstanceMetaMethod(metaMethod, mixin);
if (method.getParameterTypes().length == 1 && !method.getParameterTypes()[0].isPrimitive) {
MetaMethod noParam = pickMethod(methodName, EMPTY_CLASS_ARRAY);
// if the current call itself is with empty arg class array, no need to recurse with 'new Class[0]'
if (noParam == null && arguments.length != 0) {
try {
findMixinMethod(methodName, EMPTY_CLASS_ARRAY);
} catch (MethodSelectionException msex) {
/*
* Here we just additionally tried to find another no-arg mixin method of the same name and register that as well, if found.
* Safe to ignore a MethodSelectionException in this additional exercise. (GROOVY-4999)
*/
}
}
}
registerInstanceMethod(method);
return method;
}
}
return null;
}
use of org.codehaus.groovy.reflection.MixinInMetaClass in project groovy-core by groovy.
the class ExpandoMetaClass method findMixinMethod.
public MetaMethod findMixinMethod(String methodName, Class[] arguments) {
for (MixinInMetaClass mixin : mixinClasses) {
final CachedClass mixinClass = mixin.getMixinClass();
MetaClass metaClass = mixinClass.classInfo.getMetaClassForClass();
if (metaClass == null) {
metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(mixinClass.getTheClass());
}
MetaMethod metaMethod = metaClass.pickMethod(methodName, arguments);
if (metaMethod == null && metaClass instanceof MetaClassImpl) {
MetaClassImpl mc = (MetaClassImpl) metaClass;
for (CachedClass cl = mc.getTheCachedClass().getCachedSuperClass(); cl != null; cl = cl.getCachedSuperClass()) {
metaMethod = mc.getMethodWithoutCaching(cl.getTheClass(), methodName, arguments, false);
if (metaMethod != null)
break;
}
}
if (metaMethod != null) {
MetaMethod method = new MixinInstanceMetaMethod(metaMethod, mixin);
if (method.getParameterTypes().length == 1 && !method.getParameterTypes()[0].isPrimitive) {
MetaMethod noParam = pickMethod(methodName, EMPTY_CLASS_ARRAY);
// if the current call itself is with empty arg class array, no need to recurse with 'new Class[0]'
if (noParam == null && arguments.length != 0) {
try {
findMixinMethod(methodName, EMPTY_CLASS_ARRAY);
} catch (MethodSelectionException msex) {
/*
* Here we just additionally tried to find another no-arg mixin method of the same name and register that as well, if found.
* Safe to ignore a MethodSelectionException in this additional exercise. (GROOVY-4999)
*/
}
}
}
registerInstanceMethod(method);
return method;
}
}
return null;
}
Aggregations