From fe328f8c7a2652f45b84f8f61af570828dea091b Mon Sep 17 00:00:00 2001 From: Ivan Cilcic Date: Fri, 23 Aug 2019 11:46:53 +0300 Subject: [PATCH] Add some additional information to psi renderer 1) Trim unused spaces in annotations 2) Rewrote fq name rendering 3) Added annotations to for loop variable 4) Added type arguments render along to type parameters in functions --- compiler/visualizer/build.gradle.kts | 1 + .../kotlin/compiler/visualizer/Annotator.kt | 10 +-- .../kotlin/compiler/visualizer/PsiRenderer.kt | 76 ++++++++++++------- .../declarations/NestedOfAliasedType.kt | 2 +- .../rawBuilder/declarations/complexTypes.kt | 2 +- .../rawBuilder/declarations/derivedClass.kt | 7 +- .../testData/rawBuilder/declarations/enums.kt | 4 +- .../rawBuilder/declarations/enums2.kt | 18 +++-- .../rawBuilder/declarations/expectActual.kt | 2 + .../rawBuilder/declarations/functionTypes.kt | 13 ++-- .../declarations/genericFunctions.kt | 4 +- .../declarations/genericProperty.kt | 9 ++- .../rawBuilder/declarations/nestedClass.kt | 4 +- .../rawBuilder/declarations/simpleClass.kt | 16 ++-- .../declarations/simpleTypeAlias.kt | 2 +- .../declarations/typeParameterVsNested.kt | 4 +- .../rawBuilder/declarations/typeParameters.kt | 9 ++- .../rawBuilder/expressions/arrayAccess.kt | 32 ++++---- .../rawBuilder/expressions/arrayAssignment.kt | 5 +- .../rawBuilder/expressions/branches.kt | 42 +++++----- .../testData/rawBuilder/expressions/calls.kt | 48 +++++++----- .../testData/rawBuilder/expressions/for.kt | 12 +-- .../rawBuilder/expressions/genericCalls.kt | 11 +-- .../testData/rawBuilder/expressions/in.kt | 5 +- .../testData/rawBuilder/expressions/init.kt | 2 +- .../testData/rawBuilder/expressions/lambda.kt | 47 ++++++------ .../testData/rawBuilder/expressions/locals.kt | 29 +++---- .../rawBuilder/expressions/modifications.kt | 8 +- .../rawBuilder/expressions/nullability.kt | 16 ++-- .../testData/rawBuilder/expressions/super.kt | 2 +- .../testData/rawBuilder/expressions/these.kt | 13 ++-- .../rawBuilder/expressions/typeOperators.kt | 20 +++-- .../uncommonCases/resultFiles/innerWith.kt | 10 +-- .../uncommonCases/resultFiles/lists.kt | 8 +- .../uncommonCases/resultFiles/properties.kt | 6 +- .../uncommonCases/resultFiles/where.kt | 8 +- 36 files changed, 284 insertions(+), 223 deletions(-) diff --git a/compiler/visualizer/build.gradle.kts b/compiler/visualizer/build.gradle.kts index 8e522b5cd27..2f0dee53709 100644 --- a/compiler/visualizer/build.gradle.kts +++ b/compiler/visualizer/build.gradle.kts @@ -4,6 +4,7 @@ plugins { dependencies { testRuntime(intellijDep()) + testCompile(intellijCoreDep()) { includeJars("intellij-core") } testCompile(project(":compiler:visualizer:render-psi")) testCompile(project(":compiler:visualizer:render-fir")) diff --git a/compiler/visualizer/common/src/org/jetbrains/kotlin/compiler/visualizer/Annotator.kt b/compiler/visualizer/common/src/org/jetbrains/kotlin/compiler/visualizer/Annotator.kt index bb95ebee4eb..8ad40654494 100644 --- a/compiler/visualizer/common/src/org/jetbrains/kotlin/compiler/visualizer/Annotator.kt +++ b/compiler/visualizer/common/src/org/jetbrains/kotlin/compiler/visualizer/Annotator.kt @@ -12,9 +12,9 @@ object Annotator { private const val verticalLine = "│" private const val comment = "//" - class AnnotationInfo(val text: String, val range: TextRange) + data class AnnotationInfo(val text: String, val range: TextRange) - private fun putAnnotationToLines(annotations: List, lineStart: Int, lineSize: Int): List { + private fun putAnnotationToLines(annotations: List, lineStart: Int, lineSize: Int): List { val annotationLines = mutableListOf(StringBuilder(comment + " ".repeat(lineSize - comment.length))) val levelToOffset = mutableMapOf(0 to 0) @@ -40,10 +40,10 @@ object Annotator { } } - return annotationLines + return annotationLines.map { it.trim().toString() } } - fun annotate(text: String, annotation: List): List { + fun annotate(text: String, annotation: Set): List { val lines = text.lines() val resultLines = mutableListOf() var lineStartOffset = 0 @@ -55,7 +55,7 @@ object Annotator { if (annotations.isNotEmpty()) { val annotationLines = putAnnotationToLines(annotations, lineStartOffset, line.length) - annotationLines.asReversed().mapTo(resultLines) { it.toString() } + resultLines += annotationLines.asReversed() } resultLines.add(line) diff --git a/compiler/visualizer/render-psi/src/org/jetbrains/kotlin/compiler/visualizer/PsiRenderer.kt b/compiler/visualizer/render-psi/src/org/jetbrains/kotlin/compiler/visualizer/PsiRenderer.kt index d06a3d224ed..98419b36602 100644 --- a/compiler/visualizer/render-psi/src/org/jetbrains/kotlin/compiler/visualizer/PsiRenderer.kt +++ b/compiler/visualizer/render-psi/src/org/jetbrains/kotlin/compiler/visualizer/PsiRenderer.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.compiler.visualizer.Annotator.annotate import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor +import org.jetbrains.kotlin.descriptors.impl.LazyPackageViewDescriptorImpl import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getChildOfType @@ -24,6 +25,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.bindingContextUtil.getAbbreviatedTypeOrType import org.jetbrains.kotlin.resolve.calls.callUtil.getCall import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind import org.jetbrains.kotlin.resolve.descriptorUtil.declaresOrInheritsDefaultValue @@ -34,14 +36,14 @@ import org.jetbrains.kotlin.types.* import java.util.ArrayList class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : BaseRenderer { - val bindingContext = analysisResult.bindingContext - private val annotations = mutableListOf() + private val bindingContext = analysisResult.bindingContext + private val annotations = mutableSetOf() private val filePackage = file.packageFqName.toString().replace(".", "/") + private val argumentsLabel = "" val descriptorRenderer = PsiDescriptorRenderer() private val unnecessaryData = mapOf( - "kotlin." to "", "kotlin/" to "" ) @@ -98,6 +100,13 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba //don't resolve this expression } + override fun visitNamedFunction(function: KtNamedFunction) { + if (function.bodyExpression != null && function.equalsToken != null) { + addAnnotation(renderType(function.bodyExpression!!.getType(bindingContext)), function.equalsToken!!) + } + super.visitNamedFunction(function) + } + private fun renderVariableType(variable: KtVariableDeclaration) { val descriptor = bindingContext[VARIABLE, variable] addAnnotation(renderType(descriptor), variable.nameIdentifier!!) @@ -110,6 +119,13 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba override fun visitDestructuringDeclarationEntry(multiDeclarationEntry: KtDestructuringDeclarationEntry) = renderVariableType(multiDeclarationEntry) + override fun visitParameter(parameter: KtParameter) { + if ((parameter.isLoopParameter && parameter.destructuringDeclaration == null) || parameter.ownerFunction is KtPropertyAccessor) { + addAnnotation(renderType(bindingContext[VALUE_PARAMETER, parameter]?.returnType), parameter.nameIdentifier!!) + } + super.visitParameter(parameter) + } + override fun visitTypeReference(typeReference: KtTypeReference) { if (typeReference.text.isNotEmpty()) { val hasResolvedCall = with(object : KtVisitorVoid() { @@ -148,7 +164,10 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba } val descriptor = resolvedCall.resultingDescriptor - val annotation = descriptorRenderer.render(descriptor) + val typeArguments = if (resolvedCall.typeArguments.isNotEmpty()) { + buildString { resolvedCall.typeArguments.values.joinTo(this, ", ", "<", ">") { renderType(it) } } + } else "" + val annotation = descriptorRenderer.render(descriptor).replace(argumentsLabel, typeArguments) addAnnotation(annotation, expression, deleteDuplicate = false) fun addReceiverAnnotation(receiver: ReceiverValue?, receiverKind: ExplicitReceiverKind) { @@ -214,16 +233,15 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba } } - inner class PsiDescriptorRenderer : DeclarationDescriptorVisitor { + inner class PsiDescriptorRenderer( + private val needToRenderSpecialFun: Boolean = false + ) : DeclarationDescriptorVisitor { private val typeRenderer: DescriptorRenderer = DescriptorRenderer.withOptions { withDefinedIn = false modifiers = emptySet() classifierNamePolicy = object : ClassifierNamePolicy { override fun renderClassifier(classifier: ClassifierDescriptor, renderer: DescriptorRenderer): String { - val fqName = (if (classifier is TypeParameterDescriptor) renderer.renderName(classifier.name, false) - else renderer.renderFqName(DescriptorUtils.getFqName(classifier))).replace(".", "/") - - return removeCurrentFilePackage(fqName) + return renderFqName(classifier) } } includeAdditionalModifiers = false @@ -238,7 +256,7 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba fun render(declarationDescriptor: DeclarationDescriptor): String { if (declarationDescriptor is CallableDescriptor && declarationDescriptor.isSpecial()) { - return this.renderSpecialFunction(declarationDescriptor) + return if (needToRenderSpecialFun) this.renderSpecialFunction(declarationDescriptor) else "" } return buildString { declarationDescriptor.accept(this@PsiDescriptorRenderer, this) @@ -258,25 +276,28 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba } private fun renderFqName(descriptor: DeclarationDescriptor, removeCurrentPackage: Boolean = true): String { - val fqName = generateSequence(descriptor) { it.containingDeclaration } - .fold("") { acc, desc -> - val name = when (desc) { - is LazyPackageDescriptor -> desc.fqName.toString().replace(".", "/") - else -> desc.name.asString() - } - val separator = when { - acc.isEmpty() -> "" - else -> if (desc is PackageFragmentDescriptor || desc is PackageViewDescriptor) "/" else "." - } - if (name == FqName.ROOT.toString() || desc is ModuleDescriptor) { - return@fold acc - } - return@fold "$name$separator$acc" - } - + if (descriptor is TypeParameterDescriptor) return descriptor.name.render() + val fqName = qualifierNameCombine(descriptor) return if (removeCurrentPackage) removeCurrentFilePackage(fqName) else fqName } + private fun qualifierNameCombine(descriptor: DeclarationDescriptor): String { + val nameString = descriptor.name.render() + if (nameString == FqName.ROOT.toString()) return "" + + val containingDeclaration = descriptor.containingDeclaration + val qualifier = qualifierName(containingDeclaration) + val separator = + if (containingDeclaration is PackageFragmentDescriptor || containingDeclaration is PackageViewDescriptor) "/" else "." + return if (qualifier != "") qualifier + separator + nameString else nameString + } + + private fun qualifierName(descriptor: DeclarationDescriptor?): String = when (descriptor) { + is ModuleDescriptor, null -> "" + is PackageFragmentDescriptor, is PackageViewDescriptor -> descriptor.fqNameUnsafe.render().replace(".", "/") + else -> qualifierNameCombine(descriptor) + } + private fun removeCurrentFilePackage(fqName: String): String { return if (fqName.startsWith(filePackage) && !fqName.substring(filePackage.length + 1).contains("/")) { fqName.replaceFirst("$filePackage/", "") @@ -367,6 +388,9 @@ class PsiRenderer(private val file: KtFile, analysisResult: AnalysisResult) : Ba //render name data.append(renderName(function, receiver != null)) + //render type arguments + data.append(argumentsLabel) + //render value parameters visitValueParameters(function.valueParameters, data) diff --git a/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt b/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt index f442350b34d..893bccbcd6f 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/NestedOfAliasedType.kt @@ -10,4 +10,4 @@ class B : TA() { // constructor A.Nested() // │ class NestedInB : Nested() -} \ No newline at end of file +} diff --git a/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt b/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt index f57d26fcbc5..84312b028db 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/complexTypes.kt @@ -13,4 +13,4 @@ interface Test { // │ │ │ 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 index 5ccd35263e3..cd67ecf9e8b 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/derivedClass.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/derivedClass.kt @@ -5,7 +5,8 @@ open class Base(val x: T) // │ │ class Derived(x: T) : Base(x) -// constructor Derived(T) -// │ create.x: T -// │ │ +// Derived +// │ 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 index 0472aacda4e..8b737c48b42 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/enums.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/enums.kt @@ -41,7 +41,7 @@ enum class Planet(val m: Double, internal val r: Double) { } }; -// val (Planet/Companion).G: Double +// val (Planet.Companion).G: Double // │ fun (Double).times(Double): Double // │ │ val (Planet).m: Double // │ │ │ fun (Double).div(Double): Double @@ -59,4 +59,4 @@ enum class Planet(val m: Double, internal val r: 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 index c5c45388d26..69b95daab0e 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/enums2.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/enums2.kt @@ -7,20 +7,22 @@ object O2 : Some enum class SomeEnum(val x: Some) { // constructor SomeEnum(Some) // │object O1: Some -// ││ +// ││ FIRST(O1) { -// Boolean -// │ +// Boolean +// │ 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 -// │ │ │ +// Boolean +// │ SomeEnum.SECOND.check.y: Some +// │ │ fun (Any).equals(Any?): Boolean +// │ │ │ object O2: Some +// │ │ │ │ override fun check(y: Some): Boolean = y == O2 }; diff --git a/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt b/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt index 522af3324d2..3236df9b544 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/expectActual.kt @@ -8,6 +8,8 @@ expect val x: Int actual class MyClass +// String +// │ actual fun foo() = "Hello" // Int Int diff --git a/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt b/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt index 74917fb48f9..1ea5eb3f32b 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/functionTypes.kt @@ -1,5 +1,6 @@ -// fun ((T) -> Unit).invoke(T): Unit -// │ +// Unit +// │ fun ((T) -> Unit).invoke(T): Unit +// │ │ fun simpleRun(f: (T) -> Unit): Unit = f() // collections/List @@ -8,8 +9,8 @@ fun List.simpleMap(f: (T) -> R): R { } -// simpleWith.t: T -// │ fun T.invoke(): Unit -// │ │ +// Unit +// │ 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 index a88e9c41a82..74a0e0c79e0 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/genericFunctions.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/genericFunctions.kt @@ -1,7 +1,9 @@ interface Any +// T? +// │ 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 index 8559bd1e707..501af9d41aa 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/genericProperty.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/genericProperty.kt @@ -1,7 +1,8 @@ -// fun TODO(): Nothing -// │ +// Nothing +// │ fun TODO(): Nothing +// │ │ fun genericFoo(): T = TODO() -// T fun genericFoo(): T -// │ │ +// 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 index 572e1653064..5efca20b0b2 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/nestedClass.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/nestedClass.kt @@ -3,10 +3,10 @@ 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/simpleClass.kt b/compiler/visualizer/testData/rawBuilder/declarations/simpleClass.kt index d138d0c1dd1..4a018731bdc 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/simpleClass.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/simpleClass.kt @@ -17,21 +17,23 @@ class SomeClass : SomeInterface { // │ │ SomeClass.foo.x: Int // │ │ │ fun (String).plus(Any?): String // │ │ │ │ val (SomeClass).baz: Int -// │ │ │ │ │ +// │ │ │ │ │ return y + x + baz } -// Boolean -// │ +// Boolean +// │ override var bar: Boolean // Boolean -// │ +// │ get() = true +// Boolean +// │ set(value) {} -// Double -// │ +// Double +// │ lateinit var fau: Double } -inline class InlineClass \ No newline at end of file +inline class InlineClass diff --git a/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt b/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt index 19283c62fe5..681b3eaa974 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/simpleTypeAlias.kt @@ -4,4 +4,4 @@ typealias C = B // C /* = B */ // │ -class D : C \ No newline at end of file +class D : C diff --git a/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt b/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt index 4e7c545c34f..2be275db8b2 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/typeParameterVsNested.kt @@ -13,13 +13,13 @@ abstract class My { // [ERROR : T] // │ class My -// │ │ +// │ │ abstract val y: My.T // [ERROR : T] // │ package test // │ │ class My -// │ │ │ +// │ │ │ abstract val z: test.My.T // [ERROR : T] diff --git a/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt b/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt index d207ef3548d..761bb7e3469 100644 --- a/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt +++ b/compiler/visualizer/testData/rawBuilder/declarations/typeParameters.kt @@ -10,11 +10,14 @@ typealias AnyList = List<*> abstract class AbstractList : List // constructor AbstractList() -// │ +// │ class SomeList : AbstractList() { -// Int -// │ +// Int +// │ Int +// │ │ override fun get(index: Int): Int = 42 +// SomeList +// │ override fun concat(other: List): List = this } diff --git a/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt b/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt index 9225f861cd2..aea4b04c0db 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/arrayAccess.kt @@ -1,23 +1,25 @@ // Int Int // │ │ val p = 0 -// Int -// │ +// Int +// │ 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 -// │ │ │ │ │ │ │ │ │ │ │ │ +// Int +// │ 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 index e43b71bb3d6..79ad4f36477 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/arrayAssignment.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/arrayAssignment.kt @@ -12,8 +12,9 @@ fun test() { x[1] = 0 } -// Int -// │ +// Int +// │ Int +// │ │ fun foo() = 1 fun test2() { diff --git a/compiler/visualizer/testData/rawBuilder/expressions/branches.kt b/compiler/visualizer/testData/rawBuilder/expressions/branches.kt index 1c8381b5a27..c4c3fa57739 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/branches.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/branches.kt @@ -1,9 +1,9 @@ // foo.a: Int // │ fun (Int).compareTo(Int): Int // │ │ foo.b: Int -// │ │ │ foo.a: Int -// Int │ │ │ │ foo.b: Int -// │ │ │ │ │ │ +// 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 { @@ -43,13 +43,13 @@ fun baz(a: Long, b: Long): Long { a > b -> { // fun io/println(Long): Unit // │ baz.a: Long -// │ │ +// │ │ println(a) // baz.a: Long // │ return a } -// Nothing +// Nothing // │ baz.b: Long // │ │ else -> return b @@ -57,34 +57,34 @@ fun baz(a: Long, b: Long): Long { } fun grade(g: Int): String { -// String +// String // │ grade.g: Int -// │ │ +// │ │ return when (g) { -// Int -// │ Int String -// │ │ │ +// Int +// │ Int String +// │ │ │ 6, 7 -> "Outstanding" -// Int String -// │ │ +// Int String +// │ │ 5 -> "Excellent" // Int String -// │ │ +// │ │ 4 -> "Good" -// Int String -// │ │ +// Int String +// │ │ 3 -> "Mediocre" // fun (ranges/IntRange).contains(Int): Boolean -// │ Int +// │ Int // │ │fun (Int).rangeTo(Int): ranges/IntRange // │ ││ Int String -// │ ││ │ │ +// │ ││ │ │ in 1..2 -> "Fail" -// String -// │ +// String +// │ is Number -> "Number" -// String -// │ +// String +// │ else -> "Unknown" } } diff --git a/compiler/visualizer/testData/rawBuilder/expressions/calls.kt b/compiler/visualizer/testData/rawBuilder/expressions/calls.kt index 413a0f80795..59b48150ac6 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/calls.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/calls.kt @@ -1,38 +1,44 @@ -// distance.x: Int -// │ fun (Int).plus(Int): Int -// │ │ distance.y: Int -// │ │ │ +// Int +// │ 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 -// │ │ │ +// [ERROR: unknown type] +// │ Int +// │ │ [ERROR: not resolved] +// │ │ │ Int +// │ │ │ │ fun test(): Int = 3 distance 4 -// fun distance(Int, Int): Int -// │ Int -// │ │ Int -// │ │ │ +// Int +// │ fun distance(Int, Int): Int +// │ │ Int +// │ │ │ Int +// │ │ │ │ fun testRegular(): Int = distance(3, 4) class My(var x: Int) { -// var (My).x: Int -// │ +// Int +// │ var (My).x: Int +// │ │ operator fun invoke() = x fun foo() {} -// constructor My(Int) -// │ var (My).x: Int -// │ │ +// My +// │ constructor My(Int) +// │ │ var (My).x: Int +// │ │ │ fun copy() = My(x) } -// constructor My(Int) -// fun (My).invoke(): Int -// │ Int -// │ │ +// Int +// │ constructor My(Int) +// │ fun (My).invoke(): Int +// │ │ Int +// │ │ │ fun testInvoke(): Int = My(13)() fun testQualified(first: My, second: My?) { diff --git a/compiler/visualizer/testData/rawBuilder/expressions/for.kt b/compiler/visualizer/testData/rawBuilder/expressions/for.kt index 33f5e722d6a..3be8509bb28 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/for.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/for.kt @@ -1,8 +1,8 @@ fun foo() { // Int // │fun (Int).rangeTo(Int): ranges/IntRange -// ││ Int -// ││ │ +// Int ││ Int +// │ ││ │ for (i in 1..10) { // fun io/println(Int): Unit // │ val foo.i: Int @@ -17,8 +17,8 @@ fun bar(list: List) { // bar.list: collections/List // │ fun (collections/List).subList(Int, Int): collections/List // │ │ Int -// │ │ │ Int -// │ │ │ │ +// String │ │ │ Int +// │ │ │ │ │ for (element in list.subList(0, 10)) { // fun io/println(Any?): Unit // │ val bar.element: String @@ -28,8 +28,8 @@ fun bar(list: List) { // bar.list: collections/List // │ fun (collections/List).subList(Int, Int): collections/List // │ │ fun io/println(Any?): Unit -// │ │ Int Int │ val bar.element: String -// │ │ │ │ │ │ +// String │ │ Int Int │ val bar.element: String +// │ │ │ │ │ │ │ for (element in list.subList(10, 20)) println(element) } diff --git a/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt b/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt index 64f18f808a4..5d61edb31bd 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/genericCalls.kt @@ -1,18 +1,19 @@ -// Nothing? -// │ +// Nothing? +// │ Nothing? +// │ │ fun nullableValue(): T? = null fun test() { // Int? -// │ fun nullableValue(): Int? +// │ fun nullableValue(): Int? // │ │ val n = nullableValue() // Double? -// │ fun nullableValue(): Double? +// │ fun nullableValue(): Double? // │ │ val x = nullableValue() // String? -// │ fun 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 index 03d07884f13..1876beee12c 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/in.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/in.kt @@ -1,5 +1,6 @@ // collections/Collection -// │ +// │ Boolean +// │ │ fun foo(x: Int, y: Int, c: Collection) = // foo.x: Int // │ fun (collections/Collection).contains(Int): Boolean @@ -8,4 +9,4 @@ fun foo(x: Int, y: Int, c: Collection) = // │ │ │ │ fun (collections/Collection).contains(Int): Boolean // │ │ │ │ │ foo.c: collections/Collection // │ │ │ │ │ │ - x in c && y !in c \ No newline at end of file + x in c && y !in c diff --git a/compiler/visualizer/testData/rawBuilder/expressions/init.kt b/compiler/visualizer/testData/rawBuilder/expressions/init.kt index 29c9c2ab999..9129d0df8ca 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/init.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/init.kt @@ -9,4 +9,4 @@ class 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 index a229b81c18f..a242fe9129b 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/lambda.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/lambda.kt @@ -1,15 +1,16 @@ data class Tuple(val x: Int, val y: Int) -// fun ((Tuple) -> Int).invoke(Tuple): Int -// │ constructor Tuple(Int, Int) -// │ │ Int -// │ │ │ Int -// │ │ │ │ +// 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 -// │ +// (Tuple) -> Int +// │ val l1 = { t: Tuple -> // foo..t: Tuple // Int │ val (Tuple).x: Int @@ -29,13 +30,13 @@ fun foo(): 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 +// Unit // │ foo..it: Tuple // │ │ val (Tuple).x: Int // │ │ │ fun (Any).equals(Any?): Boolean @@ -51,9 +52,9 @@ fun foo(): Int { fun bar(): Int { // fun use((Tuple) -> Int): Int -// │ +// │ return use lambda@{ -// Unit +// Unit // │ bar..it: Tuple // │ │ val (Tuple).x: Int // │ │ │ fun (Any).equals(Any?): Boolean @@ -71,24 +72,24 @@ fun bar(): Int { // │ fun test(list: List) { // collections/MutableMap -// │ fun collections/mutableMapOf(): collections/MutableMap -// │ │ +// │ fun collections/mutableMapOf(): collections/MutableMap +// │ │ val map = mutableMapOf() // test.list: collections/List -// │ fun collections/Iterable.forEach((Int) -> Unit): Unit +// │ fun collections/Iterable.forEach((Int) -> Unit): Unit // │ │ val test.map: collections/MutableMap -// │ │ │ fun collections/MutableMap.getOrPut(Int, () -> String): String +// │ │ │ fun collections/MutableMap.getOrPut(Int, () -> String): String // │ │ │ │ test..it: Int -// │ │ │ │ │ fun collections/mutableListOf(): collections/MutableList +// │ │ │ │ │ fun collections/mutableListOf(): collections/MutableList // │ │ │ │ │ │ fun (String).plus(Any?): String -// │ │ │ │ │ │ │ +// │ │ │ │ │ │ │ list.forEach { map.getOrPut(it, { mutableListOf() }) += "" } } -// () -> Unit -// │ +// () -> Unit +// │ val simple = { } -// () -> Int Int -// │ │ -val another = { 42 } \ No newline at end of file +// () -> Int Int +// │ │ +val another = { 42 } diff --git a/compiler/visualizer/testData/rawBuilder/expressions/locals.kt b/compiler/visualizer/testData/rawBuilder/expressions/locals.kt index 491b022b7ba..7a125cfdb5d 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/locals.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/locals.kt @@ -1,14 +1,15 @@ fun withLocals(p: Int): Int { class Local(val pp: Int) { -// val (withLocals/Local).pp: Int -// │ fun (Int).minus(Int): Int -// │ │ withLocals.p: Int -// │ │ │ +// 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 +// Int │ Int fun (withLocals.Local).diff(): Int // │ │ │ │ val x = Local(42).diff() @@ -26,10 +27,11 @@ fun withLocals(p: Int): Int { // Int constructor Any() // │ │ val code = (object : Any() { -// fun (Any).hashCode(): Int -// │ +// Int +// │ fun (Any).hashCode(): Int +// │ │ fun foo() = hashCode() -// fun (withLocals/).foo(): Int +// fun (withLocals.).foo(): Int // │ }).foo() @@ -37,10 +39,11 @@ fun withLocals(p: 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 -// │ │ │ │ │ │ │ │ +// │ │ │ │ fun (withLocals.Local).diff(): Int +// │ │ │ │ │ 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 index b91e077d789..990ae78b2e3 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/modifications.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/modifications.kt @@ -27,18 +27,18 @@ fun simple() { // collections/List // │ fun List.modify() { -// fun collections/Collection.plus(String): collections/List +// fun collections/Collection.plus(String): collections/List // │ this += "Alpha" -// fun collections/Collection.plus(String): collections/List +// fun collections/Collection.plus(String): collections/List // │ this += "Omega" } fun Any.modify() { // collections/List -// │ fun collections/Collection.plus(Int): 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/nullability.kt b/compiler/visualizer/testData/rawBuilder/expressions/nullability.kt index cc59f8837a5..3fcc9b65258 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/nullability.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/nullability.kt @@ -1,10 +1,10 @@ -// orFourtyTwo.arg: Int? -// │ fun ?: (Int?, Int): Int -// │ │ Int -// │ │ │ +// Int +// │ orFourtyTwo.arg: 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 +// Int +// │ bang.arg: Int? +// │ │ +fun bang(arg: Int?) = arg!! diff --git a/compiler/visualizer/testData/rawBuilder/expressions/super.kt b/compiler/visualizer/testData/rawBuilder/expressions/super.kt index b21710d7dd4..899888f7792 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/super.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/super.kt @@ -22,4 +22,4 @@ class C : A, B { // │ 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 index f6bde914494..73c06f374c6 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/these.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/these.kt @@ -1,6 +1,7 @@ class Some { -// Int -// │ +// Int +// │ Int +// │ │ fun foo(): Int = 1 fun bar(): Int { @@ -23,12 +24,12 @@ class Some { } } -// fun (Some).bar(): Int -// │ +// Int fun (Some).bar(): Int +// │ │ fun Some.extension() = this.bar() fun test(some: Some): Int { -// fun with(Some, Some.() -> Int): Int +// fun with(Some, Some.() -> Int): Int // │ test.some: Some // │ │ with@0 // │ │ │ @@ -39,4 +40,4 @@ fun test(some: Some): Int { // │ │ │ this.foo() + this@with.extension() } -} \ No newline at end of file +} diff --git a/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt b/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt index d9a333fde50..be6a9c52d96 100644 --- a/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt +++ b/compiler/visualizer/testData/rawBuilder/expressions/typeOperators.kt @@ -1,14 +1,18 @@ interface IThing -// test1.x: Any -// │ +// Boolean +// │ test1.x: Any +// │ │ fun test1(x: Any) = x is IThing -// test2.x: Any -// │ +// Boolean +// │ test2.x: Any +// │ │ fun test2(x: Any) = x !is IThing -// test3.x: Any -// │ +// IThing +// │ test3.x: Any +// │ │ fun test3(x: Any) = x as IThing -// test4.x: Any -// │ +// IThing? +// │ test4.x: Any +// │ │ fun test4(x: Any) = x as? IThing diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt index 5ce3e32094f..0e1231c8353 100644 --- a/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/innerWith.kt @@ -13,7 +13,7 @@ class B { } fun foo(a: Int, b: Int): Int { -// fun with(A, A.() -> Int): Int +// fun with(A, A.() -> Int): Int // │ constructor A() // │ │ with@0 // │ │ │ @@ -23,7 +23,7 @@ fun foo(a: Int, b: Int): Int { // │ aProp -// fun with(B, B.() -> Int): Int +// fun with(B, B.() -> Int): Int // │ constructor B() // │ │ with@1 // │ │ │ @@ -43,7 +43,7 @@ fun foo(a: Int, b: Int): Int { } } -// fun with(A, A.() -> Int): Int +// fun with(A, A.() -> Int): Int // │ constructor A() // │ │ with@0 // │ │ │ @@ -53,7 +53,7 @@ fun foo(a: Int, b: Int): Int { // │ aProp -// fun with(B, B.() -> Int): Int +// fun with(B, B.() -> Int): Int // │ constructor B() // │ │ with@1 // │ │ │ @@ -68,7 +68,7 @@ fun foo(a: Int, b: Int): Int { bProp } -// fun with(B, B.() -> Int): Int +// fun with(B, B.() -> Int): Int // │ constructor B() // │ │ with@1 // │ │ │ diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt index 00c8ff19d4a..44c8ba4190a 100644 --- a/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/lists.kt @@ -1,7 +1,7 @@ package org.jetbrains.kotlin.test // collections/List -// │ fun collections/listOf(vararg Int): collections/List +// │ fun collections/listOf(vararg Int): collections/List // │ │ Int // │ │ │ Int // │ │ │ │ Int @@ -9,7 +9,7 @@ package org.jetbrains.kotlin.test val listOfInt = listOf(1, 2, 3) // java/util/ArrayList // │ package java -// │ │ constructor util/ArrayList() +// │ │ constructor java/util/ArrayList() // │ │ │ val javaList = java.util.ArrayList() @@ -17,8 +17,8 @@ val javaList = java.util.ArrayList() // │ package java/util // │ │ fun move(): java.util.ArrayList { -// val listOfInt: collections/List -// │ +// Int val listOfInt: collections/List +// │ │ for (elem in listOfInt) { // val javaList: java/util/ArrayList // │ fun (java/util/ArrayList).add(Int): Boolean diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt index d6d68fff010..f7ef9a8f922 100644 --- a/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/properties.kt @@ -45,8 +45,8 @@ var withSetter // val p4: String // │ get() = p4 -// .value: String -// │ +// String .value: String +// │ │ set(value) = value // Boolean @@ -62,6 +62,8 @@ val withGetter2: Boolean // │ var withSetter2: String get() = "1" +// String +// │ set(value) { // var .field: String // │ .value: String diff --git a/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt b/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt index a59c5240ba3..7ea09ec2c6a 100644 --- a/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt +++ b/compiler/visualizer/testData/uncommonCases/resultFiles/where.kt @@ -4,11 +4,11 @@ fun copyWhenGreater(list: List, threshold: T): List where T : CharSequence, T : Comparable { // copyWhenGreater.list: collections/List -// │ fun collections/Iterable.filter((T) -> Boolean): 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 +// │ │ │ │ │ fun collections/Iterable.map((T) -> String): collections/List // │ │ │ │ │ │ copyWhenGreater..it: T // │ │ │ │ │ │ │ fun (Any).toString(): String // │ │ │ │ │ │ │ │ @@ -17,11 +17,11 @@ fun copyWhenGreater(list: List, threshold: T): List fun main() { // collections/List -// │ fun collections/listOf(vararg String): 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 +// │ fun copyWhenGreater(collections/List, String): collections/List where T : Comparable // │ │ val main.list: collections/List // │ │ │ val copy = copyWhenGreater(list, "2")