Search in sources :

Example 11 with SourceCodeTraversal

use of org.codehaus.groovy.antlr.treewalker.SourceCodeTraversal in project groovy by apache.

the class Java2GroovyProcessor method mindmap.

public static String mindmap(String input) throws Exception {
    JavaRecognizer parser = getJavaParser(input);
    String[] tokenNames = parser.getTokenNames();
    parser.compilationUnit();
    AST ast = parser.getAST();
    // modify the Java AST into a Groovy AST
    modifyJavaASTintoGroovyAST(tokenNames, ast);
    String[] groovyTokenNames = getGroovyTokenNames(input);
    // groovify the fat Java-Like Groovy AST
    groovifyFatJavaLikeGroovyAST(ast, groovyTokenNames);
    // now output
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Visitor visitor = new MindMapPrinter(new PrintStream(baos), groovyTokenNames);
    AntlrASTProcessor traverser = new SourceCodeTraversal(visitor);
    traverser.process(ast);
    return new String(baos.toByteArray());
}
Also used : PrintStream(java.io.PrintStream) AST(antlr.collections.AST) Visitor(org.codehaus.groovy.antlr.treewalker.Visitor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MindMapPrinter(org.codehaus.groovy.antlr.treewalker.MindMapPrinter) AntlrASTProcessor(org.codehaus.groovy.antlr.AntlrASTProcessor) SourceCodeTraversal(org.codehaus.groovy.antlr.treewalker.SourceCodeTraversal)

Aggregations

SourceCodeTraversal (org.codehaus.groovy.antlr.treewalker.SourceCodeTraversal)11 Visitor (org.codehaus.groovy.antlr.treewalker.Visitor)11 AST (antlr.collections.AST)10 AntlrASTProcessor (org.codehaus.groovy.antlr.AntlrASTProcessor)10 PrintStream (java.io.PrintStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 MindMapPrinter (org.codehaus.groovy.antlr.treewalker.MindMapPrinter)5 PreOrderTraversal (org.codehaus.groovy.antlr.treewalker.PreOrderTraversal)5 SourceBuffer (org.codehaus.groovy.antlr.SourceBuffer)4 FileNotFoundException (java.io.FileNotFoundException)3 FileOutputStream (java.io.FileOutputStream)3 SourcePrinter (org.codehaus.groovy.antlr.treewalker.SourcePrinter)3 Groovifier (org.codehaus.groovy.antlr.java.Groovifier)2 Java2GroovyConverter (org.codehaus.groovy.antlr.java.Java2GroovyConverter)2 JavaRecognizer (org.codehaus.groovy.antlr.java.JavaRecognizer)2 GroovyRecognizer (org.codehaus.groovy.antlr.parser.GroovyRecognizer)2 NodePrinter (org.codehaus.groovy.antlr.treewalker.NodePrinter)2 ArrayList (java.util.ArrayList)1 CompositeVisitor (org.codehaus.groovy.antlr.treewalker.CompositeVisitor)1 NodeAsHTMLPrinter (org.codehaus.groovy.antlr.treewalker.NodeAsHTMLPrinter)1