### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.apt.core Index: src/org/eclipse/jdt/apt/core/internal/env/APTProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.apt.core/src/org/eclipse/jdt/apt/core/internal/env/APTProblem.java,v retrieving revision 1.11 diff -u -r1.11 APTProblem.java --- src/org/eclipse/jdt/apt/core/internal/env/APTProblem.java 7 May 2008 15:37:45 -0000 1.11 +++ src/org/eclipse/jdt/apt/core/internal/env/APTProblem.java 30 Nov 2009 21:47:21 -0000 @@ -102,6 +102,10 @@ return _severity == Severity.WARNING; } + public boolean isPromotedWarning() { + return false; + } + public String toString() { return _message == null ? "" : _message ; //$NON-NLS-1$ #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/core/compiler/IProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/core/compiler/IProblem.java,v retrieving revision 1.220 diff -u -r1.220 IProblem.java --- compiler/org/eclipse/jdt/core/compiler/IProblem.java 11 Nov 2009 19:28:04 -0000 1.220 +++ compiler/org/eclipse/jdt/core/compiler/IProblem.java 30 Nov 2009 21:47:21 -0000 @@ -206,6 +206,13 @@ boolean isWarning(); /** + * Checks the severity to see if the promotedWarning bit is set. + * + * @return true if the promotedWarning bit is set for the severity, false otherwise + */ +boolean isPromotedWarning(); + +/** * Set the end position of the problem (inclusive), or -1 if unknown. * Used for shifting problem positions. * Index: compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java,v retrieving revision 1.64 diff -u -r1.64 CompilationResult.java --- compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java 6 Oct 2009 18:17:25 -0000 1.64 +++ compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java 30 Nov 2009 21:47:21 -0000 @@ -278,6 +278,20 @@ return false; } +/** + * Difference between this and {@link #hasErrors()} is that this variant + * ignores errors that were promoted up from warnings due to the + * "Promote all warnings to errors" option. + */ +public boolean hasGenuineErrors() { + if (this.problems != null) + for (int i = 0; i < this.problemCount; i++) { + if (this.problems[i].isError() && !this.problems[i].isPromotedWarning()) + return true; + } + return false; +} + public boolean hasProblems() { return this.problemCount != 0; } 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.86 diff -u -r1.86 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 12 May 2009 20:49:55 -0000 1.86 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 30 Nov 2009 21:47:21 -0000 @@ -217,7 +217,7 @@ nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) { CategorizedProblem problem = problems[iProblem]; int problemID = problem.getID(); - if (problem.isError()) { + if (problem.isError() && !problem.isPromotedWarning()) { // honor @SupressWarnings for errors promoted up from warnings if (problemID != IProblem.UnusedWarningToken) { // tolerate unused warning tokens which were promoted as errors hasErrors = true; @@ -528,7 +528,10 @@ this.types[i].resolve(this.scope); } } - if (!this.compilationResult.hasErrors()) checkUnusedImports(); + // Warnings that have been promoted up to errors are subject to + // being silenced by @SuppressWarnings. Check unused imports only if + // there are no "real" errors + if (!this.compilationResult.hasGenuineErrors()) checkUnusedImports(); reportNLSProblems(); } catch (AbortCompilationUnit e) { this.ignoreFurtherInvestigation = true; Index: compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java,v retrieving revision 1.225 diff -u -r1.225 CompilerOptions.java --- compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 26 Nov 2009 16:20:04 -0000 1.225 +++ compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java 30 Nov 2009 21:47:21 -0000 @@ -115,6 +115,7 @@ public static final String OPTION_ReportUnusedWarningToken = "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"; //$NON-NLS-1$ public static final String OPTION_ReportUnusedLabel = "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$ public static final String OPTION_FatalOptionalError = "org.eclipse.jdt.core.compiler.problem.fatalOptionalError"; //$NON-NLS-1$ + public static final String OPTION_PromoteWarningsToErrors = "org.eclipse.jdt.core.compiler.problem.promoteWarningsToErrors"; //$NON-NLS-1$ public static final String OPTION_ReportParameterAssignment = "org.eclipse.jdt.core.compiler.problem.parameterAssignment"; //$NON-NLS-1$ public static final String OPTION_ReportFallthroughCase = "org.eclipse.jdt.core.compiler.problem.fallthroughCase"; //$NON-NLS-1$ public static final String OPTION_ReportOverridingMethodWithoutSuperInvocation = "org.eclipse.jdt.core.compiler.problem.overridingMethodWithoutSuperInvocation"; //$NON-NLS-1$ @@ -335,6 +336,8 @@ public boolean generateClassFiles; /** Indicate if method bodies should be ignored */ public boolean ignoreMethodBodies; + /** Indicate if all warnings should be promoted to errors */ + private boolean promoteWarningsToErrors; // keep in sync with warningTokenToIrritant and warningTokenFromIrritant public final static String[] warningTokens = { @@ -861,6 +864,7 @@ optionsMap.put(OPTION_Source, versionFromJdkLevel(this.sourceLevel)); optionsMap.put(OPTION_TargetPlatform, versionFromJdkLevel(this.targetJDK)); optionsMap.put(OPTION_FatalOptionalError, this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); + optionsMap.put(OPTION_PromoteWarningsToErrors, this.promoteWarningsToErrors ? ENABLED : DISABLED); if (this.defaultEncoding != null) { optionsMap.put(OPTION_Encoding, this.defaultEncoding); } @@ -1009,6 +1013,9 @@ // treat optional error as fatal or just like warning? this.treatOptionalErrorAsFatal = true; + // promote all warnings to errors? + this.promoteWarningsToErrors = false; + // parser perform statements recovery this.performMethodsFullRecovery = true; @@ -1224,6 +1231,13 @@ this.treatOptionalErrorAsFatal = false; } } + if ((optionValue = optionsMap.get(OPTION_PromoteWarningsToErrors)) != null) { + if (ENABLED.equals(optionValue)) { + this.promoteWarningsToErrors = true; + } else if (DISABLED.equals(optionValue)) { + this.promoteWarningsToErrors = false; + } + } if ((optionValue = optionsMap.get(OPTION_ReportMissingOverrideAnnotationForInterfaceMethodImplementation)) != null) { if (ENABLED.equals(optionValue)) { this.reportMissingOverrideAnnotationForInterfaceMethodImplementation = true; @@ -1477,6 +1491,7 @@ buf.append("\n\t- unused warning token: ").append(getSeverityString(UnusedWarningToken)); //$NON-NLS-1$ buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$ buf.append("\n\t- treat optional error as fatal: ").append(this.treatOptionalErrorAsFatal ? ENABLED : DISABLED); //$NON-NLS-1$ + buf.append("\n\t- promote warnings to errors: ").append(this.promoteWarningsToErrors ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- parameter assignment: ").append(getSeverityString(ParameterAssignment)); //$NON-NLS-1$ buf.append("\n\t- generate class files: ").append(this.generateClassFiles ? ENABLED : DISABLED); //$NON-NLS-1$ buf.append("\n\t- process annotations: ").append(this.processAnnotations ? ENABLED : DISABLED); //$NON-NLS-1$ Index: compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java,v retrieving revision 1.51 diff -u -r1.51 DefaultProblem.java --- compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java 7 Mar 2009 01:08:10 -0000 1.51 +++ compiler/org/eclipse/jdt/internal/compiler/problem/DefaultProblem.java 30 Nov 2009 21:47:21 -0000 @@ -242,6 +242,14 @@ return (this.severity & ProblemSeverities.Error) == 0; } +/* + * @see org.eclipse.jdt.core.compiler.IProblem#isPromotedWarning() + */ +public boolean isPromotedWarning() { + return isError() && ((this.severity & ProblemSeverities.Promoted) != 0); +} + + public void setOriginatingFileName(char[] fileName) { this.fileName = fileName; } Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java,v retrieving revision 1.35 diff -u -r1.35 ProblemHandler.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java 7 Mar 2009 01:08:10 -0000 1.35 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java 30 Nov 2009 21:47:21 -0000 @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.problem; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.CompilationResult; @@ -131,6 +132,17 @@ int columnNumber = problemStartPosition >= 0 ? Util.searchColumnNumber(unitResult.getLineSeparatorPositions(), lineNumber, problemStartPosition) : 0; + + // User can promote all warnings to errors via an option. If this is a warning + // and the option is on, then promote the problem to an error, but mark it + // to allow for special handling (e.g., honor @SuppressWarning) + if ((severity & ProblemSeverities.Error) == 0) { + String option = (String)this.options.getMap().get(JavaCore.COMPILER_PB_PROMOTE_WARNINGS_TO_ERRS); + if (option != null && option.equals(JavaCore.ENABLED)) { + severity |= (ProblemSeverities.Error | ProblemSeverities.Promoted); + } + } + CategorizedProblem problem = this.createProblem( unitResult.getFileName(), Index: compiler/org/eclipse/jdt/internal/compiler/problem/ProblemSeverities.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemSeverities.java,v retrieving revision 1.16 diff -u -r1.16 ProblemSeverities.java --- compiler/org/eclipse/jdt/internal/compiler/problem/ProblemSeverities.java 22 Jul 2009 20:03:28 -0000 1.16 +++ compiler/org/eclipse/jdt/internal/compiler/problem/ProblemSeverities.java 30 Nov 2009 21:47:21 -0000 @@ -24,4 +24,5 @@ final int Optional = 32; // when bit is set: problem was configurable final int SecondaryError = 64; final int Fatal = 128; // when bit is set: problem was either a mandatory error, or an optional+treatOptionalErrorAsFatal + final int Promoted = 512; // when bit is set, the problem is a warning that has been promoted to an error via the "promote all warnings to error" setting } Index: model/org/eclipse/jdt/core/IJavaModelMarker.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/IJavaModelMarker.java,v retrieving revision 1.41 diff -u -r1.41 IJavaModelMarker.java --- model/org/eclipse/jdt/core/IJavaModelMarker.java 27 Jun 2008 16:04:01 -0000 1.41 +++ model/org/eclipse/jdt/core/IJavaModelMarker.java 30 Nov 2009 21:47:21 -0000 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.jdt.core; +import org.eclipse.core.resources.IMarker; + /** * Markers used by the Java model. *

