Add test methods and data base on raw fir builder test data

This commit is contained in:
Ivan Cilcic
2019-08-15 00:45:00 +03:00
committed by Mikhail Glukhikh
parent fd8205e317
commit 8047aa22a4
50 changed files with 1664 additions and 0 deletions
+1
View File
@@ -47,6 +47,7 @@ dependencies {
testCompile(projectTests(":compiler:fir:psi2fir"))
testCompile(projectTests(":compiler:fir:fir2ir"))
testCompile(projectTests(":compiler:fir:resolve"))
testCompile(projectTests(":compiler:visualizer"))
testCompile(projectTests(":generators:test-generator"))
testCompile(project(":compiler:ir.ir2cfg"))
testCompile(project(":compiler:ir.tree")) // used for deepCopyWithSymbols call that is removed by proguard from the compiler TODO: make it more straightforward
@@ -54,6 +54,7 @@ import org.jetbrains.kotlin.resolve.constraintSystem.AbstractConstraintSystemTes
import org.jetbrains.kotlin.serialization.AbstractLocalClassProtoTest
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.types.AbstractTypeBindingTest
import org.jetbrains.kotlin.visualizer.AbstractPsiVisualizer
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -480,4 +481,9 @@ fun main(args: Array<String>) {
}
}
testGroup("compiler/visualizer/tests", "compiler/fir/psi2fir/testData") {
testClass<AbstractPsiVisualizer>("PsiVisualizerForRawFirDataGenerated") {
model("rawBuilder", testMethod = "doFirBuilderDataTest")
}
}
}
@@ -0,0 +1,4 @@
open class A
class B : A
@@ -0,0 +1,13 @@
abstract class A {
abstract class Nested
}
typealias TA = A
// fun TA.<init>(): TA /* = A */
// │
class B : TA() {
// constructor A.Nested()
// │
class NestedInB : Nested()
}
@@ -0,0 +1,21 @@
package p
abstract class My {
// constructor My()
// │
abstract class NestedOne : My() {
// constructor My.NestedOne()
// │
abstract class NestedTwo : NestedOne() {
}
}
}
// constructor My()
// │
class Your : My() {
// constructor My.NestedOne()
// │
class NestedThree : NestedOne()
}
@@ -0,0 +1,16 @@
package a.b
class C<T, out S> {
inner class D<R, in P> {
}
}
interface Test {
// C<out CharSequence, *>.D<in collections/List<*>, *>
// │ package a
// │ │ package a/b
// │ │ │ class C<T, S> collections/List<*>
// │ │ │ │ │
val x: a.b.C<out CharSequence, *>.D<in List<*>, *>
}
@@ -0,0 +1,11 @@
open class Base<T>(val x: T)
// constructor Base<T>(T)
// │ Derived.<init>.x: T
// │ │
class Derived<T : Any>(x: T) : Base<T>(x)
// constructor Derived<T : Any>(T)
// │ create.x: T
// │ │
fun <T : Any> create(x: T): Derived<T> = Derived(x)
@@ -0,0 +1,62 @@
import my.println
enum class Order {
FIRST,
SECOND,
THIRD
}
enum class Planet(val m: Double, internal val r: Double) {
// constructor Planet(Double, Double)
// │Double
// ││ Double
// ││ │
MERCURY(1.0, 2.0) {
override fun sayHello() {
// fun io/println(Any?): Unit
// │
println("Hello!!!")
}
},
// constructor Planet(Double, Double)
// │Double
// ││ Double
// ││ │
VENERA(3.0, 4.0) {
override fun sayHello() {
// fun io/println(Any?): Unit
// │
println("Ola!!!")
}
},
// constructor Planet(Double, Double)
// │Double
// ││ Double
// ││ │
EARTH(5.0, 6.0) {
override fun sayHello() {
// fun io/println(Any?): Unit
// │
println("Privet!!!")
}
};
// val (Planet/Companion).G: Double
// │ fun (Double).times(Double): Double
// │ │ val (Planet).m: Double
// │ │ │ fun (Double).div(Double): Double
// │ │ │ │ val (Planet).r: Double
// │ │ │ │ │ fun (Double).times(Double): Double
// Double │ │ │ │ │ │ val (Planet).r: Double
// │ │ │ │ │ │ │ │
val g: Double = G * m / (r * r)
abstract fun sayHello()
companion object {
// Double
// │ Double
// │ │
const val G = 6.67e-11
}
}
@@ -0,0 +1,28 @@
interface Some
object O1 : Some
object O2 : Some
enum class SomeEnum(val x: Some) {
// constructor SomeEnum(Some)
// │object O1: Some
// ││
FIRST(O1) {
// Boolean
// │
override fun check(y: Some): Boolean = true
},
// constructor SomeEnum(Some)
// │object O2: Some
// ││
SECOND(O2) {
// SomeEnum.SECOND.check.y: Some
// │ fun (Any).equals(Any?): Boolean
// │ │ object O2: Some
// │ │ │
override fun check(y: Some): Boolean = y == O2
};
abstract fun check(y: Some): Boolean
}
@@ -0,0 +1,15 @@
expect class MyClass
expect fun foo(): String
// Int
// │
expect val x: Int
actual class MyClass
actual fun foo() = "Hello"
// Int Int
// │ │
actual val x = 42
@@ -0,0 +1,15 @@
// fun ((T) -> Unit).invoke(T): Unit
// │
fun <T> simpleRun(f: (T) -> Unit): Unit = f()
// collections/List<T>
// │
fun <T, R> List<T>.simpleMap(f: (T) -> R): R {
}
// simpleWith.t: T
// │ fun T.invoke(): Unit
// │ │
fun <T> simpleWith(t: T, f: T.() -> Unit): Unit = t.f()
@@ -0,0 +1,7 @@
interface Any
inline fun <reified T : Any> Any.safeAs(): T? = this as? T
abstract class Summator {
abstract fun <T> plus(first: T, second: T): T
}
@@ -0,0 +1,7 @@
// fun TODO(): Nothing
// │
fun <T> genericFoo(): T = TODO()
// T fun <T> genericFoo(): T
// │ │
val <T> T.generic: T get() = genericFoo()
@@ -0,0 +1,12 @@
abstract class Base(val s: String)
class Outer {
// constructor Base(String)
// │ Outer.Derived.<init>.s: String
// │ │
class Derived(s: String) : Base(s)
// constructor Base(String)
// │
object Obj : Base("")
}
@@ -0,0 +1,14 @@
class NoPrimary {
// String
// │
val x: String
constructor(x: String) {
// val (NoPrimary).x: String
// │ NoPrimary.<init>.x: String
// │ │
this.x = x
}
constructor(): this("")
}
@@ -0,0 +1,37 @@
interface SomeInterface {
fun foo(x: Int, y: String): String
// Boolean
// │
val bar: Boolean
}
class SomeClass : SomeInterface {
// Int Int
// │ │
private val baz = 42
override fun foo(x: Int, y: String): String {
// SomeClass.foo.y: String
// │ fun (String).plus(Any?): String
// │ │ SomeClass.foo.x: Int
// │ │ │ fun (String).plus(Any?): String
// │ │ │ │ val (SomeClass).baz: Int
// │ │ │ │ │
return y + x + baz
}
// Boolean
// │
override var bar: Boolean
// Boolean
// │
get() = true
set(value) {}
// Double
// │
lateinit var fau: Double
}
inline class InlineClass
@@ -0,0 +1,3 @@
fun foo() {}
suspend fun bar() {}
@@ -0,0 +1,7 @@
interface B
typealias C = B
// C /* = B */
// │
class D : C
@@ -0,0 +1,9 @@
open class A
interface B<S, T : A>
typealias C<T> = B<T, A>
// C<A> /* = B<A, A> */
// │
class D : C<A>
@@ -0,0 +1,28 @@
package test
interface Some
abstract class My<T : Some> {
inner class T
// T
// │
abstract val x: T
abstract fun foo(arg: T)
// [ERROR : T]
// │ class My<T : Some>
// │ │
abstract val y: My.T
// [ERROR : T]
// │ package test
// │ │ class My<T : Some>
// │ │ │
abstract val z: test.My.T
// [ERROR : T]
// │
class Some : T()
}
@@ -0,0 +1,20 @@
interface List<out T : Any> {
operator fun get(index: Int): T
infix fun concat(other: List<T>): List<T>
}
typealias StringList = List<out String>
typealias AnyList = List<*>
abstract class AbstractList<out T : Any> : List<T>
// constructor AbstractList<T : Any>()
// │
class SomeList : AbstractList<Int>() {
// Int
// │
override fun get(index: Int): Int = 42
override fun concat(other: List<Int>): List<Int> = this
}
@@ -0,0 +1,6 @@
interface A
interface B
class C<T> where T : A, T : B {
}
@@ -0,0 +1,52 @@
//constructor annotation/Target(vararg annotation/AnnotationTarget)
//│ enum class annotation/AnnotationTarget: Enum<annotation/AnnotationTarget>
//│ │ enum entry annotation/AnnotationTarget.EXPRESSION
//│ │ │
@Target(AnnotationTarget.EXPRESSION)
//constructor annotation/Retention(annotation/AnnotationRetention = ...)
//│ enum class annotation/AnnotationRetention: Enum<annotation/AnnotationRetention>
//│ │ enum entry annotation/AnnotationRetention.SOURCE
//│ │ │
@Retention(AnnotationRetention.SOURCE)
annotation class Ann
fun foo(arg: Int): Int {
// constructor Ann()
// │ foo.arg: Int
// │ │ fun (Any).equals(Any?): Boolean
// Unit │ │ │ Int
// │ │ │ │ │
if (@Ann arg == 0) {
// constructor Ann()
// │ Int
// │ │
@Ann return 1
}
// constructor Ann()
// │ Unit
// │ │ foo.arg: Int
// │ │ │ fun (Any).equals(Any?): Boolean
// │ │ │ │ Int
// │ │ │ │ │
@Ann if (arg == 1) {
// constructor Ann()
// │ Int
// │ │
return (@Ann 1)
}
// Int
// │
return 42
}
data class Two(x: Int, y: Int)
fun bar(two: Two) {
// constructor Ann()
// │ [ERROR : component1() return type]
// │ │ constructor Ann()
// │ │ │ [ERROR : component2() return type]
// │ │ │ │ bar.two: Two
// │ │ │ │ │
val (@Ann x, @Ann y) = two
}
@@ -0,0 +1,23 @@
// Int Int
// │ │
val p = 0
// Int
// │
fun foo() = 1
class Wrapper(val v: IntArray)
// test.a: IntArray
// │ Int
// │ │ fun (Int).plus(Int): Int
// │ │ │ test.a: IntArray
// │ │ │ │ val p: Int
// │ │ │ │ │ fun (Int).plus(Int): Int
// │ │ │ │ │ │ test.a: IntArray
// │ │ │ │ │ │ │ fun foo(): Int
// │ │ │ │ │ │ │ │ fun (Int).plus(Int): Int
// │ │ │ │ │ │ │ │ │ test.w: Wrapper
// │ │ │ │ │ │ │ │ │ │ val (Wrapper).v: IntArray
// │ │ │ │ │ │ │ │ │ │ │ Int
// │ │ │ │ │ │ │ │ │ │ │ │
fun test(a: IntArray, w: Wrapper) = a[0] + a[p] + a[foo()] + w.v[0]
@@ -0,0 +1,28 @@
fun test() {
// IntArray
// │ fun intArrayOf(vararg Int): IntArray
// │ │ Int
// │ │ │ Int
// │ │ │ │ Int
// │ │ │ │ │
val x = intArrayOf(1, 2, 3)
// val test.x: IntArray
// │ Int Int
// │ │ │
x[1] = 0
}
// Int
// │
fun foo() = 1
fun test2() {
// fun intArrayOf(vararg Int): IntArray
// │ Int
// │ │ Int
// │ │ │ Int
// │ │ │ │ fun foo(): Int
// │ │ │ │ │ Int
// │ │ │ │ │ │
intArrayOf(1, 2, 3)[foo()] = 1
}
@@ -0,0 +1,90 @@
// foo.a: Int
// │ fun (Int).compareTo(Int): Int
// │ │ foo.b: Int
// │ │ │ foo.a: Int
// Int │ │ │ │ foo.b: Int
// │ │ │ │ │ │
fun foo(a: Int, b: Int) = if (a > b) a else b
fun bar(a: Double, b: Double): Double {
// Nothing
// │ bar.a: Double
// │ │ fun (Double).compareTo(Double): Int
// │ │ │ bar.b: Double
// │ │ │ │
if (a > b) {
// fun io/println(Double): Unit
// │ bar.a: Double
// │ │
println(a)
// bar.a: Double
// │
return a
} else {
// fun io/println(Double): Unit
// │ bar.b: Double
// │ │
println(b)
// bar.b: Double
// │
return b
}
}
fun baz(a: Long, b: Long): Long {
// Nothing
// │
when {
// baz.a: Long
// │ fun (Long).compareTo(Long): Int
// │ │ baz.b: Long
// │ │ │ Nothing
// │ │ │ │
a > b -> {
// fun io/println(Long): Unit
// │ baz.a: Long
// │ │
println(a)
// baz.a: Long
// │
return a
}
// Nothing
// │ baz.b: Long
// │ │
else -> return b
}
}
fun grade(g: Int): String {
// String
// │ grade.g: Int
// │ │
return when (g) {
// Int
// │ Int String
// │ │ │
6, 7 -> "Outstanding"
// Int String
// │ │
5 -> "Excellent"
// Int String
// │ │
4 -> "Good"
// Int String
// │ │
3 -> "Mediocre"
// fun (ranges/IntRange).contains(Int): Boolean
// │ Int
// │ │fun (Int).rangeTo(Int): ranges/IntRange
// │ ││ Int String
// │ ││ │ │
in 1..2 -> "Fail"
// String
// │
is Number -> "Number"
// String
// │
else -> "Unknown"
}
}
@@ -0,0 +1,51 @@
class A {
fun foo() {}
// Int Int
// │ │
val bar = 0
}
fun A.qux() {}
fun baz() {}
// reflect/KFunction0<Unit>
// │ constructor A()
// │ │ fun (A).foo(): Unit
// │ │ │
val test1 = A()::foo
// reflect/KProperty0<Int>
// │ constructor A()
// │ │ val (A).bar: Int
// │ │ │
val test2 = A()::bar
// reflect/KFunction0<Unit>
// │ constructor A()
// │ │ fun A.qux(): Unit
// │ │ │
val test3 = A()::qux
// reflect/KFunction1<A, Unit>
// │ class A
// │ │ fun (A).foo(): Unit
// │ │ │
val test4 = A::foo
// reflect/KProperty1<A, Int>
// │ class A
// │ │ val (A).bar: Int
// │ │ │
val test5 = A::bar
// reflect/KFunction1<A, Unit>
// │ class A
// │ │ fun A.qux(): Unit
// │ │ │
val test6 = A::qux
// reflect/KFunction0<Unit>
// │ fun baz(): Unit
// │ │
val test7 = ::baz
@@ -0,0 +1,67 @@
// distance.x: Int
// │ fun (Int).plus(Int): Int
// │ │ distance.y: Int
// │ │ │
infix fun distance(x: Int, y: Int) = x + y
// Int
// │ [ERROR: not resolved]
// │ │ Int
// │ │ │
fun test(): Int = 3 distance 4
// fun distance(Int, Int): Int
// │ Int
// │ │ Int
// │ │ │
fun testRegular(): Int = distance(3, 4)
class My(var x: Int) {
// var (My).x: Int
// │
operator fun invoke() = x
fun foo() {}
// constructor My(Int)
// │ var (My).x: Int
// │ │
fun copy() = My(x)
}
// constructor My(Int)
// fun (My).invoke(): Int
// │ Int
// │ │
fun testInvoke(): Int = My(13)()
fun testQualified(first: My, second: My?) {
// fun io/println(Int): Unit
// │ testQualified.first: My
// │ │ var (My).x: Int
// │ │ │
println(first.x)
// fun io/println(Any?): Unit
// │ testQualified.second: My?
// │ │ var (My).x: Int
// │ │ │
println(second?.x)
// testQualified.first: My
// │ fun (My).foo(): Unit
// │ │
first.foo()
// testQualified.second: My?
// │ fun (My).foo(): Unit
// │ │
second?.foo()
// testQualified.first: My
// │ fun (My).copy(): My
// │ │ fun (My).foo(): Unit
// │ │ │
first.copy().foo()
// testQualified.first: My
// │ var (My).x: Int
// │ │ Int
// │ │ │
first.x = 42
}
@@ -0,0 +1,27 @@
//WITH_RUNTIME
package test
class A
fun test() {
// class A
// │
A::class
// package test
// │
test.A::class
// constructor A()
// │
A()::class
// class A val <T> reflect/KClass<A>.java: java/lang/Class<A>
// │ │
A::class.java
// package test val <T> reflect/KClass<A>.java: java/lang/Class<A>
// │ │
test.A::class.java
// constructor A()
// │ val <T> reflect/KClass<out A>.java: java/lang/Class<out A>
// │ │
A()::class.java
}
@@ -0,0 +1,34 @@
annotation class Ann1(val arr: IntArray)
annotation class Ann2(val arr: DoubleArray)
annotation class Ann3(val arr: Array<String>)
//constructor Ann1(IntArray)
//│
@Ann1([])
//constructor Ann2(DoubleArray)
//│
@Ann2([])
//constructor Ann3(Array<String>)
//│
@Ann3([])
class Zero
//constructor Ann1(IntArray)
//│ Int
//│ │ Int
//│ │ │
@Ann1([1, 2])
class First
//constructor Ann2(DoubleArray)
//│ Double
//│ │
@Ann2([3.14])
class Second
//constructor Ann3(Array<String>)
//│
@Ann3(["Alpha", "Omega"])
class Third
@@ -0,0 +1,22 @@
data class Some(val first: Int, val second: Double, val third: String)
fun foo(some: Some) {
// Int
// │ Double
// │ │ String foo.some: Some
// │ │ │ │
var (x, y, z: String) = some
// var foo.x: Int
// │fun (Int).inc(): Int
// ││
x++
// var foo.y: Double
// │ fun (Double).times(Double): Double
// │ │ Double
// │ │ │
y *= 2.0
// var foo.z: String
// │
z = ""
}
@@ -0,0 +1,51 @@
fun foo() {
// Int
// │fun (Int).rangeTo(Int): ranges/IntRange
// ││ Int
// ││ │
for (i in 1..10) {
// fun io/println(Int): Unit
// │ val foo.i: Int
// │ │
println(i)
}
}
// collections/List<String>
// │
fun bar(list: List<String>) {
// bar.list: collections/List<String>
// │ fun (collections/List<String>).subList(Int, Int): collections/List<String>
// │ │ Int
// │ │ │ Int
// │ │ │ │
for (element in list.subList(0, 10)) {
// fun io/println(Any?): Unit
// │ val bar.element: String
// │ │
println(element)
}
// bar.list: collections/List<String>
// │ fun (collections/List<String>).subList(Int, Int): collections/List<String>
// │ │ fun io/println(Any?): Unit
// │ │ Int Int │ val bar.element: String
// │ │ │ │ │ │
for (element in list.subList(10, 20)) println(element)
}
data class Some(val x: Int, val y: Int)
// collections/Set<Some>
// │
fun baz(set: Set<Some>) {
// Int
// │ Int baz.set: collections/Set<Some>
// │ │ │
for ((x, y) in set) {
// fun io/println(Any?): Unit
// │ val baz.x: Int
// │ │ val baz.y: Int
// │ │ │
println("x = $x y = $y")
}
}
@@ -0,0 +1,18 @@
// Nothing?
// │
fun <T> nullableValue(): T? = null
fun test() {
// Int?
// │ fun <T> nullableValue(): Int?
// │ │
val n = nullableValue<Int>()
// Double?
// │ fun <T> nullableValue(): Double?
// │ │
val x = nullableValue<Double>()
// String?
// │ fun <T> nullableValue(): String?
// │ │
val s = nullableValue<String>()
}
@@ -0,0 +1,11 @@
// collections/Collection<Int>
// │
fun foo(x: Int, y: Int, c: Collection<Int>) =
// foo.x: Int
// │ fun (collections/Collection<Int>).contains(Int): Boolean
// │ │ foo.c: collections/Collection<Int>
// │ │ │ foo.y: Int
// │ │ │ │ fun (collections/Collection<Int>).contains(Int): Boolean
// │ │ │ │ │ foo.c: collections/Collection<Int>
// │ │ │ │ │ │
x in c && y !in c
@@ -0,0 +1,12 @@
class WithInit(x: Int) {
// Int
// │
val x: Int
init {
// val (WithInit).x: Int
// │ WithInit.<init>.x: Int
// │ │
this.x = x
}
}
@@ -0,0 +1,94 @@
data class Tuple(val x: Int, val y: Int)
// fun ((Tuple) -> Int).invoke(Tuple): Int
// │ constructor Tuple(Int, Int)
// │ │ Int
// │ │ │ Int
// │ │ │ │
inline fun use(f: (Tuple) -> Int) = f(Tuple(1, 2))
fun foo(): Int {
// (Tuple) -> Int
// │
val l1 = { t: Tuple ->
// foo.<anonymous>.t: Tuple
// Int │ val (Tuple).x: Int
// │ │ │
val x = t.x
// foo.<anonymous>.t: Tuple
// Int │ val (Tuple).y: Int
// │ │ │
val y = t.y
// val foo.<anonymous>.x: Int
// │ fun (Int).plus(Int): Int
// │ │ val foo.<anonymous>.y: Int
// │ │ │
x + y
}
// fun use((Tuple) -> Int): Int
// │ val foo.<anonymous>.x: Int
// │ Int │ fun (Int).plus(Int): Int
// │ │ Int │ │ val foo.<anonymous>.y: Int
// │ │ │ │ │ │
use { (x, y) -> x + y }
// fun use((Tuple) -> Int): Int
// │
return use {
// Unit
// │ foo.<anonymous>.it: Tuple
// │ │ val (Tuple).x: Int
// │ │ │ fun (Any).equals(Any?): Boolean
// │ │ │ │ Int Int
// │ │ │ │ │ │
if (it.x == 0) return@foo 0
// foo.<anonymous>.it: Tuple
// │ val (Tuple).y: Int
// │ │
return@use it.y
}
}
fun bar(): Int {
// fun use((Tuple) -> Int): Int
// │
return use lambda@{
// Unit
// │ bar.<anonymous>.it: Tuple
// │ │ val (Tuple).x: Int
// │ │ │ fun (Any).equals(Any?): Boolean
// │ │ │ │ Int Int
// │ │ │ │ │ │
if (it.x == 0) return@bar 0
// bar.<anonymous>.it: Tuple
// │ val (Tuple).y: Int
// │ │
return@lambda it.y
}
}
// collections/List<Int>
// │
fun test(list: List<Int>) {
// collections/MutableMap<Int, String>
// │ fun <K, V> collections/mutableMapOf(): collections/MutableMap<Int, String>
// │ │
val map = mutableMapOf<Int, String>()
// test.list: collections/List<Int>
// │ fun <T> collections/Iterable<Int>.forEach((Int) -> Unit): Unit
// │ │ val test.map: collections/MutableMap<Int, String>
// │ │ │ fun <K, V> collections/MutableMap<Int, String>.getOrPut(Int, () -> String): String
// │ │ │ │ test.<anonymous>.it: Int
// │ │ │ │ │ fun <T> collections/mutableListOf(): collections/MutableList<???>
// │ │ │ │ │ │ fun (String).plus(Any?): String
// │ │ │ │ │ │ │
list.forEach { map.getOrPut(it, { mutableListOf() }) += "" }
}
// () -> Unit
// │
val simple = { }
// () -> Int Int
// │ │
val another = { 42 }
@@ -0,0 +1,46 @@
fun withLocals(p: Int): Int {
class Local(val pp: Int) {
// val (withLocals/Local).pp: Int
// │ fun (Int).minus(Int): Int
// │ │ withLocals.p: Int
// │ │ │
fun diff() = pp - p
}
// constructor withLocals.Local(Int)
// Int │ Int fun (withLocals/Local).diff(): Int
// │ │ │ │
val x = Local(42).diff()
fun sum(y: Int, z: Int, f: (Int, Int) -> Int): Int {
// val withLocals.x: Int
// │ fun (Int).plus(Int): Int
// │ │ fun ((Int, Int) -> Int).invoke(Int, Int): Int
// │ │ │ withLocals.sum.y: Int
// │ │ │ │ fun (Int).plus(Int): Int
// │ │ │ │ │ withLocals.sum.z: Int
// │ │ │ │ │ │
return x + f(y + z)
}
// Int constructor Any()
// │ │
val code = (object : Any() {
// fun (Any).hashCode(): Int
// │
fun foo() = hashCode()
// fun (withLocals/<no name provided>).foo(): Int
// │
}).foo()
// fun withLocals.sum(Int, Int, (Int, Int) -> Int): Int
// │ val withLocals.code: Int
// │ │ constructor withLocals.Local(Int)
// │ │ │ Int
// │ │ │ │ fun (withLocals/Local).diff(): Int
// │ │ │ │ │ withLocals.<no name provided>.x: Int
// │ │ │ │ │ │ fun (Int).plus(Int): Int
// │ │ │ │ │ │ │ withLocals.<no name provided>.y: Int
// │ │ │ │ │ │ │ │
return sum(code, Local(1).diff(), fun(x: Int, y: Int) = x + y)
}
@@ -0,0 +1,44 @@
fun simple() {
// Int Int
// │ │
var x = 10
// var simple.x: Int
// │ fun (Int).plus(Int): Int
// │ │ Int
// │ │ │
x += 20
// var simple.x: Int
// │ fun (Int).minus(Int): Int
// │ │ Int
// │ │ │
x -= 5
// var simple.x: Int
// │ fun (Int).div(Int): Int
// │ │ Int
// │ │ │
x /= 5
// var simple.x: Int
// │ fun (Int).times(Int): Int
// │ │ Int
// │ │ │
x *= 10
}
// collections/List<String>
// │
fun List<String>.modify() {
// fun <T> collections/Collection<String>.plus(String): collections/List<String>
// │
this += "Alpha"
// fun <T> collections/Collection<String>.plus(String): collections/List<String>
// │
this += "Omega"
}
fun Any.modify() {
// collections/List<Int>
// │ fun <T> collections/Collection<Int>.plus(Int): collections/List<Int>
// │ │ Int
// │ │ │
(this as List<Int>) += 42
}
@@ -0,0 +1,26 @@
// Boolean Double
// │ │
fun foo(first: String = "", second: Boolean = true, third: Double = 3.1415) {}
fun test() {
// fun foo(String = ..., Boolean = ..., Double = ...): Unit
// │
foo()
// fun foo(String = ..., Boolean = ..., Double = ...): Unit
// │ Boolean
// │ │ Double
// │ │ │
foo("Alpha", false, 2.71)
// fun foo(String = ..., Boolean = ..., Double = ...): Unit
// │ Boolean
// │ │
foo(first = "Hello", second = true)
// fun foo(String = ..., Boolean = ..., Double = ...): Unit
// │ fun (Double).unaryMinus(): Double
// │ │Double
// │ ││
foo(third = -1.0, first = "123")
// fun foo(String = ..., Boolean = ..., Double = ...): Unit
// │
foo(= "")
}
@@ -0,0 +1,10 @@
// orFourtyTwo.arg: Int?
// │ fun ?: (Int?, Int): Int
// │ │ Int
// │ │ │
fun orFourtyTwo(arg: Int?) = arg ?: 42
// bang.arg: Int?
// │ fun !! (Int?): Int
// │ │
fun bang(arg: Int?) = arg!!
@@ -0,0 +1,7 @@
fun foo() {
return
}
fun bar(): String {
return "Hello"
}
@@ -0,0 +1,25 @@
interface A {
fun foo() {}
}
interface B {
fun foo() {}
fun bar() {}
}
class C : A, B {
override fun bar() {
// fun (B).bar(): Unit
// │
super.bar()
}
override fun foo() {
// fun (A).foo(): Unit
// │
super<A>.foo()
// fun (B).foo(): Unit
// │
super<B>.foo()
}
}
@@ -0,0 +1,42 @@
class Some {
// Int
// │
fun foo(): Int = 1
fun bar(): Int {
// fun (Some).foo(): Int
// │
return this.foo()
}
// Some
// │
val instance: Some
get() = this@Some
fun String.extension(): Int {
// fun (Some).bar(): Int
// │ fun (Int).plus(Int): Int
// │ │ val (String).length: Int
// │ │ │
return this@Some.bar() + this.length
}
}
// fun (Some).bar(): Int
// │
fun Some.extension() = this.bar()
fun test(some: Some): Int {
// fun <T, R> with(Some, Some.() -> Int): Int
// │ test.some: Some
// │ │ with@0
// │ │ │
return with(some) {
// fun (Some).foo(): Int
// │ fun (Int).plus(Int): Int
// │ │ fun Some.extension(): Int
// │ │ │
this.foo() + this@with.extension()
}
}
@@ -0,0 +1,23 @@
fun some() {
try {
// constructor KotlinNullPointerException()
// │
throw KotlinNullPointerException()
// RuntimeException /* = java/lang/RuntimeException */
// │
} catch (e: RuntimeException) {
// fun io/println(Any?): Unit
// │
println("Runtime exception")
// Exception /* = java/lang/Exception */
// │
} catch (e: Exception) {
// fun io/println(Any?): Unit
// │
println("Some exception")
} finally {
// fun io/println(Any?): Unit
// │
println("finally")
}
}
@@ -0,0 +1,14 @@
interface IThing
// test1.x: Any
// │
fun test1(x: Any) = x is IThing
// test2.x: Any
// │
fun test2(x: Any) = x !is IThing
// test3.x: Any
// │
fun test3(x: Any) = x as IThing
// test4.x: Any
// │
fun test4(x: Any) = x as? IThing
@@ -0,0 +1,77 @@
fun test() {
// Int Int
// │ │
var x = 0
// var test.x: Int
// Int │fun (Int).inc(): Int
// │ ││
val x1 = x++
// fun (Int).inc(): Int
// Int │ var test.x: Int
// │ │ │
val x2 = ++x
// fun (Int).dec(): Int
// Int │ var test.x: Int
// │ │ │
val x3 = --x
// var test.x: Int
// Int │fun (Int).dec(): Int
// │ ││
val x4 = x--
// Unit
// │ fun (Boolean).not(): Boolean
// │ │ var test.x: Int
// │ │ │ fun (Any).equals(Any?): Boolean
// │ │ │ │ Int
// │ │ │ │ │
if (!(x == 0)) {
// fun io/println(Any?): Unit
// │
println("000")
}
}
class X(val i: Int)
fun test2(x: X) {
// test2.x: X
// │ val (X).i: Int
// Int │ │fun (Int).inc(): Int
// │ │ ││
val x1 = x.i++
// fun (Int).inc(): Int
// │ test2.x: X
// Int │ │ val (X).i: Int
// │ │ │ │
val x2 = ++x.i
}
fun test3(arr: Array<Int>) {
// test3.arr: Array<Int>
// │ Int
// Int │ │ fun (Int).inc(): Int
// │ │ │ │
val x1 = arr[0]++
// fun (Int).inc(): Int
// │ test3.arr: Array<Int>
// Int │ │ Int
// │ │ │ │
val x2 = ++arr[1]
}
class Y(val arr: Array<Int>)
fun test4(y: Y) {
// test4.y: Y
// │ val (Y).arr: Array<Int>
// │ │ Int
// Int │ │ │ fun (Int).inc(): Int
// │ │ │ │ │
val x1 = y.arr[0]++
// fun (Int).inc(): Int
// │ test4.y: Y
// │ │ val (Y).arr: Array<Int>
// Int │ │ │ Int
// │ │ │ │ │
val x2 = ++y.arr[1]
}
@@ -0,0 +1,29 @@
fun foo() {
// Int Int
// │ │
val x = 1
// val foo.x: Int
// │ fun (Int).plus(Int): Int
// Int │ │ Int
// │ │ │ │
var y = x + 1
// var foo.y: Int
// │ fun (Int).times(Int): Int
// Int │ │ Int
// │ │ │ │
val z = y * 2
// var foo.y: Int
// │ var foo.y: Int
// │ │ fun (Int).plus(Int): Int
// │ │ │ val foo.z: Int
// │ │ │ │
y = y + z
// var foo.y: Int
// │ fun (Int).minus(Int): Int
// Int │ │ val foo.x: Int
// │ │ │ │
val w = y - x
// val foo.w: Int
// │
return w
}
@@ -0,0 +1,61 @@
fun foo(limit: Int) {
// Int Int
// │ │
var k = 0
// var foo.k: Int
// │ fun (Int).compareTo(Int): Int
// │ │ foo.limit: Int
// │ │ │
some@ while (k < limit) {
// var foo.k: Int
// │fun (Int).inc(): Int
// ││
k++
// fun io/println(Int): Unit
// │ var foo.k: Int
// │ │
println(k)
// var foo.k: Int
// │ fun (Any).equals(Any?): Boolean
// │ │ Int
// │ │ │
while (k == 13) {
// var foo.k: Int
// │fun (Int).inc(): Int
// ││
k++
// Unit
// │ var foo.k: Int
// │ │ fun (Int).compareTo(Int): Int
// │ │ │ foo.limit: Int
// │ │ │ │
if (k < limit) break@some
// Unit
// │ var foo.k: Int
// │ │ fun (Int).compareTo(Int): Int
// │ │ │ foo.limit: Int
// │ │ │ │
if (k > limit) continue
}
}
}
fun bar(limit: Int) {
// Int bar.limit: Int
// │ │
var k = limit
do {
// var bar.k: Int
// │fun (Int).dec(): Int
// ││
k--
// fun io/println(Int): Unit
// │ var bar.k: Int
// │ │
println(k)
// var bar.k: Int
// │ fun (Int).compareTo(Int): Int
// │ │ Int
// │ │ │
} while (k >= 0)
}
@@ -0,0 +1,51 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.visualizer
import org.jetbrains.kotlin.checkers.KotlinMultiFileTestWithJava
import org.jetbrains.kotlin.compiler.visualizer.PsiRenderer
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.TestJdkKind
import java.io.File
abstract class AbstractPsiVisualizer: KotlinMultiFileTestWithJava<Void?, Void?>() {
lateinit var replacement: Pair<String, String>
override fun createTestModule(name: String): Void? = null
override fun createTestFile(module: Void?, fileName: String?, text: String?, directives: MutableMap<String, String>?): Void? = null
override fun doMultiFileTest(file: File, modules: MutableMap<String, ModuleAndDependencies>?, files: MutableList<Void?>) {
val environment = createEnvironment(file)
val ktFiles = environment.getSourceFiles()
val analysisResult = JvmResolveUtil.analyze(ktFiles, environment)
val renderer = PsiRenderer(ktFiles.first(), analysisResult)
val psiRenderResult = renderer.render()
val expectedPath = file.absolutePath.replace(replacement.first, replacement.second)
KotlinTestUtils.assertEqualsToFile(File(expectedPath), psiRenderResult)
}
override fun isKotlinSourceRootNeeded(): Boolean {
return true
}
override fun getTestJdkKind(file: File): TestJdkKind {
return TestJdkKind.FULL_JDK
}
override fun getConfigurationKind(): ConfigurationKind {
return ConfigurationKind.ALL
}
fun doFirBuilderDataTest(filePath: String) {
replacement = "fir\\psi2fir" to "visualizer"
doTest(filePath)
}
}
@@ -0,0 +1,287 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.visualizer;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class PsiVisualizerForRawFirDataGenerated extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInRawBuilder() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder/declarations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Declarations extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInDeclarations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder/declarations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("complexTypes.kt")
public void testComplexTypes() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/complexTypes.kt");
}
@TestMetadata("derivedClass.kt")
public void testDerivedClass() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/derivedClass.kt");
}
@TestMetadata("enums.kt")
public void testEnums() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/enums.kt");
}
@TestMetadata("enums2.kt")
public void testEnums2() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/enums2.kt");
}
@TestMetadata("expectActual.kt")
public void testExpectActual() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/expectActual.kt");
}
@TestMetadata("F.kt")
public void testF() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/F.kt");
}
@TestMetadata("functionTypes.kt")
public void testFunctionTypes() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/functionTypes.kt");
}
@TestMetadata("genericFunctions.kt")
public void testGenericFunctions() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/genericFunctions.kt");
}
@TestMetadata("genericProperty.kt")
public void testGenericProperty() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/genericProperty.kt");
}
@TestMetadata("nestedClass.kt")
public void testNestedClass() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/nestedClass.kt");
}
@TestMetadata("NestedOfAliasedType.kt")
public void testNestedOfAliasedType() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/NestedOfAliasedType.kt");
}
@TestMetadata("NestedSuperType.kt")
public void testNestedSuperType() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/NestedSuperType.kt");
}
@TestMetadata("noPrimaryConstructor.kt")
public void testNoPrimaryConstructor() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/noPrimaryConstructor.kt");
}
@TestMetadata("simpleClass.kt")
public void testSimpleClass() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleClass.kt");
}
@TestMetadata("simpleFun.kt")
public void testSimpleFun() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleFun.kt");
}
@TestMetadata("simpleTypeAlias.kt")
public void testSimpleTypeAlias() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/simpleTypeAlias.kt");
}
@TestMetadata("typeAliasWithGeneric.kt")
public void testTypeAliasWithGeneric() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeAliasWithGeneric.kt");
}
@TestMetadata("typeParameterVsNested.kt")
public void testTypeParameterVsNested() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameterVsNested.kt");
}
@TestMetadata("typeParameters.kt")
public void testTypeParameters() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/typeParameters.kt");
}
@TestMetadata("where.kt")
public void testWhere() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/declarations/where.kt");
}
}
@TestMetadata("compiler/fir/psi2fir/testData/rawBuilder/expressions")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Expressions extends AbstractPsiVisualizer {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doFirBuilderDataTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInExpressions() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/psi2fir/testData/rawBuilder/expressions"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("annotated.kt")
public void testAnnotated() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/annotated.kt");
}
@TestMetadata("arrayAccess.kt")
public void testArrayAccess() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAccess.kt");
}
@TestMetadata("arrayAssignment.kt")
public void testArrayAssignment() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/arrayAssignment.kt");
}
@TestMetadata("branches.kt")
public void testBranches() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/branches.kt");
}
@TestMetadata("callableReferences.kt")
public void testCallableReferences() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/callableReferences.kt");
}
@TestMetadata("calls.kt")
public void testCalls() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/calls.kt");
}
@TestMetadata("classReference.kt")
public void testClassReference() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/classReference.kt");
}
@TestMetadata("collectionLiterals.kt")
public void testCollectionLiterals() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/collectionLiterals.kt");
}
@TestMetadata("destructuring.kt")
public void testDestructuring() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/destructuring.kt");
}
@TestMetadata("for.kt")
public void testFor() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/for.kt");
}
@TestMetadata("genericCalls.kt")
public void testGenericCalls() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/genericCalls.kt");
}
@TestMetadata("in.kt")
public void testIn() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/in.kt");
}
@TestMetadata("init.kt")
public void testInit() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/init.kt");
}
@TestMetadata("lambda.kt")
public void testLambda() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/lambda.kt");
}
@TestMetadata("locals.kt")
public void testLocals() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/locals.kt");
}
@TestMetadata("modifications.kt")
public void testModifications() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/modifications.kt");
}
@TestMetadata("namedArgument.kt")
public void testNamedArgument() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/namedArgument.kt");
}
@TestMetadata("nullability.kt")
public void testNullability() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/nullability.kt");
}
@TestMetadata("simpleReturns.kt")
public void testSimpleReturns() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/simpleReturns.kt");
}
@TestMetadata("super.kt")
public void testSuper() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/super.kt");
}
@TestMetadata("these.kt")
public void testThese() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/these.kt");
}
@TestMetadata("try.kt")
public void testTry() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/try.kt");
}
@TestMetadata("typeOperators.kt")
public void testTypeOperators() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/typeOperators.kt");
}
@TestMetadata("unary.kt")
public void testUnary() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/unary.kt");
}
@TestMetadata("variables.kt")
public void testVariables() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/variables.kt");
}
@TestMetadata("while.kt")
public void testWhile() throws Exception {
runTest("compiler/fir/psi2fir/testData/rawBuilder/expressions/while.kt");
}
}
}