本文整理了Java中groovy.lang.MetaClass.invokeMethod()
方法的一些代码示例,展示了MetaClass.invokeMethod()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MetaClass.invokeMethod()
方法的具体详情如下:
包路径:groovy.lang.MetaClass
类名称:MetaClass
方法名:invokeMethod
[英]Invokes a method on the given receiver for the specified arguments. The sender is the class that invoked the method on the object. The MetaClass will attempt to establish the method to invoke based on the name and arguments provided.
The isCallToSuper and fromInsideClass help the Groovy runtime perform optimisations on the call to go directly to the super class if necessary
[中]为指定的参数调用给定接收器上的方法。sender是在对象上调用方法的类。元类将根据提供的名称和参数尝试建立要调用的方法。
isCallToSuper和FromInsidelClass可帮助Groovy运行时在调用时执行优化,以便在必要时直接转到超级类
代码示例来源:origin: spring-projects/spring-framework
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: spring-projects/spring-framework
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: spring-projects/spring-framework
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: jenkinsci/jenkins
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: org.springframework/spring-context
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: org.springframework/spring-beans
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: org.springframework/spring-web
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
代码示例来源:origin: apache/nifi
/**
* GroovyObject support method
*/
@Override
public Object invokeMethod(String name, Object args) {
return this.metaClass.invokeMethod(this, name, args);
}
/*----------------------<< GroovyObject methods---------------------------*/
代码示例来源:origin: groovy/groovy-core
public Object invokeMethod(String name, Object arguments) {
return metaClass.invokeMethod(this, name, arguments);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
private static Object invokeStaticClosureProperty(Object[] originalArguments, Object prop) {
Closure closure = (Closure) prop;
MetaClass delegateMetaClass = closure.getMetaClass();
return delegateMetaClass.invokeMethod(closure.getClass(), closure, CLOSURE_DO_CALL_METHOD, originalArguments, false, false);
}
代码示例来源:origin: groovy/groovy-core
public Object invokeMethod(final String name, final Object args) {
if ("x".equals(name)) {
return "dynamic method";
} else {
return this.metaClass.invokeMethod(this, name, args);
}
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object invokeMethod(Object object, String methodName, Object arguments) {
final Object owner = getOwner();
final MetaClass ownerMetaClass = getOwnerMetaClass(owner);
return ownerMetaClass.invokeMethod(owner, methodName, arguments);
}
代码示例来源:origin: spring-projects/spring-framework
return mc.invokeMethod(getRegistry(), name, args);
代码示例来源:origin: jenkinsci/jenkins
/**
* This method is invoked by Groovy when a method that's not defined in Java is invoked.
* We use that as a syntax for bean definition.
*/
public Object methodMissing(String name, Object arg) {
Object[] args = (Object[])arg;
if(args.length == 0)
throw new MissingMethodException(name,getClass(),args);
if(args[0] instanceof Closure) {
// abstract bean definition
return invokeBeanDefiningMethod(name, args);
}
else if(args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) {
return invokeBeanDefiningMethod(name, args);
}
else if (args.length > 1 && args[args.length -1] instanceof Closure) {
return invokeBeanDefiningMethod(name, args);
}
WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
if(!mc.respondsTo(ctx, name, args).isEmpty()){
return mc.invokeMethod(ctx,name, args);
}
return this;
}
代码示例来源:origin: groovy/groovy-core
public void testMetaClass() {
Class foo = String[].class;
System.out.println(foo + " name: " + foo.getName());
MetaClass metaClass = InvokerHelper.getMetaClass(this);
assertTrue("got metaclass", metaClass != null);
metaClass.invokeMethod(this, "doSomething", new Object[0]);
}
代码示例来源:origin: org.codehaus.groovy/groovy
public Object call(Object receiver, Object[] args) throws Throwable {
if (receiver != null && info.hasPerInstanceMetaClasses()) {
try {
return InvokerHelper.getMetaClass(receiver).invokeMethod(receiver, name, args);
} catch (GroovyRuntimeException gre) {
throw ScriptBytecodeAdapter.unwrap(gre);
}
} else {
return CallSiteArray.defaultCall(this, receiver, args);
}
}
}
代码示例来源:origin: groovy/groovy-core
public void testObject() {
Object value = new Object();
MetaClass metaClass = InvokerHelper.getMetaClass(value);
assertTrue("got metaclass", metaClass != null);
metaClass.invokeMethod(value, "toString", new Object[0]);
}
代码示例来源:origin: groovy/groovy-core
public void testArray() {
String[] value = new String[]{"hello"};
MetaClass metaClass = InvokerHelper.getMetaClass(value);
assertTrue("got metaclass", metaClass != null);
metaClass.invokeMethod(value, "toString", new Object[0]);
}
代码示例来源:origin: spockframework/spock
@Override
public Object respond(IMockInvocation invocation) {
Object instance = invocation.getMockObject().getInstance();
Object[] arguments = invocation.getArguments().toArray();
if (invocation.getMethod().isStatic()) {
if ("<init>".equals(invocation.getMethod().getName())) {
return metaClass.invokeConstructor(arguments);
}
return metaClass.invokeStaticMethod(instance, invocation.getMethod().getName(), arguments);
}
return metaClass.invokeMethod(instance, invocation.getMethod().getName(), arguments);
}
}
代码示例来源:origin: groovy/groovy-core
public void testString() {
String value = "hello";
MetaClass metaClass = InvokerHelper.getMetaClass(value);
assertTrue("got metaclass", metaClass != null);
Object answer = metaClass.invokeMethod(value, "toString", new Object[0]);
assertEquals("hello", answer);
}
内容来源于网络,如有侵权,请联系作者删除!