diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt index 77979ccca0c..0bdf02e8dfe 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateCompilerTests.kt @@ -486,4 +486,10 @@ fun main(args: Array) { model("rawBuilder", testMethod = "doFirBuilderDataTest") } } + + testGroup("compiler/visualizer/tests", "compiler/visualizer/testData") { + testClass("PsiVisualizerForUncommonCasesGenerated") { + model("uncommonCases/testFiles", testMethod = "doUncommonCasesTest") + } + } } diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt new file mode 100644 index 00000000000..5ce3e32094f --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt @@ -0,0 +1,89 @@ +package p + +class A { +// Int Int +// │ │ + val aProp = 10 +} + +class B { +// Int Int +// │ │ + val bProp = 1 +} + +fun foo(a: Int, b: Int): Int { +// fun with(A, A.() -> Int): Int +// │ constructor A() +// │ │ with@0 +// │ │ │ + with(A()) { +// this@0 +// val (A).aProp: Int +// │ + aProp + +// fun with(B, B.() -> Int): Int +// │ constructor B() +// │ │ with@1 +// │ │ │ + with(B()) { +// this@0 +// val (A).aProp: Int +// │ + aProp +// this@1 +// val (B).bProp: Int +// │ + bProp +// this@0 +// val (A).aProp: Int +// │ + aProp + } + } + +// fun with(A, A.() -> Int): Int +// │ constructor A() +// │ │ with@0 +// │ │ │ + with(A()) { +// this@0 +// val (A).aProp: Int +// │ + aProp + +// fun with(B, B.() -> Int): Int +// │ constructor B() +// │ │ with@1 +// │ │ │ + with(B()) { +// this@0 +// val (A).aProp: Int +// │ + aProp +// this@1 +// val (B).bProp: Int +// │ + bProp + } + +// fun with(B, B.() -> Int): Int +// │ constructor B() +// │ │ with@1 +// │ │ │ + with(B()) { +// this@0 +// val (A).aProp: Int +// │ + aProp +// this@1 +// val (B).bProp: Int +// │ + bProp + } + } +// foo.a: Int +// │ + return a +} diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt new file mode 100644 index 00000000000..00c8ff19d4a --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt @@ -0,0 +1,33 @@ +package org.jetbrains.kotlin.test + +// collections/List +// │ fun collections/listOf(vararg Int): collections/List +// │ │ Int +// │ │ │ Int +// │ │ │ │ Int +// │ │ │ │ │ +val listOfInt = listOf(1, 2, 3) +// java/util/ArrayList +// │ package java +// │ │ constructor util/ArrayList() +// │ │ │ +val javaList = java.util.ArrayList() + +// package java +// │ package java/util +// │ │ +fun move(): java.util.ArrayList { +// val listOfInt: collections/List +// │ + for (elem in listOfInt) { +// val javaList: java/util/ArrayList +// │ fun (java/util/ArrayList).add(Int): Boolean +// │ │ val move.elem: Int +// │ │ │ + javaList.add(elem) + } + +// val javaList: java/util/ArrayList +// │ + return javaList +} diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt new file mode 100644 index 00000000000..d6d68fff010 --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt @@ -0,0 +1,81 @@ +package org.jetbrains.kotlin.test + +// Int Int +// │ │ +val p1 = 10 +// Double Double +// │ │ +val p2: Double = 1.0 +// Float Float +// │ │ +val p3: Float = 2.5f +// String +// │ +val p4 = "some string" + +// Double +// │ val p1: Int +// │ │ fun (Int).plus(Double): Double +// │ │ │ val p2: Double +// │ │ │ │ +val p5 = p1 + p2 +// Double +// │ val p1: Int +// │ │ fun (Int).times(Double): Double +// │ │ │ val p2: Double +// │ │ │ │ fun (Double).plus(Double): Double +// │ │ │ │ │ val p5: Double +// │ │ │ │ │ │ fun (Double).minus(Float): Double +// │ │ │ │ │ │ │ val p3: Float +// │ │ │ │ │ │ │ │ +val p6 = p1 * p2 + (p5 - p3) + +// Float +// │ +val withGetter +// val p1: Int +// │ fun (Int).times(Float): Float +// │ │ val p3: Float +// │ │ │ + get() = p1 * p3 + +// String +// │ +var withSetter +// val p4: String +// │ + get() = p4 +// .value: String +// │ + set(value) = value + +// Boolean +// │ +val withGetter2: Boolean + get() { +// Boolean +// │ + return true + } + +// String +// │ +var withSetter2: String + get() = "1" + set(value) { +// var .field: String +// │ .value: String +// │ │ fun (String).plus(Any?): String +// │ │ │ + field = value + "!" + } + +// String +// │ +private val privateGetter: String = "cba" + get + +// String +// │ +var privateSetter: String = "abc" + private set diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/superTypes.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/superTypes.kt new file mode 100644 index 00000000000..6695b344c54 --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/superTypes.kt @@ -0,0 +1,24 @@ +package org.jetbrains.kotlin.test + +abstract class Base(var x: T) { + fun replace(newValue: T) +} + +// constructor Base(Int) +// │ +class Derived(var x: Int): Base() { + override fun replace(newValue: Int) { +// var (Derived).x: Int +// │ Derived.replace.newValue: Int +// │ │ + x = newValue + } +} + +fun test() { +// constructor Derived(Int) +// │ fun (Derived).replace(Int): Unit +// │ Int │ Int +// │ │ │ │ + Derived(10).replace(20) +} diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/variance.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/variance.kt new file mode 100644 index 00000000000..2009bb5aea2 --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/variance.kt @@ -0,0 +1,24 @@ +interface Source { + fun nextT(): T +} + +fun demo(strs: Source) { +// Source demo.strs: Source +// │ │ + val objects: Source = strs +} + +interface Comparable { + operator fun compareTo(other: T): Int +} + +fun demo(x: Comparable) { +// demo.x: Comparable +// │ fun (Comparable).compareTo(Number): Int +// │ │ Double +// │ │ │ + x.compareTo(1.0) +// Comparable demo.x: Comparable +// │ │ + val y: Comparable = x +} diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt new file mode 100644 index 00000000000..a59c5240ba3 --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt @@ -0,0 +1,28 @@ +// collections/List collections/List +// │ │ +fun copyWhenGreater(list: List, threshold: T): List + where T : CharSequence, + T : Comparable { +// copyWhenGreater.list: collections/List +// │ fun collections/Iterable.filter((T) -> Boolean): collections/List +// │ │ copyWhenGreater..it: T +// │ │ │ fun (Comparable).compareTo(T): Int +// │ │ │ │ copyWhenGreater.threshold: T +// │ │ │ │ │ fun collections/Iterable.map((T) -> String): collections/List +// │ │ │ │ │ │ copyWhenGreater..it: T +// │ │ │ │ │ │ │ fun (Any).toString(): String +// │ │ │ │ │ │ │ │ + return list.filter { it > threshold }.map { it.toString() } +} + +fun main() { +// collections/List +// │ fun collections/listOf(vararg String): collections/List +// │ │ + val list = listOf("1", "2", "3") +// collections/List +// │ fun copyWhenGreater(collections/List, String): collections/List where copyWhenGreater.T : Comparable +// │ │ val main.list: collections/List +// │ │ │ + val copy = copyWhenGreater(list, "2") +} diff --git a/compiler/visualizer/testData/uncommonCases/testFiles/innerWith.kt b/compiler/visualizer/testData/uncommonCases/testFiles/innerWith.kt new file mode 100644 index 00000000000..040c46c96ed --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/testFiles/innerWith.kt @@ -0,0 +1,36 @@ +package p + +class A { + val aProp = 10 +} + +class B { + val bProp = 1 +} + +fun foo(a: Int, b: Int): Int { + with(A()) { + aProp + + with(B()) { + aProp + bProp + aProp + } + } + + with(A()) { + aProp + + with(B()) { + aProp + bProp + } + + with(B()) { + aProp + bProp + } + } + return a +} \ No newline at end of file diff --git a/compiler/visualizer/testData/uncommonCases/testFiles/lists.kt b/compiler/visualizer/testData/uncommonCases/testFiles/lists.kt new file mode 100644 index 00000000000..75c3a8b374f --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/testFiles/lists.kt @@ -0,0 +1,12 @@ +package org.jetbrains.kotlin.test + +val listOfInt = listOf(1, 2, 3) +val javaList = java.util.ArrayList() + +fun move(): java.util.ArrayList { + for (elem in listOfInt) { + javaList.add(elem) + } + + return javaList +} diff --git a/compiler/visualizer/testData/uncommonCases/testFiles/properties.kt b/compiler/visualizer/testData/uncommonCases/testFiles/properties.kt new file mode 100644 index 00000000000..f75c19ba623 --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/testFiles/properties.kt @@ -0,0 +1,34 @@ +package org.jetbrains.kotlin.test + +val p1 = 10 +val p2: Double = 1.0 +val p3: Float = 2.5f +val p4 = "some string" + +val p5 = p1 + p2 +val p6 = p1 * p2 + (p5 - p3) + +val withGetter + get() = p1 * p3 + +var withSetter + get() = p4 + set(value) = value + +val withGetter2: Boolean + get() { + return true + } + +var withSetter2: String + get() = "1" + set(value) { + field = value + "!" + } + +private val privateGetter: String = "cba" + get + +var privateSetter: String = "abc" + private set + diff --git a/compiler/visualizer/testData/uncommonCases/testFiles/superTypes.kt b/compiler/visualizer/testData/uncommonCases/testFiles/superTypes.kt new file mode 100644 index 00000000000..e7106b19973 --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/testFiles/superTypes.kt @@ -0,0 +1,15 @@ +package org.jetbrains.kotlin.test + +abstract class Base(var x: T) { + fun replace(newValue: T) +} + +class Derived(var x: Int): Base() { + override fun replace(newValue: Int) { + x = newValue + } +} + +fun test() { + Derived(10).replace(20) +} \ No newline at end of file diff --git a/compiler/visualizer/testData/uncommonCases/testFiles/variance.kt b/compiler/visualizer/testData/uncommonCases/testFiles/variance.kt new file mode 100644 index 00000000000..d390a1286de --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/testFiles/variance.kt @@ -0,0 +1,16 @@ +interface Source { + fun nextT(): T +} + +fun demo(strs: Source) { + val objects: Source = strs +} + +interface Comparable { + operator fun compareTo(other: T): Int +} + +fun demo(x: Comparable) { + x.compareTo(1.0) + val y: Comparable = x +} \ No newline at end of file diff --git a/compiler/visualizer/testData/uncommonCases/testFiles/where.kt b/compiler/visualizer/testData/uncommonCases/testFiles/where.kt new file mode 100644 index 00000000000..f5111a9b23b --- /dev/null +++ b/compiler/visualizer/testData/uncommonCases/testFiles/where.kt @@ -0,0 +1,10 @@ +fun copyWhenGreater(list: List, threshold: T): List + where T : CharSequence, + T : Comparable { + return list.filter { it > threshold }.map { it.toString() } +} + +fun main() { + val list = listOf("1", "2", "3") + val copy = copyWhenGreater(list, "2") +} \ No newline at end of file diff --git a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt index dd47d113553..7e4f1255a6a 100644 --- a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt +++ b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/AbstractPsiVisualizer.kt @@ -48,4 +48,9 @@ abstract class AbstractPsiVisualizer: KotlinMultiFileTestWithJava( replacement = "fir\\psi2fir" to "visualizer" doTest(filePath) } + + fun doUncommonCasesTest(filePath: String) { + replacement = "testFiles" to "resultFiles" + doTest(filePath) + } } diff --git a/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/PsiVisualizerForUncommonCasesGenerated.java b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/PsiVisualizerForUncommonCasesGenerated.java new file mode 100644 index 00000000000..d38f60c6e3d --- /dev/null +++ b/compiler/visualizer/tests/org/jetbrains/kotlin/visualizer/PsiVisualizerForUncommonCasesGenerated.java @@ -0,0 +1,61 @@ +/* + * 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/visualizer/testData/uncommonCases/testFiles") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class PsiVisualizerForUncommonCasesGenerated extends AbstractPsiVisualizer { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doUncommonCasesTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInTestFiles() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/visualizer/testData/uncommonCases/testFiles"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("innerWith.kt") + public void testInnerWith() throws Exception { + runTest("compiler/visualizer/testData/uncommonCases/testFiles/innerWith.kt"); + } + + @TestMetadata("lists.kt") + public void testLists() throws Exception { + runTest("compiler/visualizer/testData/uncommonCases/testFiles/lists.kt"); + } + + @TestMetadata("properties.kt") + public void testProperties() throws Exception { + runTest("compiler/visualizer/testData/uncommonCases/testFiles/properties.kt"); + } + + @TestMetadata("superTypes.kt") + public void testSuperTypes() throws Exception { + runTest("compiler/visualizer/testData/uncommonCases/testFiles/superTypes.kt"); + } + + @TestMetadata("variance.kt") + public void testVariance() throws Exception { + runTest("compiler/visualizer/testData/uncommonCases/testFiles/variance.kt"); + } + + @TestMetadata("where.kt") + public void testWhere() throws Exception { + runTest("compiler/visualizer/testData/uncommonCases/testFiles/where.kt"); + } +}