PsiArrayAccessExpression (PsiForStatement forStatement) { PsiStatement body = forStatement.getBody(); while (body instanceof PsiBlockStatement blockStatement) { final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); final PsiStatement[] statements = codeBlock.getStatements(); if (statements.length == 1 || statements.length == 2) { body = statements[0]; } else { return null; } } final PsiExpression arrayAccessExpression; if (body instanceof PsiDeclarationStatement declarationStatement) { final PsiElement[] declaredElements = declarationStatement.getDeclaredElements(); if (declaredElements.length != 1) { return null; } final PsiElement declaredElement = declaredElements[0]; if (!(declaredElement instanceof PsiVariable variable)) { return null; } arrayAccessExpression = variable.getInitializer(); } else if (body instanceof PsiExpressionStatement expressionStatement) { final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof PsiAssignmentExpression assignmentExpression)) { return null; } arrayAccessExpression = assignmentExpression.getRExpression(); } else { return null; } final PsiExpression unparenthesizedExpression = PsiUtil.skipParenthesizedExprDown(arrayAccessExpression); if (!(unparenthesizedExpression instanceof PsiArrayAccessExpression)) { return null; } return (PsiArrayAccessExpression)unparenthesizedExpression; }