From 387eeab0506aeea1605cc06ea85f2c893ea3abbc Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Wed, 11 Dec 2024 15:59:42 -0500 Subject: [PATCH] Group Javadoc tags together. Signed-off-by: Roland Grunberg --- .../javadoc/JavadocContentAccess2.java | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/javadoc/JavadocContentAccess2.java b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/javadoc/JavadocContentAccess2.java index 3e189ee0a5..f83be625d4 100644 --- a/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/javadoc/JavadocContentAccess2.java +++ b/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/javadoc/JavadocContentAccess2.java @@ -21,8 +21,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Deque; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import org.eclipse.core.runtime.CoreException; import org.eclipse.jdt.core.IBuffer; @@ -90,11 +92,47 @@ public static Reader getMarkdownContentReader(IJavaElement element) { String content = getJavaDocNode(element); if (content != null && content.startsWith("///")) { Javadoc node = CoreJavadocContentAccessUtility.getJavadocNode(element, content); + Map> javadocTags = new HashMap<>(); StringBuilder buf = new StringBuilder(); - for (Object tag : node.tags()) { + for (Object obj : node.tags()) { + TagElement tag = (TagElement) obj; + if (tag.getTagName() != null) { + javadocTags.computeIfAbsent(tag.getTagName(), k -> new ArrayList<>()).add((tag)); + } else { + buf.append("\n"); + collectTagElements(content, element, tag, buf); + } + } + + for (Map.Entry> entry : javadocTags.entrySet()) { + String tagName = entry.getKey(); + + String heading = switch (tagName) { + case TagElement.TAG_API_NOTE -> "API Note:"; + case TagElement.TAG_AUTHOR -> "Author:"; + case TagElement.TAG_IMPL_SPEC -> "Impl Spec:"; + case TagElement.TAG_IMPL_NOTE -> "Impl Note:"; + case TagElement.TAG_PARAM -> "Parameters:"; + case TagElement.TAG_PROVIDES -> "Provides:"; + case TagElement.TAG_RETURN -> "Returns:"; + case TagElement.TAG_THROWS -> "Throws:"; + case TagElement.TAG_EXCEPTION -> "Throws:"; + case TagElement.TAG_SINCE -> "Since:"; + case TagElement.TAG_SEE -> "See:"; + case TagElement.TAG_VERSION -> "See:"; + case TagElement.TAG_USES -> "Uses:"; + default -> ""; + }; buf.append("\n"); - collectTagElements(content, element, (TagElement) tag, buf); + buf.append("* **" + heading + "**"); + + for (TagElement tag : entry.getValue()) { + buf.append("\n"); + buf.append(" * "); + collectTagElements(content, element, tag, buf); + } } + return buf.length() > 0 ? new StringReader(buf.substring(1)) : new StringReader(content); } else { String rawHtml = access.getHTMLContent(element, true); @@ -109,27 +147,6 @@ public static Reader getMarkdownContentReader(IJavaElement element) { } private static void collectTagElements(String content, IJavaElement element, TagElement tag, StringBuilder buf) { - if (tag.getTagName() != null) { - String heading = switch (tag.getTagName()) { - case TagElement.TAG_API_NOTE -> "API Note:"; - case TagElement.TAG_AUTHOR -> "Author:"; - case TagElement.TAG_IMPL_SPEC -> "Impl Spec:"; - case TagElement.TAG_IMPL_NOTE -> "Impl Note:"; - case TagElement.TAG_PARAM -> "Parameters:"; - case TagElement.TAG_PROVIDES -> "Provides:"; - case TagElement.TAG_RETURN -> "Returns:"; - case TagElement.TAG_THROWS -> "Throws:"; - case TagElement.TAG_EXCEPTION -> "Throws:"; - case TagElement.TAG_SINCE -> "Since:"; - case TagElement.TAG_SEE -> "See:"; - case TagElement.TAG_VERSION -> "See:"; - case TagElement.TAG_USES -> "Uses:"; - default -> ""; - }; - buf.append("* **" + heading + "**"); - buf.append("\n"); - buf.append(" * "); - } Deque queue = new LinkedList<>(); queue.addAll(tag.fragments()); while (!queue.isEmpty()) {