There is currently no way to access a ModuleTree from a CompilationUnitTree.
This is made most evident by looking at the "USE" of ModuleTree in the API specs.
https://docs.oracle.com/en/java/javase/15/docs/api/jdk.compiler/com/sun/source/tree/class-use/ModuleTree.html
Note that JLS 7.3 defines:
CompilationUnit:
OrdinaryCompilationUnit
ModularCompilationUnit
OrdinaryCompilationUnit:
[PackageDeclaration] {ImportDeclaration} {TypeDeclaration}
ModularCompilationUnit:
{ImportDeclaration} ModuleDeclaration
https://docs.oracle.com/javase/specs/jls/se15/html/jls-7.html#jls-7.3
It is therefore appropriate to provide access to the ModuleDeclaration when that is the content.
This is made most evident by looking at the "USE" of ModuleTree in the API specs.
https://docs.oracle.com/en/java/javase/15/docs/api/jdk.compiler/com/sun/source/tree/class-use/ModuleTree.html
Note that JLS 7.3 defines:
CompilationUnit:
OrdinaryCompilationUnit
ModularCompilationUnit
OrdinaryCompilationUnit:
[PackageDeclaration] {ImportDeclaration} {TypeDeclaration}
ModularCompilationUnit:
{ImportDeclaration} ModuleDeclaration
https://docs.oracle.com/javase/specs/jls/se15/html/jls-7.html#jls-7.3
It is therefore appropriate to provide access to the ModuleDeclaration when that is the content.
- csr for
-
JDK-8255478 Cannot access ModuleTree in a CompilationUnitTree
-
- Closed
-