@Override
  public void visitComment(@NotNull PsiComment comment) {
    PsiComment other = null;

    final PsiElement element = myMatchingVisitor.getElement();
    if (!(element instanceof PsiComment)) {
      if (element instanceof PsiMember && PsiTreeUtil.skipWhitespacesAndCommentsForward(comment) instanceof PsiDeclarationStatement) {
        other = ObjectUtils.tryCast(element.getFirstChild(), PsiComment.class);
      }
    }
    else {
      other = (PsiComment)element;
    }

    if (!myMatchingVisitor.setResult(other != null)) {
      return;
    }

    final MatchingHandler handler = comment.getUserData(CompiledPattern.HANDLER_KEY);
    if (handler instanceof SubstitutionHandler substitutionHandler) {
      final RegExpPredicate predicate = substitutionHandler.findPredicate(RegExpPredicate.class);
      if (predicate != null) {
        predicate.setNodeTextGenerator(e -> JavaMatchUtil.getCommentText((PsiComment)e).trim());
        myMatchingVisitor.setResult(substitutionHandler.handle(other, myMatchingVisitor.getMatchContext()));
      }
      else {
        final String text = other.getText();
        final int length = text.length();
        final IElementType tokenType = other.getTokenType();
        int start = tokenType == JavaDocTokenType.DOC_COMMENT_START ? 3 : 2;
        while (start < length && text.charAt(start) == ' ') start++;
        int end = tokenType == JavaTokenType.END_OF_LINE_COMMENT || length < 4 ? length : length - 2;
        while (end > 0 && text.charAt(end - 1) == ' ') end--;
        myMatchingVisitor.setResult(substitutionHandler.handle(other, start, end, myMatchingVisitor.getMatchContext()));
      }
    }
    else if (handler instanceof LiteralWithSubstitutionHandler) {
      if (comment instanceof PsiDocComment) {
        myMatchingVisitor.setResult(handler.match(comment, other, myMatchingVisitor.getMatchContext()));
      } else {
        final LiteralWithSubstitutionHandler lwsHandler = (LiteralWithSubstitutionHandler) handler;
        int offset = other.getTokenType() == JavaDocTokenType.DOC_COMMENT_START ? 3 : 2;
        String commentText = other.getText();
        while (commentText.length() > offset && commentText.charAt(offset) <= ' ') {
          offset++;
        }
        myMatchingVisitor.setResult(lwsHandler.match(other, JavaMatchUtil.getCommentText(other).trim(), offset, myMatchingVisitor.getMatchContext()));
      }
    }
    else if (handler != null) {
      myMatchingVisitor.setResult(handler.match(comment, other, myMatchingVisitor.getMatchContext()));
    }
    else {
      myMatchingVisitor.setResult(myMatchingVisitor.matchText(MatchUtil.normalize(JavaMatchUtil.getCommentText(comment)),
                                                              MatchUtil.normalize(JavaMatchUtil.getCommentText(other))));
    }
  }
@Override
  public void visitComment(@NotNull PsiComment comment)