Lines 15-20
Link Here
|
15 |
|
15 |
|
16 |
import org.eclipse.jdt.core.compiler.CategorizedProblem; |
16 |
import org.eclipse.jdt.core.compiler.CategorizedProblem; |
17 |
import org.eclipse.jdt.core.compiler.CharOperation; |
17 |
import org.eclipse.jdt.core.compiler.CharOperation; |
|
|
18 |
import org.eclipse.jdt.core.compiler.IProblem; |
18 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
19 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
19 |
import org.eclipse.jdt.internal.compiler.ClassFile; |
20 |
import org.eclipse.jdt.internal.compiler.ClassFile; |
20 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
21 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
Lines 207-240
Link Here
|
207 |
CategorizedProblem[] problems = this.compilationResult.problems; |
208 |
CategorizedProblem[] problems = this.compilationResult.problems; |
208 |
int problemCount = this.compilationResult.problemCount; |
209 |
int problemCount = this.compilationResult.problemCount; |
209 |
long[] foundIrritants = new long[this.suppressWarningsCount]; |
210 |
long[] foundIrritants = new long[this.suppressWarningsCount]; |
|
|
211 |
CompilerOptions options = scope.compilerOptions(); |
212 |
boolean hasErrors = false; |
210 |
nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) { |
213 |
nextProblem: for (int iProblem = 0, length = problemCount; iProblem < length; iProblem++) { |
211 |
CategorizedProblem problem = problems[iProblem]; |
214 |
CategorizedProblem problem = problems[iProblem]; |
212 |
int problemID = problem.getID(); |
215 |
int problemID = problem.getID(); |
213 |
long problemIrritant = ProblemReporter.getIrritant(problemID); |
216 |
if (problem.isError()) { |
214 |
boolean isWarning = problem.isWarning(); |
217 |
if (problemID != IProblem.UnusedWarningToken) { |
|
|
218 |
// tolerate unused warning tokens which were promoted as errors |
219 |
hasErrors = true; |
220 |
} |
221 |
continue; |
222 |
} |
215 |
int start = problem.getSourceStart(); |
223 |
int start = problem.getSourceStart(); |
216 |
int end = problem.getSourceEnd(); |
224 |
int end = problem.getSourceEnd(); |
|
|
225 |
long irritant = ProblemReporter.getIrritant(problemID); |
217 |
nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { |
226 |
nextSuppress: for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { |
218 |
long position = this.suppressWarningScopePositions[iSuppress]; |
227 |
long position = this.suppressWarningScopePositions[iSuppress]; |
219 |
int startSuppress = (int) (position >>> 32); |
228 |
int startSuppress = (int) (position >>> 32); |
220 |
int endSuppress = (int) position; |
229 |
int endSuppress = (int) position; |
221 |
if (start < startSuppress) continue nextSuppress; |
230 |
if (start < startSuppress) continue nextSuppress; |
222 |
if (end > endSuppress) continue nextSuppress; |
231 |
if (end > endSuppress) continue nextSuppress; |
223 |
if (isWarning) { |
232 |
if ((irritant & this.suppressWarningIrritants[iSuppress]) == 0) |
224 |
if ((problemIrritant & this.suppressWarningIrritants[iSuppress]) == 0) |
233 |
continue nextSuppress; |
225 |
continue nextSuppress; |
234 |
// discard suppressed warning |
226 |
// discard suppressed warning |
235 |
removed++; |
227 |
removed++; |
236 |
problems[iProblem] = null; |
228 |
problems[iProblem] = null; |
237 |
if (compilationResult.problemsMap != null) compilationResult.problemsMap.remove(problem); |
229 |
if (compilationResult.problemsMap != null) compilationResult.problemsMap.remove(problem); |
238 |
if (compilationResult.firstErrors != null) compilationResult.firstErrors.remove(problem); |
230 |
if (compilationResult.firstErrors != null) compilationResult.firstErrors.remove(problem); |
239 |
foundIrritants[iSuppress] |= irritant; |
231 |
foundIrritants[iSuppress] |= problemIrritant; |
240 |
continue nextProblem; |
232 |
continue nextProblem; |
|
|
233 |
} else { |
234 |
// any error may prevent further warnings to be emitted, hence shouldn't report unused warning tokens if in same scope |
235 |
foundIrritants[iSuppress] = this.suppressWarningIrritants[iSuppress]; // treat as used |
236 |
continue nextSuppress; |
237 |
} |
238 |
} |
241 |
} |
239 |
} |
242 |
} |
240 |
// compact remaining problems |
243 |
// compact remaining problems |
Lines 251-278
Link Here
|
251 |
} |
254 |
} |
252 |
this.compilationResult.problemCount -= removed; |
255 |
this.compilationResult.problemCount -= removed; |
253 |
} |
256 |
} |
254 |
// flag SuppressWarnings which had no effect |
257 |
// flag SuppressWarnings which had no effect (only if no (mandatory) error got detected within unit |
255 |
if (scope.compilerOptions().getSeverity(CompilerOptions.UnusedWarningToken) != ProblemSeverities.Ignore) { |
258 |
if (!hasErrors) { |
256 |
for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { |
259 |
int severity = options.getSeverity(CompilerOptions.UnusedWarningToken); |
257 |
Annotation annotation = this.suppressWarningAnnotations[iSuppress]; |
260 |
if (severity != ProblemSeverities.Ignore) { |
258 |
if (annotation == null) continue; // implicit annotation |
261 |
for (int iSuppress = 0, suppressCount = this.suppressWarningsCount; iSuppress < suppressCount; iSuppress++) { |
259 |
long irritants = this.suppressWarningIrritants[iSuppress]; |
262 |
Annotation annotation = this.suppressWarningAnnotations[iSuppress]; |
260 |
if (~irritants == 0) continue; // @SuppressWarnings("all") also suppresses unused warning token |
263 |
if (annotation == null) continue; // implicit annotation |
261 |
if (irritants != foundIrritants[iSuppress]) { // mismatch, some warning tokens were unused |
264 |
long irritants = this.suppressWarningIrritants[iSuppress]; |
262 |
MemberValuePair[] pairs = annotation.memberValuePairs(); |
265 |
if (severity == ProblemSeverities.Warning && ~irritants == 0) continue; // @SuppressWarnings("all") also suppresses unused warning token |
263 |
pairLoop: for (int iPair = 0, pairCount = pairs.length; iPair < pairCount; iPair++) { |
266 |
if (irritants != foundIrritants[iSuppress]) { // mismatch, some warning tokens were unused |
264 |
MemberValuePair pair = pairs[iPair]; |
267 |
MemberValuePair[] pairs = annotation.memberValuePairs(); |
265 |
if (CharOperation.equals(pair.name, TypeConstants.VALUE)) { |
268 |
pairLoop: for (int iPair = 0, pairCount = pairs.length; iPair < pairCount; iPair++) { |
266 |
Expression value = pair.value; |
269 |
MemberValuePair pair = pairs[iPair]; |
267 |
if (value instanceof ArrayInitializer) { |
270 |
if (CharOperation.equals(pair.name, TypeConstants.VALUE)) { |
268 |
ArrayInitializer initializer = (ArrayInitializer) value; |
271 |
Expression value = pair.value; |
269 |
Expression[] inits = initializer.expressions; |
272 |
if (value instanceof ArrayInitializer) { |
270 |
if (inits != null) { |
273 |
ArrayInitializer initializer = (ArrayInitializer) value; |
271 |
for (int iToken = 0, tokenCount = inits.length; iToken < tokenCount; iToken++) { |
274 |
Expression[] inits = initializer.expressions; |
272 |
Constant cst = inits[iToken].constant; |
275 |
if (inits != null) { |
273 |
if (cst != Constant.NotAConstant && cst.typeID() == TypeIds.T_JavaLangString) { |
276 |
for (int iToken = 0, tokenCount = inits.length; iToken < tokenCount; iToken++) { |
274 |
long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); |
277 |
Constant cst = inits[iToken].constant; |
275 |
if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { |
278 |
if (cst != Constant.NotAConstant && cst.typeID() == TypeIds.T_JavaLangString) { |
|
|
279 |
long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); |
280 |
if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { |
281 |
if (severity == ProblemSeverities.Warning) { |
282 |
int start = value.sourceStart, end = value.sourceEnd; |
283 |
nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { |
284 |
long position = this.suppressWarningScopePositions[jSuppress]; |
285 |
int startSuppress = (int) (position >>> 32); |
286 |
int endSuppress = (int) position; |
287 |
if (start < startSuppress) continue nextSuppress; |
288 |
if (end > endSuppress) continue nextSuppress; |
289 |
if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? |
290 |
} |
291 |
} |
292 |
scope.problemReporter().unusedWarningToken(inits[iToken]); |
293 |
} |
294 |
} |
295 |
} |
296 |
} |
297 |
} else { |
298 |
Constant cst = value.constant; |
299 |
if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) { |
300 |
long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); |
301 |
if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { |
302 |
if (severity == ProblemSeverities.Warning) { |
276 |
int start = value.sourceStart, end = value.sourceEnd; |
303 |
int start = value.sourceStart, end = value.sourceEnd; |
277 |
nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { |
304 |
nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { |
278 |
long position = this.suppressWarningScopePositions[jSuppress]; |
305 |
long position = this.suppressWarningScopePositions[jSuppress]; |
Lines 282-311
Link Here
|
282 |
if (end > endSuppress) continue nextSuppress; |
309 |
if (end > endSuppress) continue nextSuppress; |
283 |
if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? |
310 |
if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? |
284 |
} |
311 |
} |
285 |
scope.problemReporter().unusedWarningToken(inits[iToken]); |
|
|
286 |
} |
312 |
} |
|
|
313 |
scope.problemReporter().unusedWarningToken(value); |
287 |
} |
314 |
} |
288 |
} |
315 |
} |
289 |
} |
316 |
} |
290 |
} else { |
317 |
break pairLoop; |
291 |
Constant cst = value.constant; |
|
|
292 |
if (cst != Constant.NotAConstant && cst.typeID() == T_JavaLangString) { |
293 |
long irritant = CompilerOptions.warningTokenToIrritant(cst.stringValue()); |
294 |
if (irritant != 0 && (foundIrritants[iSuppress] & irritant) == 0) { |
295 |
int start = value.sourceStart, end = value.sourceEnd; |
296 |
nextSuppress: for (int jSuppress = iSuppress - 1; jSuppress >= 0; jSuppress--) { |
297 |
long position = this.suppressWarningScopePositions[jSuppress]; |
298 |
int startSuppress = (int) (position >>> 32); |
299 |
int endSuppress = (int) position; |
300 |
if (start < startSuppress) continue nextSuppress; |
301 |
if (end > endSuppress) continue nextSuppress; |
302 |
if (~this.suppressWarningIrritants[jSuppress] == 0) break pairLoop; // suppress all? |
303 |
} |
304 |
scope.problemReporter().unusedWarningToken(value); |
305 |
} |
306 |
} |
307 |
} |
318 |
} |
308 |
break pairLoop; |
|
|
309 |
} |
319 |
} |
310 |
} |
320 |
} |
311 |
} |
321 |
} |