diff --git a/java/ql/lib/change-notes/2022-09-20-CompilationUnit-getATypeInScope.md b/java/ql/lib/change-notes/2022-09-20-CompilationUnit-getATypeInScope.md deleted file mode 100644 index dfb7e9390601..000000000000 --- a/java/ql/lib/change-notes/2022-09-20-CompilationUnit-getATypeInScope.md +++ /dev/null @@ -1,4 +0,0 @@ ---- -category: feature ---- -* Added the predicate `CompilationUnit.getATypeInScope()`. diff --git a/java/ql/lib/semmle/code/java/CompilationUnit.qll b/java/ql/lib/semmle/code/java/CompilationUnit.qll index 74396e7086b4..9b4b58e9a9bd 100644 --- a/java/ql/lib/semmle/code/java/CompilationUnit.qll +++ b/java/ql/lib/semmle/code/java/CompilationUnit.qll @@ -31,38 +31,5 @@ class CompilationUnit extends Element, File { */ Module getModule() { cumodule(this, result) } - /** - * Gets a type which is available in the top-level scope of this compilation unit. - * This can be a type: - * - declared in this compilation unit as top-level type - * - imported with an `import` declaration - * - declared in the same package as this compilation unit - * - declared in the package `java.lang` - * - * This predicate not consider "shadowing", it can have types as result whose simple name is - * shadowed by another type in scope. - */ - ClassOrInterface getATypeInScope() { - // See "Shadowing", https://docs.oracle.com/javase/specs/jls/se17/html/jls-6.html#jls-6.4.1 - // Currently shadowing is not considered - result.(TopLevelType).getCompilationUnit() = this - or - exists(Import importDecl | importDecl.getCompilationUnit() = this | - result = - [ - importDecl.(ImportStaticTypeMember).getATypeImport(), - importDecl.(ImportType).getImportedType(), - importDecl.(ImportStaticOnDemand).getATypeImport(), - importDecl.(ImportOnDemandFromType).getAnImport(), - importDecl.(ImportOnDemandFromPackage).getAnImport(), - ] - ) - or - // From same package or java.lang, see https://docs.oracle.com/javase/specs/jls/se17/html/jls-7.html - result.(TopLevelType).getPackage() = this.getPackage() - or - result.(TopLevelType).getPackage().hasName("java.lang") - } - override string getAPrimaryQlClass() { result = "CompilationUnit" } } diff --git a/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql b/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql index 42fd2049289c..7f8f4d4f983d 100644 --- a/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql +++ b/java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql @@ -11,9 +11,9 @@ import java -ClassOrInterface getTaggedType(ThrowsTag tag) { +RefType getTaggedType(ThrowsTag tag) { result.hasName(tag.getExceptionName()) and - result = tag.getFile().(CompilationUnit).getATypeInScope() + exists(ImportType i | i.getFile() = tag.getFile() | i.getImportedType() = result) } // Uses ClassOrInterface as type for thrownType to also cover case where erroneously an interface diff --git a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected index 5b031604e567..f94a6f61f33a 100644 --- a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected +++ b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.expected @@ -1,3 +1,2 @@ | ImpossibleJavadocThrows.java:9:5:9:12 | @throws | Javadoc for bad1 claims to throw InterruptedException but this is impossible. | | ImpossibleJavadocThrows.java:16:5:16:15 | @exception | Javadoc for bad2 claims to throw Exception but this is impossible. | -| ImpossibleJavadocThrows.java:23:5:23:12 | @throws | Javadoc for bad3 claims to throw Runnable but this is impossible. | diff --git a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java index b0b27397359b..7ba8988c38be 100644 --- a/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java +++ b/java/ql/test/query-tests/Javadoc/ImpossibleJavadocThrows.java @@ -18,13 +18,6 @@ public void bad1() { public void bad2() { } - /** - * - * @throws Runnable - */ - public void bad3() { - } - /** * * @throws InterruptedException