Use custom doclet to extract configuration metadata with the help of#1965
Use custom doclet to extract configuration metadata with the help of#1965kwin wants to merge 5 commits into
Conversation
javadoc Remove unused "maven" mode
gnodet
left a comment
There was a problem hiding this comment.
Review Summary
Nice work, @kwin! Replacing the Roaster + ASM dependencies with a standard JDK javadoc doclet is a clean architectural improvement. The intermediate properties file format provides good separation between metadata extraction and rendering, and the fileContains pre-filtering to avoid classpath resolution issues is a smart optimization. The behavioral equivalence with the old code looks correct — e.g., the Long suffix stripping is correctly omitted since VariableElement.getConstantValue() returns a proper Long object.
Two minor observations on the new code:
Low Severity
-
Redundant
BufferedWriterwrapping — InConfigurationCollectorDoclet.java,Files.newBufferedWriter()already returns aBufferedWriter, so the outernew BufferedWriter(...)wrapper is unnecessary. Harmless, but an extra allocation:try (Writer writer = Files.newBufferedWriter(output, StandardCharsets.UTF_8)) { -
Broad exception catch in
fileContains— InCollectConfiguration.java, thefileContainsmethod catchesExceptioninstead ofIOException. SinceFiles.readString()only throwsIOExceptionas a checked exception, catching the broaderExceptioncould mask programming errors (e.g.,NullPointerException) by silently returningfalse. Consider narrowing toIOException.
Notes
- The PR title appears truncated: "Use custom doclet to extract configuration metadata with the help of" — consider completing it.
- CI checks are still pending at time of review.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
|
The maven mode is used in maven: |
gnodet
left a comment
There was a problem hiding this comment.
Follow-up Review
Thanks for the quick update, @kwin! Both findings from the initial review have been addressed in the new commit:
- ✅ Redundant
BufferedWriterwrapping removed - ✅ Broad
Exceptioncatch narrowed toIOException
The new enum resolution logic is well-structured — the fallback chain from compile-time constant → enum constant kind → initializer expression analysis covers the practical cases nicely. The test fixture exercises both indirect enum references (DEFAULT_ENUM = SampleEnum.VALUE_A) and direct enum constant references (SampleEnum#VALUE_B), which is good coverage.
Three minor observations on the new code (all low severity):
- Stale assertion message —
assertEquals(4, ...)says "expected three configuration keys" (see inline) - Redundant
docTrees.getTree(field)call — called twice inresolveEnumReference, could use Java 16+ pattern matchinginstanceof(see inline) - Theoretical null from
docTrees.getPath()—resolveReferencedFieldpasses the result ofdocTrees.getPath(contextField)directly tonew DocTreePath(...)without a null check. In practice this is very unlikely since the doclet only processes included source elements, but a null guard would be more defensive.
None of these are blocking — the PR looks good overall.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
| runDoclet(sourceFile, output); | ||
|
|
||
| Map<String, Map<String, String>> keys = readKeys(output); | ||
| assertEquals(4, keys.size(), "expected three configuration keys"); |
There was a problem hiding this comment.
Nit: the assertion expects 4 keys but the failure message still says "three":
| assertEquals(4, keys.size(), "expected three configuration keys"); | |
| assertEquals(4, keys.size(), "expected four configuration keys"); |
| if (!(docTrees.getTree(field) instanceof VariableTree)) { | ||
| return null; | ||
| } | ||
| ExpressionTree initializer = ((VariableTree) docTrees.getTree(field)).getInitializer(); |
There was a problem hiding this comment.
Minor: docTrees.getTree(field) is called twice — once for the instanceof guard and again for the cast. Since the project targets Java 17+, pattern matching instanceof eliminates the redundant call:
| ExpressionTree initializer = ((VariableTree) docTrees.getTree(field)).getInitializer(); | |
| private String resolveEnumReference(VariableElement field) { | |
| if (!(docTrees.getTree(field) instanceof VariableTree variableTree)) { | |
| return null; | |
| } | |
| ExpressionTree initializer = variableTree.getInitializer(); |
gnodet
left a comment
There was a problem hiding this comment.
Follow-up Review (commits 3 & 4)
Thanks for applying the suggestions from the last review, @kwin — commit 4 (727e16bf) correctly adopts pattern matching instanceof and fixes the assertion message. Both look good.
Regarding commit 3 ("Restore maven mode"), the dual-mode architecture is clean — the split into processResolverField / processMavenField keeps the two code paths well-separated, and the @Config annotation attribute reading is correct. The mode is properly threaded from picocli CLI through to the doclet. A few observations:
Medium
- No test coverage for Maven mode — The existing test only exercises the resolver path (Javadoc block tags). The Maven mode has meaningfully different logic (annotation-based metadata extraction), and without a test fixture that includes an
@Config-annotated field, regressions inprocessMavenField/getAnnotationwould go undetected. Consider adding a second fixture and test method similar to the existing one but with--mode=maven.
Low
-
No mode validation in doclet — The
modefield is a rawStringset by the--modeoption. An invalid value (e.g.--mode=typo) silently falls through to resolver mode sincedoRunchecks"maven".equals(mode)and treats everything else as resolver. Practical risk is low becauseCollectConfigurationvalidates via the picocliModeenum, but if the doclet is ever invoked standalone, this could be surprising. -
Dead null check on
description— InprocessMavenField, theif (description != null)guard on thereplace("*", ...)call is unreachable: whendocComment != null,renderContent(getFullBody())returns a non-nullString; whendocComment == null,descriptionis"". Harmless, but slightly misleading.
Notes
- The PR description still says "Remove unused 'maven' mode" — consider updating it to reflect that Maven mode is now restored.
- Good use of
Locale.ROOTinsource.toLowerCase()— an improvement over the default-locale alternative.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
|
Long term I would rather move the Maven specific part to https://github.com/apache/maven so that it does not need to use reflection (to prevent dependencies from Resolver to Maven). Therefore I wouldn't spend time here now to add additional tests for Maven. For example https://maven.apache.org/ref/4.0.0-rc-5/maven-configuration.html still emits |
gnodet
left a comment
There was a problem hiding this comment.
Follow-up review #4 — commit 154e76df (mode validation & cleanup)
Nice work — this commit addresses two of the three findings from the previous round:
✅ Mode validation (previously flagged): The explicit "resolver".equals(mode) check with else throw IllegalArgumentException correctly prevents unknown modes from silently falling through to resolver processing. The exception is caught by the RuntimeException handler in run() and properly reported.
✅ Dead null check (previously flagged): The if (description != null) guard was correctly removed — the ternary always produces a non-null string.
✅ system_properties source: Good addition completing the enum mapping alongside model and user_properties.
One low-severity observation (not blocking): The mode validation happens inside the field iteration loop (line 157). If scanned sources happened to contain no constant fields, the loop body would never execute and an invalid mode would silently succeed. In practice this is unreachable because CollectConfiguration constrains the mode to valid enum values and pre-filters sources to those containing configuration markers — but moving the validation to the top of doRun() (alongside the existing output == null check) would make the invariant self-documenting.
Still open from prior rounds: No test coverage for the maven mode path or the new IllegalArgumentException path. Not blocking for this commit.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
|
This requires some more work for error reporting and also for emitting types (should be FQCN for non simple types) |
javadoc
Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
mvn -Prun-its verify).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.