本文整理汇总了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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例11: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
return new ASTTransformationCustomizer(ThreadInterrupt.class);
}
示例12: create
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer; //导入依赖的package包/类
@Override
public CompilationCustomizer create() {
return new ASTTransformationCustomizer(InterpreterMode.class);
}