本文整理汇总了Java中org.codehaus.groovy.runtime.InvokerHelper.invokeStaticMethod方法的典型用法代码示例。如果您正苦于以下问题:Java InvokerHelper.invokeStaticMethod方法的具体用法?Java InvokerHelper.invokeStaticMethod怎么用?Java InvokerHelper.invokeStaticMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.groovy.runtime.InvokerHelper
的用法示例。
在下文中一共展示了InvokerHelper.invokeStaticMethod方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryMacroMethod
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Attempts to call given macroMethod
* @param call MethodCallExpression before the transformation
* @param macroMethod a macro method candidate
* @param macroArguments arguments to pass to
* @return true if call succeeded and current call was transformed
*/
private boolean tryMacroMethod(MethodCallExpression call, ExtensionMethodNode macroMethod, Object[] macroArguments) {
Expression result = (Expression) InvokerHelper.invokeStaticMethod(
macroMethod.getExtensionMethodNode().getDeclaringClass().getTypeClass(),
macroMethod.getName(),
macroArguments
);
if (result == null) {
// Allow macro methods to return null as an indicator that they didn't match a method call
return false;
}
call.setObjectExpression(MACRO_STUB_INSTANCE);
call.setMethod(new ConstantExpression(MACRO_STUB_METHOD_NAME));
// TODO check that we reset everything here
call.setSpreadSafe(false);
call.setSafe(false);
call.setImplicitThis(false);
call.setArguments(result);
call.setGenericsTypes(new GenericsType[0]);
return true;
}
示例2: run
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Run the specified class extending TestCase as a unit test.
* This is done through reflection, to avoid adding a dependency to the JUnit framework.
* Otherwise, developers embedding Groovy and using GroovyShell to load/parse/compile
* groovy scripts and classes would have to add another dependency on their classpath.
*
* @param scriptClass the class to be run as a unit test
* @param loader the class loader
*/
@Override
public Object run(Class<?> scriptClass, GroovyClassLoader loader) {
try {
Class<?> junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
"runClasses", new Object[]{scriptClass});
System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
List<?> failures = (List<?>) InvokerHelper.getProperty(result, "failures");
for (Object f : failures) {
System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
System.out.println(InvokerHelper.getProperty(f, "trace"));
}
return result;
} catch (ClassNotFoundException e) {
throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
}
}
示例3: realRunJUnit4Test
import org.codehaus.groovy.runtime.InvokerHelper; //导入方法依赖的package包/类
/**
* Utility method to run a JUnit4 test.
*
* @param scriptClass the class we want to run as a test
* @return the result of running the test
*/
static Object realRunJUnit4Test(Class scriptClass, GroovyClassLoader loader) {
// invoke through reflection to eliminate mandatory JUnit 4 jar dependency
try {
Class junitCoreClass = loader.loadClass("org.junit.runner.JUnitCore");
Object result = InvokerHelper.invokeStaticMethod(junitCoreClass,
"runClasses", new Object[]{scriptClass});
System.out.print("JUnit 4 Runner, Tests: " + InvokerHelper.getProperty(result, "runCount"));
System.out.print(", Failures: " + InvokerHelper.getProperty(result, "failureCount"));
System.out.println(", Time: " + InvokerHelper.getProperty(result, "runTime"));
List failures = (List) InvokerHelper.getProperty(result, "failures");
for (int i = 0; i < failures.size(); i++) {
Object f = failures.get(i);
System.out.println("Test Failure: " + InvokerHelper.getProperty(f, "description"));
System.out.println(InvokerHelper.getProperty(f, "trace"));
}
return result;
} catch (ClassNotFoundException e) {
throw new GroovyRuntimeException("Error running JUnit 4 test.", e);
}
}
示例4: 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];
}
示例5: 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];
}