PsiArrayAccessExpression (PsiForStatement forStatement) { final PsiStatement body = getBody(forStatement); if (body == null) { return null; } final PsiExpression arrayAccessExpression; if (body instanceof PsiExpressionStatement expressionStatement) { final PsiExpression expression = expressionStatement.getExpression(); if (!(expression instanceof PsiMethodCallExpression methodCallExpression)) { return null; } final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); PsiExpression[] expressions = argumentList.getExpressions(); arrayAccessExpression = expressions.length == 0 ? null : expressions[0]; } else 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 { return null; } final PsiExpression deparenthesizedArgument = PsiUtil.skipParenthesizedExprDown(arrayAccessExpression); if (!(deparenthesizedArgument instanceof PsiArrayAccessExpression)) { return null; } return (PsiArrayAccessExpression)deparenthesizedArgument; }