void (@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 IElementType tokenType = other.getTokenType(); final int length = other.getTextLength(); final int start = tokenType == JavaDocTokenType.DOC_COMMENT_START ? 3 : 2; final int end = tokenType == JavaTokenType.END_OF_LINE_COMMENT || length < 4 ? length : length - 2; 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 { 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)))); } }