boolean (@NotNull PsiThisExpression pattern, @NotNull PsiElement candidate, @NotNull Match match) { final PsiJavaCodeReferenceElement qualifier = pattern.getQualifier(); final PsiElement contextClass = qualifier == null ? RefactoringChangeUtil.getThisClass(pattern) : qualifier.resolve(); if (candidate instanceof PsiReferenceExpression) { final PsiElement parent = candidate.getParent(); return parent instanceof PsiReferenceExpression && contextClass instanceof PsiClass && match.registerInstanceExpression(((PsiReferenceExpression)parent).getQualifierExpression(), (PsiClass)contextClass); } if (candidate instanceof PsiThisExpression) { final PsiJavaCodeReferenceElement candidateQualifier = ((PsiThisExpression)candidate).getQualifier(); final PsiElement candidateContextClass = candidateQualifier == null ? RefactoringChangeUtil.getThisClass(candidate) : candidateQualifier.resolve(); return contextClass == candidateContextClass; } return false; }