File tree Expand file tree Collapse file tree 8 files changed +51
-0
lines changed
test/kotlin/query-tests/DeadCode Expand file tree Collapse file tree 8 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ import semmle.code.java.deadcode.DeadCode
14
14
15
15
from DeadClass c , Element origin , string reason
16
16
where
17
+ not c .getFile ( ) .isKotlinSourceFile ( ) and
18
+ not origin .getFile ( ) .isKotlinSourceFile ( ) and
17
19
if exists ( DeadRoot root | root = c .getADeadRoot ( ) | not root = c .getACallable ( ) )
18
20
then (
19
21
// Report a list of the dead roots.
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import semmle.code.java.deadcode.DeadCode
15
15
16
16
from DeadField f , Element origin , string reason
17
17
where
18
+ not f .getFile ( ) .isKotlinSourceFile ( ) and
19
+ not origin .getFile ( ) .isKotlinSourceFile ( ) and
18
20
not f .isInDeadScope ( ) and
19
21
if f .getAnAccess ( ) instanceof FieldRead
20
22
then (
Original file line number Diff line number Diff line change @@ -15,6 +15,8 @@ import semmle.code.java.deadcode.DeadCode
15
15
16
16
from DeadMethod c , Callable origin , string reason
17
17
where
18
+ not c .getFile ( ) .isKotlinSourceFile ( ) and
19
+ not origin .getFile ( ) .isKotlinSourceFile ( ) and
18
20
not c .isInDeadScope ( ) and
19
21
if exists ( DeadRoot deadRoot | deadRoot = getADeadRoot ( c ) | deadRoot .getSourceDeclaration ( ) != c )
20
22
then (
Original file line number Diff line number Diff line change
1
+ | Test.kt:0:0:0:0 | TestKt | The class TestKt is entirely unused. | Test.kt:0:0:0:0 | TestKt | TestKt |
2
+ | Test.kt:1:1:1:26 | DbAddexpr | The class DbAddexpr is entirely unused. | Test.kt:1:1:1:26 | DbAddexpr | DbAddexpr |
3
+ | Test.kt:3:1:4:1 | Label | The class Label is only used from dead code originating at $@. | Test.kt:15:1:17:1 | main1 | main1 |
4
+ | Test.kt:19:1:27:1 | Foo | The class Foo is only used from dead code originating at $@. | Test.kt:29:1:31:1 | main2 | main2 |
Original file line number Diff line number Diff line change
1
+ DeadCode/DeadClass.ql
Original file line number Diff line number Diff line change
1
+ | Test.kt:0:0:0:0 | component1 | The method component1 is entirely unused. | Test.kt:0:0:0:0 | component1 | component1 |
2
+ | Test.kt:0:0:0:0 | component2 | The method component2 is entirely unused. | Test.kt:0:0:0:0 | component2 | component2 |
3
+ | Test.kt:0:0:0:0 | copy | The method copy is only used from dead code originating at $@. | Test.kt:0:0:0:0 | copy$default | copy$default |
4
+ | Test.kt:0:0:0:0 | copy$default | The method copy$default is entirely unused. | Test.kt:0:0:0:0 | copy$default | copy$default |
5
+ | Test.kt:20:10:20:41 | DC | The method DC is only used from dead code originating at $@. | Test.kt:0:0:0:0 | copy$default | copy$default |
6
+ | Test.kt:20:10:20:41 | DC | The method DC is only used from dead code originating at $@. | Test.kt:29:1:31:1 | main2 | main2 |
7
+ | Test.kt:20:19:20:28 | getX | The method getX is only used from dead code originating at $@. | Test.kt:29:1:31:1 | main2 | main2 |
8
+ | Test.kt:20:31:20:40 | getY | The method getY is only used from dead code originating at $@. | Test.kt:29:1:31:1 | main2 | main2 |
Original file line number Diff line number Diff line change
1
+ DeadCode/DeadMethod.ql
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments