daniellansun opened a new pull request, #3235: URL: https://github.com/apache/groovy/pull/3235
## GROOVY-9273 / GROOVY-9668: support JPMS module declarations (module-info) - https://issues.apache.org/jira/browse/GROOVY-9273 - https://issues.apache.org/jira/browse/GROOVY-9668 ## Summary Groovy now accepts a modular compilation unit (`module-info.groovy` or `module-info.java`) and compiles it to a real `module-info.class` (JVMS §4.7.25), following JLS §7.7. - Grammar: `{Annotation} [open] module Identifier{.Identifier} { directives }`, with imports allowed before the declaration (JLS §7.3). `requires`, `exports`, `opens`, `uses`, `provides`, `to`, `with`, `transitive`, and `open` are contextual identifiers inside that file only, so existing Groovy code that uses those names is unchanged. - Directives: `requires` [`transitive`] [`static`] (either modifier order), `exports`/`opens` with an optional `to` clause, `uses`, and `provides` … `with` one or more providers. - Checks: duplicate requires/exports/opens/uses/provides, duplicate `to` / `with` targets, duplicate modifiers, `opens` in an `open` module, `requires java.base` with modifiers, `requires` in module `java.base`, self-requires and resolution failures (missing module, cycle), exports of a package with no compilation unit in the module, enum services, provider visibility / nesting / module membership, provider constructor or `public static provider()` method, and readability of service and annotation types. An absent `requires java.base` is emitted as `ACC_MANDATED`. - `import module` (GROOVY-11896) is unchanged in ordinary compilation units and may appear before the module declaration. `module-info.class` is written with ASM `ClassWriter.visitModule`: requires flags `TRANSITIVE` / `STATIC_PHASE`, exports and opens (including qualified targets), uses, provides, concealed packages in `ModulePackages`, and module annotations (`ElementType.MODULE`). ## Tests ``` ./gradlew :test --tests org.apache.groovy.jpms.ModuleDeclarationTest --tests org.apache.groovy.classgen.ModuleDeclarationCoverageTest --tests org.codehaus.groovy.ast.AnnotationNodeTest --tests groovy.ImportTest ``` 46 tests passed, including directive round-trips via `ModuleDescriptor.read`, ServiceLoader, `requires transitive` readability, automatic modules (`Automatic-Module-Name`), qualified exports, `java --describe-module`, and `jdeps`. JaCoCo on that run (`:jacocoTestReport`): `ModuleDeclarationNode` 100% instruction / 100% branch. `ModuleDeclarationVerifier` 99% instruction / 91% branch. Residual uncovered lines are a `ModuleFinder.find` miss after a successful resolve, a `FindException` handler in version lookup, and a closing brace. The class-file version floor below Java 9 is covered by a direct emitter call; the compiler's minimum target is 17, so that path is not reachable through `CompilerConfiguration`. -- 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]
