PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitDocComment(@NotNull PsiDocComment comment) { if (comment.getOwner() == null) return; for (PsiReference reference : ReferenceProvidersRegistry.getReferencesFromProviders(comment)) { if (!(reference instanceof WebReference)) continue; String url = ((WebReference)reference).getValue(); if (!url.startsWith(URLUtil.HTTP_PROTOCOL) && !url.startsWith(URLUtil.HTTPS_PROTOCOL)) return; String commentText = comment.getText(); Matcher matcher = WHITESPACE_STAR.matcher(commentText); commentText = matcher.replaceAll(result -> " ".repeat(result.group().length())); TextRange range = reference.getRangeInElement(); int start = range.getStartOffset(); int end = range.getEndOffset(); PsiElement element = comment.findElementAt(start); if (element == null) return; PsiDocTag tag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class, true, PsiDocComment.class); if (tag != null) { String tagName = tag.getName(); if (tagName.equals("see")) continue; // handled by JavaDocReferenceInspection if (tagName.equals("code")) continue; } String prefix = commentText.substring(0, start); String suffix = commentText.substring(end); if (isContentOfATag(prefix, suffix) || isHtmlTagAttribute(prefix, suffix)) continue; holder.problem(comment, JavaBundle.message("inspection.javadoc.link.as.plain.text.message")) .range(range).fix(new UrlToHtmlFix(comment, start, end)).register(); } } private static boolean isContentOfATag(String prefix, String suffix) { return START_TAG.matcher(prefix).find() && END_TAG.matcher(suffix).find(); } private static boolean isHtmlTagAttribute(String prefix, String suffix) { return TAG_BEFORE_ATTRIBUTE.matcher(prefix).find() && TAG_AFTER_ATTRIBUTE.matcher(suffix).find(); } }; }