### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.65 diff -u -r1.65 CompilationResult.java --- compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java 11 May 2010 18:47:09 -0000 1.65 +++ compiler/org/eclipse/jdt/internal/compiler/CompilationResult.java 28 Apr 2011 16:18:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -72,6 +72,7 @@ public boolean hasSyntaxError = false; public char[][] packageName; public boolean checkSecondaryTypes = false; // check for secondary types which were created after the initial buildTypeBindings call + public int numberOfErrors; private static final int[] EMPTY_LINE_ENDS = Util.EMPTY_INT_ARRAY; private static final Comparator PROBLEM_COMPARATOR = new Comparator() { @@ -270,12 +271,7 @@ } public boolean hasErrors() { - if (this.problems != null) - for (int i = 0; i < this.problemCount; i++) { - if (this.problems[i].isError()) - return true; - } - return false; + return this.numberOfErrors != 0; } public boolean hasProblems() { @@ -345,8 +341,14 @@ if (newProblem.isError() && !referenceContext.hasErrors()) this.firstErrors.add(newProblem); this.problemsMap.put(newProblem, referenceContext); } - if ((newProblem.getID() & IProblem.Syntax) != 0 && newProblem.isError()) - this.hasSyntaxError = true; + if ((newProblem.getID() & IProblem.Syntax) != 0) { + if (newProblem.isError()) { + this.hasSyntaxError = true; + this.numberOfErrors++; + } + } else if (newProblem.isError()) { + this.numberOfErrors++; + } } /** 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.91 diff -u -r1.91 CompilationUnitDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 25 Jun 2010 14:58:36 -0000 1.91 +++ compiler/org/eclipse/jdt/internal/compiler/ast/CompilationUnitDeclaration.java 28 Apr 2011 16:18:46 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -218,7 +218,8 @@ CategorizedProblem problem = problems[iProblem]; int problemID = problem.getID(); int irritant = ProblemReporter.getIrritant(problemID); - if (problem.isError()) { + boolean isError = problem.isError(); + if (isError) { if (irritant == 0) { // tolerate unused warning tokens when mandatory errors hasMandatoryErrors = true; @@ -241,6 +242,9 @@ // discard suppressed warning removed++; problems[iProblem] = null; + if (isError) { + this.compilationResult.numberOfErrors--; + } if (this.compilationResult.problemsMap != null) this.compilationResult.problemsMap.remove(problem); if (this.compilationResult.firstErrors != null) this.compilationResult.firstErrors.remove(problem); if (foundIrritants[iSuppress] == null){ @@ -340,7 +344,34 @@ } } } - +// find out if the given problem is filtered out because of SuppressWarning annotations +public boolean filterOutProblem(CategorizedProblem problem) { + if (this.suppressWarningsCount == 0) { + return false; + } + int problemID = problem.getID(); + int irritant = ProblemReporter.getIrritant(problemID); + if (irritant == 0) { + return false; // mandatory error + } + CompilerOptions options = this.scope.compilerOptions(); + if (!options.suppressOptionalErrors) { + 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)) + continue nextSuppress; + return true; + } + return false; +} /** * Bytecode generation */ Index: compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java,v retrieving revision 1.124 diff -u -r1.124 BlockScope.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java 16 Feb 2011 08:09:18 -0000 1.124 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/BlockScope.java 28 Apr 2011 16:18:46 -0000 @@ -10,12 +10,23 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.compiler.ast.*; +import org.eclipse.jdt.core.compiler.IProblem; +import org.eclipse.jdt.internal.compiler.CompilationResult; +import org.eclipse.jdt.internal.compiler.ast.ASTNode; +import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.Argument; +import org.eclipse.jdt.internal.compiler.ast.CaseStatement; +import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; +import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration; +import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; +import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; +import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; public class BlockScope extends Scope { @@ -154,12 +165,6 @@ varBinding.modifiers = modifiers; } -/* Compute variable positions in scopes given an initial position offset - * ignoring unused local variables. - * - * No argument is expected here (ilocal is the first non-argument local of the outermost scope) - * Arguments are managed by the MethodScope method - */ void computeLocalVariablePositions(int ilocal, int initOffset, CodeStream codeStream) { this.offset = initOffset; this.maxOffset = initOffset; @@ -195,14 +200,34 @@ // do not report fake used variable if (local.useFlag == LocalVariableBinding.UNUSED - && (local.declaration != null) // unused (and non secret) local - && ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable + && (local.declaration != null) // unused (and non secret) local + && ((local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0)) { // declaration is reachable - if (!(local.declaration instanceof Argument)) // do not report unused catch arguments - // https://bugs.eclipse.org/bugs/show_bug.cgi?id=336648 - if (!this.referenceCompilationUnit().compilationResult.hasErrors()) { - problemReporter().unusedLocalVariable(local.declaration); + if (!(local.declaration instanceof Argument)) { + ProblemReporter problemReporter = problemReporter(); + int severity = problemReporter.computeSeverity(IProblem.LocalVariableIsNeverUsed); + if (severity != ProblemSeverities.Ignore) { + CompilationResult compilationResult = this.referenceCompilationUnit().compilationResult; + boolean hasError = false; + // need to check if any error is reported within the unit declaration + if (compilationResult.hasErrors()) { + CategorizedProblem[] problems = compilationResult.problems; + loop: for (int i = 0, max = compilationResult.problemCount; i < max; i++) { + CategorizedProblem problem = problems[i]; + if (problem.isError()) { + CompilationUnitDeclaration compilationUnitDeclaration = this.compilationUnitScope().referenceContext; + if (!compilationUnitDeclaration.filterOutProblem(problem)) { + hasError = true; + } + break loop; + } + } + } + if (!hasError) { + problemReporter.unusedLocalVariable(local.declaration); + } } + } } // could be optimized out, but does need to preserve unread variables ?