View | Details | Raw Unified | Return to bug 340691 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (+5 lines)
Lines 1016-1021 Link Here
1016
		}
1016
		}
1017
		if (node instanceof TypeDeclaration){
1017
		if (node instanceof TypeDeclaration){
1018
			TypeDeclaration type = (TypeDeclaration) node;
1018
			TypeDeclaration type = (TypeDeclaration) node;
1019
			if ((type.modifiers & ClassFileConstants.AccEnum) != 0) {
1020
				// do not allow enums to be build as recovery types
1021
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340691
1022
				continue;
1023
			}
1019
			if (type.declarationSourceEnd == 0){
1024
			if (type.declarationSourceEnd == 0){
1020
				element = element.add(type, 0);
1025
				element = element.add(type, 0);
1021
				this.lastCheckPoint = type.bodyStart;
1026
				this.lastCheckPoint = type.bodyStart;
(-)src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java (-14 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7619-7637 Link Here
7619
			"}\n";
7619
			"}\n";
7620
	} else {
7620
	} else {
7621
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7621
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7622
			"public class Test {\n" +
7622
			"public class Test {\n" + 
7623
			"  public Test() {\n" +
7623
			"  public Test() {\n" + 
7624
			"    super();\n" +
7624
			"    super();\n" + 
7625
			"  }\n" +
7625
			"  }\n" + 
7626
			"  void aMethod() {\n" +
7626
			"  void aMethod() {\n" + 
7627
			"    public static @m1() enum $missing$ {\n" +
7627
			"  }\n" + 
7628
			"      public $missing$() {\n" +
7629
			"        super();\n" +
7630
			"      }\n" +
7631
			"      <clinit>() {\n" +
7632
			"      }\n" +
7633
			"    }\n" +
7634
			"  }\n" +
7635
			"}\n";
7628
			"}\n";
7636
	}
7629
	}
7637
7630
(-)src/org/eclipse/jdt/core/tests/compiler/parser/StatementRecoveryTest_1_5.java (-1 / +62 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 728-731 Link Here
728
		expectedFullWithStatementRecoveryUnitToString,
728
		expectedFullWithStatementRecoveryUnitToString,
729
		testName);
729
		testName);
730
}
730
}
731
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340691
732
// Verify that we don't get a recovered enum declaration when the error token is after an
733
// incorrectly used modifier
734
public void test0008() {
735
	String s =
736
		"public class Try {\n" + 
737
		"\n" + 
738
		"    void m() {\n" + 
739
		"\n" + 
740
		"        synchronized new Object();\n" + 
741
		"\n" + 
742
		"    }\n" +
743
		"}\n" + 
744
		"\n";
745
746
	String expectedDietUnitToString =
747
			"public class Try {\n" + 
748
			"  public Try() {\n" + 
749
			"  }\n" + 
750
			"  void m() {\n" + 
751
			"  }\n" + 
752
			"}\n";
753
754
		String expectedDietWithStatementRecoveryUnitToString =
755
			expectedDietUnitToString;
756
757
		String expectedDietPlusBodyUnitToString =
758
				"public class Try {\n" + 
759
				"  public Try() {\n" + 
760
				"    super();\n" + 
761
				"  }\n" + 
762
				"  void m() {\n" + 
763
				"  }\n" + 
764
				"}\n";
765
766
		String expectedDietPlusBodyWithStatementRecoveryUnitToString =
767
				"public class Try {\n" + 
768
				"  public Try() {\n" + 
769
				"    super();\n" + 
770
				"  }\n" + 
771
				"  void m() {\n" + 
772
				"  }\n" + 
773
				"}\n";
774
775
		String expectedFullUnitToString =
776
			expectedDietUnitToString;
777
778
		String expectedFullWithStatementRecoveryUnitToString =
779
			expectedFullUnitToString;
780
781
	String testName = "test";
782
	checkParse(
783
			s.toCharArray(),
784
			expectedDietUnitToString,
785
			expectedDietWithStatementRecoveryUnitToString,
786
			expectedDietPlusBodyUnitToString,
787
			expectedDietPlusBodyWithStatementRecoveryUnitToString,
788
			expectedFullUnitToString,
789
			expectedFullWithStatementRecoveryUnitToString,
790
			testName);
791
}
731
}
792
}
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java (-1 / +31 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2010 IBM Corporation and others.
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 1077-1080 Link Here
1077
		checkSourceRange(anonymousClassDeclaration, "new Object() {hash}", source); //$NON-NLS-1$
1077
		checkSourceRange(anonymousClassDeclaration, "new Object() {hash}", source); //$NON-NLS-1$
1078
		checkSourceRange(assignment, "field= new Object() {hash}", source); //$NON-NLS-1$
1078
		checkSourceRange(assignment, "field= new Object() {hash}", source); //$NON-NLS-1$
1079
	}
1079
	}
1080
	
1081
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=340691
1082
		public void test0021() throws JavaModelException {
1083
			this.workingCopies = new ICompilationUnit[1];
1084
			this.workingCopies[0] = getWorkingCopy(
1085
				"/Converter/src/test/X.java",
1086
				"package test;\n"+
1087
				"public class X {\n"+
1088
				"	void foo() {\n" + 
1089
				"		synchronized new Object();\n" + 
1090
				"	}\n" + 
1091
				"}\n");
1092
			ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
1093
1094
			assertASTNodeEquals(
1095
				"package test;\n" + 
1096
				"public class X {\n" + 
1097
				"  void foo(){\n" + 
1098
				"  }\n" + 
1099
				"}\n",
1100
				result);
1101
1102
			ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
1103
			assertNotNull(node);
1104
			assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
1105
			MethodDeclaration methodDeclaration = (MethodDeclaration) node;
1106
			Block block = methodDeclaration.getBody();
1107
			List statements = block.statements();
1108
			assertEquals("wrong size", 0, statements.size()); //$NON-NLS-1$
1109
		}
1080
}
1110
}

Return to bug 340691