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

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java (+2 lines)
Lines 809-814 Link Here
809
		expectedProblemAttributes.put("SuperclassNotFound", DEPRECATED);
809
		expectedProblemAttributes.put("SuperclassNotFound", DEPRECATED);
810
		expectedProblemAttributes.put("SuperclassNotVisible", DEPRECATED);
810
		expectedProblemAttributes.put("SuperclassNotVisible", DEPRECATED);
811
		expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
811
		expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(CategorizedProblem.CAT_POTENTIAL_PROGRAMMING_PROBLEM));
812
		expectedProblemAttributes.put("SwitchOnEnumNotBelow15", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
812
		expectedProblemAttributes.put("SwitchOnStringsNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
813
		expectedProblemAttributes.put("SwitchOnStringsNotBelow17", new ProblemAttributes(CategorizedProblem.CAT_TYPE));
813
		expectedProblemAttributes.put("Task", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
814
		expectedProblemAttributes.put("Task", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
814
		expectedProblemAttributes.put("ThisInStaticContext", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
815
		expectedProblemAttributes.put("ThisInStaticContext", new ProblemAttributes(CategorizedProblem.CAT_INTERNAL));
Lines 1482-1487 Link Here
1482
		expectedProblemAttributes.put("SuperclassNotFound", SKIP);
1483
		expectedProblemAttributes.put("SuperclassNotFound", SKIP);
1483
		expectedProblemAttributes.put("SuperclassNotVisible", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE));
1484
		expectedProblemAttributes.put("SuperclassNotVisible", new ProblemAttributes(JavaCore.COMPILER_PB_REDUNDANT_SUPERINTERFACE));
1484
		expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(JavaCore.COMPILER_PB_EMPTY_STATEMENT));
1485
		expectedProblemAttributes.put("SuperfluousSemicolon", new ProblemAttributes(JavaCore.COMPILER_PB_EMPTY_STATEMENT));
1486
		expectedProblemAttributes.put("SwitchOnEnumNotBelow15", SKIP);
1485
		expectedProblemAttributes.put("SwitchOnStringsNotBelow17", SKIP);
1487
		expectedProblemAttributes.put("SwitchOnStringsNotBelow17", SKIP);
1486
		expectedProblemAttributes.put("Task", SKIP);
1488
		expectedProblemAttributes.put("Task", SKIP);
1487
		expectedProblemAttributes.put("ThisInStaticContext", SKIP);
1489
		expectedProblemAttributes.put("ThisInStaticContext", SKIP);
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (-1 / +99 lines)
Lines 37-43 Link Here
37
	super(name);
37
	super(name);
38
}
38
}
39
static {
39
static {
40
//	TESTS_NAMES = new String[] { "testAddExternalLibFolder6" };
40
//	TESTS_NAMES = new String[] { "testBug360164" };
41
}
41
}
42
public static Test suite() {
42
public static Test suite() {
43
	TestSuite suite = (TestSuite) buildModelTestSuite(JavaProjectTests.class);
43
	TestSuite suite = (TestSuite) buildModelTestSuite(JavaProjectTests.class);
Lines 2389-2392 Link Here
2389
		deleteProject("JavaProjectTestsInvalidProject");
2389
		deleteProject("JavaProjectTestsInvalidProject");
2390
	}
2390
	}
2391
}
2391
}
2392
// Bug 360164 - Compile error in XSDImpl
2393
// test that we can tolerate if a 1.4 project refers to an enum inside a library.
2394
public void testBug360164() throws IOException, CoreException {
2395
	String libPath = getWorkspacePath()+"JavaProjectTests/bin/bug360164.jar";
2396
	try {
2397
		this.createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", libPath}, "bin", JavaCore.VERSION_1_4);
2398
		IFile file = createFile("/P/src/X.java", 
2399
				"import p360164.Provider;\n" +
2400
				"import p360164.MyEnum;\n" +
2401
				"public class X {\n" +
2402
				"    int foo(Provider p) {\n" +
2403
				"        MyEnum e = p.getE();\n" +
2404
				"        switch (e.getValue()) {\n" +
2405
				"        case MyEnum.ONE_COMPAT: return 1;\n" +
2406
				"        case MyEnum.TWO_COMPAT: return 2;\n" +
2407
				"        }\n" +
2408
				"        return 0;\n" +
2409
				"    }\n" +
2410
				"}"
2411
		);	
2412
		ICompilationUnit unit = (ICompilationUnit)JavaCore.create(file);
2413
		ProblemRequestor problemRequestor = new ProblemRequestor();
2414
		WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor);
2415
		unit.getWorkingCopy(owner, null);
2416
		assertProblems("Unexpected problems", 
2417
				"----------\n" + 
2418
				"----------\n", 
2419
				problemRequestor);
2420
	} finally {
2421
		this.deleteProject("P");
2422
	}
