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

(-)src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java (+56 lines)
Lines 2316-2319 Link Here
2316
		expected15ProblemLog
2316
		expected15ProblemLog
2317
	);
2317
	);
2318
}
2318
}
2319
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154811
2320
public void test0052() {
2321
	String[] testFiles = new String[] {
2322
		"X.java",
2323
		"public class X {\n" +
2324
		"	void foo1() {\n" +
2325
		"		class Y  {\n" +
2326
		"		}\n" +
2327
		"		void foo2() {\n" +
2328
		"		}\n" +
2329
		"		class Z<T> { \n" +
2330
		"		}\n" +
2331
		"	}\n" +
2332
		"} \n"
2333
	};
2334
	
2335
	String expected13ProblemLog =
2336
		"----------\n" + 
2337
		"1. ERROR in X.java (at line 5)\n" + 
2338
		"	void foo2() {\n" + 
2339
		"	^^^^\n" + 
2340
		"Syntax error on token \"void\", new expected\n" + 
2341
		"----------\n" + 
2342
		"2. ERROR in X.java (at line 7)\n" + 
2343
		"	class Z<T> { \n" + 
2344
		"	^^^^^\n" + 
2345
		"Syntax error on token \"class\", invalid AssignmentOperator\n" + 
2346
		"----------\n" + 
2347
		"3. ERROR in X.java (at line 7)\n" + 
2348
		"	class Z<T> { \n" + 
2349
		"	         ^\n" + 
2350
		"Syntax error on token \">\", ; expected\n" + 
2351
		"----------\n";
2352
	String expected14ProblemLog =
2353
		expected13ProblemLog;
2354
	
2355
	String expected15ProblemLog = 
2356
		"----------\n" + 
2357
		"1. ERROR in X.java (at line 5)\n" + 
2358
		"	void foo2() {\n" + 
2359
		"	^^^^\n" + 
2360
		"Syntax error on token \"void\", new expected\n" + 
2361
		"----------\n" + 
2362
		"2. ERROR in X.java (at line 6)\n" + 
2363
		"	}\n" + 
2364
		"	^\n" + 
2365
		"Syntax error, insert \";\" to complete Statement\n" + 
2366
		"----------\n";
2367
	
2368
	runComplianceParserTest(
2369
		testFiles,
2370
		expected13ProblemLog,
2371
		expected14ProblemLog,
2372
		expected15ProblemLog
2373
	);
2374
}
2319
}
2375
}
(-)src/org/eclipse/jdt/core/tests/compiler/parser/DietRecoveryTest.java (+143 lines)
Lines 6950-6953 Link Here
6950
		expectedFullUnitToString,
6950
		expectedFullUnitToString,
6951
		expectedCompletionDietUnitToString, testName);
6951
		expectedCompletionDietUnitToString, testName);
