PsiReferenceExpression (PsiElement position) { PsiElement each = position; while (each != null && !(each instanceof PsiFile)) { if (each instanceof PsiExpressionList || each instanceof PsiPrefixExpression || each instanceof PsiPolyadicExpression) { return null; } if (each instanceof PsiAssignmentExpression assignment) { final PsiExpression left = assignment.getLExpression(); if (left instanceof PsiReferenceExpression referenceExpression) { final PsiElement qualifier = referenceExpression.getQualifier(); if (qualifier == null || qualifier instanceof PsiThisExpression thisExpression && thisExpression.getQualifier() == null) { return referenceExpression; } } return null; } each = each.getContext(); } return null; }