Search in sources :

Example 1 with ST

use of edu.princeton.cs.algs4.ST in project che by eclipse.

the class TypeScriptDtoGenerator method execute.

/**
     * Execute this generator.
     */
public String execute() {
    init();
    ST template = getTemplate();
    template.add("dtos", this.dtoModels);
    String output = template.render();
    return output;
}
Also used : ST(org.stringtemplate.v4.ST)

Example 2 with ST

use of edu.princeton.cs.algs4.ST in project buck by facebook.

the class StringTemplateStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws IOException, InterruptedException {
    String template;
    try {
        template = new String(Files.readAllBytes(templatePath), Charsets.UTF_8);
    } catch (IOException e) {
        context.logError(e, "Could not read sh_binary template file");
        return StepExecutionResult.ERROR;
    }
    ST st = new ST(template);
    return new WriteFileStep(filesystem, Preconditions.checkNotNull(configure.apply(st).render()), outputPath, /* executable */
    false).execute(context);
}
Also used : ST(org.stringtemplate.v4.ST) IOException(java.io.IOException)

Example 3 with ST

use of edu.princeton.cs.algs4.ST in project buck by facebook.

the class IjProjectWriter method writeGeneratedByIdeaClassToFile.

private void writeGeneratedByIdeaClassToFile(IjModuleAndroidFacet androidFacet, IJProjectCleaner cleaner, String packageName, String className, @Nullable String content) throws IOException {
    ST contents = getST(StringTemplateFile.GENERATED_BY_IDEA_CLASS).add("package", packageName).add("className", className).add("content", content);
    Path fileToWrite = androidFacet.getGeneratedSourcePath().resolve(packageName.replace(".", "/")).resolve(className + ".java");
    cleaner.doNotDelete(fileToWrite);
    writeToFile(contents, fileToWrite);
}
Also used : Path(java.nio.file.Path) ST(org.stringtemplate.v4.ST)

Example 4 with ST

use of edu.princeton.cs.algs4.ST in project buck by facebook.

the class IjProjectWriter method writeLibrary.

private Path writeLibrary(IjLibrary library) throws IOException {
    projectFilesystem.mkdirs(LIBRARIES_PREFIX);
    Path path = LIBRARIES_PREFIX.resolve(library.getName() + ".xml");
    ST contents = getST(StringTemplateFile.LIBRARY_TEMPLATE);
    contents.add("name", library.getName());
    contents.add("binaryJar", library.getBinaryJar().map(MorePaths::pathWithUnixSeparators).orElse(null));
    contents.add("classPaths", library.getClassPaths().stream().map(MorePaths::pathWithUnixSeparators).collect(MoreCollectors.toImmutableSet()));
    contents.add("sourceJar", library.getSourceJar().map(MorePaths::pathWithUnixSeparators).orElse(null));
    contents.add("javadocUrl", library.getJavadocUrl().orElse(null));
    //TODO(marcinkosiba): support res and assets for aar.
    writeToFile(contents, path);
    return path;
}
Also used : Path(java.nio.file.Path) ST(org.stringtemplate.v4.ST) MorePaths(com.facebook.buck.io.MorePaths)

Example 5 with ST

use of edu.princeton.cs.algs4.ST in project buck by facebook.

the class IjProjectWriter method writeModule.

private Path writeModule(IjModule module) throws IOException {
    projectFilesystem.mkdirs(MODULES_PREFIX);
    Path path = module.getModuleImlFilePath();
    ST moduleContents = getST(StringTemplateFile.MODULE_TEMPLATE);
    moduleContents.add("contentRoot", projectDataPreparer.getContentRoot(module));
    moduleContents.add("dependencies", projectDataPreparer.getDependencies(module));
    moduleContents.add("generatedSourceFolders", projectDataPreparer.getGeneratedSourceFolders(module));
    moduleContents.add("androidFacet", projectDataPreparer.getAndroidProperties(module));
    moduleContents.add("sdk", module.getSdkName().orElse(null));
    moduleContents.add("sdkType", module.getSdkType().orElse(null));
    moduleContents.add("languageLevel", JavaLanguageLevelHelper.convertLanguageLevelToIjFormat(module.getLanguageLevel().orElse(null)));
    moduleContents.add("moduleType", module.getModuleType().orElse(IjModuleType.DEFAULT));
    moduleContents.add("metaInfDirectory", module.getMetaInfDirectory().map((dir) -> module.getModuleBasePath().relativize(dir)).orElse(null));
    writeToFile(moduleContents, path);
    return path;
}
Also used : Path(java.nio.file.Path) ST(org.stringtemplate.v4.ST)

Aggregations

ST (org.stringtemplate.v4.ST)197 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)37 STGroup (org.stringtemplate.v4.STGroup)24 File (java.io.File)19 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)12 STGroupFile (org.stringtemplate.v4.STGroupFile)12 Path (java.nio.file.Path)10 Test (org.junit.Test)10 ATNFactory (org.antlr.v4.automata.ATNFactory)9 LexerATNFactory (org.antlr.v4.automata.LexerATNFactory)9 ParserATNFactory (org.antlr.v4.automata.ParserATNFactory)9 CodeGenerator (org.antlr.v4.codegen.CodeGenerator)9 SemanticPipeline (org.antlr.v4.semantics.SemanticPipeline)9 Grammar (org.antlr.v4.tool.Grammar)9 LexerGrammar (org.antlr.v4.tool.LexerGrammar)9 STGroupString (org.stringtemplate.v4.STGroupString)9 LinkedHashMap (java.util.LinkedHashMap)7 URL (java.net.URL)6 Map (java.util.Map)6