Merge pull request #20097 from github/idrissrio/module-import-declarations

Java: Add support to `ModuleImportDeclaration`
This commit is contained in:
Idriss Riouak
2025-09-06 13:11:48 +02:00
committed by GitHub
8 changed files with 1626 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
category: feature
---
* Added support for Java 25 module import declarations.
* Add `ModuleImportDeclaration` class.

View File

@@ -154,3 +154,35 @@ class ImportStaticTypeMember extends Import {
override string getAPrimaryQlClass() { result = "ImportStaticTypeMember" }
}
/**
* A module import declaration, which imports an entire module.
*
* For example, `import module java.base;` makes all packages exported
* by the `java.base` module available, and through those packages,
* the types they declare become accessible.
*/
class ModuleImportDeclaration extends Import {
ModuleImportDeclaration() { imports(this, _, _, 6) }
/** Gets the name of the imported module. */
string getModuleName() { imports(this, _, result, _) }
/** Gets the imported module. */
Module getModule() { result.getName() = this.getModuleName() }
/** Gets an exported package from the imported module. */
Package getAnImportedPackage() {
exists(ExportsDirective exports |
exports = this.getModule().getADirective() and
result = exports.getExportedPackage()
)
}
/** Gets a type from a package that is accessible through this module import. */
RefType getAnImportedType() { result.getPackage() = this.getAnImportedPackage() }
override string toString() { result = "import module " + this.getModuleName() }
override string getAPrimaryQlClass() { result = "ModuleImportDeclaration" }
}

View File

@@ -0,0 +1,61 @@
| java.base | java.io |
| java.base | java.lang |
| java.base | java.lang.annotation |
| java.base | java.lang.classfile |
| java.base | java.lang.classfile.attribute |
| java.base | java.lang.classfile.constantpool |
| java.base | java.lang.classfile.instruction |
| java.base | java.lang.constant |
| java.base | java.lang.foreign |
| java.base | java.lang.invoke |
| java.base | java.lang.module |
| java.base | java.lang.ref |
| java.base | java.lang.reflect |
| java.base | java.lang.runtime |
| java.base | java.math |
| java.base | java.net |
| java.base | java.net.spi |
| java.base | java.nio |
| java.base | java.nio.channels |
| java.base | java.nio.channels.spi |
| java.base | java.nio.charset |
| java.base | java.nio.charset.spi |
| java.base | java.nio.file |
| java.base | java.nio.file.attribute |
| java.base | java.nio.file.spi |
| java.base | java.security |
| java.base | java.security.cert |
| java.base | java.security.interfaces |
| java.base | java.security.spec |
| java.base | java.text |
| java.base | java.text.spi |
| java.base | java.time |
| java.base | java.time.chrono |
| java.base | java.time.format |
| java.base | java.time.temporal |
| java.base | java.time.zone |
| java.base | java.util |
| java.base | java.util.concurrent |
| java.base | java.util.concurrent.atomic |
| java.base | java.util.concurrent.locks |
| java.base | java.util.function |
| java.base | java.util.jar |
| java.base | java.util.random |
| java.base | java.util.regex |
| java.base | java.util.spi |
| java.base | java.util.stream |
| java.base | java.util.zip |
| java.base | javax.crypto |
| java.base | javax.crypto.interfaces |
| java.base | javax.crypto.spec |
| java.base | javax.net |
| java.base | javax.net.ssl |
| java.base | javax.security.auth |
| java.base | javax.security.auth.callback |
| java.base | javax.security.auth.login |
| java.base | javax.security.auth.spi |
| java.base | javax.security.auth.x500 |
| java.base | javax.security.cert |
| java.base | jdk.internal.event |
| java.base | jdk.internal.javac |
| java.base | jdk.internal.vm.vector |

View File

@@ -0,0 +1,4 @@
import java
from ModuleImportDeclaration mid
select mid.getModuleName(), mid.getAnImportedPackage().getName()

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,4 @@
import java
from ModuleImportDeclaration mid
select mid.getModuleName(), mid.getAnImportedType().getQualifiedName()

View File

@@ -0,0 +1,6 @@
import module java.base;
class Test {
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1 @@
//semmle-extractor-options: --javac-args --release 25 --enable-preview