RFR: 8341342: Elements.getAllModuleElements() does not work properly before JavacTask.analyze()
Chen Liang
liach at openjdk.org
Fri Aug 8 17:28:11 UTC 2025
On Fri, 8 Aug 2025 12:03:54 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> When calling `Elements.getTypeElement(...)` or `Elements.getPackageElement(...)`, javac itself ensures that the enter phase is already done. That is, sadly, not done for `Elements.getAllModuleElements()`. This PR fixes that.
>
> See:
> https://github.com/openjdk/jdk/pull/18934/files#r1767657515
> for a practical case.
I remember this from the APIDiff: https://github.com/openjdk/apidiff/blob/1dbbcb5b87f75edcbdf9caf7314c56bce1a110df/src/share/classes/jdk/codetools/apidiff/model/API.java#L460
test/langtools/tools/javac/processing/model/util/elements/TestElementsProgrammatic.java line 55:
> 53: public void automaticallyEnter() {
> 54: //make sure the get{All,}{Module,Package,Type}Element{s,} methods will automatically enter:
> 55: List<Consumer<JavacTask>> testCases = List.of(
You can use `@ParameterizedTest @MethodSource("taskFactory")` for each test case, and `static JavacTask taskFactory() { /* ... */}` for junit to call to create the task argument for each test.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26694#issuecomment-3168791855
PR Review Comment: https://git.openjdk.org/jdk/pull/26694#discussion_r2263634347
More information about the compiler-dev
mailing list