本文整理汇总了Java中org.codehaus.groovy.runtime.InvokerHelper.invokeMethod方法的典型用法代码示例。如果您正苦于以下问题:Java InvokerHelper.invokeMethod方法的具体用法?Java InvokerHelper.invokeMethod怎么用?Java InvokerHelper.invokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.runtime.InvokerHelper
的用法示例。
在下文中一共展示了InvokerHelper.invokeMethod方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeImpl
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
private Object invokeImpl(Object thiz, String name, Object... args)
throws ScriptException, NoSuchMethodException {
if (name == null) {
throw new NullPointerException("method name is null");
}
try {
if (thiz != null) {
return InvokerHelper.invokeMethod(thiz, name, args);
} else {
return callGlobal(name, args);
}
} catch (MissingMethodException mme) {
throw new NoSuchMethodException(mme.getMessage());
} catch (Exception e) {
throw new ScriptException(e);
}
}
示例2: addListeners
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Add listeners to a specific object. Updates the bould flags and update set
*
* @param listener This listener to attach.
* @param newObject The object we should read our property off of.
* @param updateSet The list of objects we have added listeners to
*/
public void addListeners(PropertyChangeListener listener, Object newObject, Set updateSet) {
removeListeners();
if (newObject != null) {
// check for local synthetics
TriggerBinding syntheticTrigger = getSyntheticTriggerBinding(newObject);
MetaClass mc = InvokerHelper.getMetaClass(newObject);
if (syntheticTrigger != null) {
PropertyBinding psb = new PropertyBinding(newObject, propertyName);
PropertyChangeProxyTargetBinding proxytb = new PropertyChangeProxyTargetBinding(newObject, propertyName, listener);
syntheticFullBinding = syntheticTrigger.createBinding(psb, proxytb);
syntheticFullBinding.bind();
updateSet.add(newObject);
} else if (!mc.respondsTo(newObject, "addPropertyChangeListener", NAME_PARAMS).isEmpty()) {
InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", new Object[] {propertyName, listener});
localListener = listener;
updateSet.add(newObject);
} else if (!mc.respondsTo(newObject, "addPropertyChangeListener", GLOBAL_PARAMS).isEmpty()) {
InvokerHelper.invokeMethod(newObject, "addPropertyChangeListener", listener);
globalListener = listener;
updateSet.add(newObject);
}
}
currentObject = newObject;
}
示例3: testConstruction
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testConstruction() {
Sequence sequence = new Sequence(String.class);
sequence.add("James");
sequence.add("Bob");
assertEquals("Size", 2, sequence.size());
assertEquals("Element", "James", sequence.get(0));
assertEquals("Element", "Bob", sequence.get(1));
// now lets try some methods on each item in the list
List answer = (List) InvokerHelper.invokeMethod(sequence, "startsWith", new Object[]{"Ja"});
assertArrayEquals(new Object[]{Boolean.TRUE, Boolean.FALSE}, answer.toArray());
answer = (List) InvokerHelper.invokeMethod(sequence, "length", null);
assertArrayEquals(new Object[]{new Integer(5), new Integer(3)}, answer.toArray());
}
示例4: invokeMethod
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
@Override
public Object invokeMethod(String name, Object args) {
if (name.equals("dependency") || name.equals("dependencies") || name.equals("module")) {
return InvokerHelper.invokeMethod(moduleFactoryDelegate, name, args);
} else {
return InvokerHelper.invokeMethod(clientModule, name, args);
}
}
示例5: addAll
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public boolean addAll(Collection values) {
boolean retVal = (Boolean) InvokerHelper.invokeMethod(this.propertyValue, "addAll", values);
for (Object value : values) {
updateDeferredProperties(value);
}
return retVal;
}
示例6: invokeImpl
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
private Object invokeImpl(final Object thiz, final String name, final Object args[]) throws ScriptException, NoSuchMethodException {
if (name == null) {
throw new NullPointerException("Method name can not be null");
}
try {
if (thiz != null) {
return InvokerHelper.invokeMethod(thiz, name, args);
}
} catch (MissingMethodException mme) {
throw new NoSuchMethodException(mme.getMessage());
} catch (Exception e) {
throw new ScriptException(e);
}
return callGlobal(name, args);
}
示例7: methodMissing
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
@SuppressWarnings("UnusedDeclaration")
@Nullable
public Object methodMissing(String name, Object args) {
final Object[] newArgs = constructNewArgs((Object[])args);
// Get other DSL methods from extensions
for (GdslMembersProvider provider : PROVIDERS) {
final List<MetaMethod> variants = DefaultGroovyMethods.getMetaClass(provider).respondsTo(provider, name, newArgs);
if (variants.size() == 1) {
return InvokerHelper.invokeMethod(provider, name, newArgs);
}
}
return null;
}
示例8: printf
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Prints a formatted string using the specified format string and argument.
*
* @param format the format to follow
* @param value the value to be formatted
*/
public void printf(String format, Object value) {
Object object;
try {
object = getProperty("out");
} catch (MissingPropertyException e) {
DefaultGroovyMethods.printf(System.out, format, value);
return;
}
InvokerHelper.invokeMethod(object, "printf", new Object[] { format, value });
}
示例9: testLoop
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE.makeArray(), "coll")};
Statement loopStatement = createPrintlnStatement(new VariableExpression("i"));
ForStatement statement = new ForStatement(new Parameter(ClassHelper.OBJECT_TYPE, "i"), new VariableExpression("coll"), loopStatement);
classNode.addMethod(new MethodNode("iterateDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method with looping");
Object[] array = {new Integer(1234), "abc", "def"};
try {
InvokerHelper.invokeMethod(bean, "iterateDemo", new Object[]{array});
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}
示例10: invokeMethod
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Overloaded to implement duck typing for Strings
* so that any method that can't be evaluated on this
* object will be forwarded to the toString() object instead.
*/
@Override
public Object invokeMethod(String name, Object args) {
try {
return super.invokeMethod(name, args);
}
catch (MissingMethodException e) {
// lets try invoke the method on the real String
return InvokerHelper.invokeMethod(toString(), name, args);
}
}
示例11: testNonLoop
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public void testNonLoop() throws Exception {
ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC, ClassHelper.OBJECT_TYPE);
classNode.addConstructor(new ConstructorNode(ACC_PUBLIC, null));
Parameter[] parameters = {new Parameter(ClassHelper.OBJECT_TYPE, "coll")};
Statement statement = createPrintlnStatement(new VariableExpression("coll"));
classNode.addMethod(new MethodNode("oneParamDemo", ACC_PUBLIC, ClassHelper.VOID_TYPE, parameters, ClassNode.EMPTY_ARRAY, statement));
Class fooClass = loadClass(classNode);
assertTrue("Loaded a new class", fooClass != null);
Object bean = fooClass.newInstance();
assertTrue("Managed to create bean", bean != null);
System.out.println("################ Now about to invoke a method without looping");
Object value = new Integer(10000);
try {
InvokerHelper.invokeMethod(bean, "oneParamDemo", new Object[]{value});
} catch (InvokerInvocationException e) {
System.out.println("Caught: " + e.getCause());
e.getCause().printStackTrace();
fail("Should not have thrown an exception");
}
System.out.println("################ Done");
}
示例12: castToBoolean
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Method used for coercing an object to a boolean value,
* thanks to an <code>asBoolean()</code> method added on types.
*
* @param object to coerce to a boolean value
* @return a boolean value
*/
public static boolean castToBoolean(Object object) {
// null is always false
if (object == null) {
return false;
}
// equality check is enough and faster than instanceof check, no need to check superclasses since Boolean is final
if (object.getClass() == Boolean.class) {
return ((Boolean) object).booleanValue();
}
// if the object is not null and no Boolean, try to call an asBoolean() method on the object
return (Boolean) InvokerHelper.invokeMethod(object, "asBoolean", InvokerHelper.EMPTY_ARGS);
}
示例13: next
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* This method is called by the ++ operator for enums. It will invoke
* Groovy's default next behaviour for enums do not have their own
* next method.
*
* @param self an Enum
* @return the next defined enum from the enum class
*/
public static Object next(Enum self) {
final Method[] methods = self.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("next") && method.getParameterTypes().length == 0) {
return InvokerHelper.invokeMethod(self, "next", NO_ARGS);
}
}
Object[] values = (Object[]) InvokerHelper.invokeStaticMethod(self.getClass(), "values", NO_ARGS);
int index = Arrays.asList(values).indexOf(self);
return values[index < values.length - 1 ? index + 1 : 0];
}
示例14: previous
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* This method is called by the -- operator for enums. It will invoke
* Groovy's default previous behaviour for enums that do not have
* their own previous method.
*
* @param self an Enum
* @return the previous defined enum from the enum class
*/
public static Object previous(Enum self) {
final Method[] methods = self.getClass().getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals("previous") && method.getParameterTypes().length == 0) {
return InvokerHelper.invokeMethod(self, "previous", NO_ARGS);
}
}
Object[] values = (Object[]) InvokerHelper.invokeStaticMethod(self.getClass(), "values", NO_ARGS);
int index = Arrays.asList(values).indexOf(self);
return values[index > 0 ? index - 1 : values.length - 1];
}
示例15: isSatisfiedBy
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
public boolean isSatisfiedBy(T element) {
Object value = closure.call(element);
return (Boolean)InvokerHelper.invokeMethod(value, "asBoolean", null);
}