groovy.transform.CompileStatic Java Examples

The following examples show how to use groovy.transform.CompileStatic. 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: 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 #3
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);
}