From a3aacb032c7e55468e5325718aa40d5abf5c1b55 Mon Sep 17 00:00:00 2001 From: anna Date: Fri, 18 Mar 2011 12:17:31 +0100 Subject: [PATCH] redundant suppression: correct redundancy for tools with the same id --- .../RedundantSuppressInspection.java | 72 ++++++++++--------- .../redundantUncheckedVarargs/before11.java | 19 +++++ 2 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUncheckedVarargs/before11.java diff --git a/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java b/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java index d4f332d8d148..1139e1613e59 100644 --- a/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/RedundantSuppressInspection.java @@ -187,50 +187,56 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{ for (PsiElement suppressedScope : suppressedScopes.keySet()) { Collection suppressedIds = suppressedScopes.get(suppressedScope); if (!suppressedIds.contains(toolId)) continue; - boolean hasErrorInsideSuppressedScope = false; for (CommonProblemDescriptor descriptor : descriptors) { if (!(descriptor instanceof ProblemDescriptor)) continue; PsiElement element = ((ProblemDescriptor)descriptor).getPsiElement(); if (element == null) continue; PsiElement annotation = SuppressManager.getInstance().getElementToolSuppressedIn(element, toolId); if (annotation != null && PsiTreeUtil.isAncestor(suppressedScope, annotation, false) || annotation == null && !PsiTreeUtil.isAncestor(suppressedScope, element, false)) { - hasErrorInsideSuppressedScope = true; + suppressedIds.remove(toolId); break; } } - if (!hasErrorInsideSuppressedScope) { - PsiMember psiMember; - String problemLine = null; - if (suppressedScope instanceof PsiMember) { - psiMember = (PsiMember)suppressedScope; - } else { - psiMember = PsiTreeUtil.getParentOfType(suppressedScope, PsiDocCommentOwner.class); - final PsiStatement statement = PsiTreeUtil.getNextSiblingOfType(suppressedScope, PsiStatement.class); - problemLine = statement != null ? statement.getText() : null; + } + } + for (PsiElement suppressedScope : suppressedScopes.keySet()) { + Collection suppressedIds = suppressedScopes.get(suppressedScope); + for (String toolId : suppressedIds) { + PsiMember psiMember; + String problemLine = null; + if (suppressedScope instanceof PsiMember) { + psiMember = (PsiMember)suppressedScope; + } + else { + psiMember = PsiTreeUtil.getParentOfType(suppressedScope, PsiDocCommentOwner.class); + final PsiStatement statement = PsiTreeUtil.getNextSiblingOfType(suppressedScope, PsiStatement.class); + problemLine = statement != null ? statement.getText() : null; + } + if (psiMember != null && psiMember.isValid()) { + String description = InspectionsBundle.message("inspection.redundant.suppression.description"); + if (myQuickFixes == null) myQuickFixes = new BidirectionalMap(); + final String key = toolId + (problemLine != null ? ";" + problemLine : ""); + QuickFix fix = myQuickFixes.get(key); + if (fix == null) { + fix = new RemoveSuppressWarningAction(toolId, problemLine); + myQuickFixes.put(key, fix); } - if (psiMember != null && psiMember.isValid()) { - String description = InspectionsBundle.message("inspection.redundant.suppression.description"); - if (myQuickFixes == null) myQuickFixes = new BidirectionalMap(); - final String key = toolId + (problemLine != null ? ";" + problemLine : ""); - QuickFix fix = myQuickFixes.get(key); - if (fix == null) { - fix = new RemoveSuppressWarningAction(toolId, problemLine); - myQuickFixes.put(key, fix); - } - PsiElement identifier = null; - if (psiMember instanceof PsiMethod) { - identifier = ((PsiMethod)psiMember).getNameIdentifier(); - } else if (psiMember instanceof PsiField) { - identifier = ((PsiField)psiMember).getNameIdentifier(); - } else if (psiMember instanceof PsiClass) { - identifier = ((PsiClass)psiMember).getNameIdentifier(); - } - if (identifier == null) { - identifier = psiMember; - } - result.add(manager.createProblemDescriptor(identifier, description, (LocalQuickFix)fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, - false)); + PsiElement identifier = null; + if (psiMember instanceof PsiMethod) { + identifier = ((PsiMethod)psiMember).getNameIdentifier(); } + else if (psiMember instanceof PsiField) { + identifier = ((PsiField)psiMember).getNameIdentifier(); + } + else if (psiMember instanceof PsiClass) { + identifier = ((PsiClass)psiMember).getNameIdentifier(); + } + if (identifier == null) { + identifier = psiMember; + } + result.add( + manager.createProblemDescriptor(identifier, description, (LocalQuickFix)fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, + false)); } } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUncheckedVarargs/before11.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUncheckedVarargs/before11.java new file mode 100644 index 000000000000..847ae2b318fd --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/redundantUncheckedVarargs/before11.java @@ -0,0 +1,19 @@ +// "Remove 'unchecked' suppression" "false" +import java.util.*; + +public class SampleSafeVarargs { + + @SafeVarargs + static List asList(T... tt) { + System.out.println(tt); + return null; + } + + @SuppressWarnings({"unchecked"}) + void foo() { + asList(new ArrayList()); + List l ; + ArrayList strings = new ArrayList(); + l = strings; + } +}