### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java,v retrieving revision 1.59 diff -u -r1.59 RecoveredMethod.java --- compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java 27 Apr 2007 15:51:39 -0000 1.59 +++ compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java 28 Sep 2007 08:31:16 -0000 @@ -293,6 +293,11 @@ Block block = methodBody.updatedBlock(); if (block != null){ methodDeclaration.statements = block.statements; + + if (methodDeclaration.declarationSourceEnd == 0) { + methodDeclaration.declarationSourceEnd = block.sourceEnd; + methodDeclaration.bodyEnd = block.sourceEnd; + } /* first statement might be an explict constructor call destinated to a special slot */ if (methodDeclaration.isConstructor()) { 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.376 diff -u -r1.376 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 31 Jul 2007 19:08:58 -0000 1.376 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 28 Sep 2007 08:31:16 -0000 @@ -8229,7 +8229,11 @@ if(this.statementRecoveryActivated) { RecoveredElement recoveredElement = this.buildInitialRecoveryState(); - recoveredElement.topElement().updateParseTree(); + + if (recoveredElement != null) { + recoveredElement.topElement().updateParseTree(); + } + if(this.hasError) this.resetStacks(); } else if (this.currentElement != null){ if (VERBOSE_RECOVERY){ @@ -8849,8 +8853,10 @@ TypeDeclaration typeDeclaration = this.recoveredTypes[this.recoveredTypePtr]; boolean isAnonymous = typeDeclaration.allocation != null; - int end = this.scanner.eofPosition; - this.scanner.resetTo(typeDeclaration.declarationSourceEnd + 1, end - 1); + this.scanner.startPosition = typeDeclaration.declarationSourceEnd + 1; + this.scanner.currentPosition = typeDeclaration.declarationSourceEnd + 1; + this.scanner.diet = false; // quit jumping over method bodies + if(!isAnonymous) { ((RecoveryScanner)this.scanner).setPendingTokens(new int[]{TokenNameSEMICOLON, TokenNamebreak}); } else { Index: compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.java,v retrieving revision 1.39 diff -u -r1.39 RecoveredInitializer.java --- compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.java 29 Mar 2006 02:47:34 -0000 1.39 +++ compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredInitializer.java 28 Sep 2007 08:31:16 -0000 @@ -131,7 +131,7 @@ if (parent == null) return this; // ignore return this.parent.add(typeDeclaration, bracketBalanceValue); } - if ((typeDeclaration.bits & ASTNode.IsLocalType) != 0){ + if ((typeDeclaration.bits & ASTNode.IsLocalType) != 0 || this.parser().methodRecoveryActivated || this.parser().statementRecoveryActivated){ /* method body should have been created */ Block block = new Block(0); block.sourceStart = ((Initializer)fieldDeclaration).sourceStart; @@ -176,7 +176,13 @@ if (initializerBody != null){ Block block = initializerBody.updatedBlock(); if (block != null){ - ((Initializer)fieldDeclaration).block = block; + Initializer initializer = (Initializer) fieldDeclaration; + initializer.block = block; + + if (initializer.declarationSourceEnd == 0) { + initializer.declarationSourceEnd = block.sourceEnd; + initializer.bodyEnd = block.sourceEnd; + } } if (this.localTypeCount > 0) fieldDeclaration.bits |= ASTNode.HasLocalType; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java,v retrieving revision 1.12 diff -u -r1.12 StatementRecoveryTest.java --- src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java 6 Mar 2007 04:42:13 -0000 1.12 +++ src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest.java 28 Sep 2007 08:31:18 -0000 @@ -3649,4 +3649,229 @@ expectedFullWithStatementRecoveryUnitToString, testName); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204662 +public void test0045() { + + String s = + "public class BadClass {\n" + + "\n" + + " public void method(Object obj) {\n" + + "\n" + + " /*//this version compiles\n" + + " People oPeople;\n" + + " {oPeople= (People) obj;}//*/\n" + + "\n" + + " /*//this version fails, but the compiler errors are fine\n" + + " class People oPeople;\n" + + " oPeople= (class People) obj;//*/\n" + + "\n" + + " //this version fails with internal compiler error\n" + + " class People oPeople;\n" + + " {oPeople= (class People) obj;}\n" + + " }\n" + + "\n" + + "}\n"; + + String expectedDietUnitToString = + "public class BadClass {\n" + + " public BadClass() {\n" + + " }\n" + + " public void method(Object obj) {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class BadClass {\n" + + " public BadClass() {\n" + + " super();\n" + + " }\n" + + " public void method(Object obj) {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class BadClass {\n" + + " public BadClass() {\n" + + " super();\n" + + " }\n" + + " public void method(Object obj) {\n" + + " class People {\n" + + " {\n" + + " class People {\n" + + " People() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + " People() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204662 +public void test0046() { + + String s = + "public class X {\n" + + " public void foo() { \n" + + " class Y ;\n" + + " \n" + + " {\n" + + " class Z ;\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietUnitToString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " class Y {\n" + + " {\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=204662 +public void test0047() { + + String s = + "public class X {\n" + + " public void foo() { \n" + + " class Y ;\n" + + " \n" + + " void bar() {\n" + + " class Z ;\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedDietUnitToString = + "public class X {\n" + + " public X() {\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String expectedDietPlusBodyUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " }\n" + + "}\n"; + + String expectedDietPlusBodyWithStatementRecoveryUnitToString = + "public class X {\n" + + " public X() {\n" + + " super();\n" + + " }\n" + + " public void foo() {\n" + + " class Y {\n" + + " Y() {\n" + + " super();\n" + + " }\n" + + " void bar() {\n" + + " class Z {\n" + + " Z() {\n" + + " super();\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + + String expectedFullUnitToString = + expectedDietUnitToString; + + String expectedFullWithStatementRecoveryUnitToString = + expectedDietUnitToString; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedDietUnitToString, + expectedDietWithStatementRecoveryUnitToString, + expectedDietPlusBodyUnitToString, + expectedDietPlusBodyWithStatementRecoveryUnitToString, + expectedFullUnitToString, + expectedFullWithStatementRecoveryUnitToString, + testName); +} }