Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9889f49

Browse files
tamasvajkigfoo
authored andcommitted
Add QL for ::class expression, and add test
1 parent e8a079b commit 9889f49

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,9 +2143,7 @@ class WhenExpr extends Expr, @whenexpr {
21432143
override string getAPrimaryQlClass() { result = "WhenExpr" }
21442144

21452145
/** Gets the `i`th branch. */
2146-
WhenBranch getBranch(int i) {
2147-
when_branch(result, this, i)
2148-
}
2146+
WhenBranch getBranch(int i) { when_branch(result, this, i) }
21492147
}
21502148

21512149
/** A Kotlin `when` branch. */
@@ -2163,3 +2161,13 @@ class WhenBranch extends Top, @whenbranch {
21632161

21642162
override string getAPrimaryQlClass() { result = "WhenBranch" }
21652163
}
2164+
2165+
/** A Kotlin `::class` expression. */
2166+
class ClassExpr extends Expr, @getclassexpr {
2167+
/** Gets the expression whose class is being returned. */
2168+
Expr getExpr() { result.isNthChildOf(this, 0) }
2169+
2170+
override string toString() { result = "::class" }
2171+
2172+
override string getAPrimaryQlClass() { result = "ClassExpr" }
2173+
}

java/ql/test/kotlin/library-tests/exprs/exprs.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@
4141
| exprs.kt:46:12:46:14 | 123 | IntegerLiteral |
4242
| exprs.kt:46:12:46:20 | ... + ... | AddExpr |
4343
| exprs.kt:46:18:46:20 | 456 | IntegerLiteral |
44+
| exprs.kt:50:13:50:16 | true | BooleanLiteral |
45+
| exprs.kt:50:13:50:23 | ::class | ClassExpr |
4446
| file://:0:0:0:0 | b1 | LocalVariableDeclExpr |
4547
| file://:0:0:0:0 | b2 | LocalVariableDeclExpr |
4648
| file://:0:0:0:0 | b6 | LocalVariableDeclExpr |
4749
| file://:0:0:0:0 | b7 | LocalVariableDeclExpr |
4850
| file://:0:0:0:0 | b8 | LocalVariableDeclExpr |
4951
| file://:0:0:0:0 | c | LocalVariableDeclExpr |
52+
| file://:0:0:0:0 | d | LocalVariableDeclExpr |
5053
| file://:0:0:0:0 | i1 | LocalVariableDeclExpr |
5154
| file://:0:0:0:0 | i2 | LocalVariableDeclExpr |
5255
| file://:0:0:0:0 | i3 | LocalVariableDeclExpr |

java/ql/test/kotlin/library-tests/exprs/exprs.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ TODO
4646
return 123 + 456
4747
}
4848

49+
fun getClass() {
50+
val d = true::class
51+
}

0 commit comments

Comments
 (0)