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

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-1 / +6 lines)
Lines 480-487 Link Here
480
			// detect abnormal cases for enums
480
			// detect abnormal cases for enums
481
			if (isMemberType) { // includes member types defined inside local types
481
			if (isMemberType) { // includes member types defined inside local types
482
				final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected | ClassFileConstants.AccStatic | ClassFileConstants.AccStrictfp | ClassFileConstants.AccEnum);
482
				final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected | ClassFileConstants.AccStatic | ClassFileConstants.AccStrictfp | ClassFileConstants.AccEnum);
483
				if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
483
				if ((realModifiers & UNEXPECTED_MODIFIERS) != 0) {
484
					problemReporter().illegalModifierForMemberEnum(sourceType);
484
					problemReporter().illegalModifierForMemberEnum(sourceType);
485
					modifiers &= ~ClassFileConstants.AccAbstract; // avoid leaking abstract modifier
486
					realModifiers &= ~ClassFileConstants.AccAbstract;
487
//					modifiers &= ~(realModifiers & UNEXPECTED_MODIFIERS);
488
//					realModifiers = modifiers & ExtraCompilerModifiers.AccJustFlag;
489
				}
485
			} else if (sourceType.isLocalType()) { // each enum constant is an anonymous local type
490
			} else if (sourceType.isLocalType()) { // each enum constant is an anonymous local type
486
				final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccFinal | ClassFileConstants.AccEnum); // add final since implicitly set for anonymous type
491
				final int UNEXPECTED_MODIFIERS = ~(ClassFileConstants.AccStrictfp | ClassFileConstants.AccFinal | ClassFileConstants.AccEnum); // add final since implicitly set for anonymous type
487
				if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
492
				if ((realModifiers & UNEXPECTED_MODIFIERS) != 0)
(-)compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties (-1 / +1 lines)
Lines 569-575 Link Here
569
750 = Illegal modifier for the enum {0}; only public is permitted
569
750 = Illegal modifier for the enum {0}; only public is permitted
570
751 = Illegal modifier for the enum constant {0}; no modifier is allowed
570
751 = Illegal modifier for the enum constant {0}; no modifier is allowed
571
752 = Illegal modifier for the local enum {0}; only abstract is permitted
571
752 = Illegal modifier for the local enum {0}; only abstract is permitted
572
753 = Illegal modifier for the member enum {0}; only public, protected, private, static & abstract are permitted
572
753 = Illegal modifier for the member enum {0}; only public, protected, private & static are permitted
573
754 = The enum {1} already defines the method {0}({2}) implicitly
573
754 = The enum {1} already defines the method {0}({2}) implicitly
574
755 = The enum constant {0}.{1} reference cannot be qualified in a case label
574
755 = The enum constant {0}.{1} reference cannot be qualified in a case label
575
756 = The type {1} may not subclass {0} explicitly
575
756 = The type {1} may not subclass {0} explicitly
(-)compiler/org/eclipse/jdt/internal/compiler/ClassFile.java (-5 / +3 lines)
Lines 90-97 Link Here
90
 *      information. Those bytes are decodable with a regular class file reader,
90
 *      information. Those bytes are decodable with a regular class file reader,
91
 *      such as DietClassFileReader
91
 *      such as DietClassFileReader
92
 */
92
 */
93
public class ClassFile
93
public class ClassFile implements TypeConstants, TypeIds {
94
	implements TypeConstants, TypeIds {
95
94
96
	private byte[] bytes;
95
	private byte[] bytes;
97
	public CodeStream codeStream;
96
	public CodeStream codeStream;
Lines 135-143 Link Here
135
	 * @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
134
	 * @param typeDeclaration org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
136
	 * @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult
135
	 * @param unitResult org.eclipse.jdt.internal.compiler.CompilationUnitResult
137
	 */
136
	 */
138
	public static void createProblemType(
137
	public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) {
139
		TypeDeclaration typeDeclaration,
140
		CompilationResult unitResult) {
141
		SourceTypeBinding typeBinding = typeDeclaration.binding;
138
		SourceTypeBinding typeBinding = typeDeclaration.binding;
142
		ClassFile classFile = ClassFile.getNewInstance(typeBinding);
139
		ClassFile classFile = ClassFile.getNewInstance(typeBinding);
143
		classFile.initialize(typeBinding, null, true);
140
		classFile.initialize(typeBinding, null, true);
Lines 201-206 Link Here
201
			}
198
			}
202
			// add abstract methods
199
			// add abstract methods
203
			classFile.addDefaultAbstractMethods();
200
			classFile.addDefaultAbstractMethods();
201
			//classFile.addSpecialMethods();
204
		}
