mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant cast: process multidimensional arrays (IDEA-171047)
This commit is contained in:
@@ -738,7 +738,18 @@ public class RedundantCastUtil {
|
||||
PsiExpression lExpression = assignment.getLExpression();
|
||||
return lExpression instanceof PsiArrayAccessExpression &&
|
||||
PsiTreeUtil.isAncestor(lExpression, parent, false) &&
|
||||
!PsiTreeUtil.isAncestor(((PsiArrayAccessExpression)lExpression).getIndexExpression(), element, false);
|
||||
!isIndexExpression(element, (PsiArrayAccessExpression)lExpression);
|
||||
}
|
||||
|
||||
private static boolean isIndexExpression(PsiElement element, PsiArrayAccessExpression arrayAccessExpression) {
|
||||
if (PsiTreeUtil.isAncestor(arrayAccessExpression.getIndexExpression(), element, false)) {
|
||||
return true;
|
||||
}
|
||||
PsiExpression arrayExpression = arrayAccessExpression.getArrayExpression();
|
||||
if (arrayExpression instanceof PsiArrayAccessExpression) {
|
||||
return isIndexExpression(element, (PsiArrayAccessExpression)arrayExpression);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
class MyTest {
|
||||
void bar(Object[] update, Object[][] grid){
|
||||
grid[(int)update[0]][1] = null;
|
||||
}
|
||||
}
|
||||
@@ -41,4 +41,5 @@ public class RedundantCast18Test extends LightDaemonAnalyzerTestCase {
|
||||
public void testConditional() { doTest(); }
|
||||
public void testInferApplicabilityError() { doTest(); }
|
||||
public void testCastToRawType() { doTest(); }
|
||||
public void testCastInMultidimensionalArrayIndex() { doTest(); }
|
||||
}
|
||||
Reference in New Issue
Block a user