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 ? |