diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index 583dd618cba..991b72de8da 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -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 diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt index a93f54d75a1..77979ccca0c 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt @@ -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) { System.setProperty("java.awt.headless", "true") @@ -480,4 +481,9 @@ fun main(args: Array) { } } + testGroup("compiler/visualizer/tests", "compiler/fir/psi2fir/testData") { + testClass("PsiVisualizerForRawFirDataGenerated") { + model("rawBuilder", testMethod = "doFirBuilderDataTest") + } + } } diff --git a/compiler/visualizer/testData/rawBuilder/declarations/F.kt b/compiler/visualizer/testData/rawBuilder/declarations/F.kt new file mode 100644 index 00000000000..56206509976 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/F.kt @@ -0,0 +1,4 @@ +open class A + + +class B : A diff --git a/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt b/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt new file mode 100644 index 00000000000..f442350b34d --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt @@ -0,0 +1,13 @@ +abstract class A { + abstract class Nested +} + +typealias TA = A + +// fun TA.(): TA /* = A */ +// │ +class B : TA() { +// constructor A.Nested() +// │ + class NestedInB : Nested() +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/declarations/NestedSuperType.kt b/compiler/visualizer/testData/rawBuilder/declarations/NestedSuperType.kt new file mode 100644 index 00000000000..d98bd7697e4 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/NestedSuperType.kt @@ -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() +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt b/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt new file mode 100644 index 00000000000..f57d26fcbc5 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt @@ -0,0 +1,16 @@ +package a.b + +class C { + inner class D { + + } +} + +interface Test { +// C.D, *> +// │ package a +// │ │ package a/b +// │ │ │ class C collections/List<*> +// │ │ │ │ │ + val x: a.b.C.D, *> +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/declarations/derivedClass.kt b/compiler/visualizer/testData/rawBuilder/declarations/derivedClass.kt new file mode 100644 index 00000000000..5ccd35263e3 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/derivedClass.kt @@ -0,0 +1,11 @@ +open class Base(val x: T) + +// constructor Base(T) +// │ Derived..x: T +// │ │ +class Derived(x: T) : Base(x) + +// constructor Derived(T) +// │ create.x: T +// │ │ +fun create(x: T): Derived = Derived(x) diff --git a/compiler/visualizer/testData/rawBuilder/declarations/enums.kt b/compiler/visualizer/testData/rawBuilder/declarations/enums.kt new file mode 100644 index 00000000000..0472aacda4e --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/enums.kt @@ -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 + } +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/declarations/enums2.kt b/compiler/visualizer/testData/rawBuilder/declarations/enums2.kt new file mode 100644 index 00000000000..c5c45388d26 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/enums2.kt @@ -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 +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt b/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt new file mode 100644 index 00000000000..522af3324d2 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt @@ -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 diff --git a/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt b/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt new file mode 100644 index 00000000000..74917fb48f9 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt @@ -0,0 +1,15 @@ +// fun ((T) -> Unit).invoke(T): Unit +// │ +fun simpleRun(f: (T) -> Unit): Unit = f() + +// collections/List +// │ +fun List.simpleMap(f: (T) -> R): R { + +} + +// simpleWith.t: T +// │ fun T.invoke(): Unit +// │ │ +fun simpleWith(t: T, f: T.() -> Unit): Unit = t.f() + diff --git a/compiler/visualizer/testData/rawBuilder/declarations/genericFunctions.kt b/compiler/visualizer/testData/rawBuilder/declarations/genericFunctions.kt new file mode 100644 index 00000000000..a88e9c41a82 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/genericFunctions.kt @@ -0,0 +1,7 @@ +interface Any + +inline fun Any.safeAs(): T? = this as? T + +abstract class Summator { + abstract fun plus(first: T, second: T): T +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/declarations/genericProperty.kt b/compiler/visualizer/testData/rawBuilder/declarations/genericProperty.kt new file mode 100644 index 00000000000..8559bd1e707 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/genericProperty.kt @@ -0,0 +1,7 @@ +// fun TODO(): Nothing +// │ +fun genericFoo(): T = TODO() + +// T fun genericFoo(): T +// │ │ +val T.generic: T get() = genericFoo() diff --git a/compiler/visualizer/testData/rawBuilder/declarations/nestedClass.kt b/compiler/visualizer/testData/rawBuilder/declarations/nestedClass.kt new file mode 100644 index 00000000000..572e1653064 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/nestedClass.kt @@ -0,0 +1,12 @@ +abstract class Base(val s: String) + +class Outer { +// constructor Base(String) +// │ Outer.Derived..s: String +// │ │ + class Derived(s: String) : Base(s) + +// constructor Base(String) +// │ + object Obj : Base("") +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/noPrimaryConstructor.kt b/compiler/visualizer/testData/rawBuilder/declarations/noPrimaryConstructor.kt new file mode 100644 index 00000000000..5a2d35e9013 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/noPrimaryConstructor.kt @@ -0,0 +1,14 @@ +class NoPrimary { +// String +// │ + val x: String + + constructor(x: String) { +// val (NoPrimary).x: String +// │ NoPrimary..x: String +// │ │ + this.x = x + } + + constructor(): this("") +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/simpleClass.kt b/compiler/visualizer/testData/rawBuilder/declarations/simpleClass.kt new file mode 100644 index 00000000000..d138d0c1dd1 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/simpleClass.kt @@ -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 \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/declarations/simpleFun.kt b/compiler/visualizer/testData/rawBuilder/declarations/simpleFun.kt new file mode 100644 index 00000000000..1a3d7d35be4 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/simpleFun.kt @@ -0,0 +1,3 @@ +fun foo() {} + +suspend fun bar() {} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt b/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt new file mode 100644 index 00000000000..19283c62fe5 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt @@ -0,0 +1,7 @@ +interface B + +typealias C = B + +// C /* = B */ +// │ +class D : C \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/declarations/typeAliasWithGeneric.kt b/compiler/visualizer/testData/rawBuilder/declarations/typeAliasWithGeneric.kt new file mode 100644 index 00000000000..2e914b73ef4 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/typeAliasWithGeneric.kt @@ -0,0 +1,9 @@ +open class A + +interface B + +typealias C = B + +// C /* = B */ +// │ +class D : C diff --git a/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt b/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt new file mode 100644 index 00000000000..4e7c545c34f --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt @@ -0,0 +1,28 @@ +package test + +interface Some + +abstract class My { + inner class T + +// T +// │ + abstract val x: T + + abstract fun foo(arg: T) + +// [ERROR : T] +// │ class My +// │ │ + abstract val y: My.T + +// [ERROR : T] +// │ package test +// │ │ class My +// │ │ │ + abstract val z: test.My.T + +// [ERROR : T] +// │ + class Some : T() +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt b/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt new file mode 100644 index 00000000000..d207ef3548d --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt @@ -0,0 +1,20 @@ +interface List { + operator fun get(index: Int): T + + infix fun concat(other: List): List +} + +typealias StringList = List +typealias AnyList = List<*> + +abstract class AbstractList : List + +// constructor AbstractList() +// │ +class SomeList : AbstractList() { +// Int +// │ + override fun get(index: Int): Int = 42 + + override fun concat(other: List): List = this +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/where.kt b/compiler/visualizer/testData/rawBuilder/declarations/where.kt new file mode 100644 index 00000000000..2dfb8095b21 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/declarations/where.kt @@ -0,0 +1,6 @@ +interface A +interface B + +class C where T : A, T : B { + +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/annotated.kt b/compiler/visualizer/testData/rawBuilder/expressions/annotated.kt new file mode 100644 index 00000000000..819770b6583 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/annotated.kt @@ -0,0 +1,52 @@ +//constructor annotation/Target(vararg annotation/AnnotationTarget) +//│ enum class annotation/AnnotationTarget: Enum +//│ │ enum entry annotation/AnnotationTarget.EXPRESSION +//│ │ │ +@Target(AnnotationTarget.EXPRESSION) +//constructor annotation/Retention(annotation/AnnotationRetention = ...) +//│ enum class annotation/AnnotationRetention: Enum +//│ │ 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 +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt b/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt new file mode 100644 index 00000000000..9225f861cd2 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt @@ -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] diff --git a/compiler/visualizer/testData/rawBuilder/expressions/arrayAssignment.kt b/compiler/visualizer/testData/rawBuilder/expressions/arrayAssignment.kt new file mode 100644 index 00000000000..e43b71bb3d6 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/arrayAssignment.kt @@ -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 +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/branches.kt b/compiler/visualizer/testData/rawBuilder/expressions/branches.kt new file mode 100644 index 00000000000..1c8381b5a27 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/branches.kt @@ -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" + } +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/callableReferences.kt b/compiler/visualizer/testData/rawBuilder/expressions/callableReferences.kt new file mode 100644 index 00000000000..8892a004a91 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/callableReferences.kt @@ -0,0 +1,51 @@ +class A { + fun foo() {} +// Int Int +// │ │ + val bar = 0 +} + +fun A.qux() {} + +fun baz() {} + +// reflect/KFunction0 +// │ constructor A() +// │ │ fun (A).foo(): Unit +// │ │ │ +val test1 = A()::foo + +// reflect/KProperty0 +// │ constructor A() +// │ │ val (A).bar: Int +// │ │ │ +val test2 = A()::bar + +// reflect/KFunction0 +// │ constructor A() +// │ │ fun A.qux(): Unit +// │ │ │ +val test3 = A()::qux + +// reflect/KFunction1 +// │ class A +// │ │ fun (A).foo(): Unit +// │ │ │ +val test4 = A::foo + +// reflect/KProperty1 +// │ class A +// │ │ val (A).bar: Int +// │ │ │ +val test5 = A::bar + +// reflect/KFunction1 +// │ class A +// │ │ fun A.qux(): Unit +// │ │ │ +val test6 = A::qux + +// reflect/KFunction0 +// │ fun baz(): Unit +// │ │ +val test7 = ::baz diff --git a/compiler/visualizer/testData/rawBuilder/expressions/calls.kt b/compiler/visualizer/testData/rawBuilder/expressions/calls.kt new file mode 100644 index 00000000000..413a0f80795 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/calls.kt @@ -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 +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/classReference.kt b/compiler/visualizer/testData/rawBuilder/expressions/classReference.kt new file mode 100644 index 00000000000..77d214ef4b3 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/classReference.kt @@ -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 reflect/KClass.java: java/lang/Class +// │ │ + A::class.java +// package test val reflect/KClass.java: java/lang/Class +// │ │ + test.A::class.java +// constructor A() +// │ val reflect/KClass.java: java/lang/Class +// │ │ + A()::class.java +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/collectionLiterals.kt b/compiler/visualizer/testData/rawBuilder/expressions/collectionLiterals.kt new file mode 100644 index 00000000000..36409ef9de0 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/collectionLiterals.kt @@ -0,0 +1,34 @@ +annotation class Ann1(val arr: IntArray) + +annotation class Ann2(val arr: DoubleArray) + +annotation class Ann3(val arr: Array) + +//constructor Ann1(IntArray) +//│ +@Ann1([]) +//constructor Ann2(DoubleArray) +//│ +@Ann2([]) +//constructor Ann3(Array) +//│ +@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) +//│ +@Ann3(["Alpha", "Omega"]) +class Third diff --git a/compiler/visualizer/testData/rawBuilder/expressions/destructuring.kt b/compiler/visualizer/testData/rawBuilder/expressions/destructuring.kt new file mode 100644 index 00000000000..655f7733ac4 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/destructuring.kt @@ -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 = "" +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/for.kt b/compiler/visualizer/testData/rawBuilder/expressions/for.kt new file mode 100644 index 00000000000..33f5e722d6a --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/for.kt @@ -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 +// │ +fun bar(list: List) { +// bar.list: collections/List +// │ fun (collections/List).subList(Int, Int): collections/List +// │ │ Int +// │ │ │ Int +// │ │ │ │ + for (element in list.subList(0, 10)) { +// fun io/println(Any?): Unit +// │ val bar.element: String +// │ │ + println(element) + } +// bar.list: collections/List +// │ fun (collections/List).subList(Int, Int): collections/List +// │ │ 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 +// │ +fun baz(set: Set) { +// Int +// │ Int baz.set: collections/Set +// │ │ │ + for ((x, y) in set) { +// fun io/println(Any?): Unit +// │ val baz.x: Int +// │ │ val baz.y: Int +// │ │ │ + println("x = $x y = $y") + } +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt b/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt new file mode 100644 index 00000000000..64f18f808a4 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt @@ -0,0 +1,18 @@ +// Nothing? +// │ +fun nullableValue(): T? = null + +fun test() { +// Int? +// │ fun nullableValue(): Int? +// │ │ + val n = nullableValue() +// Double? +// │ fun nullableValue(): Double? +// │ │ + val x = nullableValue() +// String? +// │ fun nullableValue(): String? +// │ │ + val s = nullableValue() +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/in.kt b/compiler/visualizer/testData/rawBuilder/expressions/in.kt new file mode 100644 index 00000000000..03d07884f13 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/in.kt @@ -0,0 +1,11 @@ +// collections/Collection +// │ +fun foo(x: Int, y: Int, c: Collection) = +// foo.x: Int +// │ fun (collections/Collection).contains(Int): Boolean +// │ │ foo.c: collections/Collection +// │ │ │ foo.y: Int +// │ │ │ │ fun (collections/Collection).contains(Int): Boolean +// │ │ │ │ │ foo.c: collections/Collection +// │ │ │ │ │ │ + x in c && y !in c \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/init.kt b/compiler/visualizer/testData/rawBuilder/expressions/init.kt new file mode 100644 index 00000000000..29c9c2ab999 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/init.kt @@ -0,0 +1,12 @@ +class WithInit(x: Int) { +// Int +// │ + val x: Int + + init { +// val (WithInit).x: Int +// │ WithInit..x: Int +// │ │ + this.x = x + } +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/lambda.kt b/compiler/visualizer/testData/rawBuilder/expressions/lambda.kt new file mode 100644 index 00000000000..a229b81c18f --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/lambda.kt @@ -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..t: Tuple +// Int │ val (Tuple).x: Int +// │ │ │ + val x = t.x +// foo..t: Tuple +// Int │ val (Tuple).y: Int +// │ │ │ + val y = t.y +// val foo..x: Int +// │ fun (Int).plus(Int): Int +// │ │ val foo..y: Int +// │ │ │ + x + y + } +// fun use((Tuple) -> Int): Int +// │ val foo..x: Int +// │ Int │ fun (Int).plus(Int): Int +// │ │ Int │ │ val foo..y: Int +// │ │ │ │ │ │ + use { (x, y) -> x + y } + +// fun use((Tuple) -> Int): Int +// │ + return use { +// Unit +// │ foo..it: Tuple +// │ │ val (Tuple).x: Int +// │ │ │ fun (Any).equals(Any?): Boolean +// │ │ │ │ Int Int +// │ │ │ │ │ │ + if (it.x == 0) return@foo 0 +// foo..it: Tuple +// │ val (Tuple).y: Int +// │ │ + return@use it.y + } +} + +fun bar(): Int { +// fun use((Tuple) -> Int): Int +// │ + return use lambda@{ +// Unit +// │ bar..it: Tuple +// │ │ val (Tuple).x: Int +// │ │ │ fun (Any).equals(Any?): Boolean +// │ │ │ │ Int Int +// │ │ │ │ │ │ + if (it.x == 0) return@bar 0 +// bar..it: Tuple +// │ val (Tuple).y: Int +// │ │ + return@lambda it.y + } +} + +// collections/List +// │ +fun test(list: List) { +// collections/MutableMap +// │ fun collections/mutableMapOf(): collections/MutableMap +// │ │ + val map = mutableMapOf() +// test.list: collections/List +// │ fun collections/Iterable.forEach((Int) -> Unit): Unit +// │ │ val test.map: collections/MutableMap +// │ │ │ fun collections/MutableMap.getOrPut(Int, () -> String): String +// │ │ │ │ test..it: Int +// │ │ │ │ │ fun collections/mutableListOf(): collections/MutableList +// │ │ │ │ │ │ fun (String).plus(Any?): String +// │ │ │ │ │ │ │ + list.forEach { map.getOrPut(it, { mutableListOf() }) += "" } +} + +// () -> Unit +// │ +val simple = { } + +// () -> Int Int +// │ │ +val another = { 42 } \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/locals.kt b/compiler/visualizer/testData/rawBuilder/expressions/locals.kt new file mode 100644 index 00000000000..491b022b7ba --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/locals.kt @@ -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/).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..x: Int +// │ │ │ │ │ │ fun (Int).plus(Int): Int +// │ │ │ │ │ │ │ withLocals..y: Int +// │ │ │ │ │ │ │ │ + return sum(code, Local(1).diff(), fun(x: Int, y: Int) = x + y) +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/modifications.kt b/compiler/visualizer/testData/rawBuilder/expressions/modifications.kt new file mode 100644 index 00000000000..b91e077d789 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/modifications.kt @@ -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 +// │ +fun List.modify() { +// fun collections/Collection.plus(String): collections/List +// │ + this += "Alpha" +// fun collections/Collection.plus(String): collections/List +// │ + this += "Omega" +} + +fun Any.modify() { +// collections/List +// │ fun collections/Collection.plus(Int): collections/List +// │ │ Int +// │ │ │ + (this as List) += 42 +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/namedArgument.kt b/compiler/visualizer/testData/rawBuilder/expressions/namedArgument.kt new file mode 100644 index 00000000000..bd2b8d5dd7b --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/namedArgument.kt @@ -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(= "") +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/nullability.kt b/compiler/visualizer/testData/rawBuilder/expressions/nullability.kt new file mode 100644 index 00000000000..cc59f8837a5 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/nullability.kt @@ -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!! \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/simpleReturns.kt b/compiler/visualizer/testData/rawBuilder/expressions/simpleReturns.kt new file mode 100644 index 00000000000..54b503130cf --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/simpleReturns.kt @@ -0,0 +1,7 @@ +fun foo() { + return +} + +fun bar(): String { + return "Hello" +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/super.kt b/compiler/visualizer/testData/rawBuilder/expressions/super.kt new file mode 100644 index 00000000000..b21710d7dd4 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/super.kt @@ -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.foo() +// fun (B).foo(): Unit +// │ + super.foo() + } +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/these.kt b/compiler/visualizer/testData/rawBuilder/expressions/these.kt new file mode 100644 index 00000000000..f6bde914494 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/these.kt @@ -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 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() + } +} \ No newline at end of file diff --git a/compiler/visualizer/testData/rawBuilder/expressions/try.kt b/compiler/visualizer/testData/rawBuilder/expressions/try.kt new file mode 100644 index 00000000000..8403f89b388 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/try.kt @@ -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") + } +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt b/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt new file mode 100644 index 00000000000..d9a333fde50 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt @@ -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 diff --git a/compiler/visualizer/testData/rawBuilder/expressions/unary.kt b/compiler/visualizer/testData/rawBuilder/expressions/unary.kt new file mode 100644 index 00000000000..6667bd964d6 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/unary.kt @@ -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) { +// test3.arr: Array +// │ Int +// Int │ │ fun (Int).inc(): Int +// │ │ │ │ + val x1 = arr[0]++ +// fun (Int).inc(): Int +// │ test3.arr: Array +// Int │ │ Int +// │ │ │ │ + val x2 = ++arr[1] +} + +class Y(val arr: Array) + +fun test4(y: Y) { +// test4.y: Y +// │ val (Y).arr: Array +// │ │ Int +// Int │ │ │ fun (Int).inc(): Int +// │ │ │ │ │ + val x1 = y.arr[0]++ +// fun (Int).inc(): Int +// │ test4.y: Y +// │ │ val (Y).arr: Array +// Int │ │ │ Int +// │ │ │ │ │ + val x2 = ++y.arr[1] +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/variables.kt b/compiler/visualizer/testData/rawBuilder/expressions/variables.kt new file mode 100644 index 00000000000..8598d4ce3e6 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/variables.kt @@ -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 +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/while.kt b/compiler/visualizer/testData/rawBuilder/expressions/while.kt new file mode 100644 index 00000000000..156a84f4f63 --- /dev/null +++ b/compiler/visualizer/testData/rawBuilder/expressions/while.kt @@ -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) +} diff --git a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt new file mode 100644 index 00000000000..dd47d113553 --- /dev/null +++ b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt @@ -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() { + lateinit var replacement: Pair + + override fun createTestModule(name: String): Void? = null + + override fun createTestFile(module: Void?, fileName: String?, text: String?, directives: MutableMap?): Void? = null + + override fun doMultiFileTest(file: File, modules: MutableMap?, files: MutableList) { + 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) + } +} diff --git a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/PsiVisualizerForRawFirDataGenerated.java b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/PsiVisualizerForRawFirDataGenerated.java new file mode 100644 index 00000000000..cf397aae07a --- /dev/null +++ b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/PsiVisualizerForRawFirDataGenerated.java @@ -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"); + } + } +}