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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java (+68 lines)
Lines 4875-4878 Link Here
4875
     },
4875
     },
4876
	"0");
4876
	"0");
4877
}
4877
}
4878
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156591
4879
public void test138() {
4880
 this.runNegativeTest(
4881
     new String[] {
4882
    	        "X.java",
4883
 			"public enum X {\n" + 
4884
			"	PLUS {\n" + 
4885
			"		double eval(double x, double y) {\n" + 
4886
			"			return x + y;\n" + 
4887
			"		}\n" + 
4888
			"	},\n" + 
4889
			"	MINUS {\n" + 
4890
			"		@Override\n" +
4891
			"		abstract double eval(double x, double y);\n" + 
4892
			"	};\n" + 
4893
			"\n" + 
4894
			"	abstract double eval(double x, double y);\n" + 
4895
			"}\n" + 
4896
			"\n", // =================
4897
     },
4898
		"----------\n" + 
4899
		"1. WARNING in X.java (at line 3)\n" + 
4900
		"	double eval(double x, double y) {\n" + 
4901
		"	       ^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
4902
		"The method eval(double, double) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + 
4903
		"----------\n" + 
4904
		"2. ERROR in X.java (at line 9)\n" + 
4905
		"	abstract double eval(double x, double y);\n" + 
4906
		"	                ^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
4907
		"The abstract method eval in type new X(){} can only be defined by an abstract class\n" + 
4908
		"----------\n");
4909
}
4910
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=156591 - variation
4911
public void test139() {
4912
 this.runNegativeTest(
4913
     new String[] {
4914
    	        "X.java",
4915
 			"public enum X {\n" + 
4916
			"	PLUS {\n" + 
4917
			"		double eval(double x, double y) {\n" + 
4918
			"			return x + y;\n" + 
4919
			"		}\n" + 
4920
			"	},\n" + 
4921
			"	MINUS {\n" + 
4922
			"		abstract double eval2(double x, double y);\n" + 
4923
			"	};\n" + 
4924
			"\n" + 
4925
			"	abstract double eval(double x, double y);\n" + 
4926
			"}\n" + 
4927
			"\n", // =================
4928
     },
4929
		"----------\n" + 
4930
		"1. WARNING in X.java (at line 3)\n" + 
4931
		"	double eval(double x, double y) {\n" + 
4932
		"	       ^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
4933
		"The method eval(double, double) of type new X(){} should be tagged with @Override since it actually overrides a superclass method\n" + 
4934
		"----------\n" + 
4935
		"2. ERROR in X.java (at line 7)\n" + 
4936
		"	MINUS {\n" + 
4937
		"	      ^\n" + 
4938
		"The type new X(){} must implement the inherited abstract method X.eval(double, double)\n" + 
4939
		"----------\n" + 
4940
		"3. ERROR in X.java (at line 8)\n" + 
4941
		"	abstract double eval2(double x, double y);\n" + 
4942
		"	                ^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
4943
		"The abstract method eval2 in type new X(){} can only be defined by an abstract class\n" + 
4944
		"----------\n");
4945
}
4878
}
4946
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-7 / +8 lines)
Lines 456-469 Link Here
456
				if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
456
				if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
457
					problemReporter().illegalModifierForEnum(sourceType);
457
					problemReporter().illegalModifierForEnum(sourceType);
458
			}
458
			}
459
459
			if (!sourceType.isAnonymousType()) {
460
			// what about inherited interface methods?
461
			if ((referenceContext.bits & ASTNode.HasAbstractMethods) != 0) {
462
				modifiers |= ClassFileConstants.AccAbstract;
463
			} else if (!sourceType.isAnonymousType()) {
464
				// body of enum constant must implement any inherited abstract methods
465
				// enum type needs to implement abstract methods if one of its constants does not supply a body
466
				checkAbstractEnum: {
460
				checkAbstractEnum: {
461
					// does define abstract methods ?
462
					if ((referenceContext.bits & ASTNode.HasAbstractMethods) != 0) {
463
						modifiers |= ClassFileConstants.AccAbstract;
464
						break checkAbstractEnum;
465
					} 					
466
					// body of enum constant must implement any inherited abstract methods
467
					// enum type needs to implement abstract methods if one of its constants does not supply a body
467
					TypeDeclaration typeDeclaration = this.referenceContext;
468
					TypeDeclaration typeDeclaration = this.referenceContext;
468
					FieldDeclaration[] fields = typeDeclaration.fields;
469
					FieldDeclaration[] fields = typeDeclaration.fields;
469
					int fieldsLength = fields == null ? 0 : fields.length;
470
					int fieldsLength = fields == null ? 0 : fields.length;

Return to bug 156591