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 / +11 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.getID() & IProblem.Syntax) != 0) {
349
		this.hasSyntaxError = true;
345
		if (newProblem.isError()) {
346
			this.hasSyntaxError = true;
347
			this.numberOfErrors++;
348
		}
349
	} else if (newProblem.isError()) {
350
		this.numberOfErrors++;
351
	}
350
}
352
}
351
353
352
/**
354
/**
(-)compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java (-3 / +34 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 218-224 Link Here
218
		CategorizedProblem problem = problems[iProblem];
218
		CategorizedProblem problem = problems[iProblem];
219
		int problemID = problem.getID();
219
		int problemID = problem.getID();
220
		int irritant = ProblemReporter.getIrritant(problemID);
220
		int irritant = ProblemReporter.getIrritant(problemID);
221
		if (problem.isError()) {
221
		boolean isError = problem.isError();
222
		if (isError) {
222
			if (irritant == 0) {
223
			if (irritant == 0) {
223
				// tolerate unused warning tokens when mandatory errors
224
				// tolerate unused warning tokens when mandatory errors
224
				hasMandatoryErrors = true;
225
				hasMandatoryErrors = true;
Lines 241-246 Link Here
241
			// discard suppressed warning
242
			// discard suppressed warning
242
			removed++;
243
			removed++;
243
			problems[iProblem] = null;
244
			problems[iProblem] = null;
245
			if (isError) {
246
				this.compilationResult.numberOfErrors--;
247
			}
244
			if (this.compilationResult.problemsMap != null) this.compilationResult.problemsMap.remove(problem);
248
			if (this.compilationResult.problemsMap != null) this.compilationResult.problemsMap.remove(problem);
245
			if (this.compilationResult.firstErrors != null) this.compilationResult.firstErrors.remove(problem);
249
			if (this.compilationResult.firstErrors != null) this.compilationResult.firstErrors.remove(problem);
246
			if (foundIrritants[iSuppress] == null){
250
			if (foundIrritants[iSuppress] == null){
Lines 340-346 Link Here
340
		}
344
		}
341
	}
345
	}
342
}
346
}
343
347
// find out if the given problem is filtered out because of SuppressWarning annotations
348
public boolean filterOutProblem(CategorizedProblem problem) {
349
	if (this.suppressWarningsCount == 0) {
350
		return false;
351
	}
352
	int problemID = problem.getID();
353
	int irritant = ProblemReporter.getIrritant(problemID);
354
	if (irritant == 0) {
355
		return false; // mandatory error
356
	}
357
	CompilerOptions options = this.scope.compilerOptions();
358
	if (!options.suppressOptionalErrors) {
359
		return false;
360
	}
361
	int start = problem.getSourceStart();
362
	int end = problem.getSourceEnd();
363
	nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) {
364
		long position = this.suppressWarningScopePositions[iSuppress];
365
		int startSuppress = (int) (position >>> 32);
366
		int endSuppress = (int) position;
367
		if (start < startSuppress) continue nextSuppress;
368
		if (end > endSuppress) continue nextSuppress;
369
		if (!this.suppressWarningIrritants[iSuppress].isSet(irritant))
370
			continue nextSuppress;
371
		return true;
372
	}
373
	return false;
374
}
344
/**
375
/**
345
 * Bytecode generation
376
 * Bytecode generation
346
 */
377
 */
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java (-13 / +38 lines)
Lines 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import org.eclipse.jdt.core.compiler.CategorizedProblem;
13
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.core.compiler.CharOperation;
14
import org.eclipse.jdt.internal.compiler.ast.*;
15
import org.eclipse.jdt.core.compiler.IProblem;
16
import org.eclipse.jdt.internal.compiler.CompilationResult;
17
import org.eclipse.jdt.internal.compiler.ast.ASTNode;
18
import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration;
19
import org.eclipse.jdt.internal.compiler.ast.Argument;
20
import org.eclipse.jdt.internal.compiler.ast.CaseStatement;
21
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
22
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
23
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
24
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
15
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
25
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
16
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
26
import org.eclipse.jdt.internal.compiler.codegen.CodeStream;
17
import org.eclipse.jdt.internal.compiler.impl.Constant;
27
import org.eclipse.jdt.internal.compiler.impl.Constant;
18
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
28
import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
29
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
19
30
20
public class BlockScope extends Scope {
31
public class BlockScope extends Scope {
21
32
Lines 154-165 Link Here
154
	varBinding.modifiers = modifiers;
165
	varBinding.modifiers = modifiers;
155
}
166
}
156
167
157
/* Compute variable positions in scopes given an initial position offset
158
 * ignoring unused local variables.
159
 *
160
 * No argument is expected here (ilocal is the first non-argument local of the outermost scope)
161
 * Arguments are managed by the MethodScope method
162
 */
163
void computeLocalVariablePositions(int ilocal, int initOffset, CodeStream codeStream) {
168
void computeLocalVariablePositions(int ilocal, int initOffset, CodeStream codeStream) {
164
	this.offset = initOffset;
169
	this.offset = initOffset;
165
	this.maxOffset = initOffset;
170
	this.maxOffset = initOffset;
Lines 195-208 Link Here
195
200
196
			// do not report fake used variable
201
			// do not report fake used variable
197
			if (local.useFlag == LocalVariableBinding.UNUSED
202
			if (local.useFlag == LocalVariableBinding.UNUSED
198
				&& (local.declaration != null) // unused (and non secret) local
203
					&& (local.declaration != null) // unused (and non secret) local
199
				&& ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable
204
					&& ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable
200
205
201
				if (!(local.declaration instanceof Argument)) // do not report unused catch arguments
206
				if (!(local.declaration instanceof Argument)) {
202
					// https://bugs.eclipse.org/bugs/show_bug.cgi?id=336648
207
					ProblemReporter problemReporter = problemReporter();
203
					if (!this.referenceCompilationUnit().compilationResult.hasErrors()) {
208
					int severity = problemReporter.computeSeverity(IProblem.LocalVariableIsNeverUsed);
204
						problemReporter().unusedLocalVariable(local.declaration);
209
					if (severity != ProblemSeverities.Ignore) {
210
						CompilationResult compilationResult = this.referenceCompilationUnit().compilationResult;
211
						boolean hasError = false;
212
						// need to check if any error is reported within the unit declaration
213
						if (compilationResult.hasErrors()) {
214
							CategorizedProblem[] problems = compilationResult.problems;
215
							loop: for (int i = 0, max = compilationResult.problemCount; i < max; i++) {
216
								CategorizedProblem problem = problems[i];
217
								if (problem.isError()) {
218
									CompilationUnitDeclaration compilationUnitDeclaration = this.compilationUnitScope().referenceContext;
219
									if (!compilationUnitDeclaration.filterOutProblem(problem)) {
220
										hasError = true;
221
									}
222
									break loop;
223
								}
224
							}
225
						}
226
						if (!hasError) {
227
							problemReporter.unusedLocalVariable(local.declaration);
228
						}
205
					}
229
					}
230
				}
206
			}
231
			}
207
232
208
			// could be optimized out, but does need to preserve unread variables ?
233
			// could be optimized out, but does need to preserve unread variables ?

Return to bug 343621