report redundant suppressions on line with suppression or on corresponding member if member annotated (IDEA-145472)

This commit is contained in:
Anna Kozlova
2015-09-24 13:09:22 +03:00
parent eb6981dfed
commit dc5e1732f7
8 changed files with 17 additions and 15 deletions
@@ -72,10 +72,9 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
PsiElement element = descriptor.getPsiElement();
try {
if (element instanceof PsiIdentifier) {
if (element != null) {
if (!FileModificationService.getInstance().prepareFileForWrite(element.getContainingFile())) return;
final PsiIdentifier identifier = (PsiIdentifier)element;
final PsiDocCommentOwner commentOwner = PsiTreeUtil.getParentOfType(identifier, PsiDocCommentOwner.class);
final PsiDocCommentOwner commentOwner = PsiTreeUtil.getParentOfType(element, PsiDocCommentOwner.class);
if (commentOwner != null) {
final PsiElement psiElement = JavaSuppressionUtil.getElementMemberSuppressedIn(commentOwner, myID);
if (psiElement instanceof PsiAnnotation) {
@@ -292,7 +292,10 @@ public class RedundantSuppressInspectionBase extends GlobalInspectionTool {
myQuickFixes.put(key, fix);
}
PsiElement identifier = null;
if (psiMember instanceof PsiMethod) {
if (!(suppressedScope instanceof PsiMember)) {
identifier = suppressedScope;
}
else if (psiMember instanceof PsiMethod) {
identifier = ((PsiMethod)psiMember).getNameIdentifier();
}
else if (psiMember instanceof PsiField) {
@@ -6,8 +6,8 @@ public class Test {
static <T> void foo(T... t){
}
void fo<caret>o() {
//noinspection unchecked
void foo() {
//noinspec<caret>tion unchecked
foo(new ArrayList<String>());
}
}
@@ -10,7 +10,7 @@ public class SampleSafeVarargs {
}
@SuppressWarnings({"unchecked"})
void foo() {
void fo<caret>o() {
asList(new ArrayList<String>());
List<Object> l ;
ArrayList strings = new ArrayList<String>();
@@ -6,8 +6,8 @@ public class Test {
static <T> void foo(T... t){
}
void f<caret>oo() {
//noinspection unchecked,blah-blah-toolid
void foo() {
//noinsp<caret>ection unchecked,blah-blah-toolid
foo(new ArrayList<String>());
}
}
@@ -11,8 +11,8 @@ public class Test {
return null;
}
void fo<caret>o() {
//noinspection unchecked
void foo() {
//noinspe<caret>ction unchecked
foo(new ArrayList<String>()).addAll(foo1(new ArrayList<String>()));
}
}
@@ -7,8 +7,8 @@ public class Test {
return null;
}
void fo<caret>o() {
//noinspection unchecked
void foo() {
//noinspe<caret>ction unchecked
List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}
@@ -3,7 +3,7 @@
<problem>
<file>X.java</file>
<line>4</line>
<line>5</line>
<problem_class>Redundant suppression</problem_class>
<description>Redundant suppression</description>
<entry_point TYPE="method" FQNAME="x.S void f()" />
@@ -28,7 +28,7 @@
<problem>
<file>X.java</file>
<line>19</line>
<line>20</line>
<problem_class>Redundant suppression</problem_class>
<description>Redundant suppression</description>
<entry_point TYPE="method" FQNAME="x.S void h()" />