Skip to content

Commit 659f86c

Browse files
authored
Merge pull request github#11310 from tamasvajk/kotlin-dead-code
Kotlin: Exclude .kt files from dead code queries
2 parents 95fdea8 + 8b6bf91 commit 659f86c

File tree

8 files changed

+39
-0
lines changed

8 files changed

+39
-0
lines changed

java/ql/src/DeadCode/DeadClass.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import semmle.code.java.deadcode.DeadCode
1414

1515
from DeadClass c, Element origin, string reason
1616
where
17+
not c.getFile().isKotlinSourceFile() and
18+
not origin.getFile().isKotlinSourceFile() and
1719
if exists(DeadRoot root | root = c.getADeadRoot() | not root = c.getACallable())
1820
then (
1921
// Report a list of the dead roots.

java/ql/src/DeadCode/DeadField.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import semmle.code.java.deadcode.DeadCode
1515

1616
from DeadField f, Element origin, string reason
1717
where
18+
not f.getFile().isKotlinSourceFile() and
19+
not origin.getFile().isKotlinSourceFile() and
1820
not f.isInDeadScope() and
1921
if f.getAnAccess() instanceof FieldRead
2022
then (

java/ql/src/DeadCode/DeadMethod.ql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import semmle.code.java.deadcode.DeadCode
1515

1616
from DeadMethod c, Callable origin, string reason
1717
where
18+
not c.getFile().isKotlinSourceFile() and
19+
not origin.getFile().isKotlinSourceFile() and
1820
not c.isInDeadScope() and
1921
if exists(DeadRoot deadRoot | deadRoot = getADeadRoot(c) | deadRoot.getSourceDeclaration() != c)
2022
then (

java/ql/test/kotlin/query-tests/DeadCode/DeadClass.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DeadCode/DeadClass.ql

java/ql/test/kotlin/query-tests/DeadCode/DeadMethod.expected

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DeadCode/DeadMethod.ql
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sealed interface DbAddexpr
2+
3+
class Label<T> {
4+
}
5+
6+
fun <T> getFreshIdLabel(): Label<T> {
7+
return Label()
8+
}
9+
10+
fun foo(): Label<DbAddexpr> {
11+
val x = getFreshIdLabel<DbAddexpr>()
12+
return x
13+
}
14+
15+
fun main1() {
16+
print(foo())
17+
}
18+
19+
class Foo {
20+
data class DC(val x: Int, val y: Int)
21+
22+
fun foo() {
23+
val dc = DC(3, 4)
24+
print(dc.x)
25+
print(dc.y)
26+
}
27+
}
28+
29+
fun main2() {
30+
Foo().foo()
31+
}

0 commit comments

Comments
 (0)