6952
}
6952
}
6953
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=154811
6954
public void test117() {
6955
	String s = 
6956
		"public class X {\n" + 
6957
		"	void foo1() {\n" + 
6958
		"		class Y  {\n" + 
6959
		"		}\n" + 
6960
		"		void foo2() {\n" + 
6961
		"		}\n" + 
6962
		"		class Z<T> { \n" + 
6963
		"		}\n" + 
6964
		"	}\n" + 
6965
		"} \n";
6966
		
6967
	String expectedDietUnitToString = null;
6968
	String expectedDietPlusBodyUnitToString = null;
6969
	String expectedDietPlusBodyPlusStatementsRecoveryUnitToString = null;
6970
	String expectedFullUnitToString = null;
6971
	String expectedCompletionDietUnitToString = null;
6972
	
6973
	
6974
	if(COMPLIANCE_1_3.equals(this.complianceLevel) || 
6975
			COMPLIANCE_1_4.equals(this.complianceLevel)) {
6976
		
6977
		expectedDietUnitToString = 
6978
			"public class X {\n" + 
6979
			"  public X() {\n" + 
6980
			"  }\n" + 
6981
			"  void foo1() {\n" + 
6982
			"  }\n" + 
6983
			"}\n";
6984
6985
		expectedDietPlusBodyUnitToString = 
6986
			"public class X {\n" + 
6987
			"  public X() {\n" + 
6988
			"    super();\n" + 
6989
			"  }\n" + 
6990
			"  void foo1() {\n" + 
6991
			"  }\n" + 
6992
			"}\n";
6993
		
6994
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
6995
			"public class X {\n" + 
6996
			"  public X() {\n" + 
6997
			"    super();\n" + 
6998
			"  }\n" + 
6999
			"  void foo1() {\n" + 
7000
			"    class Y {\n" + 
7001
			"      Y() {\n" + 
7002
			"        super();\n" + 
7003
			"      }\n" + 
7004
			"    }\n" + 
7005
			"    class Z<T> {\n" + 
7006
			"      Z() {\n" + 
7007
			"        super();\n" + 
7008
			"      }\n" + 
7009
			"    }\n" + 
7010
			"  }\n" + 
7011
			"}\n";
7012
		
7013
		expectedFullUnitToString =
7014
			"public class X {\n" + 
7015
			"  class Z<T> {\n" + 
7016
			"    Z() {\n" + 
7017
			"    }\n" + 
7018
			"  }\n" + 
7019
			"  public X() {\n" + 
7020
			"  }\n" + 
7021
			"  void foo1() {\n" + 
7022
			"  }\n" + 
7023
			"  void foo2() {\n" + 
7024
			"  }\n" + 
7025
			"}\n";
7026
		
7027
		expectedCompletionDietUnitToString = 
7028
			expectedDietUnitToString;
7029
	} else if(this.complianceLevel.compareTo(COMPLIANCE_1_5) >= 0) {
7030
		
7031
		expectedDietUnitToString = 
7032
			"public class X {\n" + 
7033
			"  public X() {\n" + 
7034
			"  }\n" + 
7035
			"  void foo1() {\n" + 
7036
			"  }\n" + 
7037
			"}\n";
7038
7039
		expectedDietPlusBodyUnitToString = 
7040
			"public class X {\n" + 
7041
			"  public X() {\n" + 
7042
			"    super();\n" + 
7043
			"  }\n" + 
7044
			"  void foo1() {\n" + 
7045
			"  }\n" + 
7046
			"}\n";
7047
		
7048
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString =
7049
			"public class X {\n" + 
7050
			"  public X() {\n" + 
7051
			"    super();\n" + 
7052
			"  }\n" + 
7053
			"  void foo1() {\n" + 
7054
			"    class Y {\n" + 
7055
			"      Y() {\n" + 
7056
			"        super();\n" + 
7057
			"      }\n" + 
7058
			"    }\n" + 
7059
			"    new foo2() {\n" + 
7060
			"    };\n" + 
7061
			"    class Z<T> {\n" + 
7062
			"      Z() {\n" + 
7063
			"        super();\n" + 
7064
			"      }\n" + 
7065
			"    }\n" + 
7066
			"  }\n" + 
7067
			"}\n";
7068
		
7069
		expectedFullUnitToString =
7070
			"public class X {\n" + 
7071
			"  class Z<T> {\n" + 
7072
			"    Z() {\n" + 
7073
			"    }\n" + 
7074
			"  }\n" + 
7075
			"  public X() {\n" + 
7076
			"  }\n" + 
7077
			"  void foo1() {\n" + 
7078
			"  }\n" + 
7079
			"  void foo2() {\n" + 
7080
			"  }\n" + 
7081
			"}\n";
7082
		
7083
		expectedCompletionDietUnitToString = 
7084
			expectedDietUnitToString;
7085
	}
7086
	
7087
	String testName = "test foreach toString";
7088
	checkParse(
7089
		s.toCharArray(),
7090
		expectedDietUnitToString,
7091
		expectedDietPlusBodyUnitToString,
7092
		expectedDietPlusBodyPlusStatementsRecoveryUnitToString,		
7093
		expectedFullUnitToString,
7094
		expectedCompletionDietUnitToString, testName);
7095
}
6953
}
7096
}
(-)compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredBlock.java (+11 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.compiler.parser;
11
package org.eclipse.jdt.internal.compiler.parser;
12
12
13
import org.eclipse.jdt.core.compiler.*;
13
import org.eclipse.jdt.core.compiler.*;
14
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
14
import org.eclipse.jdt.internal.compiler.ast.Argument;
15
import org.eclipse.jdt.internal.compiler.ast.Argument;
15
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
16
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
16
import org.eclipse.jdt.internal.compiler.ast.Block;
17
import org.eclipse.jdt.internal.compiler.ast.Block;
Lines 36-41 Link Here
36
	
37
	
37
	this.preserveContent = this.parser().methodRecoveryActivated || this.parser().statementRecoveryActivated;
38
	this.preserveContent = this.parser().methodRecoveryActivated || this.parser().statementRecoveryActivated;
38
}
39
}
40
public RecoveredElement add(AbstractMethodDeclaration methodDeclaration, int bracketBalanceValue) {
41
	if (this.parent != null && this.parent instanceof RecoveredMethod) {
42
		RecoveredMethod enclosingRecoveredMethod = (RecoveredMethod) this.parent;
43
		if (enclosingRecoveredMethod.methodBody == this && enclosingRecoveredMethod.parent == null) {
44
			// the element cannot be added because we are in the body of a top level method
45
			return this; // ignore this element
46
		}
47
	}
48
	return super.add(methodDeclaration, bracketBalanceValue);
49
}
39
/*
50
/*
40
 * Record a nested block declaration 
51
 * Record a nested block declaration 
41
 */
52
 */

Return to bug 154811