Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
category: feature
---
* Added support for Java 25 module import declarations.
* Add `ModuleImportDeclaration` class.
32 changes: 32 additions & 0 deletions java/ql/lib/semmle/code/java/Import.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
}
Original file line number Diff line number Diff line change
@@ -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 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import java

from ModuleImportDeclaration mid
select mid.getModuleName(), mid.getAnImportedPackage().getName()
Loading