Skip to content

Commit e89433e

Browse files
committed
Java: Add ModuleImportDeclaration QL class
1 parent cf87e8b commit e89433e

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,38 @@ 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;`.
162+
*/
163+
class ModuleImportDeclaration extends Import {
164+
ModuleImportDeclaration() { imports(this, _, _, 6) }
165+
166+
/** Gets the name of the imported module. */
167+
string getModuleName() { imports(this, _, result, _) }
168+
169+
/** Gets the imported module. */
170+
Module getModule() { result.getName() = this.getModuleName() }
171+
172+
/** Gets an exported package from the imported module. */
173+
Package getAnImportedPackage() {
174+
exists(ExportsDirective exports |
175+
exports = this.getModule().getADirective() and
176+
result = exports.getExportedPackage()
177+
)
178+
}
179+
180+
/** Gets a type that is imported from the module. */
181+
RefType getAnImportedType() {
182+
exists(Package pkg |
183+
pkg = this.getAnImportedPackage() and
184+
result.getPackage() = pkg
185+
)
186+
}
187+
188+
override string toString() { result = "import module " + this.getModuleName() }
189+
190+
override string getAPrimaryQlClass() { result = "ModuleImportDeclaration" }
191+
}

0 commit comments

Comments
 (0)