[Stubs] Pass proper container source to stub-based FIR declarations
Backend, which is used by the expression evaluator, relies on the class name in 'FacadeClassSource'. To pass the correct JVM class name, stubs for top-level functions and properties got the 'origin'.
This commit is contained in:
@@ -23,12 +23,12 @@ object KotlinStubVersions {
|
||||
// Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version
|
||||
// if you are not 100% sure it can be avoided.
|
||||
// Increasing this version will lead to reindexing of all kotlin source files on the first IDE startup with the new version.
|
||||
const val SOURCE_STUB_VERSION = 153
|
||||
const val SOURCE_STUB_VERSION = 154
|
||||
|
||||
// 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 = 91
|
||||
private const val BINARY_STUB_VERSION = 92
|
||||
|
||||
// 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.
|
||||
|
||||
+14
-4
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.KtNamedFunction;
|
||||
import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinFunctionStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinFunctionStubImpl;
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinStubOrigin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -52,7 +53,8 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
|
||||
(StubElement<?>) parentStub, StringRef.fromString(psi.getName()), isTopLevel, fqName,
|
||||
isExtension, hasBlockBody, hasBody, psi.hasTypeParameterListBeforeFunctionName(),
|
||||
psi.mayHaveContract(),
|
||||
null
|
||||
/* contract = */ null,
|
||||
/* origin = */ null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -70,8 +72,14 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
|
||||
dataStream.writeBoolean(stub.hasTypeParameterListBeforeFunctionName());
|
||||
boolean haveContract = stub.mayHaveContract();
|
||||
dataStream.writeBoolean(haveContract);
|
||||
if (haveContract && stub instanceof KotlinFunctionStubImpl) {
|
||||
((KotlinFunctionStubImpl) stub).serializeContract(dataStream);
|
||||
if (stub instanceof KotlinFunctionStubImpl) {
|
||||
KotlinFunctionStubImpl stubImpl = (KotlinFunctionStubImpl) stub;
|
||||
|
||||
if (haveContract) {
|
||||
stubImpl.serializeContract(dataStream);
|
||||
}
|
||||
|
||||
KotlinStubOrigin.serialize(stubImpl.getOrigin(), dataStream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +99,9 @@ public class KtFunctionElementType extends KtStubElementType<KotlinFunctionStub,
|
||||
boolean mayHaveContract = dataStream.readBoolean();
|
||||
return new KotlinFunctionStubImpl(
|
||||
(StubElement<?>) parentStub, name, isTopLevel, fqName, isExtension, hasBlockBody, hasBody,
|
||||
hasTypeParameterListBeforeFunctionName, mayHaveContract, mayHaveContract ? KotlinFunctionStubImpl.Companion.deserializeContract(dataStream) : null
|
||||
hasTypeParameterListBeforeFunctionName, mayHaveContract,
|
||||
mayHaveContract ? KotlinFunctionStubImpl.Companion.deserializeContract(dataStream) : null,
|
||||
KotlinStubOrigin.deserialize(dataStream)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+18
-8
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt;
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinPropertyStub;
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinConstantValueKt;
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinPropertyStubImpl;
|
||||
import org.jetbrains.kotlin.psi.stubs.impl.KotlinStubOrigin;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -50,7 +51,9 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
|
||||
psi.isVar(), psi.isTopLevel(), psi.hasDelegate(),
|
||||
psi.hasDelegateExpression(), psi.hasInitializer(),
|
||||
psi.getReceiverTypeReference() != null, psi.getTypeReference() != null,
|
||||
KtPsiUtilKt.safeFqNameForLazyResolve(psi), null
|
||||
KtPsiUtilKt.safeFqNameForLazyResolve(psi),
|
||||
/* constantInitializer = */ null,
|
||||
/* origin = */ null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -67,12 +70,18 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
|
||||
|
||||
FqName fqName = stub.getFqName();
|
||||
dataStream.writeName(fqName != null ? fqName.asString() : null);
|
||||
ConstantValue<?> constantInitializer = stub instanceof KotlinPropertyStubImpl ? ((KotlinPropertyStubImpl) stub).getConstantInitializer() : null;
|
||||
if (constantInitializer != null) {
|
||||
KotlinConstantValueKt.serialize(constantInitializer, dataStream);
|
||||
}
|
||||
else {
|
||||
dataStream.writeInt(-1);
|
||||
|
||||
if (stub instanceof KotlinPropertyStubImpl) {
|
||||
KotlinPropertyStubImpl stubImpl = (KotlinPropertyStubImpl) stub;
|
||||
|
||||
ConstantValue<?> constantInitializer = ((KotlinPropertyStubImpl) stub).getConstantInitializer();
|
||||
if (constantInitializer != null) {
|
||||
KotlinConstantValueKt.serialize(constantInitializer, dataStream);
|
||||
} else {
|
||||
dataStream.writeInt(-1);
|
||||
}
|
||||
|
||||
KotlinStubOrigin.serialize(stubImpl.getOrigin(), dataStream);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +102,8 @@ public class KtPropertyElementType extends KtStubElementType<KotlinPropertyStub,
|
||||
|
||||
return new KotlinPropertyStubImpl(
|
||||
(StubElement<?>) parentStub, name, isVar, isTopLevel, hasDelegate, hasDelegateExpression, hasInitializer,
|
||||
hasReceiverTypeRef, hasReturnTypeRef, fqName, KotlinConstantValueKt.createConstantValue(dataStream)
|
||||
hasReceiverTypeRef, hasReturnTypeRef, fqName, KotlinConstantValueKt.createConstantValue(dataStream),
|
||||
KotlinStubOrigin.deserialize(dataStream)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ class KotlinFunctionStubImpl(
|
||||
private val hasBody: Boolean,
|
||||
private val hasTypeParameterListBeforeFunctionName: Boolean,
|
||||
private val mayHaveContract: Boolean,
|
||||
val contract: List<KtContractDescriptionElement<KotlinTypeBean, Nothing?>>?
|
||||
val contract: List<KtContractDescriptionElement<KotlinTypeBean, Nothing?>>?,
|
||||
val origin: KotlinStubOrigin?
|
||||
) : KotlinStubBaseImpl<KtNamedFunction>(parent, KtStubElementTypes.FUNCTION), KotlinFunctionStub {
|
||||
init {
|
||||
if (isTopLevel && fqName == null) {
|
||||
|
||||
@@ -36,7 +36,8 @@ class KotlinPropertyStubImpl(
|
||||
private val isExtension: Boolean,
|
||||
private val hasReturnTypeRef: Boolean,
|
||||
private val fqName: FqName?,
|
||||
val constantInitializer: ConstantValue<*>?
|
||||
val constantInitializer: ConstantValue<*>?,
|
||||
val origin: KotlinStubOrigin?
|
||||
) : KotlinStubBaseImpl<KtProperty>(parent, KtStubElementTypes.PROPERTY), KotlinPropertyStub {
|
||||
|
||||
init {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.psi.stubs.impl
|
||||
|
||||
import com.intellij.psi.stubs.StubInputStream
|
||||
import com.intellij.psi.stubs.StubOutputStream
|
||||
|
||||
sealed class KotlinStubOrigin {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun serialize(origin: KotlinStubOrigin?, dataStream: StubOutputStream) {
|
||||
if (origin == null) {
|
||||
dataStream.writeInt(0)
|
||||
} else {
|
||||
dataStream.writeInt(origin.kind)
|
||||
origin.serializeContent(dataStream)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deserialize(dataStream: StubInputStream): KotlinStubOrigin? {
|
||||
return when (dataStream.readInt()) {
|
||||
Facade.KIND -> Facade.deserializeContent(dataStream)
|
||||
MultiFileFacade.KIND -> MultiFileFacade.deserializeContent(dataStream)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract val kind: Int
|
||||
|
||||
protected abstract fun serializeContent(dataStream: StubOutputStream)
|
||||
|
||||
data class Facade(
|
||||
val className: String // Internal name of the package part class
|
||||
) : KotlinStubOrigin() {
|
||||
companion object {
|
||||
const val KIND = 1
|
||||
|
||||
fun deserializeContent(dataStream: StubInputStream): Facade? {
|
||||
val className = dataStream.readNameString() ?: return null
|
||||
return Facade(className)
|
||||
}
|
||||
}
|
||||
|
||||
override val kind: Int get() = KIND
|
||||
|
||||
override fun serializeContent(dataStream: StubOutputStream) {
|
||||
dataStream.writeName(className)
|
||||
}
|
||||
}
|
||||
|
||||
data class MultiFileFacade(
|
||||
val className: String, // Internal name of the package part class
|
||||
val facadeClassName: String // Internal name of the facade class
|
||||
) : KotlinStubOrigin() {
|
||||
companion object {
|
||||
const val KIND = 2
|
||||
|
||||
fun deserializeContent(dataStream: StubInputStream): MultiFileFacade? {
|
||||
val classId = dataStream.readNameString() ?: return null
|
||||
val facadeClassId = dataStream.readNameString() ?: return null
|
||||
return MultiFileFacade(classId, facadeClassId)
|
||||
}
|
||||
}
|
||||
|
||||
override val kind: Int get() = Facade.KIND
|
||||
|
||||
override fun serializeContent(dataStream: StubOutputStream) {
|
||||
dataStream.writeName(className)
|
||||
dataStream.writeName(facadeClassName)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user