@@ -84,6 +86,18 @@ String FLAGS = "flags"; //$NON-NLS-1$ /** + * Boolean marker attribute indicating if the marker is for an error that + * was promoted up from a warning by the "Promote all warnings to errors" + * option (value "promotedWarning"). The + * {@link IMarker#SEVERITY} attribute will contain + * SEVERITY_ERROR if this attribute is present and set to true. + * That is, this attribute merely further qualifies the error marker. + * + * @since 3.6 + */ + String PROMOTED_WARNING = "promotedWarning"; //$NON-NLS-1$ + + /** * Cycle detected marker attribute (value "cycleDetected"). * Used only on buildpath problem markers. The value of this attribute is * either "true" or "false". Index: model/org/eclipse/jdt/core/JavaCore.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java,v retrieving revision 1.643 diff -u -r1.643 JavaCore.java --- model/org/eclipse/jdt/core/JavaCore.java 26 Oct 2009 17:21:09 -0000 1.643 +++ model/org/eclipse/jdt/core/JavaCore.java 30 Nov 2009 21:47:22 -0000 @@ -1281,6 +1281,21 @@ * @category CompilerOptionID */ public static final String COMPILER_PB_FATAL_OPTIONAL_ERROR = PLUGIN_ID + ".compiler.problem.fatalOptionalError"; //$NON-NLS-1$ + + /** + * Compiler option ID: Promote all warnings to errors + *

