String (PsiForStatement forStatement) { PsiStatement body = forStatement.getBody(); while (body instanceof PsiBlockStatement blockStatement) { final PsiCodeBlock codeBlock = blockStatement.getCodeBlock(); final PsiStatement[] statements = codeBlock.getStatements(); if (statements.length == 2) { body = statements[1]; } else if (statements.length == 1) { body = statements[0]; } else { return null; } } if (!(body instanceof PsiExpressionStatement)) return null; final PsiExpression expression = PsiUtil.skipParenthesizedExprDown(((PsiExpressionStatement)body).getExpression()); if (!(expression instanceof PsiMethodCallExpression call)) return null; PsiExpression qualifier = ExpressionUtils.getEffectiveQualifier(call.getMethodExpression()); return qualifier != null ? qualifier.getText() : null; }