View | Details | Raw Unified | Return to bug 157570
Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java (+98 lines)
Lines 7588-7591 Link Here
7588
		expectedFullUnitToString,
7588
		expectedFullUnitToString,
7589
		expectedCompletionDietUnitToString, testName);
7589
		expectedCompletionDietUnitToString, testName);
7590
}
7590
}
7591
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=157570
7592
public void test124() {
7593
	String s = 
7594
		"public class Test {\n" + 
7595
		"	void aMethod() {\n" + 
7596
		"		public static void m1()\n" + 
7597
		"		{\n" + 
7598
		"			int a;\n" + 
7599
		"			int b;\n" + 
7600
		"		}\n" + 
7601
		"		public static void m2()\n" + 
7602
		"		{\n" + 
7603
		"			int c;\n" + 
7604
		"			int d;\n" + 
7605
		"		}\n" +
7606
		"	}\n" + 
7607
		"}\n";
7608
		
7609
	String expectedDietUnitToString = 
7610
		"public class Test {\n" + 
7611
		"  public Test() {\n" + 
7612
		"  }\n" + 
7613
		"  void aMethod() {\n" + 
7614
		"  }\n" + 
7615
		"}\n";
7616
7617
	String expectedDietPlusBodyUnitToString = 
7618
		"public class Test {\n" + 
7619
		"  public Test() {\n" + 
7620
		"    super();\n" + 
7621
		"  }\n" + 
7622
		"  void aMethod() {\n" + 
7623
		"  }\n" + 
7624
		"}\n";
7625
	
7626
	String expectedDietPlusBodyPlusStatementsRecoveryUnitToString = null;
7627
	if(COMPLIANCE_1_3.equals(this.complianceLevel) || 
7628
			COMPLIANCE_1_4.equals(this.complianceLevel)) {
7629
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7630
			"public class Test {\n" + 
7631
			"  public Test() {\n" + 
7632
			"    super();\n" + 
7633
			"  }\n" + 
7634
			"  void aMethod() {\n" + 
7635
			"    m1();\n" + 
7636
			"    {\n" + 
7637
			"      int a;\n" + 
7638
			"      int b;\n" + 
7639
			"    }\n" + 
7640
			"    m2();\n" + 
7641
			"    {\n" + 
7642
			"      int c;\n" + 
7643
			"      int d;\n" + 
7644
			"    }\n" + 
7645
			"  }\n" + 
7646
			"}\n";
7647
	} else {
7648
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7649
			"public class Test {\n" + 
7650
			"  public Test() {\n" + 
7651
			"    super();\n" + 
7652
			"  }\n" + 
7653
			"  void aMethod() {\n" + 
7654
			"    public static @m1() enum $missing$ {\n" + 
7655
			"      public $missing$() {\n" + 
7656
			"        super();\n" + 
7657
			"      }\n" + 
7658
			"      <clinit>() {\n" + 
7659
			"      }\n" + 
7660
			"    }\n" + 
7661
			"  }\n" + 
7662
			"}\n";
7663
	}
7664
	
7665
	String expectedFullUnitToString =
7666
		"public class Test {\n" + 
7667
		"  public Test() {\n" + 
7668
		"  }\n" + 
7669
		"  void aMethod() {\n" + 
7670
		"  }\n" + 
7671
		"  public static void m1() {\n" + 
7672
		"  }\n" + 
7673
		"  public static void m2() {\n" + 
7674
		"  }\n" + 
7675
		"}\n";
7676
	
7677
	String expectedCompletionDietUnitToString = 
7678
		expectedDietUnitToString;
7679
	
7680
	String testName = "test";
7681
	checkParse(
7682
		s.toCharArray(),
7683
		expectedDietUnitToString,
7684
		expectedDietPlusBodyUnitToString,
7685
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString,		
7686
		expectedFullUnitToString,
7687
		expectedCompletionDietUnitToString, testName);
7688
}
7591
}
7689
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java (-1 / +7 lines)
Lines 4160-4166 Link Here
4160
			if (this.currentElement.parseTree() == method && this.currentElement.parent != null) {
4160
			if (this.currentElement.parseTree() == method && this.currentElement.parent != null) {
4161
				this.currentElement = this.currentElement.parent;
4161
				this.currentElement = this.currentElement.parent;
4162
			}
4162
			}
4163
		}		
4163
		} else if(this.currentToken == TokenNameLBRACE) {
4164
			if (this.currentElement instanceof RecoveredMethod && 
4165
					((RecoveredMethod)this.currentElement).methodDeclaration != method) {
4166
				this.ignoreNextOpeningBrace = true;
4167
				this.currentElement.bracketBalance++; 
4168
			}
4169
		}
4164
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
4170
		this.restartRecovery = true; // used to avoid branching back into the regular automaton
4165
	}		
4171
	}		
4166
}
4172
}
(-)dom/org/eclipse/jdt/core/dom/ASTParser.java (-9 / +4 lines)
Lines 982-987 Link Here
982
				compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
982
				compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
