|
6 | 6 |
|
7 | 7 | import semmle.code.Location |
8 | 8 | import CompilationUnit |
| 9 | +import Modules |
9 | 10 |
|
10 | 11 | /** A common super-class for all kinds of Java import declarations. */ |
11 | 12 | class Import extends Element, @import { |
@@ -154,3 +155,42 @@ class ImportStaticTypeMember extends Import { |
154 | 155 |
|
155 | 156 | override string getAPrimaryQlClass() { result = "ImportStaticTypeMember" } |
156 | 157 | } |
| 158 | + |
| 159 | +/** |
| 160 | + * A module import declaration, which imports an entire module. |
| 161 | + * |
| 162 | + * For example, `import module java.base;`. |
| 163 | + */ |
| 164 | +class ModuleImportDeclaration extends Element, @moduleimportdeclaration { |
| 165 | + /** Gets the compilation unit in which this module import declaration occurs. */ |
| 166 | + override CompilationUnit getCompilationUnit() { result = this.getFile() } |
| 167 | + |
| 168 | + /** Holds if this module import declaration occurs in source code. */ |
| 169 | + override predicate fromSource() { any() } |
| 170 | + |
| 171 | + /** Gets the name of the imported module. */ |
| 172 | + string getModuleName() { moduleImportDeclarations(this, _, result) } |
| 173 | + |
| 174 | + /** Gets the imported module. */ |
| 175 | + Module getModule() { result.getName() = this.getModuleName() } |
| 176 | + |
| 177 | + /** Gets an exported package from the imported module. */ |
| 178 | + Package getAnImportedPackage() { |
| 179 | + exists(ExportsDirective exports | |
| 180 | + exports = this.getModule().getADirective() and |
| 181 | + result = exports.getExportedPackage() |
| 182 | + ) |
| 183 | + } |
| 184 | + |
| 185 | + /** Gets a type that is imported from the module. */ |
| 186 | + RefType getAnImportedType() { |
| 187 | + exists(Package pkg | |
| 188 | + pkg = this.getAnImportedPackage() and |
| 189 | + result.getPackage() = pkg |
| 190 | + ) |
| 191 | + } |
| 192 | + |
| 193 | + override string toString() { result = "import module " + this.getModuleName() } |
| 194 | + |
| 195 | + override string getAPrimaryQlClass() { result = "ModuleImportDeclaration" } |
| 196 | +} |
0 commit comments