redundant suppressions: remove suppression from local variable annotation fixed

This commit is contained in:
Anna.Kozlova
2018-09-26 17:51:41 +02:00
parent 09ee7d2e36
commit 89c0f4af1c
4 changed files with 35 additions and 4 deletions
@@ -64,7 +64,7 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
PsiElement element = descriptor.getPsiElement();
try {
if (element != null) {
final PsiJavaDocumentedElement commentOwner = PsiTreeUtil.getParentOfType(element, PsiJavaDocumentedElement.class, false);
final PsiModifierListOwner commentOwner = PsiTreeUtil.getParentOfType(element, PsiModifierListOwner.class, false);
if (commentOwner != null) {
final PsiElement psiElement = JavaSuppressionUtil.getElementMemberSuppressedIn(commentOwner, myID);
if (psiElement instanceof PsiAnnotation) {
@@ -90,8 +90,11 @@ public class JavaSuppressionUtil {
JavaSuppressionUtil::getInspectionIdSuppressedInAnnotationAttribute);
}
public static PsiElement getElementMemberSuppressedIn(@NotNull PsiJavaDocumentedElement owner, @NotNull String inspectionToolID) {
PsiElement element = getDocCommentToolSuppressedIn(owner, inspectionToolID);
public static <T extends PsiElement> PsiElement getElementMemberSuppressedIn(@NotNull T owner, @NotNull String inspectionToolID) {
PsiElement element = null;
if (owner instanceof PsiJavaDocumentedElement) {
element = getDocCommentToolSuppressedIn((PsiJavaDocumentedElement)owner, inspectionToolID);
}
if (element != null) return element;
if (owner instanceof PsiModifierListOwner) {
element = getAnnotationMemberSuppressedIn((PsiModifierListOwner)owner, inspectionToolID);
@@ -192,7 +195,7 @@ public class JavaSuppressionUtil {
return null;
}
static PsiElement getElementToolSuppressedIn(@NotNull final PsiElement place, @NotNull final String toolId) {
public static PsiElement getElementToolSuppressedIn(@NotNull final PsiElement place, @NotNull final String toolId) {
if (place instanceof PsiFile) return null;
return ReadAction.compute(() -> {
final PsiElement statement = SuppressionUtil.getStatementToolSuppressedIn(place, toolId, PsiStatement.class);
@@ -0,0 +1,14 @@
// "Remove 'unchecked' suppression" "true"
import java.util.*;
public class Test {
@SafeVarargs
static <T> List<T> foo(T... t){
return null;
}
void foo() {
List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}
@@ -0,0 +1,14 @@
// "Remove 'unchecked' suppression" "true"
import java.util.*;
public class Test {
@SafeVarargs
static <T> List<T> foo(T... t){
return null;
}
void foo() {
@SuppressWarnings("unche<caret>cked") List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}