### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java,v retrieving revision 1.87 diff -u -r1.87 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 25 Feb 2010 19:17:03 -0000 1.87 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 26 Feb 2010 16:49:12 -0000 @@ -16,7 +16,6 @@ import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; @@ -214,17 +213,18 @@ int problemCount = this.compilationResult.problemCount; IrritantSet[] foundIrritants = new IrritantSet[this.suppressWarningsCount]; CompilerOptions options = this.scope.compilerOptions(); - boolean hasErrors = false; + boolean hasMandatoryErrors = false; nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) { CategorizedProblem problem = problems[iProblem]; int problemID = problem.getID(); int irritant = ProblemReporter.getIrritant(problemID); if (problem.isError()) { - if (problemID != IProblem.UnusedWarningToken) { - // tolerate unused warning tokens which were promoted as errors - hasErrors = true; + if (irritant == 0) { + // tolerate unused warning tokens when mandatory errors + hasMandatoryErrors = true; + continue; } - if (irritant == 0 || !options.suppressOptionalErrors) { + if (!options.suppressOptionalErrors) { continue; } } @@ -266,7 +266,7 @@ this.compilationResult.problemCount -= removed; } // flag SuppressWarnings which had no effect (only if no (mandatory) error got detected within unit - if (!hasErrors) { + if (!hasMandatoryErrors) { int severity = options.getSeverity(CompilerOptions.UnusedWarningToken); if (severity != ProblemSeverities.Ignore) { boolean unusedWarningTokenIsWarning = (severity & ProblemSeverities.Error) == 0; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java,v retrieving revision 1.211 diff -u -r1.211 AnnotationTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 25 Feb 2010 19:16:59 -0000 1.211 +++ src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java 26 Feb 2010 16:49:13 -0000 @@ -45,7 +45,7 @@ // All specified tests which do not belong to the class are skipped... static { // TESTS_NAMES = new String[] { "test127" }; -// TESTS_NUMBERS = new int[] { 278 }; +// TESTS_NUMBERS = new int[] { 286 }; // TESTS_RANGE = new int[] { 249, -1 }; } @@ -998,7 +998,7 @@ this.runConformTest( new String[] { "X.java", - "@Foo(type=String.class) public class X {\r\n" + + "@Foo(type=String.class) public class X {\n" + "}" }, "", @@ -1247,8 +1247,8 @@ "}\n" }, "----------\n" + - "1. ERROR in X.java (at line 12)\r\n" + - " public @MyAnn void something() { } \r\n" + + "1. ERROR in X.java (at line 12)\n" + + " public @MyAnn void something() { } \n" + " ^^^^^^\n" + "The annotation @MyAnn is disallowed for this location\n" + "----------\n"); @@ -2724,8 +2724,8 @@ "}\n" }, "----------\n" + - "1. ERROR in X.java (at line 4)\r\n" + - " @Inherited\r\n" + + "1. ERROR in X.java (at line 4)\n" + + " @Inherited\n" + " ^^^^^^^^^^\n" + "The annotation @Inherited is disallowed for this location\n" + "----------\n"); @@ -2959,8 +2959,8 @@ "}\n", }, "----------\n" + - "1. ERROR in X.java (at line 3)\r\n" + - " @Target(Element)\r\n" + + "1. ERROR in X.java (at line 3)\n" + + " @Target(Element)\n" + " ^^^^^^^\n" + "Element cannot be resolved to a variable\n" + "----------\n"); @@ -4369,8 +4369,8 @@ public void test140() { String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6 ? "----------\n" + - "1. ERROR in X.java (at line 6)\r\n" + - " static void foo(){} \r\n" + + "1. ERROR in X.java (at line 6)\n" + + " static void foo(){} \n" + " ^^^^^\n" + "The method foo() of type Bar must override a superclass method\n" + "----------\n" @@ -4504,6 +4504,8 @@ true, raiseInvalidJavadocSeverity); } +// check that @SuppressWarning is reported as unused when corresponding warning is moved from +// warning to error public void test142c() { Map raiseDeprecationReduceInvalidJavadocSeverity = new HashMap(2); @@ -4535,16 +4537,21 @@ }, null, raiseDeprecationReduceInvalidJavadocSeverity, - "----------\n" + - "1. ERROR in X.java (at line 2)\n" + - " public class X extends p.OldStuff {\n" + - " ^^^^^^^^^^\n" + - "The type OldStuff is deprecated\n" + - "----------\n" + - "2. ERROR in X.java (at line 8)\n" + - " super.foo();\n" + - " ^^^^^^^^^^^\n" + - "The method foo() from the type OldStuff is deprecated\n" + + "----------\n" + + "1. WARNING in X.java (at line 1)\n" + + " @SuppressWarnings(\"deprecation\")\n" + + " ^^^^^^^^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"deprecation\")\n" + + "----------\n" + + "2. ERROR in X.java (at line 2)\n" + + " public class X extends p.OldStuff {\n" + + " ^^^^^^^^^^\n" + + "The type OldStuff is deprecated\n" + + "----------\n" + + "3. ERROR in X.java (at line 8)\n" + + " super.foo();\n" + + " ^^^^^^^^^^^\n" + + "The method foo() from the type OldStuff is deprecated\n" + "----------\n", JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); } @@ -5832,10 +5839,10 @@ "import static java.lang.annotation.RetentionPolicy.*;\n" + "import java.lang.annotation.Retention;\n" + "import java.lang.annotation.Target;\n" + - "@Target({TYPE, FIELD, METHOD,\r\n" + - " PARAMETER, CONSTRUCTOR,\r\n" + - " LOCAL_VARIABLE, PACKAGE,})\r\n" + - "@Retention(CLASS)\r\n" + + "@Target({TYPE, FIELD, METHOD,\n" + + " PARAMETER, CONSTRUCTOR,\n" + + " LOCAL_VARIABLE, PACKAGE,})\n" + + "@Retention(CLASS)\n" + "public @interface X {}" }, "", @@ -6328,8 +6335,8 @@ "}" }, "----------\n" + - "1. ERROR in A.java (at line 2)\r\n" + - " A circular1();\r\n" + + "1. ERROR in A.java (at line 2)\n" + + " A circular1();\n" + " ^\n" + "Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" + "----------\n" @@ -6346,18 +6353,18 @@ "}" }, "----------\n" + - "1. ERROR in A.java (at line 2)\r\n" + - " B circular2();\r\n" + + "1. ERROR in A.java (at line 2)\n" + + " B circular2();\n" + " ^\n" + "Cycle detected: a cycle exists between annotation attributes of A and B\n" + "----------\n" + - "2. ERROR in A.java (at line 3)\r\n" + - " A circular1();\r\n" + + "2. ERROR in A.java (at line 3)\n" + + " A circular1();\n" + " ^\n" + "Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" + "----------\n" + - "3. ERROR in A.java (at line 6)\r\n" + - " A circular();\r\n" + + "3. ERROR in A.java (at line 6)\n" + + " A circular();\n" + " ^\n" + "Cycle detected: a cycle exists between annotation attributes of B and A\n" + "----------\n" @@ -6374,18 +6381,18 @@ "}" }, "----------\n" + - "1. ERROR in A.java (at line 2)\r\n" + - " A circular1();\r\n" + + "1. ERROR in A.java (at line 2)\n" + + " A circular1();\n" + " ^\n" + "Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" + "----------\n" + - "2. ERROR in A.java (at line 3)\r\n" + - " B circular2();\r\n" + + "2. ERROR in A.java (at line 3)\n" + + " B circular2();\n" + " ^\n" + "Cycle detected: a cycle exists between annotation attributes of A and B\n" + "----------\n" + - "3. ERROR in A.java (at line 6)\r\n" + - " A circular();\r\n" + + "3. ERROR in A.java (at line 6)\n" + + " A circular();\n" + " ^\n" + "Cycle detected: a cycle exists between annotation attributes of B and A\n" + "----------\n" @@ -7092,8 +7099,8 @@ if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) { this.runNegativeTest(sources, "----------\n" + - "1. ERROR in Y.java (at line 3)\r\n" + - " public void foo() {}\r\n" + + "1. ERROR in Y.java (at line 3)\n" + + " public void foo() {}\n" + " ^^^^^\n" + "The method foo() of type Y must override a superclass method\n" + "----------\n"); @@ -8148,8 +8155,8 @@ "}" }, "----------\n" + - "1. ERROR in TestAnnotation.java (at line 2)\r\n" + - " String targetItem() default void.class;\r\n" + + "1. ERROR in TestAnnotation.java (at line 2)\n" + + " String targetItem() default void.class;\n" + " ^^^^^^^^^^\n" + "Type mismatch: cannot convert from Class to String\n" + "----------\n"); @@ -9403,4 +9410,108 @@ expectedErrorString, JavacTestOptions.SKIP); } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031 +public void test284() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING); + customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " @SuppressWarnings(\"cast\")\n" + + " int i= (int) 0;\n" + + " @SuppressWarnings(\"cast\")\n" + + " byte b= (byte) i;\n" + + " System.out.println(b);\n" + + " }\n" + + "}" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @SuppressWarnings(\"cast\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"cast\")\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031 +public void test285() { + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + String testFiles [] = new String[] { + "X.java", + "public class X {\n" + + " void m() {\n" + + " @SuppressWarnings(\"cast\")\n" + + " int i= (int) 0;\n" + + " @SuppressWarnings(\"cast\")\n" + + " byte b= (byte) i;\n" + + " System.out.println(b);\n" + + " }\n" + + "}" + }; + String expectedErrorString = + "----------\n" + + "1. ERROR in X.java (at line 5)\n" + + " @SuppressWarnings(\"cast\")\n" + + " ^^^^^^\n" + + "Unnecessary @SuppressWarnings(\"cast\")\n" + + "----------\n"; + runNegativeTest( + true, + testFiles, + null, + customOptions, + expectedErrorString, + JavacTestOptions.SKIP); +} +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031 +public void test286() { + Map raiseDeprecationReduceInvalidJavadocSeverity = + new HashMap(2); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED); + raiseDeprecationReduceInvalidJavadocSeverity.put( + CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING); + this.runConformTest( + new String[] { + "X.java", + "@SuppressWarnings(\"deprecation\")\n" + + "public class X extends p.OldStuff {\n" + + " /**\n" + + " * @see p.OldStuff#foo()\n" + + " */\n" + + " @Override\n" + + " public void foo() {\n" + + " super.foo();\n" + + " }\n" + + "}\n", + "p/OldStuff.java", + "package p;\n" + + "@Deprecated\n" + + "public class OldStuff {\n" + + " public void foo() {\n" + + " } \n" + + "}\n", + }, + "", + null, + true, + null, + raiseDeprecationReduceInvalidJavadocSeverity, + null); +} }