fix remove redundant suppress from javadoc tag (IDEA-205073)

This commit is contained in:
Anna.Kozlova
2019-01-08 14:41:43 +01:00
parent 753878ddc1
commit e0e26f5b95
5 changed files with 97 additions and 7 deletions

View File

@@ -140,14 +140,33 @@ public class RemoveSuppressWarningAction implements LocalQuickFix {
private void removeFromJavaDoc(PsiDocComment docComment) throws IncorrectOperationException {
PsiDocTag tag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
if (tag == null) return;
String newText = removeFromElementText(tag.getDataElements());
if (newText != null && newText.isEmpty()) {
tag.delete();
String text = tag.getText();
int i = text.indexOf(myID);
if (i < 0) return;
String noInspectionText = StringUtil.trimEnd(text.substring(0, i), " ");
String nextText = StringUtil.trimStart(text.substring(i + myID.length()), " ");
String nextTagText;
if (noInspectionText.endsWith(",")) {
nextTagText = noInspectionText.substring(0, noInspectionText.length() - 1) + nextText;
}
else if (newText != null) {
newText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + newText;
PsiDocTag newTag = JavaPsiFacade.getElementFactory(tag.getProject()).createDocTagFromText(newText);
tag.replace(newTag);
else if (nextText.startsWith(",")) {
nextTagText = noInspectionText + nextText.substring(1);
}
else {
nextTagText = null;
}
if (nextTagText != null) {
tag.replace(JavaPsiFacade.getElementFactory(tag.getProject()).createDocTagFromText(nextTagText));
}
else {
PsiElement[] descriptionElements =
JavaPsiFacade.getElementFactory(tag.getProject()).createDocCommentFromText("/**" + nextText + "*/", tag).getDescriptionElements();
if (descriptionElements.length > 0) {
docComment.addRangeAfter(descriptionElements[0], descriptionElements[descriptionElements.length - 1], tag);
}
tag.delete();
}
}

View File

@@ -0,0 +1,18 @@
// "Remove 'unchecked' suppression" "true"
import java.util.*;
/**
*
* unrelated text
*/
public class Test {
@SafeVarargs
static <T> List<T> foo(T... t){
return null;
}
void foo() {
List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}

View File

@@ -0,0 +1,17 @@
// "Remove 'unchecked' suppression" "true"
import java.util.*;
/**
* @noinspection a1, b2
*/
public class Test {
@SafeVarargs
static <T> List<T> foo(T... t){
return null;
}
void foo() {
List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}

View File

@@ -0,0 +1,19 @@
// "Remove 'unchecked' suppression" "true"
import java.util.*;
/**
* @noinspection unch<caret>ecked
*
* unrelated text
*/
public class Test {
@SafeVarargs
static <T> List<T> foo(T... t){
return null;
}
void foo() {
List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}

View File

@@ -0,0 +1,17 @@
// "Remove 'unchecked' suppression" "true"
import java.util.*;
/**
* @noinspection a1,unch<caret>ecked, b2
*/
public class Test {
@SafeVarargs
static <T> List<T> foo(T... t){
return null;
}
void foo() {
List<ArrayList<String>> list = foo(new ArrayList<String>());
}
}