Search in sources :

Example 1 with CompiledST

use of org.stringtemplate.v4.compiler.CompiledST in project bndtools by bndtools.

the class StringTemplateEngine method loadRawTemplate.

private CompiledST loadRawTemplate(STGroup stg, String name, Resource resource) throws IOException {
    if (resource.getType() != ResourceType.File)
        throw new IllegalArgumentException(String.format("Cannot build resource from resource of type %s (name='%s').", resource.getType(), name));
    try (InputStream is = resource.getContent()) {
        ANTLRInputStream templateStream = new ANTLRInputStream(is, resource.getTextEncoding());
        String template = templateStream.substring(0, templateStream.size() - 1);
        CompiledST impl = new Compiler(stg).compile(name, template);
        CommonToken nameT = new CommonToken(STLexer.SEMI);
        nameT.setInputStream(templateStream);
        stg.rawDefineTemplate("/" + name, impl, nameT);
        impl.defineImplicitlyDefinedTemplates(stg);
        return impl;
    }
}
Also used : Compiler(org.stringtemplate.v4.compiler.Compiler) ANTLRInputStream(st4hidden.org.antlr.runtime.ANTLRInputStream) InputStream(java.io.InputStream) CommonToken(st4hidden.org.antlr.runtime.CommonToken) ANTLRInputStream(st4hidden.org.antlr.runtime.ANTLRInputStream) CompiledST(org.stringtemplate.v4.compiler.CompiledST)

Aggregations

InputStream (java.io.InputStream)1 CompiledST (org.stringtemplate.v4.compiler.CompiledST)1 Compiler (org.stringtemplate.v4.compiler.Compiler)1 ANTLRInputStream (st4hidden.org.antlr.runtime.ANTLRInputStream)1 CommonToken (st4hidden.org.antlr.runtime.CommonToken)1