Copilot commented on code in PR #2218:
URL: https://github.com/apache/maven-resolver/pull/2218#discussion_r4329858228
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -723,28 +739,11 @@ public String visitText(TextTree node, Void p) {
@Override
public String visitLink(LinkTree node, Void p) {
- String ref = node.getReference() != null ?
node.getReference().getSignature() : "";
List<? extends DocTree> labelTrees = node.getLabel();
String label = (labelTrees != null && !labelTrees.isEmpty())
? renderContent(docTreePath, mode, false, labelTrees)
: "";
- String text = label.isEmpty() ? ref : label;
- String rendered = node.getKind() == DocTree.Kind.LINK_PLAIN ?
escape(mode, text) : renderAsCode(text);
- if (mode == RenderMode.HTML) {
- VariableElement referenced =
resolveReferencedField(docTreePath, node);
- String configurationKey = getConfigurationKey(referenced);
- if (configurationKey != null) {
- rendered = node.getKind() == DocTree.Kind.LINK_PLAIN
- ? escape(mode, configurationKey)
- : renderAsCode(configurationKey);
- return "<a href=\"#" + escape(mode, configurationKey)
+ "\">" + rendered + "</a>";
- }
- Optional<String> javadocUrl = getJavadocUrl(docTreePath,
node.getReference());
- if (javadocUrl.isPresent()) {
- return "<a href=\"" + javadocUrl.get() + "\">" +
rendered + "</a>";
- }
- }
- return rendered;
+ return renderReference(node.getReference(), node.getKind() ==
DocTree.Kind.LINK_PLAIN, label);
Review Comment:
`renderReference(...)` assumes `ReferenceTree node` is non-null (calls
`node.getSignature()` and passes it into `resolveReferencedField`), but
`visitLink` passes `node.getReference()` directly. This can throw an NPE for
links without a resolved/reference part (the previous implementation explicitly
handled `node.getReference() == null`). Add a null guard either in `visitLink`
(fallback to rendering label/plain text when reference is missing) or inside
`renderReference` (early return rendered label when `node == null`).
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -141,7 +142,9 @@ private record ConfigurationEntry(
String typeJavadocUrl,
boolean supportsRepoIdSuffix,
// is empty if not deprecated
- String deprecated) {
+ String deprecated,
+ // see also section, comma-separated list
+ Collection<String> see) {
Review Comment:
The comment says “comma-separated list”, but the field type is
`Collection<String>` (the comma-separated formatting happens later in
`writeEntry` via `String.join`). Update the comment to match the actual
type/meaning (e.g., “rendered `@see` entries in encounter order”).
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -812,6 +811,49 @@ public String visitDeprecated(DeprecatedTree node, Void p)
{
return sb.toString();
}
+ @Override
+ public String visitSee(SeeTree node, Void p) {
+ // if the first reference is of type REFERENCE, the label may
follow afterwards
+ if (!node.getReference().isEmpty() &&
node.getReference().get(0) instanceof ReferenceTree reference) {
+ String label = renderContent(
+ docTreePath,
+ mode,
+ trim,
+ node.getReference().subList(1,
node.getReference().size()));
+ return renderReference(reference, false, label);
+ } else {
+ return renderContent(docTreePath, mode, trim,
node.getReference());
+ }
+ }
+
+ /**
+ * Used from {@link #visitLink(LinkTree, Void)} and {@link
#visitSee(SeeTree, Void)} to render a reference to a field or type (optionally
with a label).
+ * @param node the reference node
+ * @param isPlain true if it should be emitted outside of a code
block, false otherwise
+ * @param label may be empty, in which case the reference
signature is used as the label
+ * @return the rendered reference (never {@code null})
+ */
+ private String renderReference(ReferenceTree node, boolean
isPlain, String label) {
+ String effectiveLabel = label.isEmpty() ? node.getSignature()
: label;
+ String escapedLabel = isPlain ? escape(mode, effectiveLabel) :
renderAsCode(effectiveLabel);
+ if (mode == RenderMode.HTML) {
+ VariableElement referenced =
resolveReferencedField(docTreePath, node);
Review Comment:
`renderReference(...)` assumes `ReferenceTree node` is non-null (calls
`node.getSignature()` and passes it into `resolveReferencedField`), but
`visitLink` passes `node.getReference()` directly. This can throw an NPE for
links without a resolved/reference part (the previous implementation explicitly
handled `node.getReference() == null`). Add a null guard either in `visitLink`
(fallback to rendering label/plain text when reference is missing) or inside
`renderReference` (early return rendered label when `node == null`).
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -419,6 +423,16 @@ private Optional<String> getDeprecated(Element element) {
}
}
+ private Collection<String> getSee(DocTreePath path, Element element) {
+ Objects.requireNonNull(path, "path must not be null");
+ Objects.requireNonNull(element, "field must not be null");
Review Comment:
The parameter is named `element`, but the null-check message says `"field
must not be null"`. To avoid confusion during debugging, align the message with
the parameter name (e.g., `"element must not be null"`) or rename the parameter
to `field` if that’s the intended meaning here.
--
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]