2423
}
2424
// Bug 360164 - Compile error in XSDImpl
2425
// test that we still report the missing superclass when resolving non-local methods
2426
public void testBug360164a() throws IOException, CoreException {
2427
	String libPath = getWorkspacePath()+"JavaProjectTests/bin/bug360164.jar";
2428
	try {
2429
		this.createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", libPath}, "bin", JavaCore.VERSION_1_4);
2430
		IFile file = createFile("/P/src/X.java", 
2431
				"import p360164.Provider;\n" +
2432
				"import p360164.MyEnum;\n" +
2433
				"public class X {\n" +
2434
				"    String foo(Provider p) {\n" +
2435
				"        MyEnum e = p.getE();\n" +
2436
				"        return e.toString();\n" +
2437
				"    }\n" +
2438
				"}"
2439
		);	
2440
		ICompilationUnit unit = (ICompilationUnit)JavaCore.create(file);
2441
		ProblemRequestor problemRequestor = new ProblemRequestor();
2442
		WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor);
2443
		unit.getWorkingCopy(owner, null);
2444
		assertProblems("Unexpected problems", 
2445
				"----------\n" + 
2446
				"1. ERROR in /P/src/X.java\n" + 
2447
				"The type java.lang.Enum cannot be resolved. It is indirectly referenced from required .class files\n" + 
2448
				"----------\n", 
2449
				problemRequestor);
2450
	} finally {
2451
		this.deleteProject("P");
2452
	}
2453
}
2454
// Bug 360317 - [compiler] report switch over enum in 1.4- mode
2455
public void testBug360317() throws IOException, CoreException {
2456
	// use the setup from testBug360164():
2457
	String libPath = getWorkspacePath()+"JavaProjectTests/bin/bug360164.jar";
2458
	try {
2459
		this.createJavaProject("P", new String[] {"src"}, new String[] {"JCL_LIB", libPath}, "bin", JavaCore.VERSION_1_4);
2460
		String sourceX = "import p360164.Provider;\n" +
2461
						 "import p360164.MyEnum;\n" +
2462
						 "public class X {\n" +
2463
						 "    int foo(Provider p) {\n" +
2464
						 "        MyEnum e = p.getE();\n" +
2465
						 "        switch (e) {\n" +
2466
						 "        case ONE: return 1;\n" +
2467
						 "        case TWO: return 2;\n" +
2468
						 "        }\n" +
2469
						 "        return 0;\n" +
2470
						 "    }\n" +
2471
						 "}";
2472
		IFile file = createFile("/P/src/X.java", sourceX);	
2473
		ICompilationUnit unit = (ICompilationUnit)JavaCore.create(file);
2474
		ProblemRequestor problemRequestor = new ProblemRequestor();
2475
		problemRequestor.initialize(sourceX.toCharArray());
2476
		WorkingCopyOwner owner = newWorkingCopyOwner(problemRequestor);
2477
		unit.getWorkingCopy(owner, null);
2478
		assertProblems("Unexpected problems", 
2479
				"----------\n" +
2480
				"1. ERROR in /P/src/X.java (at line 6)\n" +
2481
				"	switch (e) {\n" +
2482
				"	        ^\n" +
2483
				"Cannot switch on an enum value for source level below 1.5. Only convertible int values are permitted\n" +
2484
				"----------\n",
2485
				problemRequestor);
2486
	} finally {
2487
		this.deleteProject("P");
2488
	}
2489
}
2392
}
2490
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java (+2 lines)
Added Link Here
1409
	int UnclosedCloseableAtExit = Internal + 888;
1409
	int UnclosedCloseableAtExit = Internal + 888;
1410
	/** @since 3.8 */
1410
	/** @since 3.8 */
1411
	int ExplicitlyClosedAutoCloseable = Internal + 889;
1411
	int ExplicitlyClosedAutoCloseable = Internal + 889;
1412
	/** @since 3.8 */
1413
	int SwitchOnEnumNotBelow15 = TypeRelated + 890;	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=360317
1412
	/**
1414
	/**
1413
	 * External problems -- These are problems defined by other plugins
1415
	 * External problems -- These are problems defined by other plugins
1414
	 */
1416
	 */
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java (+3 lines)
Lines 463-468 Link Here
463
							break checkType;
463
							break checkType;
