IDEA-205482 "Use removal by object" fix may change semantics for List<Integer>

This commit is contained in:
Tagir Valeev
2019-01-16 16:04:35 +07:00
parent 32e8190948
commit c51dbd9bc6
3 changed files with 20 additions and 0 deletions
@@ -0,0 +1,8 @@
// "Use removal by object" "true"
import java.util.List;
class Test {
void test(List<Integer> list, int key) {
list.remove((Integer) key);
}
}
@@ -0,0 +1,9 @@
// "Use removal by object" "true"
import java.util.List;
class Test {
void test(List<Integer> list, int key) {
int idx = list.indexOf(key);
list.r<caret>emove(idx);
}
}
@@ -131,6 +131,9 @@ public class RedundantCollectionOperationInspection extends AbstractBaseJavaLoca
if (indexOfArg == null) return;
CommentTracker ct = new CommentTracker();
String text = ct.text(indexOfArg);
if (PsiType.INT.equals(indexOfArg.getType())) {
text = "(" + CommonClassNames.JAVA_LANG_INTEGER + ")" + text;
}
if (!PsiTreeUtil.isAncestor(call, removeArg, false)) {
PsiDeclarationStatement declaration = PsiTreeUtil.getParentOfType(removeArg, PsiDeclarationStatement.class);
if (declaration == null) return;