Skip to content

Commit 1d8547d

Browse files
committed
Avoid using count(...) = 0
1 parent 0024e54 commit 1d8547d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

java/ql/consistency-queries/visibility.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ string visibility(Method m) {
1010
result = "internal" and m.isInternal()
1111
}
1212

13+
predicate hasPackagePrivateVisibility(Method m) { not exists(visibility(m)) }
14+
1315
// TODO: This ought to check more than just methods
1416
from Method m
1517
where
@@ -20,5 +22,5 @@ where
2022
not m.getName() = "<clinit>" and
2123
count(visibility(m)) != 1 and
2224
not (count(visibility(m)) = 2 and visibility(m) = "public" and visibility(m) = "internal") and // This is a reasonable result, since the JVM symbol is declared public, but Kotlin metadata flags it as internal
23-
not (count(visibility(m)) = 0 and m.getName().matches("%$default")) // This is a reasonable result because the $default forwarder methods corresponding to private methods are package-private.
25+
not (hasPackagePrivateVisibility(m) and m.getName().matches("%$default")) // This is a reasonable result because the $default forwarder methods corresponding to private methods are package-private.
2426
select m, concat(visibility(m), ", ")

0 commit comments

Comments
 (0)