202
		}
205
203
206
		// propagate generation of (problem) member types
204
		// propagate generation of (problem) member types
(-)src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java (+223 lines)
Lines 5039-5042 Link Here
5039
		"The blank final field test may not have been initialized\n" + 
5039
		"The blank final field test may not have been initialized\n" + 
5040
		"----------\n");
5040
		"----------\n");
5041
}
5041
}
5042
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502
5043
public void test147() {
5044
	this.runNegativeTest(
5045
			new String[] {
5046
					"p/X.java",
5047
					"package p;\n" +
5048
					"public class X {\n" + 
5049
					"	public abstract enum E {\n" + 
5050
					"		SUCCESS;\n" +
5051
					"	}\n" + 
5052
					"}\n"
5053
			},
5054
			"----------\n" + 
5055
			"1. ERROR in p\\X.java (at line 3)\n" + 
5056
			"	public abstract enum E {\n" + 
5057
			"	                     ^\n" + 
5058
			"Illegal modifier for the member enum E; only public, protected, private & static are permitted\n" + 
5059
			"----------\n",
5060
			null,
5061
			true, // flush output
5062
			null,
5063
			true, // generate output
5064
			false,
5065
			false);			
5066
	this.runConformTest(
5067
		new String[] {
5068
				"Y.java",
5069
				"import p.X;\n" +
5070
				"public class Y {\n" + 
5071
				"	public static void main(String[] args) {\n" + 
5072
				"		System.out.println(X.E.SUCCESS);\n" + 
5073
				"	}\n" + 
5074
				"}\n"
5075
		},
5076
		"null",
5077
		null,
5078
		false,
5079
		null);
5080
}
5081
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation
5082
public void test148() {
5083
	this.runNegativeTest(
5084
			new String[] {
5085
					"p/X.java",
5086
					"package p;\n" +
5087
					"public class X {\n" + 
5088
					"	public abstract enum E implements Runnable {\n" + 
5089
					"		SUCCESS;\n" +
5090
					"	}\n" + 
5091
					"}\n"
5092
			},
5093
			"----------\n" + 
5094
			"1. ERROR in p\\X.java (at line 3)\n" + 
5095
			"	public abstract enum E implements Runnable {\n" + 
5096
			"	                     ^\n" + 
5097
			"Illegal modifier for the member enum E; only public, protected, private & static are permitted\n" + 
5098
			"----------\n" + 
5099
			"2. ERROR in p\\X.java (at line 3)\n" + 
5100
			"	public abstract enum E implements Runnable {\n" + 
5101
			"	                     ^\n" + 
5102
			"The type X.E must implement the inherited abstract method Runnable.run()\n" + 
5103
			"----------\n",
5104
			null,
5105
			true, // flush output
5106
			null,
5107
			true, // generate output
5108
			false,
5109
			false);			
5110
	this.runConformTest(
5111
		new String[] {
5112
				"Y.java",
5113
				"import p.X;\n" +
5114
				"public class Y {\n" + 
5115
				"	public static void main(String[] args) {\n" + 
5116
				"		System.out.println(X.E.SUCCESS);\n" + 
5117
				"	}\n" + 
5118
				"}\n"
5119
		},
5120
		"null",
5121
		null,
5122
		false,
5123
		null);
5124
}
5125
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation
5126
public void test149() throws Exception {
5127
	this.runConformTest(
5128
			new String[] {
5129
					"p/X.java",
5130
					"package p;\n" +
5131
					"public class X {\n" + 
5132
					"	public enum E implements Runnable {\n" + 
5133
					"		SUCCESS;\n" + 
5134
					"		public void run(){}\n" + 
5135
					"	}\n" + 
5136
					"	public static void main(String[] args) {\n" + 
5137
					"		Class<E> c = E.class;\n" + 
5138
					"		System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + 
5139
					"	}\n" + 
5140
					"}\n"
5141
			},
5142
			"p.X$E:SUCCESS");
5143
	
5144
	String expectedOutput = 
5145
		"// Signature: Ljava/lang/Enum<Lp/X$E;>;Ljava/lang/Runnable;\n" + 
5146
		"public static final enum p.X$E implements java.lang.Runnable {\n"; 
5147
5148
	ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
5149
	byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator  +"p" + File.separator + "X$E.class"));
