Skip to content

Commit c5cb86a

Browse files
authored
Merge pull request #20097 from github/idrissrio/module-import-declarations
Java: Add support to `ModuleImportDeclaration`
2 parents 6148590 + ed9ed43 commit c5cb86a

File tree

8 files changed

+1626
-0
lines changed

8 files changed

+1626
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: feature
3+
---
4+
* Added support for Java 25 module import declarations.
5+
* Add `ModuleImportDeclaration` class.

java/ql/lib/semmle/code/java/Import.qll

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,35 @@ class ImportStaticTypeMember extends Import {
154154

155155
override string getAPrimaryQlClass() { result = "ImportStaticTypeMember" }
156156
}
157+
158+
/**
159+
* A module import declaration, which imports an entire module.
160+
*
161+
* For example, `import module java.base;` makes all packages exported
162+
* by the `java.base` module available, and through those packages,
163+
* the types they declare become accessible.
164+
*/
165+
class ModuleImportDeclaration extends Import {
166+
ModuleImportDeclaration() { imports(this, _, _, 6) }
167+
168+
/** Gets the name of the imported module. */
169+
string getModuleName() { imports(this, _, result, _) }
170+
171+
/** Gets the imported module. */
172+
Module getModule() { result.getName() = this.getModuleName() }
173+
174+
/** Gets an exported package from the imported module. */
175+
Package getAnImportedPackage() {
176+
exists(ExportsDirective exports |
177+
exports = this.getModule().getADirective() and
178+
result = exports.getExportedPackage()
179+
)
180+
}
181+
182+
/** Gets a type from a package that is accessible through this module import. */
183+
RefType getAnImportedType() { result.getPackage() = this.getAnImportedPackage() }
184+
185+
override string toString() { result = "import module " + this.getModuleName() }
186+
187+
override string getAPrimaryQlClass() { result = "ModuleImportDeclaration" }
188+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
| java.base | java.io |
2+
| java.base | java.lang |
3+
| java.base | java.lang.annotation |
4+
| java.base | java.lang.classfile |
5+
| java.base | java.lang.classfile.attribute |
6+
| java.base | java.lang.classfile.constantpool |
7+
| java.base | java.lang.classfile.instruction |
8+
| java.base | java.lang.constant |
9+
| java.base | java.lang.foreign |
10+
| java.base | java.lang.invoke |
11+
| java.base | java.lang.module |
12+
| java.base | java.lang.ref |
13+
| java.base | java.lang.reflect |
14+
| java.base | java.lang.runtime |
15+
| java.base | java.math |
16+
| java.base | java.net |
17+
| java.base | java.net.spi |
18+
| java.base | java.nio |
19+
| java.base | java.nio.channels |
20+
| java.base | java.nio.channels.spi |
21+
| java.base | java.nio.charset |
22+
| java.base | java.nio.charset.spi |
23+
| java.base | java.nio.file |
24+
| java.base | java.nio.file.attribute |
25+
| java.base | java.nio.file.spi |
26+
| java.base | java.security |
27+
| java.base | java.security.cert |
28+
| java.base | java.security.interfaces |
29+
| java.base | java.security.spec |
30+
| java.base | java.text |
31+
| java.base | java.text.spi |
32+
| java.base | java.time |
33+
| java.base | java.time.chrono |
34+
| java.base | java.time.format |
35+
| java.base | java.time.temporal |
36+
| java.base | java.time.zone |
37+
| java.base | java.util |
38+
| java.base | java.util.concurrent |
39+
| java.base | java.util.concurrent.atomic |
40+
| java.base | java.util.concurrent.locks |
41+
| java.base | java.util.function |
42+
| java.base | java.util.jar |
43+
| java.base | java.util.random |
44+
| java.base | java.util.regex |
45+
| java.base | java.util.spi |
46+
| java.base | java.util.stream |
47+
| java.base | java.util.zip |
48+
| java.base | javax.crypto |
49+
| java.base | javax.crypto.interfaces |
50+
| java.base | javax.crypto.spec |
51+
| java.base | javax.net |
52+
| java.base | javax.net.ssl |
53+
| java.base | javax.security.auth |
54+
| java.base | javax.security.auth.callback |
55+
| java.base | javax.security.auth.login |
56+
| java.base | javax.security.auth.spi |
57+
| java.base | javax.security.auth.x500 |
58+
| java.base | javax.security.cert |
59+
| java.base | jdk.internal.event |
60+
| java.base | jdk.internal.javac |
61+
| java.base | jdk.internal.vm.vector |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import java
2+
3+
from ModuleImportDeclaration mid
4+
select mid.getModuleName(), mid.getAnImportedPackage().getName()

0 commit comments

Comments
 (0)