Bug 65090 - ASTParser with kind == K_STATEMENTS doesn't work unless source range specified
Summary: ASTParser with kind == K_STATEMENTS doesn't work unless source range specified
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 RC2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-01 14:09 EDT by Harold Gartner CLA
Modified: 2004-06-11 07:24 EDT (History)
0 users

See Also:


Attachments
Apply on HEAD (2.99 KB, patch)
2004-06-02 12:43 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Harold Gartner CLA 2004-06-01 14:09:15 EDT
Using eclipse-SDK-3.0RC1-win32.zip.

I'm trying to create an AST tree from a snippet of Java code using code like this:

String src = "\tSystem.out.println(\"Hello\");\n\tSystem.out.println(\"World\");\n";
char[] source = src.toCharArray();
ASTParser parser = ASTParser.newParser(AST.JLS2);
parser.setKind (ASTParser.K_STATEMENTS);
parser.setSource (source);
ASTNode result = parser.createAST (new NullProgressMonitor());

The result I get back is always an empty block, and I would expect it to be a
block with two ExpressionStatements in it.

If I add one line of code before the parser.createAST call to set the source range:
   parser.setSourceRange(0, source.length);

then I get back a block with two ExpressionStatements in it.

According to the JavaDoc for 'setSourceRange':
"Sets the subrange of the source code to be parsed. By default, the entire
source string will be parsed (offset 0 and length -1)."

So from that text it seems that it is not required to set the source range.
It appears that the 'ASTParser.setSource (char[] source)' method should be
setting the source range or there is some other defect elsewhere when the
sourceLength == -1 is not being honoured.
Comment 1 Olivier Thomann CLA 2004-06-02 09:14:50 EDT
I am investigating.
Comment 2 Olivier Thomann CLA 2004-06-02 12:43:16 EDT
Created attachment 11476 [details]
Apply on HEAD
Comment 3 Philipe Mulet CLA 2004-06-02 12:45:18 EDT
Change approved. Please release for RC2.
Comment 4 Olivier Thomann CLA 2004-06-02 12:48:44 EDT
Fixed and released in HEAD.
Regression test added.
Comment 5 Olivier Thomann CLA 2004-06-02 12:50:10 EDT
All tests passed.
Comment 6 David Audel CLA 2004-06-11 07:24:42 EDT
Verified for 3.0RC2