gnodet commented on code in PR #1981:
URL: https://github.com/apache/maven-resolver/pull/1981#discussion_r3645620650
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -457,121 +467,172 @@ private String resolveReferencedType(
: signature;
}
- private String renderContent(List<? extends DocTree> content) {
+ /**
+ * Renders the content of a Javadoc tag into a string, escaping HTML
special characters and rendering inline tags.
+ * @param content
+ * @param context
+ * @param contextDoc
+ * @param trim if true, trims the result string
+ * @return
+ * @see <a
href="https://docs.oracle.com/en/java/javase/25/docs/specs/javadoc/doc-comment-spec.html#standard-tags">Javadoc
tags</a>
+ * @see <a
href="https://docs.oracle.com/en/java/javase/25/docs/api/jdk.compiler/com/sun/source/doctree/InlineTagTree.html">InlineTagTree
(common superinterface of all inline tags)</a>
+ */
+ private String renderContent(
+ List<? extends DocTree> content, VariableElement context,
DocCommentTree contextDoc, boolean trim) {
if (content == null) {
return null;
}
StringBuilder sb = new StringBuilder();
+ SimpleDocTreeVisitor<String, Void> visitor = new
SimpleDocTreeVisitor<String, Void>() {
+ @Override
+ public String visitText(TextTree node, Void p) {
+ return escapeHtml(node.getBody());
+ }
+
+ @Override
+ public String visitLink(LinkTree node, Void p) {
+ String ref = node.getReference() != null ?
node.getReference().getSignature() : "";
+ String label = renderContent(node.getLabel(), null, null,
false);
+ String text = label == null || label.isEmpty() ? ref : label;
+ return node.getKind() == DocTree.Kind.LINK_PLAIN ?
escapeHtml(text) : renderAsCode(text);
+ }
+
+ @Override
+ public String visitLiteral(LiteralTree node, Void p) {
+ if (node.getKind() == DocTree.Kind.LITERAL) {
Review Comment:
The condition here is inverted. `DocTree.Kind.CODE` corresponds to the
`{@code}` tag (monospace, wrapped in `<code>`) while `DocTree.Kind.LITERAL`
corresponds to the `{@literal}` tag (plain text, HTML-escaped, no monospace).
The current code wraps `{@literal}` content in `<code>` and leaves `{@code}`
content unwrapped — the opposite of what the standard doclet does.
Notably, `visitLink` (line 497) gets this right: it maps `LINK` (code-font
semantics) to `renderAsCode` and `LINK_PLAIN` (plain-text semantics) to
`escapeHtml`. The same pattern should apply here.
```suggestion
public String visitLiteral(LiteralTree node, Void p) {
if (node.getKind() == DocTree.Kind.CODE) {
return renderAsCode(node.getBody().getBody());
} else {
return escapeHtml(node.getBody().getBody());
}
}
```
##########
maven-resolver-tools/src/test/java/org/eclipse/aether/tools/ConfigurationCollectorDocletTest.java:
##########
@@ -78,8 +78,11 @@ void extractsBooleanStringAndEnumConfigurations(@TempDir
Path tempDir) throws Ex
assertNotNull(string, "string key missing");
assertEquals("String", string.get("configurationType"));
assertEquals("\"hello\"", string.get("defaultValue"));
- assertEquals("Yes", string.get("supportRepoIdSuffix"));
assertEquals("", string.get("since"), "no @since expected");
+ assertEquals("Yes", string.get("supportRepoIdSuffix"));
+ assertEquals(
+ "A string value with some inline tags. Value
<code>\"hello\"</code> is the default. <code>some.property</code> is used. This
text is code. <code>This text is literal.</code> <code>java.lang.String</code>
is the type.",
Review Comment:
The expected string here reflects the inverted behavior — it expects `{@code
This text is code.}` to render without a `<code>` wrapper and `{@literal This
text is literal.}` to render with one. Once the condition in `visitLiteral` is
fixed, this expectation should be updated to match:
```suggestion
"A string value with some inline tags. Value
<code>\"hello\"</code> is the default. <code>some.property</code> is used.
<code>This text is code.</code> This text is literal.
<code>java.lang.String</code> is the type.",
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]