bam.web.dtc.compiler.Compiler.java Source code

Java tutorial

Introduction

Here is the source code for bam.web.dtc.compiler.Compiler.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package bam.web.dtc.compiler;

import bam.web.dtc.parse.TypeScriptLexer;
import bam.web.dtc.parse.TypeScriptParser;
import java.io.File;
import java.nio.file.Files;
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTreeWalker;

/**
 *
 * @author bennyl
 */
public class Compiler {

    String _package = "js.global";
    String mainInterface = "js.global.Window";
    //    File typescriptDefinitionFile = new File("/home/bennyl/projects/dts-to-teavm-compiler/lib-dts/lib.d.ts");
    File typescriptDefinitionFile = new File("test-files/type-script-features.d.ts");
    File outputDirectory = new File("/home/bennyl/NetBeansProjects/t-rex/src/main/java/js/global");

    public void compile() throws Exception {
        outputDirectory.mkdirs();

        String src = new String(Files.readAllBytes(typescriptDefinitionFile.toPath()));
        TypeScriptLexer lexer = new TypeScriptLexer(new ANTLRInputStream(src));
        TypeScriptParser parser = new TypeScriptParser(new CommonTokenStream(lexer));

        ParseTreeWalker walker = new ParseTreeWalker(); // create standard walker
        CodeModelGenerator generator = new CodeModelGenerator();
        walker.walk(generator, parser.definitionsFile()); // initiate walk of tree with listener

        //        TypeScriptDefinitionsLexer lexer = new TypeScriptDefinitionsLexer(new ANTLRInputStream(src));
        //        TypeScriptDefinitionsParser parser = new TypeScriptDefinitionsParser(new CommonTokenStream(lexer));
        //        TypeScriptDefinitionsParser.DtsContext dts = parser.dts();
        //
        //        JCodeModel model = new JCodeModel();
        //        new CodeModelProcessor().appendDefinitionFile(dts, model, "jsn.core");
        //        try (FileOutputStream fileOutputStream = new FileOutputStream(new File("output"))) {
        //            CodeWriter cw = new SingleStreamCodeWriter(fileOutputStream);
        //            model.build(cw);
        //        }

    }

    public static void main(String[] args) throws Exception {
        new Compiler().compile();
    }

}