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

Collapse All | Expand All

(-)batch/org/eclipse/jdt/internal/compiler/batch/Main.java (-3 / +9 lines)
Lines 11-16 Link Here
11
 *     Tom Tromey - Contribution for bug 159641
11
 *     Tom Tromey - Contribution for bug 159641
12
 *     Benjamin Muskalla - Contribution for bug 239066
12
 *     Benjamin Muskalla - Contribution for bug 239066
13
 *     Stephan Herrmann  - Contribution for bug 236385
13
 *     Stephan Herrmann  - Contribution for bug 236385
14
 *     Stephan Herrmann  - Contribution for bug 295551
14
 *******************************************************************************/
15
 *******************************************************************************/
15
package org.eclipse.jdt.internal.compiler.batch;
16
package org.eclipse.jdt.internal.compiler.batch;
16
17
Lines 3339-3347 Link Here
3339
				setSeverity(CompilerOptions.OPTION_ReportMissingSerialVersion, severity, isEnabling);
3340
				setSeverity(CompilerOptions.OPTION_ReportMissingSerialVersion, severity, isEnabling);
3340
				return;
3341
				return;
3341
			} else if (token.equals("suppress")) {//$NON-NLS-1$
3342
			} else if (token.equals("suppress")) {//$NON-NLS-1$
3342
				this.options.put(
3343
				if (severity == ProblemSeverities.Warning || isEnabling)
3343
					CompilerOptions.OPTION_SuppressWarnings,
3344
					this.options.put(
3344
					isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3345
						CompilerOptions.OPTION_SuppressWarnings,
3346
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3347
				if (severity == ProblemSeverities.Error || !isEnabling)
3348
					this.options.put(
3349
						CompilerOptions.OPTION_SuppressOptionalErrors,
3350
						isEnabling ? CompilerOptions.ENABLED : CompilerOptions.DISABLED);
3345
				return;
3351
				return;
3346
			} else if (token.equals("static-access")) { //$NON-NLS-1$
3352
			} else if (token.equals("static-access")) { //$NON-NLS-1$
3347
				setSeverity(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, severity, isEnabling);
3353
				setSeverity(CompilerOptions.OPTION_ReportNonStaticAccessToStatic, severity, isEnabling);
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (-1 / +2 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann  - Contribution for bug 295551
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.ast;
12
package org.eclipse.jdt.internal.compiler.ast;
12
13
Lines 217-223 Link Here
217
	nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) {
218
	nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) {
218
		CategorizedProblem problem = problems[iProblem];
219
		CategorizedProblem problem = problems[iProblem];
219
		int problemID = problem.getID();
220
		int problemID = problem.getID();
220
		if (problem.isError()) {
221
		if (problem.isError() && !options.suppressOptionalErrors) {
221
			if (problemID != IProblem.UnusedWarningToken) {
222
			if (problemID != IProblem.UnusedWarningToken) {
222
			// tolerate unused warning tokens which were promoted as errors
223
			// tolerate unused warning tokens which were promoted as errors
223
				hasErrors = true;
224
				hasErrors = true;
(-)compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (-1 / +17 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *     Stephan Herrmann  - Contribution for bug 236385
12
 *     Stephan Herrmann  - Contribution for bug 295551
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.internal.compiler.impl;
14
package org.eclipse.jdt.internal.compiler.impl;
14
15
Lines 112-117 Link Here
112
	public static final String OPTION_ReportForbiddenReference =  "org.eclipse.jdt.core.compiler.problem.forbiddenReference"; //$NON-NLS-1$
113
	public static final String OPTION_ReportForbiddenReference =  "org.eclipse.jdt.core.compiler.problem.forbiddenReference"; //$NON-NLS-1$
113
	public static final String OPTION_ReportDiscouragedReference =  "org.eclipse.jdt.core.compiler.problem.discouragedReference"; //$NON-NLS-1$
114
	public static final String OPTION_ReportDiscouragedReference =  "org.eclipse.jdt.core.compiler.problem.discouragedReference"; //$NON-NLS-1$
114
	public static final String OPTION_SuppressWarnings =  "org.eclipse.jdt.core.compiler.problem.suppressWarnings"; //$NON-NLS-1$
115
	public static final String OPTION_SuppressWarnings =  "org.eclipse.jdt.core.compiler.problem.suppressWarnings"; //$NON-NLS-1$
116
	public static final String OPTION_SuppressOptionalErrors = "org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors"; //$NON-NLS-1$
115
	public static final String OPTION_ReportUnhandledWarningToken =  "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
117
	public static final String OPTION_ReportUnhandledWarningToken =  "org.eclipse.jdt.core.compiler.problem.unhandledWarningToken"; //$NON-NLS-1$
116
	public static final String OPTION_ReportUnusedWarningToken =  "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"; //$NON-NLS-1$
118
	public static final String OPTION_ReportUnusedWarningToken =  "org.eclipse.jdt.core.compiler.problem.unusedWarningToken"; //$NON-NLS-1$
117
	public static final String OPTION_ReportUnusedLabel =  "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
119
	public static final String OPTION_ReportUnusedLabel =  "org.eclipse.jdt.core.compiler.problem.unusedLabel"; //$NON-NLS-1$
Lines 320-327 Link Here
320
	public boolean reportMissingJavadocCommentsOverriding;
322
	public boolean reportMissingJavadocCommentsOverriding;
321
	/** Indicate whether the JSR bytecode should be inlined to avoid its presence in classfile */
323
	/** Indicate whether the JSR bytecode should be inlined to avoid its presence in classfile */
322
	public boolean inlineJsrBytecode;
324
	public boolean inlineJsrBytecode;
323
	/** Indicate if @SuppressWarning annotation are activated */
325
	/** Indicate if @SuppressWarning annotations are activated */
324
	public boolean suppressWarnings;
326
	public boolean suppressWarnings;
327
	/** Indicate if @SuppressWarning annotations should also suppress optional errors */
328
	public boolean suppressOptionalErrors;
325
	/** Specify if should treat optional error as fatal or just like warning */
329
	/** Specify if should treat optional error as fatal or just like warning */
326
	public boolean treatOptionalErrorAsFatal;
330
	public boolean treatOptionalErrorAsFatal;
327
	/** Specify if parser should perform structural recovery in methods */
331
	/** Specify if parser should perform structural recovery in methods */
Lines 884-889 Link Here
884
		optionsMap.put(OPTION_ReportPotentialNullReference, getSeverityString(PotentialNullReference));
888
		optionsMap.put(OPTION_ReportPotentialNullReference, getSeverityString(PotentialNullReference));
885
		optionsMap.put(OPTION_ReportRedundantNullCheck, getSeverityString(RedundantNullCheck));
889
		optionsMap.put(OPTION_ReportRedundantNullCheck, getSeverityString(RedundantNullCheck));
886
		optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED);
890
		optionsMap.put(OPTION_SuppressWarnings, this.suppressWarnings ? ENABLED : DISABLED);
891
		optionsMap.put(OPTION_SuppressOptionalErrors, this.suppressOptionalErrors ? ENABLED : DISABLED);
887
		optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken));
892
		optionsMap.put(OPTION_ReportUnhandledWarningToken, getSeverityString(UnhandledWarningToken));
888
		optionsMap.put(OPTION_ReportUnusedWarningToken, getSeverityString(UnusedWarningToken));
893
		optionsMap.put(OPTION_ReportUnusedWarningToken, getSeverityString(UnusedWarningToken));
889
		optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment));
894
		optionsMap.put(OPTION_ReportParameterAssignment, getSeverityString(ParameterAssignment));
Lines 1014-1019 Link Here
1014
		// suppress warning annotation
1019
		// suppress warning annotation
1015
		this.suppressWarnings = true;
1020
		this.suppressWarnings = true;
1016
1021
1022
		// suppress also optional errors
1023
		this.suppressOptionalErrors = false;
1024
1017
		// treat optional error as non fatal
1025
		// treat optional error as non fatal
1018
		this.treatOptionalErrorAsFatal = false;
1026
		this.treatOptionalErrorAsFatal = false;
1019
1027
Lines 1225-1230 Link Here
1225
				this.suppressWarnings = false;
1233
				this.suppressWarnings = false;
1226
			}
1234
			}
1227
		}
1235
		}
