gnodet commented on code in PR #2059:
URL: https://github.com/apache/maven-resolver/pull/2059#discussion_r3797303219
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -675,11 +731,17 @@ public String visitSince(SinceTree node, Void p) {
return escape(mode, node.getBody().toString());
}
+ @Override
+ public String visitDeprecated(DeprecatedTree node, Void p) {
+ StringBuilder sb = new StringBuilder();
+ node.getBody().forEach(child -> sb.append(child.accept(this,
p)));
+ return sb.toString();
+ }
+
@Override
protected String defaultAction(DocTree node, Void p) {
// the default action internally calls node.toString(), which
uses
// com.sun.tools.javac.tree.DCTree.toString() which relies on
com.sun.tools.javac.tree.DocPretty to
Review Comment:
Looks like the next comment line (`// render the node`) was accidentally
removed, leaving this sentence truncated mid-phrase ("...DocPretty to").
##########
maven-resolver-tools/src/test/resources/org/eclipse/aether/sample/SampleConfigurationKeys.java:
##########
@@ -62,7 +62,9 @@ public final class SampleConfigurationKeys {
* @configurationSource {@link System#getProperty(String,String)}
* @configurationType {@link SampleEnum}
* @configurationDefaultValue {@link #DEFAULT_ENUM}
+ * @deprecated Use {@link ENUM2_KEY} instead
Review Comment:
Minor: `{@link ENUM2_KEY}` should be `{@link #ENUM2_KEY}` to reference a
field in the same class (consistent with the other `{@link #DEFAULT_*}`
references in this file).
```suggestion
* @deprecated Use {@link #ENUM2_KEY} instead
```
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -122,7 +123,9 @@ private record ConfigurationEntry(
String since,
String source,
String type,
- boolean supportsRepoIdSuffix) {
+ boolean supportsRepoIdSuffix,
+ // is empty if not deprecate
Review Comment:
Tiny typo: `deprecate` → `deprecated`
```suggestion
// is empty if not deprecated
```
##########
maven-resolver-tools/src/main/java/org/eclipse/aether/tools/ConfigurationCollectorDoclet.java:
##########
@@ -310,7 +330,39 @@ private ConfigurationEntry
processResolverField(DocTreePath path, VariableElemen
getSince(path).orElse(""),
getConfigurationSource(path, blockTags).orElse(""),
getConfigurationType(path, blockTags),
- isSupportsRepoIdSuffix(path, blockTags));
+ isSupportsRepoIdSuffix(path, blockTags),
+ getDeprecated(path, field).orElse(""));
+ }
+
+ private Optional<String> getDeprecated(DocTreePath path, Element element) {
+ Objects.requireNonNull(path, "path must not be null");
+ Objects.requireNonNull(element, "field must not be null");
+
+ // first check for deprecated annotation
+ if (element.getAnnotation(Deprecated.class) == null) {
+ // if not existing check enclosing elements recursively
+ return getDeprecated(element.getEnclosingElement());
+ }
+ Optional<? extends DocTree> deprecatedTag =
path.getDocComment().getBlockTags().stream()
+ .filter(t -> com.sun.source.doctree.DocTree.Kind.DEPRECATED ==
t.getKind())
+ .findFirst();
+ if (deprecatedTag.isPresent()) {
+ return Optional.of(renderContent(DocTreePath.getPath(path,
deprecatedTag.get()), RenderMode.HTML, true));
+ }
+ return Optional.of("");
+ }
+
+ private Optional<String> getDeprecated(Element element) {
+ if (element == null) {
+ return Optional.empty();
+ }
+ DocCommentTree docCommentTree = docTrees.getDocCommentTree(element);
+ if (docCommentTree == null) {
+ // traverse to enclosing element
+ return getDeprecated(element.getEnclosingElement());
Review Comment:
When `docCommentTree` is null, this method recurses to the enclosing element
without checking `element.getAnnotation(Deprecated.class)`. If an enclosing
class has `@Deprecated` but no Javadoc comment, the deprecation is silently
skipped.
The two-argument overload `getDeprecated(DocTreePath, Element)` correctly
checks the annotation, but this overload doesn't. Consider adding the
annotation check before recursing:
```suggestion
if (docCommentTree == null) {
if (element.getAnnotation(Deprecated.class) != null) {
return Optional.of("");
}
// traverse to enclosing element
return getDeprecated(element.getEnclosingElement());
```
--
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]