Skip to content

Commit 01b950f

Browse files
committed
Revert "Java: Rename predicate to getATypeInScope"
This reverts commit fd99ae7.
1 parent df29e05 commit 01b950f

File tree

4 files changed

+37
-25
lines changed

4 files changed

+37
-25
lines changed

java/ql/lib/change-notes/2022-09-20-CompilationUnit-getATypeInScope.md

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added the predicate `CompilationUnit.getATypeAvailableBySimpleName()`.

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,42 @@ class CompilationUnit extends Element, File {
3232
Module getModule() { cumodule(this, result) }
3333

3434
/**
35-
* Gets a type which is available in the top-level scope of this compilation unit.
36-
* This can be a type:
37-
* - declared in this compilation unit as top-level type
38-
* - imported with an `import` declaration
39-
* - declared in the same package as this compilation unit
40-
* - declared in the package `java.lang`
41-
*
42-
* This predicate not consider "shadowing", it can have types as result whose simple name is
43-
* shadowed by another type in scope.
35+
* Gets a type which is available by its simple name in this compilation unit.
36+
* Reasons for this can be:
37+
* - The type is declared in this compilation unit as top-level type
38+
* - The type is imported
39+
* - The type is declared in the same package as this compilation unit
40+
* - The type is declared in the package `java.lang`
4441
*/
45-
ClassOrInterface getATypeInScope() {
42+
ClassOrInterface getATypeAvailableBySimpleName() {
4643
// See "Shadowing", https://docs.oracle.com/javase/specs/jls/se17/html/jls-6.html#jls-6.4.1
47-
// Currently shadowing is not considered
44+
// Note: Currently the logic below does not consider shadowing and might have multiple results
45+
// with the same type name
4846
result.(TopLevelType).getCompilationUnit() = this
4947
or
50-
exists(Import importDecl | importDecl.getCompilationUnit() = this |
51-
result =
52-
[
53-
importDecl.(ImportStaticTypeMember).getATypeImport(),
54-
importDecl.(ImportType).getImportedType(),
55-
importDecl.(ImportStaticOnDemand).getATypeImport(),
56-
importDecl.(ImportOnDemandFromType).getAnImport(),
57-
importDecl.(ImportOnDemandFromPackage).getAnImport(),
58-
]
48+
exists(ImportStaticTypeMember importDecl |
49+
importDecl.getCompilationUnit() = this and
50+
result = importDecl.getATypeImport()
51+
)
52+
or
53+
exists(ImportType importDecl |
54+
importDecl.getCompilationUnit() = this and
55+
result = importDecl.getImportedType()
56+
)
57+
or
58+
exists(ImportStaticOnDemand importDecl |
59+
importDecl.getCompilationUnit() = this and
60+
result = importDecl.getATypeImport()
61+
)
62+
or
63+
exists(ImportOnDemandFromType importDecl |
64+
importDecl.getCompilationUnit() = this and
65+
result = importDecl.getAnImport()
66+
)
67+
or
68+
exists(ImportOnDemandFromPackage importDecl |
69+
importDecl.getCompilationUnit() = this and
70+
result = importDecl.getAnImport()
5971
)
6072
or
6173
// From same package or java.lang, see https://docs.oracle.com/javase/specs/jls/se17/html/jls-7.html

java/ql/src/Advisory/Documentation/ImpossibleJavadocThrows.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import java
1313

1414
Class getTaggedType(ThrowsTag tag) {
1515
result.hasName(tag.getExceptionName()) and
16-
result = tag.getFile().(CompilationUnit).getATypeInScope()
16+
result = tag.getFile().(CompilationUnit).getATypeAvailableBySimpleName()
1717
}
1818

1919
predicate canThrow(Callable callable, Class exception) {

0 commit comments

Comments
 (0)