本文整理了Java中groovy.lang.MetaClass.pickMethod()
方法的一些代码示例,展示了MetaClass.pickMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.pickMethod()
方法的具体详情如下:
包路径:groovy.lang.MetaClass
类名称:MetaClass
方法名:pickMethod
[英]Selects a method by name and argument classes. This method does not search for an exact match, it searches for a compatible method. For this the method selection mechanism is used as provided bye the implementation of this MetaClass. pickMethod may or may not used during the method selection process when invoking a method thereis no warranty for that.
[中]按名称和参数类选择方法。此方法不搜索精确匹配,而是搜索兼容的方法。为此,该元类的实现提供了方法选择机制。调用方法时,在方法选择过程中可以使用或不使用pickMethod,对此不作任何保证。
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* @deprecated
*/
@Deprecated
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return delegate.pickMethod(methodName, arguments);
}
代码示例来源:origin: org.codehaus.groovy/groovy
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;
}
代码示例来源:origin: spockframework/spock
@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;
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
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);
}
代码示例来源:origin: spockframework/spock
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;
}
代码示例来源:origin: org.codehaus.groovy/groovy
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;
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
} else {
MetaClass delegateMetaClass = lookupObjectMetaClass(delegate);
MetaMethod method = delegateMetaClass.pickMethod(methodName, argClasses);
if (method != null) {
return method;
代码示例来源:origin: spockframework/spock
MetaMethod metaMethod = delegate.pickMethod(methodName, ReflectionUtil.getTypes(arguments));
Method method = GroovyRuntimeUtil.toMethod(metaMethod);
代码示例来源:origin: org.codehaus.groovy/groovy
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);
代码示例来源:origin: org.codehaus.groovy/groovy
MetaMethod metaMethod = metaClass.pickMethod(methodName, arguments);
if (metaMethod == null && metaClass instanceof MetaClassImpl) {
MetaClassImpl mc = (MetaClassImpl) metaClass;
代码示例来源:origin: org.gmock/gmock
public Object call() {
return adaptee.pickMethod(methodName, arguments);
}
}, new Callable() {
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return delegate.pickMethod(methodName,arguments);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return delegate.pickMethod(methodName, arguments);
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return delegate.pickMethod(methodName, arguments);
}
代码示例来源:origin: org.kohsuke.droovy/groovy
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
return delegate.pickMethod(methodName,arguments);
}
代码示例来源:origin: org.gradle/gradle-core
@Nullable
protected MetaMethod lookupMethod(MetaClass metaClass, String name, Class[] arguments) {
return metaClass.pickMethod(name, arguments);
}
代码示例来源:origin: org.codehaus.groovy/groovy-jdk14
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.pickMethod(methodName,arguments);
}
代码示例来源:origin: org.kohsuke.droovy/groovy
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.pickMethod(methodName,arguments);
}
代码示例来源:origin: com.thinkaurelius.groovy-shaded-asm/groovy-shaded-asm
/**
* @deprecated
*/
public MetaMethod pickMethod(String methodName, Class[] arguments) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.pickMethod(methodName,arguments);
}
代码示例来源:origin: org.codehaus.groovy/groovy-all-minimal
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);
}
}
内容来源于网络,如有侵权,请联系作者删除!