jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
groovy
  • groovy
  • GROOVY-1985

Sourceprinter

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1-beta-2
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

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());

Activity

  • All
  • Comments
  • Work Log
  • History
  • Activity

People

  • Assignee:
    Unassigned
    Reporter:
    Christiaan
Vote (0)
Watch (0)

Dates

  • Created:
    16/Jul/07 9:30 AM
    Updated:
    03/Feb/13 1:28 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.