983
				if (constructorDeclaration != null) {
983
				if (constructorDeclaration != null) {
984
					Block block = ast.newBlock();
984
					Block block = ast.newBlock();
985
					block.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength);
985
					org.eclipse.jdt.internal.compiler.ast.Statement[] statements = constructorDeclaration.statements;
986
					org.eclipse.jdt.internal.compiler.ast.Statement[] statements = constructorDeclaration.statements;
986
					if (statements != null) {
987
					if (statements != null) {
987
						int statementsLength = statements.length;
988
						int statementsLength = statements.length;
Lines 997-1005 Link Here
997
						}
998
						}
998
					}
999
					}
999
					rootNodeToCompilationUnit(ast, compilationUnit, block, recordedParsingInformation, data);
1000
					rootNodeToCompilationUnit(ast, compilationUnit, block, recordedParsingInformation, data);
1000
					if (data != null) {
1001
						block.setFlags(block.getFlags() | ASTNode.RECOVERED);
1002
					}
1003
					ast.setDefaultNodeFlag(0);
1001
					ast.setDefaultNodeFlag(0);
1004
					ast.setOriginalModificationCount(ast.modificationCount());
1002
					ast.setOriginalModificationCount(ast.modificationCount());
1005
					return block;
1003
					return block;
Lines 1045-1050 Link Here
1045
				compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
1043
				compilationUnit.setLineEndTable(recordedParsingInformation.lineEnds);
1046
				if (nodes != null) {
1044
				if (nodes != null) {
1047
					TypeDeclaration typeDeclaration = converter.convert(nodes);
1045
					TypeDeclaration typeDeclaration = converter.convert(nodes);
1046
					typeDeclaration.setSourceRange(this.sourceOffset, this.sourceOffset + this.sourceLength);
1048
					rootNodeToCompilationUnit(typeDeclaration.getAST(), compilationUnit, typeDeclaration, codeSnippetParsingUtil.recordedParsingInformation, null);
1047
					rootNodeToCompilationUnit(typeDeclaration.getAST(), compilationUnit, typeDeclaration, codeSnippetParsingUtil.recordedParsingInformation, null);
1049
					ast.setDefaultNodeFlag(0);
1048
					ast.setDefaultNodeFlag(0);
1050
					ast.setOriginalModificationCount(ast.modificationCount());
1049
					ast.setOriginalModificationCount(ast.modificationCount());
Lines 1078-1086 Link Here
1078
					if (problemsCount != 0) {
1077
					if (problemsCount != 0) {
1079
						// propagate and record problems
1078
						// propagate and record problems
1080
						final CategorizedProblem[] problems = recordedParsingInformation.problems;
1079
						final CategorizedProblem[] problems = recordedParsingInformation.problems;
1081
						for (int i = 0, max = block.statements().size(); i < max; i++) {
1080
						propagateErrors(block, problems, data);
1082
							propagateErrors((ASTNode) block.statements().get(i), problems, data);
1083
						}
1084
						compilationUnit.setProblems(problems);
1081
						compilationUnit.setProblems(problems);
1085
					}
1082
					}
1086
					TypeDeclaration typeDeclaration = ast.newTypeDeclaration();
1083
					TypeDeclaration typeDeclaration = ast.newTypeDeclaration();
Lines 1096-1104 Link Here
1096
					if (problemsCount != 0) {
1093
					if (problemsCount != 0) {
1097
						// propagate and record problems
1094
						// propagate and record problems
1098
						final CategorizedProblem[] problems = recordedParsingInformation.problems;
1095
						final CategorizedProblem[] problems = recordedParsingInformation.problems;
1099
						for (int i = 0, max = typeDeclaration.bodyDeclarations().size(); i < max; i++) {
1096
						propagateErrors(typeDeclaration, problems, data);
1100
							propagateErrors((ASTNode) typeDeclaration.bodyDeclarations().get(i), problems, data);
1101
						}
1102
						compilationUnit.setProblems(problems);
1097
						compilationUnit.setProblems(problems);
1103
					}
1098
					}
1104
					compilationUnit.types().add(typeDeclaration);
1099
					compilationUnit.types().add(typeDeclaration);
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java (-1 / +1 lines)
Lines 8243-8249 Link Here
8243
		assertEquals("Not a block", ASTNode.BLOCK, result.getNodeType());
8243
		assertEquals("Not a block", ASTNode.BLOCK, result.getNodeType());
8244
		Block block = (Block) result;
8244
		Block block = (Block) result;
8245
		List statements = block.statements();
8245
		List statements = block.statements();
8246
		assertEquals("Should be empty", 2, statements.size());
8246
		assertEquals("Should be empty", 4, statements.size());
8247
		assertTrue("Not recovered", isRecovered(block));
8247
		assertTrue("Not recovered", isRecovered(block));
8248
		ASTNode root = block.getRoot();
8248
		ASTNode root = block.getRoot();
8249
		assertNotNull("No root", root);
8249
		assertNotNull("No root", root);

Return to bug 157570