5150
	String actualOutput =
5151
		disassembler.disassemble(
5152
			classFileBytes,
5153
			"\n",
5154
			ClassFileBytesDisassembler.DETAILED); 
5155
	int index = actualOutput.indexOf(expectedOutput);
5156
	if (index == -1 || expectedOutput.length() == 0) {
5157
		System.out.println(Util.displayString(actualOutput, 3));
5158
	}
5159
	if (index == -1) {
5160
		assertEquals("Wrong contents", expectedOutput, actualOutput);
5161
	}
5162
}
5163
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation
5164
public void test150() throws Exception {
5165
	this.runConformTest(
5166
			new String[] {
5167
					"p/X.java",
5168
					"package p;\n" +
5169
					"public class X {\n" + 
5170
					"	public enum E implements Runnable {\n" + 
5171
					"		SUCCESS;\n" + 
5172
					"		public void run(){}\n" + 
5173
					"	}\n" + 
5174
					"	public static void main(String[] args) {\n" + 
5175
					"		Class<E> c = E.class;\n" + 
5176
					"		System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + 
5177
					"	}\n" + 
5178
					"}\n"
5179
			},
5180
			"p.X$E:SUCCESS");
5181
	
5182
	this.runConformTest(
5183
			new String[] {
5184
					"Y.java",
5185
					"import p.X;\n" +
5186
					"public class Y {\n" + 
5187
					"	public static void main(String[] args) {\n" + 
5188
					"		System.out.println(X.E.SUCCESS);\n" + 
5189
					"	}\n" + 
5190
					"}\n"
5191
			},
5192
			"SUCCESS",
5193
			null,
5194
			false,
5195
			null);
5196
}
5197
5198
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation
5199
public void test151() throws Exception {
5200
	this.runConformTest(
5201
			new String[] {
5202
					"p/X.java",
5203
					"package p;\n" +
5204
					"public class X {\n" + 
5205
					"	public enum E implements Runnable {\n" + 
5206
					"		SUCCESS {};\n" + 
5207
					"		public void run(){}\n" + 
5208
					"	}\n" + 
5209
					"	public static void main(String[] args) {\n" + 
5210
					"		Class<E> c = E.class;\n" + 
5211
					"		System.out.println(c.getName() + \":\" + X.E.SUCCESS);\n" + 
5212
					"	}\n" + 
5213
					"}\n"
5214
			},
5215
			"p.X$E:SUCCESS");
5216
	
5217
	String expectedOutput = 
5218
		"// Signature: Ljava/lang/Enum<Lp/X$E;>;Ljava/lang/Runnable;\n" + 
5219
		"public abstract static enum p.X$E implements java.lang.Runnable {\n"; 
5220
5221
	ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
5222
	byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(OUTPUT_DIR + File.separator  +"p" + File.separator + "X$E.class"));
5223
	String actualOutput =
5224
		disassembler.disassemble(
5225
			classFileBytes,
5226
			"\n",
5227
			ClassFileBytesDisassembler.DETAILED); 
5228
	int index = actualOutput.indexOf(expectedOutput);
5229
	if (index == -1 || expectedOutput.length() == 0) {
5230
		System.out.println(Util.displayString(actualOutput, 3));
5231
	}
5232
	if (index == -1) {
5233
		assertEquals("Wrong contents", expectedOutput, actualOutput);
5234
	}
5235
}
5236
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=227502 - variation
5237
public void test152() {
5238
	this.runConformTest(
5239
			new String[] {
5240
					"p/X.java",
5241
					"package p;\n" +
5242
					"public class X {\n" + 
5243
					"	public enum E implements Runnable {\n" + 
5244
					"		SUCCESS {};\n" +
5245
					"		public void run(){}\n" + 
5246
					"	}\n" + 
5247
					"}\n"
5248
			},
5249
			"");			
5250
	this.runConformTest(
5251
		new String[] {
5252
				"Y.java",
5253
				"import p.X;\n" +
5254
				"public class Y {\n" + 
5255
				"	public static void main(String[] args) {\n" + 
5256
				"		System.out.println(X.E.SUCCESS);\n" + 
5257
				"	}\n" + 
5258
				"}\n"
5259
		},
5260
		"SUCCESS",
5261
		null,
5262
		false,
5263
		null);
5264
}
5042
}
5265
}

Return to bug 227502