PsiVariable (PsiMethodCallExpression methodCallExpression) { final PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(methodCallExpression.getType()); if (aClass == null) { return null; } final PsiMethod method = methodCallExpression.resolveMethod(); if (method == null) { return null; } final PsiClass containingClass = method.getContainingClass(); if (!aClass.equals(containingClass)) { return null; } final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final PsiExpression qualifierExpression = PsiUtil.skipParenthesizedExprDown(methodExpression.getQualifierExpression()); if (qualifierExpression instanceof PsiMethodCallExpression expression) { return getVariable(expression); } else if (!(qualifierExpression instanceof PsiReferenceExpression)) { return null; } final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifierExpression; final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiVariable)) { return null; } return (PsiVariable)target; }