Community
Participate
Working Groups
Follow-up of bug 270148... Using build I20090609-1400 and considering the following snippet: class MyCommand extends CommandBase { protected Command subcommand; //... public void execute() { // ... Compound subcommands = new CompoundCommand(); subcommands.appendAndExecute(new AddCommand(...)); if (condition) subcommands.appendAndExecute(new AddCommand(...)); subcommand = subcommands.unwrap(); } public void undo() { // ... subcommand.undo(); } public void redo() { // ... subcommand.redo(); } public void dispose() { // ... if (subcommand != null) { subcommand.dispose(); } } } Before bug 270148 was fixed, parsing the snippet using the Parser.parseClassBodyDeclarations(...) method returned null. After, e.g. using HEAD, it returns an array with one TypeDeclaration which seems to be the expected result. However, now considering another snippet: class MyCommand extends CompoundCommand { public void execute() { // ... appendAndExecute(new AddCommand(...)); if (condition) appendAndExecute(new AddCommand(...)); } } Parsing it with the same Parser method still returns null. After bug 270148 was fixed, I would expect a non null result for the second snippet either...
I'll investigate a fix for 3.5.1.
When the statement recovery is not enabled, both cases should not be parsed successfully. I need to add a bit on the resulting node to remember that the last action as ERROR_ACTION. Working on it.
When the statement recovery is not enabled, thes method org.eclipse.jdt.internal.compiler.parser.Parser.parseClassBodyDeclarations(char[], int, int, CompilationUnitDeclaration) should return consistent results whatever the given source is. In comment 0, both code snippets should return null as both contains methods with syntax errors.
Created attachment 139753 [details] Proposed fix + regression tests
Frédéric, please review.
+1 patch looks good to me
Released for 3.5.1 and 3.6M1. Added regression tests: org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0713 org.eclipse.jdt.core.tests.dom.ASTConverterTestAST3_2#test0714
Verified for 3.6M1 by regression tests verification and code inspection
Verified for 3.5.1RC2 by regression tests verification and code inspection