464
					} else if (expressionType.isEnum()) {
464
					} else if (expressionType.isEnum()) {
465
						isEnumSwitch = true;
465
						isEnumSwitch = true;
466
						if (upperScope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_5) {
467
							upperScope.problemReporter().incorrectSwitchType(this.expression, expressionType); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=360317
468
						}
466
						break checkType;
469
						break checkType;
467
					} else if (upperScope.isBoxingCompatibleWith(expressionType, TypeBinding.INT)) {
470
					} else if (upperScope.isBoxingCompatibleWith(expressionType, TypeBinding.INT)) {
468
						this.expression.computeConversion(upperScope, TypeBinding.INT, expressionType);
471
						this.expression.computeConversion(upperScope, TypeBinding.INT, expressionType);
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java (-2 / +8 lines)
Lines 975-982 Link Here
975
}
975
}
976
public boolean hasTypeBit(int bit) {
976
public boolean hasTypeBit(int bit) {
977
	// ensure hierarchy is resolved, which will propagate bits down to us
977
	// ensure hierarchy is resolved, which will propagate bits down to us
978
	superclass();
978
	boolean wasToleratingMissingTypeProcessingAnnotations = this.environment.mayTolerateMissingType;
979
	superInterfaces();
979
	this.environment.mayTolerateMissingType = true;
980
	try {
981
		superclass();
982
		superInterfaces();
983
	} finally {
984
		this.environment.mayTolerateMissingType = wasToleratingMissingTypeProcessingAnnotations;
985
	}
980
	return (this.typeBits & bit) != 0;
986
	return (this.typeBits & bit) != 0;
981
}
987
}
982
private void initializeTypeVariable(TypeVariableBinding variable, TypeVariableBinding[] existingVariables, SignatureWrapper wrapper, char[][][] missingTypeNames) {
988
private void initializeTypeVariable(TypeVariableBinding variable, TypeVariableBinding[] existingVariables, SignatureWrapper wrapper, char[][][] missingTypeNames) {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java (+1 lines)
Lines 74-79 Link Here
74
	private ArrayList missingTypes;
74
	private ArrayList missingTypes;
75
	Set typesBeingConnected;
75
	Set typesBeingConnected;
76
	public boolean isProcessingAnnotations = false;
76
	public boolean isProcessingAnnotations = false;
77
	public boolean mayTolerateMissingType = false;
77
78
78
	final static int BUILD_FIELDS_AND_METHODS = 4;
79
	final static int BUILD_FIELDS_AND_METHODS = 4;
79
	final static int BUILD_TYPE_HIERARCHY = 1;
80
	final static int BUILD_TYPE_HIERARCHY = 1;
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/UnresolvedReferenceBinding.java (-1 / +1 lines)
Lines 55-61 Link Here
55
		}
55
		}
56
		if (targetType == null || targetType == this) { // could not resolve any better, error was already reported against it
56
		if (targetType == null || targetType == this) { // could not resolve any better, error was already reported against it
57
			// report the missing class file first - only if not resolving a previously missing type
57
			// report the missing class file first - only if not resolving a previously missing type
58
			if ((this.tagBits & TagBits.HasMissingType) == 0) {
58
			if ((this.tagBits & TagBits.HasMissingType) == 0 && !environment.mayTolerateMissingType) {
59
				environment.problemReporter.isClassPathCorrect(
59
				environment.problemReporter.isClassPathCorrect(
60
					this.compoundName,
60
					this.compoundName,
61
					environment.unitBeingCompleted,
61
					environment.unitBeingCompleted,
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java (-6 / +15 lines)
Lines 2863-2874 Link Here
2863
					expression.sourceStart,
2863
					expression.sourceStart,
2864
					expression.sourceEnd);
2864
					expression.sourceEnd);
2865
		} else {
2865
		} else {
2866
			this.handle(
2866
			if (this.options.sourceLevel < ClassFileConstants.JDK1_5 && testType.isEnum()) {
2867
				IProblem.IncorrectSwitchType,
2867
				this.handle(
2868
				new String[] {new String(testType.readableName())},
2868
						IProblem.SwitchOnEnumNotBelow15,
2869
				new String[] {new String(testType.shortReadableName())},
2869
						new String[] {new String(testType.readableName())},
2870
				expression.sourceStart,
2870
						new String[] {new String(testType.shortReadableName())},
2871
				expression.sourceEnd);
2871
						expression.sourceStart,
2872
						expression.sourceEnd);
2873
			} else {
2874
				this.handle(
2875
						IProblem.IncorrectSwitchType,
2876
						new String[] {new String(testType.readableName())},
2877
						new String[] {new String(testType.shortReadableName())},
2878
						expression.sourceStart,
2879
						expression.sourceEnd);
2880
			}
2872
		}
2881
		}
2873
	} else {
2882
	} else {
2874
		this.handle(
2883
		this.handle(
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (+1 lines)
Lines 651-656 Link Here
651
887 = Resource leak: ''{0}'' is never closed
651
887 = Resource leak: ''{0}'' is never closed
652
888 = Resource leak: ''{0}'' is not closed at this location
652
888 = Resource leak: ''{0}'' is not closed at this location
653
889 = Resource ''{0}'' should be managed by try-with-resource
653
889 = Resource ''{0}'' should be managed by try-with-resource
654
890 = Cannot switch on an enum value for source level below 1.5. Only convertible int values are permitted
654
655
655
### ELABORATIONS
656
### ELABORATIONS
656
## Access restrictions
657
## Access restrictions

Return to bug 360164