1236
		if ((optionValue = optionsMap.get(OPTION_SuppressOptionalErrors)) != null) {
1237
			if (ENABLED.equals(optionValue)) {
1238
				this.suppressOptionalErrors = true;
1239
			} else if (DISABLED.equals(optionValue)) {
1240
				this.suppressOptionalErrors = false;
1241
			}
1242
		}
1228
		if ((optionValue = optionsMap.get(OPTION_FatalOptionalError)) != null) {
1243
		if ((optionValue = optionsMap.get(OPTION_FatalOptionalError)) != null) {
1229
			if (ENABLED.equals(optionValue)) {
1244
			if (ENABLED.equals(optionValue)) {
1230
				this.treatOptionalErrorAsFatal = true;
1245
				this.treatOptionalErrorAsFatal = true;
Lines 1482-1487 Link Here
1482
		buf.append("\n\t- missing @Deprecated annotation: ").append(getSeverityString(MissingDeprecatedAnnotation)); //$NON-NLS-1$
1497
		buf.append("\n\t- missing @Deprecated annotation: ").append(getSeverityString(MissingDeprecatedAnnotation)); //$NON-NLS-1$
1483
		buf.append("\n\t- incomplete enum switch: ").append(getSeverityString(IncompleteEnumSwitch)); //$NON-NLS-1$
1498
		buf.append("\n\t- incomplete enum switch: ").append(getSeverityString(IncompleteEnumSwitch)); //$NON-NLS-1$
1484
		buf.append("\n\t- suppress warnings: ").append(this.suppressWarnings ? ENABLED : DISABLED); //$NON-NLS-1$
1499
		buf.append("\n\t- suppress warnings: ").append(this.suppressWarnings ? ENABLED : DISABLED); //$NON-NLS-1$
1500
		buf.append("\n\t- suppress optional errors: ").append(this.suppressOptionalErrors ? ENABLED : DISABLED); //$NON-NLS-1$
1485
		buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$
1501
		buf.append("\n\t- unhandled warning token: ").append(getSeverityString(UnhandledWarningToken)); //$NON-NLS-1$
1486
		buf.append("\n\t- unused warning token: ").append(getSeverityString(UnusedWarningToken)); //$NON-NLS-1$
1502
		buf.append("\n\t- unused warning token: ").append(getSeverityString(UnusedWarningToken)); //$NON-NLS-1$
1487
		buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$
1503
		buf.append("\n\t- unused label: ").append(getSeverityString(UnusedLabel)); //$NON-NLS-1$
(-)model/org/eclipse/jdt/core/JavaCore.java (+16 lines)
Lines 82-87 Link Here
82
 *     IBM Corporation - added getOptionForConfigurableSeverity(int)
82
 *     IBM Corporation - added getOptionForConfigurableSeverity(int)
83
 *     Benjamin Muskalla - added COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD
83
 *     Benjamin Muskalla - added COMPILER_PB_MISSING_SYNCHRONIZED_ON_INHERITED_METHOD
84
 *     Stephan Herrmann  - added COMPILER_PB_UNUSED_OBJECT_ALLOCATION
84
 *     Stephan Herrmann  - added COMPILER_PB_UNUSED_OBJECT_ALLOCATION
85
 *     Stephan Herrmann  - added COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS
85
 *******************************************************************************/
86
 *******************************************************************************/
86
87
87
package org.eclipse.jdt.core;
88
package org.eclipse.jdt.core;
Lines 1420-1425 Link Here
1420
	 */
1421
	 */
1421
	public static final String COMPILER_PB_SUPPRESS_WARNINGS = PLUGIN_ID + ".compiler.problem.suppressWarnings"; //$NON-NLS-1$
1422
	public static final String COMPILER_PB_SUPPRESS_WARNINGS = PLUGIN_ID + ".compiler.problem.suppressWarnings"; //$NON-NLS-1$
1422
	/**
1423
	/**
1424
	 * Compiler option ID: Further Determining the Effect of <code>@SuppressWarnings</code> if also
1425
	 * <code>COMPILER_PB_SUPPRESS_WARNINGS</code> is enabled.
1426
	 * <p>When enabled, the <code>@SuppressWarnings</code> annotation can additionally be used to suppress 
1427
	 * optional compiler diagnostics that have been configured as <code>ERROR</code>.
1428
	 * <p>When disabled, all <code>@SupressWarnings</code> annotations only affects warnings.
1429
	 * <dl>
1430
	 * <dt>Option id:</dt><dd><code>"org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors"</code></dd>
1431
	 * <dt>Possible values:</dt><dd><code>{ "enabled", "disabled" }</code></dd>
1432
	 * <dt>Default:</dt><dd><code>"disabled"</code></dd>
1433
	 * </dl>
1434
	 * @since 3.6
1435
	 * @category CompilerOptionID
1436
	 */
1437
	public static final String COMPILER_PB_SUPPRESS_OPTIONAL_ERRORS = PLUGIN_ID + ".compiler.problem.suppressOptionalErrors"; //$NON-NLS-1$
1438
	/**
1423
	 * Compiler option ID: Reporting Unhandled Warning Token for <code>@SuppressWarnings</code>.
1439
	 * Compiler option ID: Reporting Unhandled Warning Token for <code>@SuppressWarnings</code>.
1424
	 * <p>When enabled, the compiler will issue an error or a warning when encountering a token
1440
	 * <p>When enabled, the compiler will issue an error or a warning when encountering a token
1425
	 *    it cannot handle inside a <code>@SuppressWarnings</code> annotation.
1441
	 *    it cannot handle inside a <code>@SuppressWarnings</code> annotation.
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (+99 lines)
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Stephan Herrmann  - Contribution for bug 295551
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.compiler.regression;
12
package org.eclipse.jdt.core.tests.compiler.regression;
12
13
Lines 9304-9307 Link Here
9304
			expectedOutput,
9305
			expectedOutput,
9305
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
9306
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
9306
}
9307
}
9308
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
9309
public void test280() {
9310
	Map customOptions = getCompilerOptions();
9311
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
9312
	customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
9313
	String testFiles [] = new String[] {
9314
			"A.java",
9315
			"public class A {\n" +
9316
			"	@SuppressWarnings(\"unused\")\n" +
9317
			"	private int i;\n" + // problem configured as warning but still suppressed
9318
			"}\n"
9319
			};
9320
	runConformTest(
9321
			testFiles,
9322
			null,
9323
			null,
9324
			true,
9325
			null,
9326
			customOptions,
9327
			null);
9328
}
9329
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
9330
public void test281() {
9331
	Map customOptions = getCompilerOptions();
9332
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
9333
	customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.DISABLED); // this option overrides the next
9334
	customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
9335
	String testFiles [] = new String[] {
9336
			"A.java",
9337
			"public class A {\n" +
9338
			"	@SuppressWarnings(\"unused\")\n" +
9339
			"	private int i;\n" +
9340
			"}\n"
9341
			};
9342
	String expectedErrorString = 
9343
			"----------\n" + 
9344
			"1. ERROR in A.java (at line 3)\n" + 
9345
			"	private int i;\n" + 
9346
			"	            ^\n" + 
9347
			"The field A.i is never read locally\n" + 
9348
			"----------\n";
9349
	runNegativeTest(
9350
			true,
9351
			testFiles,
9352
			null, 
9353
			customOptions,
9354
			expectedErrorString,
9355
			JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
9356
}
9357
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
9358
public void test282() {
9359
	Map customOptions = getCompilerOptions();
9360
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
9361
	customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
9362
	String testFiles [] = new String[] {
9363
			"A.java",
9364
			"import java.util.Map;\n" +
9365
			"public class A {\n" +
9366
			"	@SuppressWarnings({\"rawtypes\", \"unused\"})\n" + //suppress a warning and an error
9367
			"	private Map i;\n" + 
9368
			"}\n"
9369
			};
9370
	runConformTest(
9371
			testFiles,
9372
			null,
9373
			null,
9374
			true,
9375
			null,
9376
			customOptions,
9377
			null);
9378
}
9379
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
9380
public void test283() {
9381
	Map customOptions = getCompilerOptions();
9382
	customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
9383
	customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
9384
	String testFiles [] = new String[] {
9385
			"A.java",
9386
			"public class A {\n" +
9387
			"	@SuppressWarnings(\"all\")\n" +
9388
			"	private void i;\n" + // cannot suppress mandatory error
9389
			"}\n"
9390
			};
9391
	String expectedErrorString = 
9392
			"----------\n" + 
9393
			"1. ERROR in A.java (at line 3)\n" + 
9394
			"	private void i;\n" + 
9395
			"	             ^\n" + 
9396
			"void is an invalid type for the variable i\n" + 
9397
			"----------\n";
9398
	runNegativeTest(
9399
			true,
9400
			testFiles,
9401
			null, 
9402
			customOptions,
9403
			expectedErrorString,
9404
			JavacTestOptions.SKIP);
9405
}
9307
}
9406
}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java (+2 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Benjamin Muskalla - Contribution for bug 239066
10
 *     Benjamin Muskalla - Contribution for bug 239066
11
 *     Stephan Herrmann  - Contribution for bug 236385
11
 *     Stephan Herrmann  - Contribution for bug 236385
12
 *     Stephan Herrmann  - Contribution for bug 295551
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.jdt.core.tests.compiler.regression;
14
package org.eclipse.jdt.core.tests.compiler.regression;
14
15
Lines 1843-1848 Link Here
1843
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.redundantSuperinterface\" value=\"ignore\"/>\n" +
1844
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.redundantSuperinterface\" value=\"ignore\"/>\n" +
1844
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.specialParameterHidingField\" value=\"disabled\"/>\n" +
1845
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.specialParameterHidingField\" value=\"disabled\"/>\n" +
1845
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" +
1846
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" +
1847
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors\" value=\"disabled\"/>\n" +
1846
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarnings\" value=\"enabled\"/>\n" +
1848
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarnings\" value=\"enabled\"/>\n" +
1847
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation\" value=\"ignore\"/>\n" +
1849
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation\" value=\"ignore\"/>\n" +
1848
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.tasks\" value=\"warning\"/>\n" + 
1850
			"		<option key=\"org.eclipse.jdt.core.compiler.problem.tasks\" value=\"warning\"/>\n" + 

Return to bug 295551