Community
Participate
Working Groups
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.
I am investigating.
Created attachment 11476 [details] Apply on HEAD
Change approved. Please release for RC2.
Fixed and released in HEAD. Regression test added.
All tests passed.
Verified for 3.0RC2