Skip to content

Commit e66d2dd

Browse files
committed
Fix review findings
1 parent 3513bb8 commit e66d2dd

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import Element
77
/** A modifier such as `private`, `static` or `abstract`. */
88
class Modifier extends Element, @modifier {
99
/** Gets the element to which this modifier applies. */
10-
Element getElement() { hasModifier(result, this) }
10+
Element getElement() {
11+
hasModifier(result, this) and
12+
// Kotlin "internal" elements may also get "public" modifiers, so we want to filter those out
13+
not exists(Modifier mod2 |
14+
hasModifier(result, mod2) and modifiers(this, "public") and modifiers(mod2, "internal")
15+
)
16+
}
1117

1218
override string getAPrimaryQlClass() { result = "Modifier" }
1319
}
@@ -25,7 +31,15 @@ abstract class Modifiable extends Element {
2531
* abstract, so `isAbstract()` will hold for them even if `hasModifier("abstract")`
2632
* does not.
2733
*/
28-
predicate hasModifier(string m) { modifiers(this.getAModifier(), m) }
34+
predicate hasModifier(string m) {
35+
exists(Modifier mod | mod = this.getAModifier() |
36+
modifiers(mod, m) and
37+
// Kotlin "internal" elements may also get "public" modifiers, so we want to filter those out
38+
not exists(Modifier mod2 |
39+
hasModifier(this, mod2) and modifiers(mod, "public") and modifiers(mod2, "internal")
40+
)
41+
)
42+
}
2943

3044
/** Holds if this element has no modifier. */
3145
predicate hasNoModifier() { not hasModifier(this, _) }
@@ -46,11 +60,8 @@ abstract class Modifiable extends Element {
4660
// TODO: `isSealed()` conflicts with `ClassOrInterface.isSealed()`. What name do we want to use here?
4761
predicate isSealedKotlin() { this.hasModifier("sealed") }
4862

49-
/**
50-
* Holds if this element has a `public` modifier or is implicitly public.
51-
* Kotlin `internal` members, which are `public` in JVM Bytecode, are not considered `public`.
52-
*/
53-
predicate isPublic() { this.hasModifier("public") and not this.isInternal() }
63+
/** Holds if this element has a `public` modifier or is implicitly public. */
64+
predicate isPublic() { this.hasModifier("public") }
5465

5566
/** Holds if this element has a `protected` modifier. */
5667
predicate isProtected() { this.hasModifier("protected") }

java/ql/test/kotlin/library-tests/java_and_kotlin_internal/visibility.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
isPublic
22
isInternal
33
| Kotlin.kt:2:11:3:2 | kotlinFun$main |
4+
modifiers_methods
5+
| file://:0:0:0:0 | final | Kotlin.kt:2:11:3:2 | kotlinFun$main |
6+
| file://:0:0:0:0 | internal | Kotlin.kt:2:11:3:2 | kotlinFun$main |
47
#select
58
| Kotlin.kt:2:11:3:2 | kotlinFun$main | final |
69
| Kotlin.kt:2:11:3:2 | kotlinFun$main | internal |
7-
| Kotlin.kt:2:11:3:2 | kotlinFun$main | public |

java/ql/test/kotlin/library-tests/java_and_kotlin_internal/visibility.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ select m, s
77
query predicate isPublic(Method m) { m.fromSource() and m.isPublic() }
88

99
query predicate isInternal(Method m) { m.fromSource() and m.isInternal() }
10+
11+
query predicate modifiers_methods(Modifier mo, Method me) {
12+
mo.getElement() = me and me.fromSource()
13+
}

0 commit comments

Comments
 (0)