private static boolean matchUnqualifiedCandidateReference(@NotNull PsiExpression patternQualifier,
                                                            @NotNull PsiReferenceExpression candidate,
                                                            @NotNull Match match) {
    if (patternQualifier instanceof PsiThisExpression) {
      final PsiJavaCodeReferenceElement qualifier = ((PsiThisExpression)patternQualifier).getQualifier();
      PsiElement contextClass = qualifier == null ? RefactoringChangeUtil.getThisClass(patternQualifier) : qualifier.resolve();
      return contextClass instanceof PsiClass && match.registerInstanceExpression(null, (PsiClass)contextClass);
    }
    final PsiType type = patternQualifier.getType();
    PsiClass contextClass = type instanceof PsiClassType ? ((PsiClassType)type).resolve() : null;
    try {
      final Parameter parameter = patternQualifier.getUserData(PARAMETER);

      if (parameter != null) {
        final PsiClass thisClass = RefactoringChangeUtil.getThisClass(parameter.getVariable());

        if (contextClass != null && InheritanceUtil.isInheritorOrSelf(thisClass, contextClass, true)) {
          contextClass = thisClass;
        }
        final PsiClass thisCandidate = RefactoringChangeUtil.getThisClass(candidate);
        if (thisCandidate != null && InheritanceUtil.isInheritorOrSelf(thisCandidate, contextClass, true)) {
          contextClass = thisCandidate;
        }
        return contextClass != null &&
               !(contextClass instanceof PsiAnonymousClass) &&
               match.putParameter(parameter, RefactoringChangeUtil.createThisExpression(patternQualifier.getManager(), contextClass));
      }

      if (patternQualifier instanceof PsiReferenceExpression) {
        final PsiElement resolved = ((PsiReferenceExpression)patternQualifier).resolve();
        if (resolved instanceof PsiClass) {
          final PsiClass classContext = RefactoringChangeUtil.getThisClass(candidate);
          if (classContext != null && InheritanceUtil.isInheritorOrSelf(classContext, (PsiClass)resolved, true)) {
            return true;
          }
        }
      }

      return false;
    }
    catch (IncorrectOperationException e) {
      LOG.error(e);
    }
    return false;
  }
private static boolean matchUnqualifiedCandidateReference(@NotNull PsiExpression patternQualifier,
                                                            @NotNull PsiReferenceExpression candidate,
                                                            @NotNull Match match)