mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
java redundant cast: parenthesis (IDEA-218757)
GitOrigin-RevId: e1854c1cca7d9fef6aabf3a25ee2fe8597a2dbec
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2832d5f81c
commit
b4993721fb
@@ -536,10 +536,9 @@ public class RedundantCastUtil {
|
||||
}
|
||||
|
||||
private static boolean checkResolveAfterRemoveCast(PsiElement parent) {
|
||||
PsiElement grandPa = parent.getParent();
|
||||
PsiElement grandPa = PsiUtil.skipParenthesizedExprUp(parent.getParent());
|
||||
if (grandPa instanceof PsiExpressionList) {
|
||||
PsiExpression[] expressions = ((PsiExpressionList)grandPa).getExpressions();
|
||||
int idx = ArrayUtil.find(expressions, parent);
|
||||
int idx = LambdaUtil.getLambdaIdx((PsiExpressionList)grandPa, parent);
|
||||
PsiElement grandGrandPa = grandPa.getParent();
|
||||
if (grandGrandPa instanceof PsiCall) {
|
||||
PsiMethod resolve = ((PsiCall)grandGrandPa).resolveMethod();
|
||||
@@ -548,7 +547,7 @@ public class RedundantCastUtil {
|
||||
if (expression == null) return false;
|
||||
PsiExpressionList argumentList = expression.getArgumentList();
|
||||
LOG.assertTrue(argumentList != null);
|
||||
PsiExpression toReplace = argumentList.getExpressions()[idx];
|
||||
PsiExpression toReplace = PsiUtil.skipParenthesizedExprDown(argumentList.getExpressions()[idx]);
|
||||
if (toReplace instanceof PsiConditionalExpression) {
|
||||
PsiExpression thenExpression = ((PsiConditionalExpression)toReplace).getThenExpression();
|
||||
PsiExpression elseExpression = ((PsiConditionalExpression)toReplace).getElseExpression();
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
import java.util.List;
|
||||
|
||||
class MyTest {
|
||||
|
||||
public void testLong(List<Long> list, int i) {
|
||||
assertEquals(1L, (i >= 0 ? (long) getLong(list, i) : 2L));
|
||||
assertEquals(1L, i >= 0 ? (long) getLong(list, i) : 2L);
|
||||
}
|
||||
|
||||
private <T> T getLong(List<T> list, int i) {
|
||||
return list.get(i);
|
||||
}
|
||||
|
||||
private static void assertEquals(long l, long l1) { }
|
||||
private static void assertEquals(Object l, Object l1) { }
|
||||
|
||||
}
|
||||
@@ -49,4 +49,5 @@ public class RedundantCast18Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testBinaryConversions() { doTest();}
|
||||
public void testInferenceIncompatibilityWithoutCast() { doTest();}
|
||||
public void testCastToPrimitive() { doTest();}
|
||||
public void testParenthesisAroundConditional() { doTest();}
|
||||
}
|
||||
Reference in New Issue
Block a user