本文整理汇总了Java中org.codehaus.groovy.control.customizers.ASTTransformationCustomizer类的典型用法代码示例。如果您正苦于以下问题:Java ASTTransformationCustomizer类的具体用法?Java ASTTransformationCustomizer怎么用?Java ASTTransformationCustomizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ASTTransformationCustomizer类属于org.codehaus.groovy.control.customizers包,在下文中一共展示了ASTTransformationCustomizer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: runGroovyDslScript
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
/**
* Runs a Groovy DSL script and returns the value returned by the script.
* @param scriptReader For reading the script text
* @param expectedType The expected type of the return value
* @param parameters Parameters used by the script, null or empty if the script doesn't need any
* @param <T> The expected type of the return value
* @return The return value of the script, not null
*/
private static <T> T runGroovyDslScript(Reader scriptReader, Class<T> expectedType, Map<String, Object> parameters) {
Map<String, Object> timeoutArgs = ImmutableMap.<String, Object>of("value", 2);
ASTTransformationCustomizer customizer = new ASTTransformationCustomizer(timeoutArgs, TimedInterrupt.class);
CompilerConfiguration config = new CompilerConfiguration();
config.addCompilationCustomizers(customizer);
config.setScriptBaseClass(SimulationScript.class.getName());
Map<String, Object> bindingMap = parameters == null ? Collections.<String, Object>emptyMap() : parameters;
//copy map to ensure that binding is mutable (for use in registerAliases)
Binding binding = new Binding(Maps.newHashMap(bindingMap));
registerAliases(binding);
GroovyShell shell = new GroovyShell(binding, config);
Script script = shell.parse(scriptReader);
Object scriptOutput = script.run();
if (scriptOutput == null) {
throw new IllegalArgumentException("Script " + scriptReader + " didn't return an object");
}
if (expectedType.isInstance(scriptOutput)) {
return expectedType.cast(scriptOutput);
} else {
throw new IllegalArgumentException("Script '" + scriptReader + "' didn't create an object of the expected type. " +
"expected type: " + expectedType.getName() + ", " +
"actual type: " + scriptOutput.getClass().getName() + ", " +
"actual value: " + scriptOutput);
}
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:34,代码来源:SimulationUtils.java
示例2: getShell
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
private GroovyShell getShell(Binding binding, GroovyInterceptor sandbox, GenericUserMessageEvent event) {
binding.setVariable("eval", getEvalFunction(binding, sandbox, event));
binding.setVariable("commands", new DynamicCommandHandler(this, event));
CompilerConfiguration cc = new CompilerConfiguration();
cc.addCompilationCustomizers(
new SandboxTransformer(),
new ASTTransformationCustomizer(ImmutableMap.of("value", TIMEOUT), TimedInterrupt.class),
new ImportCustomizer()
.addStarImports("java.lang.reflect")
.addImports(HttpRequest.class.getName())
.addImports(CommandCall.class.getName())
);
GroovyShell shell = new GroovyShell(manager.pluginClassLoader, binding, cc);
sandbox.register();
return shell;
}
开发者ID:Shockah,项目名称:Skylark,代码行数:17,代码来源:GroovyPlugin.java
示例3: GroovyConditionShell
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
public GroovyConditionShell() {
SecureASTCustomizer secureASTCustomizer = createSecureASTCustomizer();
ImportCustomizer importCustomizer = createImportCustomizer();
ASTTransformationCustomizer astTransformationCustomizer = createASTTransformationCustomizer();
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
compilerConfiguration.addCompilationCustomizers(secureASTCustomizer);
compilerConfiguration.addCompilationCustomizers(importCustomizer);
compilerConfiguration.addCompilationCustomizers(astTransformationCustomizer);
this.shell = new GroovyShell(compilerConfiguration);
}
开发者ID:eclipse,项目名称:keti,代码行数:14,代码来源:GroovyConditionShell.java
示例4: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final Map<String, Object> timedInterruptAnnotationParams = new HashMap<>();
timedInterruptAnnotationParams.put("value", interruptionTimeout);
timedInterruptAnnotationParams.put("unit", GeneralUtils.propX(GeneralUtils.classX(TimeUnit.class), TimeUnit.MILLISECONDS.toString()));
timedInterruptAnnotationParams.put("checkOnMethodStart", false);
timedInterruptAnnotationParams.put("thrown", GeneralUtils.classX(TimedInterruptTimeoutException.class));
return new ASTTransformationCustomizer(timedInterruptAnnotationParams, TimedInterrupt.class);
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:10,代码来源:TimedInterruptCustomizerProvider.java
示例5: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final Map<String, Object> annotationParams = new HashMap<>();
if (extensions != null && !extensions.isEmpty()) {
if (extensions.contains(","))
annotationParams.put("extensions", Stream.of(extensions.split(",")).collect(Collectors.toList()));
else
annotationParams.put("extensions", Collections.singletonList(extensions));
}
return new ASTTransformationCustomizer(annotationParams, TypeChecked.class);
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:12,代码来源:TypeCheckedCustomizerProvider.java
示例6: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
final Map<String, Object> annotationParams = new HashMap<>();
if (extensions != null && !extensions.isEmpty()) {
if (extensions.contains(","))
annotationParams.put("extensions", Stream.of(extensions.split(",")).collect(Collectors.toList()));
else
annotationParams.put("extensions", Collections.singletonList(extensions));
}
return new ASTTransformationCustomizer(annotationParams, CompileStatic.class);
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:13,代码来源:CompileStaticCustomizerProvider.java
示例7: createStaticConfiguration
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
protected static CompilerConfiguration createStaticConfiguration() {
CompilerConfiguration compilerConfiguration = new CompilerConfiguration();
ASTTransformationCustomizer astTransformationCustomizer = new ASTTransformationCustomizer(
Collections.singletonMap("extensions", Collections.singletonList("EngineVariablesExtension.groovy")),
CompileStatic.class, "org.codehaus.groovy.transform.sc.StaticCompileTransformation");
compilerConfiguration.addCompilationCustomizers(astTransformationCustomizer);
return compilerConfiguration;
}
开发者ID:flowable,项目名称:flowable-engine,代码行数:9,代码来源:GroovyStaticScriptEngine.java
示例8: MarkupTemplateEngine
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
public MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration tplConfig, final TemplateResolver resolver) {
compilerConfiguration = new CompilerConfiguration();
templateConfiguration = tplConfig;
compilerConfiguration.addCompilationCustomizers(new TemplateASTTransformer(tplConfig));
compilerConfiguration.addCompilationCustomizers(
new ASTTransformationCustomizer(Collections.singletonMap("extensions", "groovy.text.markup.MarkupTemplateTypeCheckingExtension"), CompileStatic.class));
if (templateConfiguration.isAutoNewLine()) {
compilerConfiguration.addCompilationCustomizers(
new CompilationCustomizer(CompilePhase.CONVERSION) {
@Override
public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException {
new AutoNewLineTransformer(source).visitClass(classNode);
}
}
);
}
groovyClassLoader = AccessController.doPrivileged(new PrivilegedAction<TemplateGroovyClassLoader>() {
public TemplateGroovyClassLoader run() {
return new TemplateGroovyClassLoader(parentLoader, compilerConfiguration);
}
});
if (DEBUG_BYTECODE) {
compilerConfiguration.setBytecodePostprocessor(BytecodeDumper.STANDARD_ERR);
}
templateResolver = resolver == null ? new DefaultTemplateResolver() : resolver;
templateResolver.configure(groovyClassLoader, templateConfiguration);
}
开发者ID:apache,项目名称:groovy,代码行数:28,代码来源:MarkupTemplateEngine.java
示例9: ScripterThread
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
public ScripterThread(String script, NetletClassLoader classLoader, boolean isExerted) {
super(tName("Script"));
this.classLoader = classLoader;
this.isExerted = isExerted;
CompilerConfiguration compilerConfig = new CompilerConfiguration();
compilerConfig.setPluginFactory(new ShebangPreprocessorFactory());
compilerConfig.addCompilationCustomizers(getImports());
compilerConfig.addCompilationCustomizers(new ASTTransformationCustomizer(new GroovyCodebaseSupport(classLoader)));
gShell = new GroovyShell(classLoader, new Binding(), compilerConfig);
this.script = script;
}
开发者ID:mwsobol,项目名称:SORCER,代码行数:14,代码来源:ScripterThread.java
示例10: createASTTransformationCustomizer
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
private ASTTransformationCustomizer createASTTransformationCustomizer() {
return new ASTTransformationCustomizer(singletonMap("extensions",
singletonList("com.ge.predix.acs.commons.policy.condition.groovy.GroovySecureExtension")),
CompileStatic.class);
}
开发者ID:eclipse,项目名称:keti,代码行数:7,代码来源:GroovyConditionShell.java
示例11: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
return new ASTTransformationCustomizer(ThreadInterrupt.class);
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:5,代码来源:ThreadInterruptCustomizerProvider.java
示例12: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
return new ASTTransformationCustomizer(InterpreterMode.class);
}
开发者ID:PKUSilvester,项目名称:LiteGraph,代码行数:5,代码来源:InterpreterModeCustomizerProvider.java
注:本文中的org.codehaus.groovy.control.customizers.ASTTransformationCustomizer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论