本文整理了Java中groovy.lang.GroovyClassLoader.parseClass()
方法的一些代码示例,展示了GroovyClassLoader.parseClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GroovyClassLoader.parseClass()
方法的具体详情如下:
包路径:groovy.lang.GroovyClassLoader
类名称:GroovyClassLoader
方法名:parseClass
[英]Parses the given code source into a Java class. If there is a class file for the given code source, then no parsing is done, instead the cached class is returned.
[中]将给定的代码源解析为Java类。如果给定的代码源有一个类文件,则不进行解析,而是返回缓存的类。
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Parses the groovy code contained in codeSource and returns a java class.
*/
private Class parseClass(final GroovyCodeSource codeSource) throws CompilationFailedException {
// Don't cache scripts
return loader.parseClass(codeSource, false);
}
代码示例来源:origin: groovy/groovy-core
public Class compile(String fileName) throws Exception {
return loader.parseClass(new File(fileName));
}
}
代码示例来源:origin: groovy/groovy-core
public Class parseClass(final GroovyCodeSource codeSource, Map<String, String> hints) throws CompilationFailedException {
modelTypes.set(hints);
try {
return super.parseClass(codeSource);
} finally {
modelTypes.set(null);
}
}
}
代码示例来源:origin: Netflix/zuul
/**
* Compiles groovy class from a file
*
* @param file
* @return
* @throws java.io.IOException
*/
public Class compile(File file) throws IOException {
GroovyClassLoader loader = getGroovyClassLoader();
Class groovyClass = loader.parseClass(file);
return groovyClass;
}
代码示例来源:origin: Netflix/zuul
/**
* compiles the Groovy source code
*
* @param sFilterCode
* @return
* @throws org.codehaus.groovy.control.CompilationFailedException
*
*/
public Class compileGroovy(String sFilterCode) throws org.codehaus.groovy.control.CompilationFailedException {
GroovyClassLoader loader = new GroovyClassLoader();
return loader.parseClass(sFilterCode);
}
代码示例来源:origin: Netflix/zuul
/**
* Compiles Groovy code and returns the Class of the compiles code.
*
* @param sCode
* @param sName
* @return
*/
public Class compile(String sCode, String sName) {
GroovyClassLoader loader = getGroovyClassLoader();
LOG.warn("Compiling filter: " + sName);
Class groovyClass = loader.parseClass(sCode, sName);
return groovyClass;
}
代码示例来源:origin: apache/groovy
Class<?> getScriptClass(String script)
throws CompilationFailedException {
Class<?> clazz = classMap.get(script);
if (clazz != null) {
return clazz;
}
clazz = loader.parseClass(script, generateScriptName());
classMap.put(script, clazz);
return clazz;
}
代码示例来源:origin: Netflix/zuul
/**
* compiles the Groovy source code
*
* @param sFilterCode
* @return
* @throws org.codehaus.groovy.control.CompilationFailedException
*
*/
public Class compileGroovy(String sFilterCode) throws org.codehaus.groovy.control.CompilationFailedException {
GroovyClassLoader loader = new GroovyClassLoader();
return loader.parseClass(sFilterCode);
}
代码示例来源:origin: org.codehaus.groovy/groovy
/**
* Parses the given file into a Java class capable of being run
*
* @param file the file name to parse
* @return the main class defined in the given script
*/
public Class parseClass(File file) throws CompilationFailedException, IOException {
return parseClass(new GroovyCodeSource(file, config.getSourceEncoding()));
}
代码示例来源:origin: Netflix/zuul
/**
* Compiles groovy class from a file
*
* @param file
* @return
* @throws java.io.IOException
*/
public Class compile(File file) throws IOException {
GroovyClassLoader loader = getGroovyClassLoader();
Class groovyClass = loader.parseClass(file);
return groovyClass;
}
代码示例来源:origin: Netflix/zuul
/**
* Compiles Groovy code and returns the Class of the compiles code.
*
* @param sCode
* @param sName
* @return
*/
public Class compile(String sCode, String sName) {
GroovyClassLoader loader = getGroovyClassLoader();
LOG.warn("Compiling filter: " + sName);
Class groovyClass = loader.parseClass(sCode, sName);
return groovyClass;
}
代码示例来源:origin: spring-projects/spring-framework
this.scriptClass = getGroovyClassLoader().parseClass(
scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
代码示例来源:origin: spring-projects/spring-framework
this.scriptClass = getGroovyClassLoader().parseClass(
scriptSource.getScriptAsString(), scriptSource.suggestedClassName());
代码示例来源:origin: groovy/groovy-core
protected Class parseClass(final GroovyCodeSource gcs) {
Class clazz = null;
try {
clazz = loader.parseClass(gcs);
} catch (Exception e) {
fail(e.toString());
}
return clazz;
}
代码示例来源:origin: groovy/groovy-core
protected void assertScript(final String text, final String scriptName) throws Exception {
log.info("About to execute script");
log.info(text);
GroovyCodeSource gcs = (GroovyCodeSource) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return new GroovyCodeSource(text, scriptName, "/groovy/testSupport");
}
});
Class groovyClass = loader.parseClass(gcs);
Script script = InvokerHelper.createScript(groovyClass, new Binding());
script.run();
}
代码示例来源:origin: groovy/groovy-core
protected GroovyObject compile(String fileName) throws Exception {
Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
GroovyObject object = (GroovyObject) groovyClass.newInstance();
assertTrue(object != null);
return object;
}
}
代码示例来源:origin: twosigma/beakerx
public Object parseClassFromScript(String script) {
Class<?> parsedClass = groovyClassLoader.parseClass(script);
Script instance = null;
try {
instance = (Script) parsedClass.newInstance();
instance.setBinding(scriptBinding);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return instance.run();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("resource")
public void classLoading() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
GroovyClassLoader gcl = new GroovyClassLoader();
Class<?> class1 = gcl.parseClass("class TestBean { def myMethod() { \"foo\" } }");
Class<?> class2 = gcl.parseClass("class TestBean { def myMethod() { \"bar\" } }");
context.registerBeanDefinition("testBean", new RootBeanDefinition(class1));
Object testBean1 = context.getBean("testBean");
Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
assertEquals("foo", result1);
context.removeBeanDefinition("testBean");
context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
Object testBean2 = context.getBean("testBean");
Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
assertEquals("bar", result2);
}
代码示例来源:origin: groovy/groovy-core
protected void assertScriptFile(String fileName) throws Exception {
log.info("About to execute script: " + fileName);
Class groovyClass = loader.parseClass(new GroovyCodeSource(new File(fileName)));
Script script = InvokerHelper.createScript(groovyClass, new Binding());
script.run();
}
代码示例来源:origin: groovy/groovy-core
private void parseAndExecute(final GroovyCodeSource gcs, Permission missingPermission) {
Class clazz = null;
try {
clazz = loader.parseClass(gcs);
} catch (Exception e) {
fail(e.toString());
}
if (TestCase.class.isAssignableFrom(clazz)) {
executeTest(clazz, missingPermission);
} else {
executeScript(clazz, missingPermission);
}
}
内容来源于网络,如有侵权,请联系作者删除!