When enabled, all warnings will be promoted up to errors. Those errors are subject to exclusion by @SuppressWarnings + *

+ *
Option id:
"org.eclipse.jdt.core.compiler.problem.promoteWarningsToErrors"
+ *
Possible values:
{ "enabled", "disabled" }
+ *
Default:
"enabled"
+ *
+ * @since 3.6 + * @category CompilerOptionID + */ + public static final String COMPILER_PB_PROMOTE_WARNINGS_TO_ERRS = PLUGIN_ID + ".compiler.problem.promoteWarningsToErrors"; //$NON-NLS-1$ + + /** * Compiler option ID: Reporting Parameter Assignment. *

When enabled, the compiler will issue an error or a warning if a parameter is Index: model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java,v retrieving revision 1.126 diff -u -r1.126 AbstractImageBuilder.java --- model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java 5 Oct 2009 14:44:21 -0000 1.126 +++ model/org/eclipse/jdt/internal/core/builder/AbstractImageBuilder.java 30 Nov 2009 21:47:22 -0000 @@ -66,6 +66,7 @@ IMarker.LINE_NUMBER, IJavaModelMarker.ARGUMENTS, IJavaModelMarker.CATEGORY_ID, + IJavaModelMarker.PROMOTED_WARNING, }; public final static String[] JAVA_TASK_MARKER_ATTRIBUTE_NAMES = { IMarker.MESSAGE, @@ -734,6 +735,8 @@ allValues[index++] = new Integer(problem.getSourceLineNumber()); // line allValues[index++] = Util.getProblemArgumentsForMarker(problem.getArguments()); // arguments allValues[index++] = new Integer(problem.getCategoryID()); // category ID + allValues[index++] = new Boolean(problem.isPromotedWarning()); // IJavaModelMarker.PROMOTED_WARNING + // SOURCE_ID attribute for JDT problems if (managedLength > 0) allValues[index++] = JavaBuilder.SOURCE_ID; #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java,v retrieving revision 1.199 diff -u -r1.199 BatchCompilerTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 7 Oct 2009 14:58:12 -0000 1.199 +++ src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java 30 Nov 2009 21:47:23 -0000 @@ -1834,6 +1834,7 @@ "