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

Skip to content

Commit c35f871

Browse files
committed
Kotlin: Add tests for file classes
1 parent 43f5088 commit c35f871

8 files changed

Lines changed: 87 additions & 4 deletions

File tree

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
| file1.kt:0:0:0:0 | File1Kt | File1Kt |
2-
| file1.kt:2:1:2:16 | Class1 | Class1 |
2+
| file1.kt:2:1:13:1 | Class1 | Class1 |
33
| file2.kt:0:0:0:0 | File2Kt | File2Kt |
4-
| file2.kt:2:1:2:16 | Class2 | Class2 |
4+
| file2.kt:2:1:4:1 | Class2 | Class2 |
55
| file3.kt:0:0:0:0 | MyJvmName | MyJvmName |
66
| file3.kt:3:1:3:16 | Class3 | Class3 |
7+
| file4.kt:0:0:0:0 | File4Kt | File4Kt |
8+
| file4.kt:2:1:2:16 | Class4 | Class4 |
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11

2-
class Class1 { }
2+
class Class1 {
3+
fun fun1() {
4+
Class2().fun2()
5+
fun3()
6+
fun4()
7+
8+
// libraries/stdlib/jvm/runtime/kotlin/jvm/internal/CollectionToArray.kt
9+
// has a @file:JvmName("CollectionToArray") annotation, and contains
10+
// a function collectionToArray with a @JvmName("toArray") annotation.
11+
kotlin.jvm.internal.collectionToArray(listOf(1))
12+
}
13+
}
314

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11

2-
class Class2 { }
2+
class Class2 {
3+
fun fun2() { }
4+
}
35

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
class Class4 { }
3+
4+
fun fun4() {
5+
}
6+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| file1.kt:2:1:13:1 | <obinit>(...) | file1.kt:2:1:13:1 | <obinit> | Class1.<obinit> | file1.kt:2:1:13:1 | Class1 |
2+
| file1.kt:4:18:4:23 | fun2(...) | file2.kt:3:5:3:18 | fun2 | Class2.fun2 | file2.kt:2:1:4:1 | Class2 |
3+
| file1.kt:5:9:5:14 | fun3(...) | file3.kt:5:1:6:1 | fun3 | MyJvmName.fun3 | file3.kt:0:0:0:0 | MyJvmName |
4+
| file1.kt:6:9:6:14 | fun4(...) | file4.kt:4:1:5:1 | fun4 | File4Kt.fun4 | file4.kt:0:0:0:0 | File4Kt |
5+
| file1.kt:11:29:11:56 | collectionToArray(...) | file://<external>/CollectionToArray.class:0:0:0:0 | collectionToArray | CollectionToArray.collectionToArray | file://<external>/CollectionToArray.class:0:0:0:0 | CollectionToArray |
6+
| file1.kt:11:47:11:55 | listOf(...) | file://<external>/CollectionsKt.class:0:0:0:0 | listOf | CollectionsKt.listOf | file://<external>/CollectionsKt.class:0:0:0:0 | CollectionsKt |
7+
| file2.kt:2:1:4:1 | <obinit>(...) | file2.kt:2:1:4:1 | <obinit> | Class2.<obinit> | file2.kt:2:1:4:1 | Class2 |
8+
| file3.kt:3:1:3:16 | <obinit>(...) | file3.kt:3:1:3:16 | <obinit> | Class3.<obinit> | file3.kt:3:1:3:16 | Class3 |
9+
| file4.kt:2:1:2:16 | <obinit>(...) | file4.kt:2:1:2:16 | <obinit> | Class4.<obinit> | file4.kt:2:1:2:16 | Class4 |
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java
2+
3+
// Stop external filepaths from appearing in the results
4+
class ClassLocation extends Class {
5+
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
6+
exists(string fullPath |
7+
super.hasLocationInfo(fullPath, sl, sc, el, ec) |
8+
if exists(this.getFile().getRelativePath())
9+
then path = fullPath
10+
else path = fullPath.regexpReplaceAll(".*/", "<external>/"))
11+
}
12+
}
13+
class MethodLocation extends Method {
14+
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
15+
exists(string fullPath |
16+
super.hasLocationInfo(fullPath, sl, sc, el, ec) |
17+
if exists(this.getFile().getRelativePath())
18+
then path = fullPath
19+
else path = fullPath.regexpReplaceAll(".*/", "<external>/"))
20+
}
21+
}
22+
23+
from MethodAccess ma, Method m
24+
where ma.getFile().(CompilationUnit).fromSource()
25+
and m = ma.getMethod()
26+
select ma, m, m.getQualifiedName(), m.getDeclaringType()
27+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| file1.kt:2:1:13:1 | <obinit> | Class1.<obinit> | file1.kt:2:1:13:1 | Class1 |
2+
| file1.kt:2:1:13:1 | equals | Class1.equals | file1.kt:2:1:13:1 | Class1 |
3+
| file1.kt:2:1:13:1 | hashCode | Class1.hashCode | file1.kt:2:1:13:1 | Class1 |
4+
| file1.kt:2:1:13:1 | toString | Class1.toString | file1.kt:2:1:13:1 | Class1 |
5+
| file1.kt:3:5:12:5 | fun1 | Class1.fun1 | file1.kt:2:1:13:1 | Class1 |
6+
| file2.kt:2:1:4:1 | <obinit> | Class2.<obinit> | file2.kt:2:1:4:1 | Class2 |
7+
| file2.kt:2:1:4:1 | equals | Class2.equals | file2.kt:2:1:4:1 | Class2 |
8+
| file2.kt:2:1:4:1 | hashCode | Class2.hashCode | file2.kt:2:1:4:1 | Class2 |
9+
| file2.kt:2:1:4:1 | toString | Class2.toString | file2.kt:2:1:4:1 | Class2 |
10+
| file2.kt:3:5:3:18 | fun2 | Class2.fun2 | file2.kt:2:1:4:1 | Class2 |
11+
| file3.kt:3:1:3:16 | <obinit> | Class3.<obinit> | file3.kt:3:1:3:16 | Class3 |
12+
| file3.kt:3:1:3:16 | equals | Class3.equals | file3.kt:3:1:3:16 | Class3 |
13+
| file3.kt:3:1:3:16 | hashCode | Class3.hashCode | file3.kt:3:1:3:16 | Class3 |
14+
| file3.kt:3:1:3:16 | toString | Class3.toString | file3.kt:3:1:3:16 | Class3 |
15+
| file3.kt:5:1:6:1 | fun3 | MyJvmName.fun3 | file3.kt:0:0:0:0 | MyJvmName |
16+
| file4.kt:2:1:2:16 | <obinit> | Class4.<obinit> | file4.kt:2:1:2:16 | Class4 |
17+
| file4.kt:2:1:2:16 | equals | Class4.equals | file4.kt:2:1:2:16 | Class4 |
18+
| file4.kt:2:1:2:16 | hashCode | Class4.hashCode | file4.kt:2:1:2:16 | Class4 |
19+
| file4.kt:2:1:2:16 | toString | Class4.toString | file4.kt:2:1:2:16 | Class4 |
20+
| file4.kt:4:1:5:1 | fun4 | File4Kt.fun4 | file4.kt:0:0:0:0 | File4Kt |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java
2+
3+
from Method m
4+
where m.fromSource()
5+
select m, m.getQualifiedName(), m.getDeclaringType()
6+

0 commit comments

Comments
 (0)