### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java,v retrieving revision 1.141 diff -u -r1.141 EnumTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 6 Feb 2009 13:38:57 -0000 1.141 +++ src/org/eclipse/jdt/core/tests/compiler/regression/EnumTest.java 25 Mar 2009 09:03:09 -0000 @@ -6132,5 +6132,74 @@ "Cannot reference a field before it is defined\n" + "----------\n"); } + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused +// warnings about enumerators. Since these could be used in indirect ways not obvious. +public void test171() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n" + + " private enum Colors {\n" + + " BLEU,\n" + + " BLANC,\n" + + " ROUGE\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " for (Colors c: Colors.values()) {\n" + + " System.out.print(c);\n" + + " }\n" + + " }\n" + + "}\n" + }, + null, customOptions, + "", + "BLEUBLANCROUGE", null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Make sure we don't emit any unused +// warnings about enumerators. Since these could be used in indirect ways not obvious. This +// test also verifies that while we don't complain about individual enumerators not being used +// we DO complain if the enumeration type itself is not used. +public void test172() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); + this.runConformTest( + true, + new String[] { + "X.java", + "public class X { \n" + + " private enum Greet {\n" + + " HELLO, HOWDY, BONJOUR; \n" + + " }\n" + + " private enum Colors {\n" + + " RED, BLACK, BLUE;\n"+ + " }\n" + + " private enum Complaint {" + + " WARNING, ERROR, FATAL_ERROR, PANIC;\n" + + " }\n" + + " public static void main(String[] args) {\n" + + " Greet g = Greet.valueOf(\"HELLO\");\n" + + " System.out.print(g);\n" + + " Colors c = Greet.valueOf(Colors.class, \"RED\");\n" + + " System.out.print(c);\n" + + " }\n" + + "}\n" + }, + null, customOptions, + "----------\n" + + "1. WARNING in X.java (at line 8)\n" + + " private enum Complaint { WARNING, ERROR, FATAL_ERROR, PANIC;\n" + + " ^^^^^^^^^\n" + + "The type X.Complaint is never used locally\n" + + "----------\n", + "HELLORED", null, + JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings); +} + } #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java,v retrieving revision 1.169 diff -u -r1.169 ClassScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 13 Feb 2009 21:40:39 -0000 1.169 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java 25 Mar 2009 09:03:12 -0000 @@ -651,7 +651,11 @@ problemReporter().illegalModifierForEnumConstant(declaringClass, fieldDecl); // set the modifiers - final int IMPLICIT_MODIFIERS = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccEnum; + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=267670. Force all enumerators to be marked + // as used locally. We are unable to track the usage of these reliably as they could be used + // in non obvious ways via the synthesized methods values() and valueOf(String) or by using + // Enum.valueOf(Class, String). + final int IMPLICIT_MODIFIERS = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal | ClassFileConstants.AccEnum | ExtraCompilerModifiers.AccLocallyUsed; fieldBinding.modifiers|= IMPLICIT_MODIFIERS; return; }