Index: src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java,v --- src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java 13 Nov 2006 10:43:04 -0000 1.48 +++ src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java 16 Nov 2006 17:40:35 -0000 @@ -7588,4 +7588,102 @@ expectedFullUnitToString, expectedCompletionDietUnitToString, testName); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=157570 +public void test124() { + String s = + "public class Test {\n" + + " void aMethod() {\n" + + " public static void m1()\n" + + " {\n" + + " int a;\n" + + " int b;\n" + + " }\n" + + " public static void m2()\n" + + " {\n" + + " int c;\n" + + " int d;\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietUnitToString = + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " void aMethod() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyUnitToString = + "public class Test {\n" + + " public Test() {\n" + + " super();\n" + + " }\n" + + " void aMethod() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyPlusStatementsRecoveryUnitToString = null; + if(COMPLIANCE_1_3.equals(this.complianceLevel) || + COMPLIANCE_1_4.equals(this.complianceLevel)) { + expectedDietPlusBodyPlusStatementsRecoveryUnitToString = + "public class Test {\n" + + " public Test() {\n" + + " super();\n" + + " }\n" + + " void aMethod() {\n" + + " m1();\n" + + " {\n" + + " int a;\n" + + " int b;\n" + + " }\n" + + " m2();\n" + + " {\n" + + " int c;\n" + + " int d;\n" + + " }\n" + + " }\n" + + "}\n"; + } else { + expectedDietPlusBodyPlusStatementsRecoveryUnitToString = + "public class Test {\n" + + " public Test() {\n" + + " super();\n" + + " }\n" + + " void aMethod() {\n" + + " public static @m1() enum $missing$ {\n" + + " public $missing$() {\n" + + " super();\n" + + " }\n" + + " () {\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + } + + String expectedFullUnitToString = + "public class Test {\n" + + " public Test() {\n" + + " }\n" + + " void aMethod() {\n" + + " }\n" + + " public static void m1() {\n" + + " }\n" + + " public static void m2() {\n" + + " }\n" + + "}\n"; + + String expectedCompletionDietUnitToString = + expectedDietUnitToString; + + String testName = "test"; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyPlusStatementsRecoveryUnitToString, + expectedFullUnitToString, + expectedCompletionDietUnitToString, testName); +} } 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 --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 13 Nov 2006 10:43:19 -0000 1.358 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 16 Nov 2006 17:40:41 -0000 @@ -4160,7 +4160,13 @@ if (this.currentElement.parseTree() == method && this.currentElement.parent != null) { this.currentElement = this.currentElement.parent; } - } + } else if(this.currentToken == TokenNameLBRACE) { + if (this.currentElement instanceof RecoveredMethod && + ((RecoveredMethod)this.currentElement).methodDeclaration != method) { + this.ignoreNextOpeningBrace = true; + this.currentElement.bracketBalance++; + } + } this.restartRecovery = true; // used to avoid branching back into the regular automaton } } Index: dom/org/eclipse/jdt/core/dom/ASTParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTParser.java,v --- dom/org/eclipse/jdt/core/dom/ASTParser.java 16 Nov 2006 04:08:02 -0000 1.67 +++ dom/org/eclipse/jdt/core/dom/ASTParser.java 16 Nov 2006 17:40:41 -0000 @@ -982,6 +982,7 @@ compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds); if (constructorDeclaration != null) { Block block = ast.newBlock(); + block.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength); org.eclipse.jdt.internal.compiler.ast.Statement[] statements = constructorDeclaration.statements; if (statements != null) { int statementsLength = statements.length; @@ -997,9 +998,6 @@ } } rootNodeToCompilationUnit(ast, compilationUnit, block, recordedParsingInformation, data); - if (data != null) { - block.setFlags(block.getFlags() | ASTNode.RECOVERED); - } ast.setDefaultNodeFlag(0); ast.setOriginalModificationCount(ast.modificationCount()); return block; @@ -1045,6 +1043,7 @@ compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds); if (nodes != null) { TypeDeclaration typeDeclaration = converter.convert(nodes); + typeDeclaration.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength); rootNodeToCompilationUnit(typeDeclaration.getAST(), compilationUnit, typeDeclaration, codeSnippetParsingUtil.recordedParsingInformation, null); ast.setDefaultNodeFlag(0); ast.setOriginalModificationCount(ast.modificationCount()); @@ -1078,9 +1077,7 @@ if (problemsCount != 0) { // propagate and record problems final CategorizedProblem[] problems = recordedParsingInformation.problems; - for (int i = 0, max = block.statements().size(); i < max; i++) { - propagateErrors((ASTNode) block.statements().get(i), problems, data); - } + propagateErrors(block, problems, data); compilationUnit.setProblems(problems); } TypeDeclaration typeDeclaration = ast.newTypeDeclaration(); @@ -1096,9 +1093,7 @@ if (problemsCount != 0) { // propagate and record problems final CategorizedProblem[] problems = recordedParsingInformation.problems; - for (int i = 0, max = typeDeclaration.bodyDeclarations().size(); i < max; i++) { - propagateErrors((ASTNode) typeDeclaration.bodyDeclarations().get(i), problems, data); - } + propagateErrors(typeDeclaration, problems, data); compilationUnit.setProblems(problems); } compilationUnit.types().add(typeDeclaration); Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java,v --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 16 Nov 2006 04:08:00 -0000 1.106 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 16 Nov 2006 17:40:54 -0000 @@ -8243,7 +8243,7 @@ assertEquals("Not a block", ASTNode.BLOCK, result.getNodeType()); Block block = (Block) result; List statements = block.statements(); - assertEquals("Should be empty", 2, statements.size()); + assertEquals("Should be empty", 4, statements.size()); assertTrue("Not recovered", isRecovered(block)); ASTNode root = block.getRoot(); assertNotNull("No root", root);