From ba797fa1b4a325e7babe0e5d7c7323d849c65329 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Thu, 16 Jun 2022 17:13:03 +0200 Subject: [PATCH] [stubs] fix cls stubs for declarations with context receivers ^KTIJ-21243 fixed --- .../ContextReceiversCallableMembers.kt | 24 ++++++ .../ContextReceiversCallableMembers.txt | 73 +++++++++++++++++++ .../ContextReceiversOnClass.kt | 14 ++++ .../ContextReceiversOnClass.txt | 18 +++++ .../ContextReceiversOnTopLevelCallables.kt | 23 ++++++ .../ContextReceiversOnTopLevelCallables.txt | 67 +++++++++++++++++ .../files/ClsStubBuilderTestGenerated.java | 18 +++++ ...DecompiledPsiStubBuilderTestGenerated.java | 18 ++++- .../decompiler/stub/CallableClsStubBuilder.kt | 17 ++++- .../decompiler/stub/ClassClsStubBuilder.kt | 7 +- .../stub/ContextReceiversListStubBuilder.kt | 28 +++++++ .../kotlin/psi/stubs/KotlinStubVersions.kt | 2 +- 12 files changed, 297 insertions(+), 12 deletions(-) create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.kt create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.txt create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.kt create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.txt create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.kt create mode 100644 analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.txt create mode 100644 analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ContextReceiversListStubBuilder.kt diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.kt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.kt new file mode 100644 index 00000000000..4aaae21da0e --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +ContextReceivers + +private open class ContextReceiversCallableMembers { + context(A, B) + private fun Int.function(): Int = valueA + valueB + + context(A, B) + private val Int.property: Int get() = valueA + valueB + + context(A, B) + private var Int.propertyWithSetter: Int + get() = valueA + valueB + set(v) { println(valueA + valueB) } +} + +class A { + val valueA: Int = 10 +} + +class B { + val valueB: Int = 11 +} + + diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.txt new file mode 100644 index 00000000000..d46a4a11d19 --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/ContextReceiversCallableMembers.txt @@ -0,0 +1,73 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE + IMPORT_LIST + CLASS[classId=/ContextReceiversCallableMembers, fqName=ContextReceiversCallableMembers, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=ContextReceiversCallableMembers, superNames=[]] + MODIFIER_LIST[open private] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + PROPERTY[fqName=ContextReceiversCallableMembers.property, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=true, isTopLevel=false, isVar=false, name=property] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[private final] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + PROPERTY[fqName=ContextReceiversCallableMembers.propertyWithSetter, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=true, isTopLevel=false, isVar=true, name=propertyWithSetter] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[private final] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + FUN[fqName=ContextReceiversCallableMembers.function, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=true, isTopLevel=false, mayHaveContract=false, name=function] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[private final] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.kt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.kt new file mode 100644 index 00000000000..b5d52e50174 --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +ContextReceivers + +context(A, B) +private open class ContextReceiversOnClass { + +} + +class A { + val valueA: Int = 10 +} + +class B { + val valueB: Int = 11 +} \ No newline at end of file diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.txt new file mode 100644 index 00000000000..132c315467f --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/ContextReceiversOnClass.txt @@ -0,0 +1,18 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE + IMPORT_LIST + CLASS[classId=/ContextReceiversOnClass, fqName=ContextReceiversOnClass, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=ContextReceiversOnClass, superNames=[]] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[open private] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.kt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.kt new file mode 100644 index 00000000000..f317f35d214 --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.kt @@ -0,0 +1,23 @@ +// JVM_FILE_NAME: ContextReceiversOnTopLevelCallablesKt +// !LANGUAGE: +ContextReceivers + +context(A, B) +private fun Int.function(): Int = valueA + valueB + +context(A, B) +private val Int.property: Int get() = valueA + valueB + +context(A, B) +private var Int.propertyWithSetter: Int + get() = valueA + valueB + set(v) { println(valueA + valueB) } + +class A { + val valueA: Int = 10 +} + +class B { + val valueB: Int = 11 +} + + diff --git a/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.txt b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.txt new file mode 100644 index 00000000000..111694f767a --- /dev/null +++ b/analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/ContextReceiversOnTopLevelCallables.txt @@ -0,0 +1,67 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE + IMPORT_LIST + PROPERTY[fqName=property, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=true, isTopLevel=true, isVar=false, name=property] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[private] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + PROPERTY[fqName=propertyWithSetter, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=true, isTopLevel=true, isVar=true, name=propertyWithSetter] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[private] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + FUN[fqName=function, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=true, isTopLevel=true, mayHaveContract=false, name=function] + CONTEXT_RECEIVER_LIST + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=A] + CONTEXT_RECEIVER + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=B] + MODIFIER_LIST[private] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Int] diff --git a/analysis/decompiled/decompiler-to-file-stubs/tests/org/jetbrains/kotlin/analysis/decompiler/stub/files/ClsStubBuilderTestGenerated.java b/analysis/decompiled/decompiler-to-file-stubs/tests/org/jetbrains/kotlin/analysis/decompiler/stub/files/ClsStubBuilderTestGenerated.java index 163ab0924ef..ebcadbc9fcd 100644 --- a/analysis/decompiled/decompiler-to-file-stubs/tests/org/jetbrains/kotlin/analysis/decompiler/stub/files/ClsStubBuilderTestGenerated.java +++ b/analysis/decompiled/decompiler-to-file-stubs/tests/org/jetbrains/kotlin/analysis/decompiler/stub/files/ClsStubBuilderTestGenerated.java @@ -96,6 +96,24 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest { runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/Const/"); } + @Test + @TestMetadata("ContextReceiversCallableMembers") + public void testContextReceiversCallableMembers() throws Exception { + runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/"); + } + + @Test + @TestMetadata("ContextReceiversOnClass") + public void testContextReceiversOnClass() throws Exception { + runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/"); + } + + @Test + @TestMetadata("ContextReceiversOnTopLevelCallables") + public void testContextReceiversOnTopLevelCallables() throws Exception { + runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/"); + } + @Test @TestMetadata("Contracts") public void testContracts() throws Exception { diff --git a/analysis/decompiled/decompiler-to-psi/tests/org/jetbrains/kotlin/analysis/decompiler/psi/ByDecompiledPsiStubBuilderTestGenerated.java b/analysis/decompiled/decompiler-to-psi/tests/org/jetbrains/kotlin/analysis/decompiler/psi/ByDecompiledPsiStubBuilderTestGenerated.java index 3cedd8b88b1..2d850dd7e1a 100644 --- a/analysis/decompiled/decompiler-to-psi/tests/org/jetbrains/kotlin/analysis/decompiler/psi/ByDecompiledPsiStubBuilderTestGenerated.java +++ b/analysis/decompiled/decompiler-to-psi/tests/org/jetbrains/kotlin/analysis/decompiler/psi/ByDecompiledPsiStubBuilderTestGenerated.java @@ -97,9 +97,21 @@ public class ByDecompiledPsiStubBuilderTestGenerated extends AbstractByDecompile } @Test - @TestMetadata("ContextReceivers") - public void testContextReceivers() throws Exception { - runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceivers/"); + @TestMetadata("ContextReceiversCallableMembers") + public void testContextReceiversCallableMembers() throws Exception { + runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversCallableMembers/"); + } + + @Test + @TestMetadata("ContextReceiversOnClass") + public void testContextReceiversOnClass() throws Exception { + runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnClass/"); + } + + @Test + @TestMetadata("ContextReceiversOnTopLevelCallables") + public void testContextReceiversOnTopLevelCallables() throws Exception { + runTest("analysis/decompiled/decompiler-to-file-stubs/testData/clsFileStubBuilder/ContextReceiversOnTopLevelCallables/"); } @Test diff --git a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt index d59b623d251..40e1824c49a 100644 --- a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt +++ b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/CallableClsStubBuilder.kt @@ -9,10 +9,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget import org.jetbrains.kotlin.metadata.ProtoBuf import org.jetbrains.kotlin.metadata.ProtoBuf.MemberKind import org.jetbrains.kotlin.metadata.ProtoBuf.Modality -import org.jetbrains.kotlin.metadata.deserialization.Flags -import org.jetbrains.kotlin.metadata.deserialization.hasReceiver -import org.jetbrains.kotlin.metadata.deserialization.receiverType -import org.jetbrains.kotlin.metadata.deserialization.returnType +import org.jetbrains.kotlin.metadata.deserialization.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes import org.jetbrains.kotlin.psi.stubs.impl.KotlinFunctionStubImpl @@ -89,10 +86,12 @@ abstract class CallableClsStubBuilder( ) { protected val c = outerContext.child(typeParameters) protected val typeStubBuilder = TypeClsStubBuilder(c) + private val contextReceiversListStubBuilder = ContextReceiversListStubBuilder(c) protected val isTopLevel: Boolean get() = protoContainer is ProtoContainer.Package protected val callableStub: StubElement by lazy(LazyThreadSafetyMode.NONE) { doCreateCallableStub(parent) } fun build() { + contextReceiversListStubBuilder.createContextReceiverStubs(callableStub, contextReceiverTypes) createModifierListStub() val typeConstraintListData = typeStubBuilder.createTypeParameterListStub(callableStub, typeParameters) createReceiverTypeReferenceStub() @@ -105,6 +104,7 @@ abstract class CallableClsStubBuilder( abstract val receiverAnnotations: List abstract val returnType: ProtoBuf.Type? + abstract val contextReceiverTypes: List private fun createReceiverTypeReferenceStub() { receiverType?.let { @@ -144,6 +144,9 @@ private class FunctionClsStubBuilder( override val returnType: ProtoBuf.Type get() = functionProto.returnType(c.typeTable) + override val contextReceiverTypes: List + get() = functionProto.contextReceiverTypes(c.typeTable) + override fun createValueParameterList() { typeStubBuilder.createValueParameterListStub(callableStub, functionProto, functionProto.valueParameterList, protoContainer) } @@ -200,6 +203,9 @@ private class PropertyClsStubBuilder( override val returnType: ProtoBuf.Type get() = propertyProto.returnType(c.typeTable) + override val contextReceiverTypes: List + get() = propertyProto.contextReceiverTypes(c.typeTable) + override fun createValueParameterList() { } @@ -261,6 +267,9 @@ private class ConstructorClsStubBuilder( override val returnType: ProtoBuf.Type? get() = null + override val contextReceiverTypes: List + get() = emptyList() + override fun createValueParameterList() { typeStubBuilder.createValueParameterListStub(callableStub, constructorProto, constructorProto.valueParameterList, protoContainer) } diff --git a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ClassClsStubBuilder.kt b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ClassClsStubBuilder.kt index 3986c98b972..2c53061df26 100644 --- a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ClassClsStubBuilder.kt +++ b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ClassClsStubBuilder.kt @@ -12,10 +12,7 @@ import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.lexer.KtModifierKeywordToken import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.metadata.ProtoBuf -import org.jetbrains.kotlin.metadata.deserialization.Flags -import org.jetbrains.kotlin.metadata.deserialization.NameResolver -import org.jetbrains.kotlin.metadata.deserialization.TypeTable -import org.jetbrains.kotlin.metadata.deserialization.supertypes +import org.jetbrains.kotlin.metadata.deserialization.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.psi.KtClassBody import org.jetbrains.kotlin.psi.KtSuperTypeEntry @@ -57,6 +54,7 @@ private class ClassClsStubBuilder( private val c = outerContext.child( classProto.typeParameterList, classId.shortClassName, nameResolver, thisAsProtoContainer.typeTable, thisAsProtoContainer ) + private val contextReceiversListStubBuilder = ContextReceiversListStubBuilder(c) private val typeStubBuilder = TypeClsStubBuilder(c) private val supertypeIds = run { val supertypeIds = classProto.supertypes(c.typeTable).map { c.nameResolver.getClassId(it.className) } @@ -85,6 +83,7 @@ private class ClassClsStubBuilder( private fun createClassOrObjectStubAndModifierListStub(): StubElement { val classOrObjectStub = doCreateClassOrObjectStub() + contextReceiversListStubBuilder.createContextReceiverStubs(classOrObjectStub, classProto.contextReceiverTypes(c.typeTable)) val modifierList = createModifierListForClass(classOrObjectStub) if (Flags.HAS_ANNOTATIONS.get(classProto.flags)) { createAnnotationStubs(c.components.annotationLoader.loadClassAnnotations(thisAsProtoContainer), modifierList) diff --git a/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ContextReceiversListStubBuilder.kt b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ContextReceiversListStubBuilder.kt new file mode 100644 index 00000000000..fe05b91492b --- /dev/null +++ b/analysis/decompiled/decompiler-to-stubs/src/org/jetbrains/kotlin/analysis/decompiler/stub/ContextReceiversListStubBuilder.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2022 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.analysis.decompiler.stub + +import com.intellij.psi.stubs.StubElement +import org.jetbrains.kotlin.metadata.ProtoBuf +import org.jetbrains.kotlin.psi.KtContextReceiver +import org.jetbrains.kotlin.psi.KtContextReceiverList +import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes +import org.jetbrains.kotlin.psi.stubs.impl.KotlinPlaceHolderStubImpl + +internal class ContextReceiversListStubBuilder(c: ClsStubBuilderContext) { + private val typeStubBuilder = TypeClsStubBuilder(c) + + fun createContextReceiverStubs(parent: StubElement<*>, contextReceiverTypes: List) { + if (contextReceiverTypes.isEmpty()) return + val contextReceiverListStub = + KotlinPlaceHolderStubImpl(parent, KtStubElementTypes.CONTEXT_RECEIVER_LIST) + for (contextReceiverType in contextReceiverTypes) { + val contextReceiverStub = + KotlinPlaceHolderStubImpl(contextReceiverListStub, KtStubElementTypes.CONTEXT_RECEIVER) + typeStubBuilder.createTypeReferenceStub(contextReceiverStub, contextReceiverType) + } + } +} \ No newline at end of file diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index f74a4857b6c..681d131d2b0 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -28,7 +28,7 @@ object KotlinStubVersions { // Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed // or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder). // Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files). - private const val BINARY_STUB_VERSION = 78 + private const val BINARY_STUB_VERSION = 79 // Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile) // Increasing this version will lead to reindexing of all classfiles.