PsiVariable (@NotNull PsiStatement statement) { PsiExpressionStatement expressionStatement = tryCast(statement, PsiExpressionStatement.class); if (expressionStatement == null) return null; PsiMethodCallExpression methodCallExpression = tryCast(expressionStatement.getExpression(), PsiMethodCallExpression.class); if (methodCallExpression == null) return null; PsiMethodCallExpression currentExpression = methodCallExpression; while (APPEND.test(methodCallExpression)) { PsiExpression qualifierExpression = currentExpression.getMethodExpression().getQualifierExpression(); PsiMethodCallExpression callerExpression = MethodCallUtils.getQualifierMethodCall(currentExpression); if (callerExpression == null) { PsiReferenceExpression refExpression = tryCast(qualifierExpression, PsiReferenceExpression.class); if(refExpression == null) return null; return tryCast(refExpression.resolve(), PsiVariable.class); } currentExpression = callerExpression; } return null; }