mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RedundantCastUtil#isCastRedundant: skip further checks if cast operand type equals to cast type
Fixes IDEA-194278 "Too weak variable type leads to unnecessary cast" does not detect some cases
This commit is contained in:
@@ -46,6 +46,8 @@ public class RedundantCastUtil {
|
||||
|
||||
public static boolean isCastRedundant (PsiTypeCastExpression typeCast) {
|
||||
PsiElement parent = typeCast.getParent();
|
||||
PsiExpression operand = typeCast.getOperand();
|
||||
if (operand != null && operand.getType() != null && operand.getType().equals(typeCast.getType())) return true;
|
||||
while(parent instanceof PsiParenthesizedExpression) parent = parent.getParent();
|
||||
if (parent instanceof PsiExpressionList) parent = parent.getParent();
|
||||
if (parent instanceof PsiReferenceExpression) parent = parent.getParent();
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Change type of 'list' to 'ArrayList<String>' and remove cast" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.ensureCapacity();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Change type of 'list' to 'ArrayList<String>' and remove cast" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test() {
|
||||
List<String> list = new ArrayList<>();
|
||||
((ArrayList<caret><String>) list).ensureCapacity();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user