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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-1 / +5 lines)
Lines 651-657 Link Here
651
				problemReporter().illegalModifierForEnumConstant(declaringClass, fieldDecl);
651
				problemReporter().illegalModifierForEnumConstant(declaringClass, fieldDecl);
652
652
653
			// set the modifiers
653
			// set the modifiers
654
			final int IMPLICIT_MODIFIERS = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccEnum;
654
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Force all enumerators to be marked
655
			// as used locally. We are unable to track the usage of these reliably as they could be used
656
			// in non obvious ways via the synthesized methods values() and valueOf(String) or by using 
657
			// Enum.valueOf(Class<T>, String).
658
			final int IMPLICIT_MODIFIERS = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccEnum | ExtraCompilerModifiers.AccLocallyUsed;
655
			fieldBinding.modifiers|= IMPLICIT_MODIFIERS;
659
			fieldBinding.modifiers|= IMPLICIT_MODIFIERS;
656
			return;
660
			return;
657
		}
661
		}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java (+69 lines)
Lines 6132-6136 Link Here
6132
		"Cannot reference a field before it is defined\n" + 
6132
		"Cannot reference a field before it is defined\n" + 
6133
		"----------\n");
6133
		"----------\n");
6134
}
6134
}
6135
6136
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused
6137
// warnings about enumerators. Since these could be used in indirect ways not obvious. 
6138
public void test171() {
6139
	Map customOptions = getCompilerOptions();
6140
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
6141
	this.runConformTest(
6142
		true,	
6143
		new String[] {
6144
			"X.java",
6145
			"public class X { \n" +
6146
			"    private enum Colors {\n" +
6147
			"	     BLEU,\n" +
6148
			"	     BLANC,\n" +
6149
			"	     ROUGE\n" +
6150
			"	 }\n" +
6151
			"	public static void main(String[] args) {\n" +
6152
			"		for (Colors c: Colors.values()) {\n" +
6153
			"           System.out.print(c);\n" +
6154
			"		}\n" +
6155
			"	}\n" +
6156
			"}\n"
6157
		},
6158
		null, customOptions,
6159
		"",
6160
		"BLEUBLANCROUGE", null, 
6161
		JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
6162
}
6163
6164
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused
6165
// warnings about enumerators. Since these could be used in indirect ways not obvious. This
6166
// test also verifies that while we don't complain about individual enumerators not being used
6167
// we DO complain if the enumeration type itself is not used.
6168
public void test172() {
6169
	Map customOptions = getCompilerOptions();
6170
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
6171
	this.runConformTest(
6172
		true,	
6173
		new String[] {
6174
			"X.java",
6175
			"public class X { \n" +
6176
			"    private enum Greet {\n" + 
6177
			"	     HELLO, HOWDY, BONJOUR; \n" +
6178
			"    }\n" +
6179
			"	 private enum Colors {\n" +
6180
			"        RED, BLACK, BLUE;\n"+
6181
			"    }\n" +
6182
            "   private enum Complaint {" +
6183
            "       WARNING, ERROR, FATAL_ERROR, PANIC;\n" +
6184
            "   }\n" +
6185
			"	public static void main(String[] args) {\n" +
6186
			"		Greet g = Greet.valueOf(\"HELLO\");\n" +	
6187
		    "		System.out.print(g);\n" +
6188
		    "       Colors c = Enum.valueOf(Colors.class, \"RED\");\n" +
6189
		    "		System.out.print(c);\n" +
6190
		    "   }\n" +
6191
			"}\n"
6192
		},
6193
		null, customOptions,
6194
		"----------\n" + 
6195
		"1. WARNING in X.java (at line 8)\n" + 
6196
		"	private enum Complaint {       WARNING, ERROR, FATAL_ERROR, PANIC;\n" + 
6197
		"	             ^^^^^^^^^\n" + 
6198
		"The type X.Complaint is never used locally\n" + 
6199
		"----------\n",
6200
		"HELLORED", null, 
6201
		JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
6202
}
6203
6135
}
6204
}
6136
6205

Return to bug 267670