use of org.codehaus.groovy.antlr.treewalker.NodePrinter in project groovy by apache.
the class Java2GroovyProcessor method nodePrinter.
public static String nodePrinter(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 NodePrinter(new PrintStream(baos), groovyTokenNames);
AntlrASTProcessor traverser = new SourceCodeTraversal(visitor);
traverser.process(ast);
return new String(baos.toByteArray());
}
use of org.codehaus.groovy.antlr.treewalker.NodePrinter in project groovy-core by groovy.
the class Java2GroovyProcessor method nodePrinter.
public static String nodePrinter(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 NodePrinter(new PrintStream(baos), groovyTokenNames);
AntlrASTProcessor traverser = new SourceCodeTraversal(visitor);
traverser.process(ast);
return new String(baos.toByteArray());
}
Aggregations