org.codehaus.groovy.control.customizers.ASTTransformationCustomizer Java Examples

The following examples show how to use org.codehaus.groovy.control.customizers.ASTTransformationCustomizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarkupTemplateEngine.java    From groovy with Apache License 2.0 6 votes vote down vote up
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((PrivilegedAction<TemplateGroovyClassLoader>) () -> new TemplateGroovyClassLoader(parentLoader, compilerConfiguration));
    if (DEBUG_BYTECODE) {
        compilerConfiguration.setBytecodePostprocessor(BytecodeDumper.STANDARD_ERR);
    }
    templateResolver = resolver == null ? new DefaultTemplateResolver() : resolver;
    templateResolver.configure(groovyClassLoader, templateConfiguration);
}
 
Example #2
Source File: AstUtilTest.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testPrint() {
    ASTTransformationCustomizer astCustomizer = new ASTTransformationCustomizer(new FakeTransformer());
    ImportCustomizer imports = new ImportCustomizer();
    CompilerConfiguration config = new CompilerConfiguration();
    config.addCompilationCustomizers(astCustomizer, imports);
    Binding binding = new Binding();
    assertNull(new GroovyShell(binding, config).evaluate("print('hello')"));
}
 
Example #3
Source File: GroovyStaticScriptEngine.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: TypeCheckedGroovyCustomizer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: CompileStaticGroovyCustomizer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: TimedInterruptGroovyCustomizer.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source File: InterpreterModeGroovyCustomizer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public CompilationCustomizer create() {
    return new ASTTransformationCustomizer(InterpreterMode.class);
}
 
Example #8
Source File: ThreadInterruptGroovyCustomizer.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public CompilationCustomizer create() {
    return new ASTTransformationCustomizer(ThreadInterrupt.class);
}