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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java (-9 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 72-77 Link Here
72
	public boolean hasSyntaxError = false;
72
	public boolean hasSyntaxError = false;
73
	public char[][] packageName;
73
	public char[][] packageName;
74
	public boolean checkSecondaryTypes = false; // check for secondary types which were created after the initial buildTypeBindings call
74
	public boolean checkSecondaryTypes = false; // check for secondary types which were created after the initial buildTypeBindings call
75
	public int numberOfErrors;
75
76
76
	private static final int[] EMPTY_LINE_ENDS = Util.EMPTY_INT_ARRAY;
77
	private static final int[] EMPTY_LINE_ENDS = Util.EMPTY_INT_ARRAY;
77
	private static final Comparator PROBLEM_COMPARATOR = new Comparator() {
78
	private static final Comparator PROBLEM_COMPARATOR = new Comparator() {
Lines 270-281 Link Here
270
}
271
}
271
272
272
public boolean hasErrors() {
273
public boolean hasErrors() {
273
	if (this.problems != null)
274
	return this.numberOfErrors != 0;
274
		for (int i = 0; i < this.problemCount; i++) {
275
			if (this.problems[i].isError())
276
				return true;
277
		}
278
	return false;
279
}
275
}
280
276
281
public boolean hasProblems() {
277
public boolean hasProblems() {
Lines 345-352 Link Here
345
		if (newProblem.isError() && !referenceContext.hasErrors()) this.firstErrors.add(newProblem);
341
		if (newProblem.isError() && !referenceContext.hasErrors()) this.firstErrors.add(newProblem);
346
		this.problemsMap.put(newProblem, referenceContext);
342
		this.problemsMap.put(newProblem, referenceContext);
347
	}
343
	}
348
	if ((newProblem.getID() & IProblem.Syntax) != 0 && newProblem.isError())
344
	if (newProblem.isError()) {
349
		this.hasSyntaxError = true;
345
		this.numberOfErrors++;
346
		if ((newProblem.getID() & IProblem.Syntax) != 0) {
347
			this.hasSyntaxError = true;
348
		}
349
	}
350
}
350
}
351
351
352
/**
352
/**
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (-6 / +60 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
16
17
import org.eclipse.jdt.core.compiler.CategorizedProblem;
17
import org.eclipse.jdt.core.compiler.CategorizedProblem;
18
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.core.compiler.CharOperation;
19
import org.eclipse.jdt.core.compiler.IProblem;
19
import org.eclipse.jdt.internal.compiler.ASTVisitor;
20
import org.eclipse.jdt.internal.compiler.ASTVisitor;
20
import org.eclipse.jdt.internal.compiler.ClassFile;
21
import org.eclipse.jdt.internal.compiler.ClassFile;
21
import org.eclipse.jdt.internal.compiler.CompilationResult;
22
import org.eclipse.jdt.internal.compiler.CompilationResult;
Lines 207-230 Link Here
207
}
208
}
208
209
209
public void finalizeProblems() {
210
public void finalizeProblems() {
210
	if (this.suppressWarningsCount == 0) return;
211
	if (this.suppressWarningsCount == 0) {
212
		if (this.compilationResult.hasErrors()) {
213
			// we need to check if we should discard unused locals warnings (336648)
214
			int removed = 0;
215
			CategorizedProblem[] problems = this.compilationResult.problems;
216
			int problemCount = this.compilationResult.problemCount;
217
			for (int i = 0; i < problemCount; i++) {
218
				if (problems[i].getID() == IProblem.LocalVariableIsNeverUsed) {
219
					problems[i] = null;
220
					removed++;
221
				}
222
			}
223
			// compact remaining problems
224
			if (removed > 0) {
225
				for (int i = 0, index = 0; i < problemCount; i++) {
226
					CategorizedProblem problem;
227
					if ((problem = problems[i]) != null) {
228
						if (i > index) {
229
							problems[index++] = problem;
230
						} else {
231
							index++;
232
						}
233
					}
234
				}
235
				this.compilationResult.problemCount -= removed;
236
			}
237
		}
238
		return;
239
	}
211
	int removed = 0;
240
	int removed = 0;
212
	CategorizedProblem[] problems = this.compilationResult.problems;
241
	CategorizedProblem[] problems = this.compilationResult.problems;
213
	int problemCount = this.compilationResult.problemCount;
242
	int problemCount = this.compilationResult.problemCount;
214
	IrritantSet[] foundIrritants = new IrritantSet[this.suppressWarningsCount];
243
	IrritantSet[] foundIrritants = new IrritantSet[this.suppressWarningsCount];
215
	CompilerOptions options = this.scope.compilerOptions();
244
	CompilerOptions options = this.scope.compilerOptions();
216
	boolean hasMandatoryErrors = false;
245
	boolean hasMandatoryErrors = false;
246
	int remainingErrors = 0;
217
	nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) {
247
	nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) {
218
		CategorizedProblem problem = problems[iProblem];
248
		CategorizedProblem problem = problems[iProblem];
219
		int problemID = problem.getID();
249
		int problemID = problem.getID();
220
		int irritant = ProblemReporter.getIrritant(problemID);
250
		int irritant = ProblemReporter.getIrritant(problemID);
221
		if (problem.isError()) {
251
		boolean isError = problem.isError();
252
		if (isError) {
222
			if (irritant == 0) {
253
			if (irritant == 0) {
223
				// tolerate unused warning tokens when mandatory errors
254
				// tolerate unused warning tokens when mandatory errors
224
				hasMandatoryErrors = true;
255
				hasMandatoryErrors = true;
256
				remainingErrors++;
225
				continue;
257
				continue;
226
			}
258
			}
227
			if (!options.suppressOptionalErrors) {
259
			if (!options.suppressOptionalErrors) {
260
				remainingErrors++;
228
				continue;
261
				continue;
229
			}
262
			}
230
		}
263
		}
Lines 234-246 Link Here
234
			long position = this.suppressWarningScopePositions[iSuppress];
267
			long position = this.suppressWarningScopePositions[iSuppress];
235
			int startSuppress = (int) (position >>> 32);
268
			int startSuppress = (int) (position >>> 32);
236
			int endSuppress = (int) position;
269
			int endSuppress = (int) position;
237
			if (start < startSuppress) continue nextSuppress;
270
			if (start < startSuppress) {
238
			if (end > endSuppress) continue nextSuppress;
239
			if (!this.suppressWarningIrritants[iSuppress].isSet(irritant))
240
				continue nextSuppress;
271
				continue nextSuppress;
272
			}
273
			if (end > endSuppress) {
274
				continue nextSuppress;
275
			}
276
			if (!this.suppressWarningIrritants[iSuppress].isSet(irritant)) {
277
				continue nextSuppress;
278
			}
241
			// discard suppressed warning
279
			// discard suppressed warning
242
			removed++;
280
			removed++;
243
			problems[iProblem] = null;
281
			problems[iProblem] = null;
282
			if (isError) {
283
				this.compilationResult.numberOfErrors--;
284
			}
244
			if (this.compilationResult.problemsMap != null) this.compilationResult.problemsMap.remove(problem);
285
			if (this.compilationResult.problemsMap != null) this.compilationResult.problemsMap.remove(problem);
245
			if (this.compilationResult.firstErrors != null) this.compilationResult.firstErrors.remove(problem);
286
			if (this.compilationResult.firstErrors != null) this.compilationResult.firstErrors.remove(problem);
246
			if (foundIrritants[iSuppress] == null){
287
			if (foundIrritants[iSuppress] == null){
Lines 250-255 Link Here
250
			}
291
			}
251
			continue nextProblem;
292
			continue nextProblem;
252
		}
293
		}
294
		if (isError) {
295
			remainingErrors++;
296
		}
297
	}
298
	// we need to check if we should discard unused locals warnings that were not already filtered out (336648)
299
	if (remainingErrors > 0) {
300
		for (int i = 0; i < problemCount; i++) {
301
			CategorizedProblem problem;
302
			if ((problem = problems[i]) != null && problem.getID() == IProblem.LocalVariableIsNeverUsed) {
303
				problems[i] = null;
304
				removed++;
305
			}
306
		}
253
	}
307
	}
254
	// compact remaining problems
308
	// compact remaining problems
255
	if (removed > 0) {
309
	if (removed > 0) {
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java (-4 / +1 lines)
Lines 199-208 Link Here
199
				&& ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable
199
				&& ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable
200
200
201
				if (!(local.declaration instanceof Argument)) // do not report unused catch arguments
201
				if (!(local.declaration instanceof Argument)) // do not report unused catch arguments
202
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336648
202
					problemReporter().unusedLocalVariable(local.declaration);
203
					if (!this.referenceCompilationUnit().compilationResult.hasErrors()) {
204
						problemReporter().unusedLocalVariable(local.declaration);
205
					}
206
			}
203
			}
207
204
208
			// could be optimized out, but does need to preserve unread variables ?
205
			// could be optimized out, but does need to preserve unread variables ?
(-)src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java (-1 / +37 lines)
Lines 46-52 Link Here
46
	// All specified tests which do not belong to the class are skipped...
46
	// All specified tests which do not belong to the class are skipped...
47
	static {
47
	static {
48
//		TESTS_NAMES = new String[] { "test293" };
48
//		TESTS_NAMES = new String[] { "test293" };
49
//		TESTS_NUMBERS = new int[] { 294 };
49
//		TESTS_NUMBERS = new int[] { 297 };
50
//		TESTS_RANGE = new int[] { 294, -1 };
50
//		TESTS_RANGE = new int[] { 294, -1 };
51
	}
51
	}
52
52
Lines 9789-9792 Link Here
9789
			customOptions,
9789
			customOptions,
9790
			null);
9790
			null);
9791
}
9791
}
9792
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=343621
9793
public void test297() {
9794
	Map customOptions = getCompilerOptions();
9795
	customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.ENABLED);
9796
	customOptions.put(CompilerOptions.OPTION_ReportUnhandledWarningToken, CompilerOptions.WARNING);
9797
	customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
9798
	customOptions.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING);
9799
	customOptions.put(CompilerOptions.OPTION_ReportComparingIdentical, CompilerOptions.ERROR);
9800
	customOptions.put(CompilerOptions.OPTION_ReportUncheckedTypeOperation, CompilerOptions.ERROR);
9801
	String testFiles [] = new String[] {
9802
			"A.java",
9803
			"public class A {\n" + 
9804
			"	public void one() {\n" + 
9805
			"		@SuppressWarnings(\"unused\")\n" + 
9806
			"		Object object = new Object();\n" + 
9807
			"	}\n" + 
9808
			"	public void two() {\n" + 
9809
			"		@SuppressWarnings({ \"unchecked\", \"unused\" })\n" + 
9810
			"		Object object = build();\n" + 
9811
			"	}\n" + 
9812
			"	public final Object build(Class<? super Object>... objects) {\n" + 
9813
			"		return null;\n" + 
9814
			"	}\n" + 
9815
			"	public boolean bar() {\n" +
9816
			"		int i = 0;\n" +
9817
			"		return i == i;\n" + 
9818
			"	}\n" + 
9819
			"}"
9820
	};
9821
	runNegativeTest(
9822
			testFiles,
9823
			"",
9824
			null,
9825
			true,
9826
			customOptions);
9827
}
9792
}
9828
}

Return to bug 343621