@Override
  public void visitClass(@NotNull PsiClass clazz) {
    final PsiClass other = myMatchingVisitor.getElement(PsiClass.class);
    if (other == null) return;
    if (clazz.hasTypeParameters()) {
      if (!myMatchingVisitor.setResult(myMatchingVisitor.match(clazz.getTypeParameterList(), other.getTypeParameterList()))) return;
    }

    final PsiDocComment comment = clazz.getDocComment();
    if (comment != null) {
      if (!myMatchingVisitor.setResult(myMatchingVisitor.match(comment, other.getDocComment()))) return;
    }

    final PsiIdentifier identifier1 = clazz.getNameIdentifier();
    final MatchContext context = myMatchingVisitor.getMatchContext();
    final CompiledPattern pattern = context.getPattern();
    final boolean isTypedVar = pattern.isTypedVar(identifier1);

    final PsiModifierList modifierList = clazz.getModifierList();
    if (modifierList != null && modifierList.getTextLength() > 0) {
      if (!myMatchingVisitor.setResult(myMatchingVisitor.match(modifierList, other.getModifierList()))) {
        return;
      }
    }

    final PsiIdentifier identifier2 = other.getNameIdentifier();
    if (myMatchingVisitor.setResult((isTypedVar || myMatchingVisitor.matchText(identifier1, identifier2)) &&
                                    matchClasses(clazz, other)) && isTypedVar) {
      final PsiElement matchElement = identifier2 == null ? other : identifier2;
      final SubstitutionHandler handler = (SubstitutionHandler)pattern.getHandler(identifier1);
      final PsiElement result = other instanceof PsiAnonymousClass
                                ? ((PsiAnonymousClass)other).getBaseClassReference().getReferenceNameElement()
                                : identifier2;
      if (handler.isSubtype() || handler.isStrictSubtype()) {
        if (myMatchingVisitor.setResult(matchWithinHierarchy(identifier1, other, handler))) {
          handler.addResult(result == null ? other : result, context);
        }
      }
      else if (myMatchingVisitor.setResult(handler.validate(matchElement, context))) {
        handler.addResult(result == null ? other : result, context);
      }
    }
  }
@Override
  public void visitClass(@NotNull PsiClass clazz)