import groovy.transform.CompileStatic; //导入依赖的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() {
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);
}