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

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Paul King added a comment - 12/Dec/09 6:36 AM

Some Groovy code to replicate the issue:

import org.codehaus.groovy.antlr.*
import org.codehaus.groovy.antlr.treewalker.*
import org.codehaus.groovy.antlr.parser.*

def code = 'x = 10; result = 15'
def baos = new ByteArrayOutputStream()
def sourceBuffer = new SourceBuffer()
def unicodeReader = new UnicodeEscapingReader(new StringReader(code), sourceBuffer)
def lexer = new GroovyLexer(unicodeReader)
unicodeReader.lexer = lexer
def parser = GroovyRecognizer.make(lexer)
parser.sourceBuffer = sourceBuffer
parser.compilationUnit()
def formatter = new SourcePrinter(new PrintStream(baos), parser.tokenNames, true)
def traverser = new SourceCodeTraversal(formatter)
traverser.process(parser.AST)
println new String(baos.toByteArray())
Show
Paul King added a comment - 12/Dec/09 6:36 AM Some Groovy code to replicate the issue: import org.codehaus.groovy.antlr.* import org.codehaus.groovy.antlr.treewalker.* import org.codehaus.groovy.antlr.parser.* def code = 'x = 10; result = 15' def baos = new ByteArrayOutputStream() def sourceBuffer = new SourceBuffer() def unicodeReader = new UnicodeEscapingReader( new StringReader(code), sourceBuffer) def lexer = new GroovyLexer(unicodeReader) unicodeReader.lexer = lexer def parser = GroovyRecognizer.make(lexer) parser.sourceBuffer = sourceBuffer parser.compilationUnit() def formatter = new SourcePrinter( new PrintStream(baos), parser.tokenNames, true ) def traverser = new SourceCodeTraversal(formatter) traverser.process(parser.AST) println new String (baos.toByteArray())
Hide
Permalink
Paul King added a comment - 19/May/10 2:14 AM

Think it will require some rejigging of visitors - so pushing until after 1_7_X stream. Probably also should split out ";" from comment parts and make comments depend on adding comments into AST.

Show
Paul King added a comment - 19/May/10 2:14 AM Think it will require some rejigging of visitors - so pushing until after 1_7_X stream. Probably also should split out ";" from comment parts and make comments depend on adding comments into AST.

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.