Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.1-beta-2
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
SourcePrinter "formats" the following code
code "x = 10; result = 15" (no newline)
into
"x = 10result = 15"
It also removes all comments from the code, which is not really handy in case you want to use it as a code-formatter.
Testcode:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SourceBuffer sourceBuffer = new SourceBuffer();
UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(new StringReader(code),sourceBuffer);
GroovyLexer lexer = new GroovyLexer(unicodeReader);
unicodeReader.setLexer(lexer);
GroovyRecognizer parser = GroovyRecognizer.make(lexer);
parser.setSourceBuffer(sourceBuffer);
String[] tokenNames = parser.getTokenNames();
parser.compilationUnit();
SourcePrinter formatter = new SourcePrinter(new PrintStream(baos), tokenNames, true);
AST ast = parser.getAST();
SourceCodeTraversal traverser = new SourceCodeTraversal(formatter);
traverser.process(ast);
return new String(baos.toByteArray());