diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java
index 1d28367..2db03cf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NonFatalErrorTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -12,6 +12,7 @@
import java.util.Map;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import junit.framework.Test;
@@ -24,7 +25,7 @@
// All specified tests which does not belong to the class are skipped...
static {
// TESTS_NAMES = new String[] { "test127" };
-// TESTS_NUMBERS = new int[] { 5 };
+// TESTS_NUMBERS = new int[] { 7 };
// TESTS_RANGE = new int[] { 169, 180 };
}
@@ -258,4 +259,41 @@
// javac options
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError /* javac test options */);
}
+ public void test007() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) {
+ return;
+ }
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_FatalOptionalError,
+ CompilerOptions.ENABLED);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal,
+ CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressWarnings,
+ CompilerOptions.ENABLED);
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors,
+ CompilerOptions.ENABLED);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken,
+ CompilerOptions.ERROR);
+ runConformTest(
+ new String[] { /* test files */
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " static void foo() {\n" +
+ " String s = null;\n" +
+ " System.out.println(\"SUCCESS\");\n" +
+ " }\n" +
+ " public static void main(String argv[]) {\n" +
+ " foo();\n" +
+ " }\n" +
+ "}"
+ },
+ "SUCCESS" /* expected output string */,
+ null /* no class libraries */,
+ true,
+ null,
+ customOptions /* custom options */,
+ // compiler results
+ null /* do not check error string */);
+ }
}
diff --git a/org.eclipse.jdt.core/buildnotes_jdt-core.html b/org.eclipse.jdt.core/buildnotes_jdt-core.html
index cf5df47..637cd1f 100644
--- a/org.eclipse.jdt.core/buildnotes_jdt-core.html
+++ b/org.eclipse.jdt.core/buildnotes_jdt-core.html
@@ -52,7 +52,9 @@
What's new in this drop
Problem Reports Fixed
-366544
+346175
+@SuppressWarnings should clear all errors including fatal optional errors
+
366544
[index] Test testUseIndexInternalJarAfterRestart failed on Mac and Linux
302850
13 failures in JavaModel tests for the N20100214-2000 Mac OS X - Cocoa test machine
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
index d9c7ad3..905c0bf 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -362,6 +362,13 @@
}
}
+ public CompilationUnitDeclaration getCompilationUnitDeclaration() {
+ if (this.scope != null) {
+ return this.scope.compilationUnitScope().referenceContext;
+ }
+ return null;
+ }
+
public boolean hasErrors() {
return this.ignoreFurtherInvestigation;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java
index eb6f64a..754305e 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -364,6 +364,10 @@
}
}
+public CompilationUnitDeclaration getCompilationUnitDeclaration() {
+ return this;
+}
+
public char[] getFileName() {
return this.compilationResult.getFileName();
}
@@ -394,6 +398,24 @@
return CharOperation.equals(getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME);
}
+public boolean isSuppressed(CategorizedProblem problem) {
+ if (this.suppressWarningsCount == 0) return false;
+ int irritant = ProblemReporter.getIrritant(problem.getID());
+ if (irritant == 0) return false;
+ int start = problem.getSourceStart();
+ int end = problem.getSourceEnd();
+ nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) {
+ long position = this.suppressWarningScopePositions[iSuppress];
+ int startSuppress = (int) (position >>> 32);
+ int endSuppress = (int) position;
+ if (start < startSuppress) continue nextSuppress;
+ if (end > endSuppress) continue nextSuppress;
+ if (this.suppressWarningIrritants[iSuppress].isSet(irritant))
+ return true;
+ }
+ return false;
+}
+
public boolean hasErrors() {
return this.ignoreFurtherInvestigation;
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
index f5d41ea..4b32c61 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -490,6 +490,13 @@
if (typeDecl != null) {
return typeDecl;
}
+ }
+ return null;
+}
+
+public CompilationUnitDeclaration getCompilationUnitDeclaration() {
+ if (this.scope != null) {
+ return this.scope.compilationUnitScope().referenceContext;
}
return null;
}
@@ -1464,4 +1471,5 @@
public boolean isSecondary() {
return (this.bits & ASTNode.IsSecondaryType) != 0;
}
+
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/ReferenceContext.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/ReferenceContext.java
index ec3f72b..6c93b26 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/ReferenceContext.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/ReferenceContext.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -18,6 +18,7 @@
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.internal.compiler.CompilationResult;
+import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
public interface ReferenceContext {
@@ -25,7 +26,10 @@
CompilationResult compilationResult();
+ CompilationUnitDeclaration getCompilationUnitDeclaration();
+
boolean hasErrors();
void tagAsHavingErrors();
+
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
index 6baad99..3765f69 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -15,6 +15,7 @@
import org.eclipse.jdt.internal.compiler.CompilationResult;
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
import org.eclipse.jdt.internal.compiler.IProblemFactory;
+import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.compiler.impl.ReferenceContext;
import org.eclipse.jdt.internal.compiler.util.Util;
@@ -150,6 +151,13 @@
case ProblemSeverities.Error :
record(problem, unitResult, referenceContext);
if ((severity & ProblemSeverities.Fatal) != 0) {
+ // don't abort or tag as error if the error is suppressed
+ if (!referenceContext.hasErrors() && (severity & ProblemSeverities.Optional) != 0 && this.options.suppressOptionalErrors) {
+ CompilationUnitDeclaration unitDecl = referenceContext.getCompilationUnitDeclaration();
+ if (unitDecl != null && unitDecl.isSuppressed(problem)) {
+ return;
+ }
+ }
referenceContext.tagAsHavingErrors();
// should abort ?
int abortLevel;