/** * @deprecated */ @Deprecated public MetaMethod pickMethod(String methodName, Class[] arguments) { return delegate.pickMethod(methodName, arguments); }
protected static MetaMethod findOwnMethod(Class instanceKlazz, String methodName, Class[] arguments, MetaClass metaClass, MetaMethod method) { // we trick ourselves here if (instanceKlazz == metaClass.getTheClass()) return method; MetaMethod ownMethod = metaClass.pickMethod(methodName, arguments); if (ownMethod != null) { if (method == null) method = ownMethod; else method = mostSpecific(method, ownMethod, instanceKlazz); } return method; }
@Override public ISlot create(Object owner, Type ownerType, String name) { String addMethodName = GroovyRuntimeUtil.propertyToMethodName("add", name); MetaMethod addMethod = GroovyRuntimeUtil.getMetaClass(owner).pickMethod(addMethodName, new Class[]{Object.class}); return addMethod != null ? new SetterLikeSlot(owner, ownerType, addMethod) : null; } }
private Tuple2<Object, MetaMethod> invokeMethod(MetaMethod method, Object delegate, Closure closure, String methodName, Class[] argClasses, Object[] originalArguments, Object owner) { if (method == null && delegate != closure && delegate != null) { MetaClass delegateMetaClass = lookupObjectMetaClass(delegate); method = delegateMetaClass.pickMethod(methodName, argClasses); if (method != null) return new Tuple2<Object,MetaMethod>(delegateMetaClass.invokeMethod(delegate, methodName, originalArguments), method); } if (method == null && owner != closure) { MetaClass ownerMetaClass = lookupObjectMetaClass(owner); method = ownerMetaClass.pickMethod(methodName, argClasses); if (method != null) return new Tuple2<Object,MetaMethod>(ownerMetaClass.invokeMethod(owner, methodName, originalArguments), method); } return new Tuple2<Object,MetaMethod>(InvokeMethodResult.NONE, method); }
public static boolean isVoidMethod(@Nullable Object target, String method, Object... args) { if (target == null) return false; // no way to tell Class[] argTypes = ReflectionUtil.getTypes(args); // the way we choose metaClass, we won't find methods on java.lang.Class // but since java.lang.Class has no void methods other than the ones inherited // from java.lang.Object, and since we operate on a best effort basis, that's OK // also we will choose a static method like Foo.getName() over the equally // named method on java.lang.Class, but this is consistent with current Groovy semantics // (see http://jira.codehaus.org/browse/GROOVY-3548) // in the end it's probably best to rely on NullAwareInvokeMethodSpec to tell us if // everything is OK MetaClass metaClass = target instanceof Class ? InvokerHelper.getMetaClass((Class) target) : InvokerHelper.getMetaClass(target); // seems to find more methods than getMetaMethod() MetaMethod metaMethod = metaClass.pickMethod(method, argTypes); if (metaMethod == null) return false; // we were unable to figure out which method was called Class returnType = metaMethod.getReturnType(); // although Void.class will occur rarely, it makes sense to handle // it in the same way as void.class return returnType == void.class || returnType == Void.class; }
private MetaMethod pickStaticMethod(String methodName, Class[] arguments) { MetaMethod method = null; MethodSelectionException mse = null; Object methods = getStaticMethods(theClass, methodName); if (!(methods instanceof FastArray) || !((FastArray)methods).isEmpty()) { try { method = (MetaMethod) chooseMethod(methodName, methods, arguments); } catch(MethodSelectionException msex) { mse = msex; } } if (method == null && theClass != Class.class) { MetaClass classMetaClass = registry.getMetaClass(Class.class); method = classMetaClass.pickMethod(methodName, arguments); } if (method == null) { method = (MetaMethod) chooseMethod(methodName, methods, MetaClassHelper.convertToTypeArray(arguments)); } if (method == null && mse != null) { throw mse; } else { return method; } }
} else { MetaClass delegateMetaClass = lookupObjectMetaClass(delegate); MetaMethod method = delegateMetaClass.pickMethod(methodName, argClasses); if (method != null) { return method;
MetaMethod metaMethod = delegate.pickMethod(methodName, ReflectionUtil.getTypes(arguments)); Method method = GroovyRuntimeUtil.toMethod(metaMethod);
method = closure.getMetaClass().pickMethod(methodName, argClasses); if (method != null) return method.invoke(closure, arguments); break; if (method == null && delegate != closure && delegate != null) { MetaClass delegateMetaClass = lookupObjectMetaClass(delegate); method = delegateMetaClass.pickMethod(methodName, argClasses); if (method != null) return delegateMetaClass.invokeMethod(delegate, methodName, originalArguments);
MetaMethod metaMethod = metaClass.pickMethod(methodName, arguments); if (metaMethod == null && metaClass instanceof MetaClassImpl) { MetaClassImpl mc = (MetaClassImpl) metaClass;
public Object call() { return adaptee.pickMethod(methodName, arguments); } }, new Callable() {
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { return delegate.pickMethod(methodName,arguments); }
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { return delegate.pickMethod(methodName, arguments); }
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { return delegate.pickMethod(methodName, arguments); }
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { return delegate.pickMethod(methodName,arguments); }
@Nullable protected MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) { return metaClass.pickMethod(name, arguments); }
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.pickMethod(methodName,arguments); }
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.pickMethod(methodName,arguments); }
/** * @deprecated */ public MetaMethod pickMethod(String methodName, Class[] arguments) { final Object owner = getOwner(); final MetaClass ownerMetaClass = getOwnerMetaClass(owner); return ownerMetaClass.pickMethod(methodName,arguments); }
private MetaMethod getDelegateMethod(Closure closure, Object delegate, String methodName, Class[] argClasses) { if (delegate == closure || delegate == null) return null; MetaClass delegateMetaClass; if (delegate instanceof Class) { delegateMetaClass = registry.getMetaClass((Class)delegate); return delegateMetaClass.getStaticMetaMethod(methodName, argClasses); } else { delegateMetaClass = lookupObjectMetaClass(delegate); return delegateMetaClass.pickMethod(methodName, argClasses); } }