### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.430 diff -u -r1.430 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 8 Sep 2011 14:18:54 -0000 1.430 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 8 Sep 2011 18:36:04 -0000 @@ -9722,6 +9722,8 @@ boolean oldMethodRecoveryActivated = this.methodRecoveryActivated; if(this.options.performMethodsFullRecovery) { this.methodRecoveryActivated = true; + // we should not relocate bodyStart if there is a block within the statements + this.ignoreNextOpeningBrace = true; } initialize(); @@ -9971,6 +9973,8 @@ boolean oldMethodRecoveryActivated = this.methodRecoveryActivated; if(this.options.performMethodsFullRecovery) { + // we should not relocate bodyStart if there is a block within the statements + this.ignoreNextOpeningBrace = true; this.methodRecoveryActivated = true; this.rParenPos = md.sourceEnd; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java,v retrieving revision 1.2 diff -u -r1.2 ASTConverterTestAST4_2.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java 28 Jul 2011 17:06:03 -0000 1.2 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST4_2.java 8 Sep 2011 18:36:05 -0000 @@ -122,7 +122,7 @@ static { // TESTS_NAMES = new String[] {"test0602"}; // TESTS_RANGE = new int[] { 721, -1 }; -// TESTS_NUMBERS = new int[] { 721, 722, 723, 724, 725 }; +// TESTS_NUMBERS = new int[] { 723, 724 }; } public static Test suite() { return buildModelTestSuite(ASTConverterTestAST4_2.class); @@ -10641,4 +10641,47 @@ } } } + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=347396 + */ + public void test0723() { + ASTParser parser = ASTParser.newParser(AST.JLS4); + parser.setKind (ASTParser.K_STATEMENTS); + String src = "int j;\nfor {};\nj=1000;"; + char[] source = src.toCharArray(); + parser.setStatementsRecovery(true); + parser.setSource(source); + ASTNode result = parser.createAST (null); + assertNotNull("no result", result); + assertEquals("Wrong type", ASTNode.BLOCK, result.getNodeType()); + Block block = (Block) result; + List statements = block.statements(); + assertNotNull("No statements", statements); + assertEquals("Wrong size", 3, statements.size()); + assertFalse(isRecovered((ASTNode) statements.get(0))); + assertFalse(isRecovered((ASTNode) statements.get(1))); + assertFalse(isRecovered((ASTNode) statements.get(2))); + } + + /** + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=347396 + */ + public void test0724() { + ASTParser parser = ASTParser.newParser(AST.JLS4); + parser.setKind (ASTParser.K_COMPILATION_UNIT); + String src = "public class X { void foo() {int j;\nfor {};\nj=1000;}}"; + char[] source = src.toCharArray(); + parser.setStatementsRecovery(true); + parser.setSource(source); + ASTNode result = parser.createAST (null); + assertNotNull("no result", result); + assertEquals("Wrong type", ASTNode.COMPILATION_UNIT, result.getNodeType()); + Block block = ((MethodDeclaration) getASTNode((CompilationUnit) result, 0, 0)).getBody(); + List statements = block.statements(); + assertNotNull("No statements", statements); + assertEquals("Wrong size", 3, statements.size()); + assertFalse(isRecovered((ASTNode) statements.get(0))); + assertFalse(isRecovered((ASTNode) statements.get(1))); + assertFalse(isRecovered((ASTNode) statements.get(2))); + } } \ No newline at end of file