[AA, LL] use stubs to build deserialized Fir elements in IDE

^KTIJ-24638

Notice on `DebugSymbolRenderer`:
stub based deserializer sets source directly,
but it's available in IDE mode only.
Thus, standalone and IDE tests have different results.
In order to avoid this, sources for compiled code are explicitly ignored

Notice on distinct callables:
for a file which belong to multiple libraries, decompiled code would be build per library.
In order to avoid ambiguity errors for members in that file,
we need to distinct provided elements by origins
failed test from IJ repo:
 FirReferenceResolveWithCrossLibTestGenerated#testSetWithTypeParameters
This commit is contained in:
Anna Kozlova
2023-02-15 14:22:59 +01:00
committed by teamcity
parent 96c15f6c71
commit d59d66e876
41 changed files with 1957 additions and 90 deletions
@@ -270,7 +270,7 @@ private fun FirRegularClassBuilder.addSerializableIfNeeded(classId: ClassId) {
}
}
private fun FirRegularClassBuilder.addCloneForArrayIfNeeded(classId: ClassId, dispatchReceiver: ConeClassLikeType?) {
fun FirRegularClassBuilder.addCloneForArrayIfNeeded(classId: ClassId, dispatchReceiver: ConeClassLikeType?) {
if (classId.packageFqName != StandardClassIds.BASE_KOTLIN_PACKAGE) return
if (classId.shortClassName !in ARRAY_CLASSES) return
superTypeRefs += buildResolvedTypeRef {
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.name.Name
// Use it in application sessions for loading classes from Java files listed on the command line.
// For library and incremental compilation sessions use `KotlinDeserializedJvmSymbolsProvider`
// in order to load Kotlin classes as well.
//Also used in IDE for loading java classes separately from stub based kotlin classes
class JavaSymbolProvider(
session: FirSession,
private val javaFacade: FirJavaFacade,
@@ -1056,6 +1056,7 @@ fun <T> FirRegularClassBuilder.createDataClassCopyFunction(
status = FirDeclarationStatusImpl(Visibilities.Public, Modality.FINAL)
symbol = FirNamedFunctionSymbol(CallableId(classId.packageFqName, classId.relativeClassName, StandardNames.DATA_CLASS_COPY))
dispatchReceiverType = dispatchReceiver
resolvePhase = this@createDataClassCopyFunction.resolvePhase
for ((ktParameter, firProperty) in zippedParameters) {
val propertyName = firProperty.name
val parameterSource = toFirSource(ktParameter, KtFakeSourceElementKind.DataClassGeneratedMembers)
@@ -160,7 +160,7 @@ fun FirRegularClassBuilder.generateEntriesGetter(
getter = FirDefaultPropertyGetter(
sourceElement?.fakeElement(KtFakeSourceElementKind.EnumGeneratedDeclaration),
moduleData, origin, returnTypeRef.copyWithNewSourceKind(KtFakeSourceElementKind.EnumGeneratedDeclaration),
Visibilities.Public, symbol
Visibilities.Public, symbol, resolvePhase = this@generateEntriesGetter.resolvePhase
).apply {
this.status = createStatus(this@generateEntriesGetter.status).apply {
isStatic = true
@@ -41,12 +41,15 @@ public class KtNameReferenceExpressionElementType extends KtStubElementType<Kotl
@Override
public void serialize(@NotNull KotlinNameReferenceExpressionStub stub, @NotNull StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getReferencedName());
dataStream.writeBoolean(
stub instanceof KotlinNameReferenceExpressionStubImpl && ((KotlinNameReferenceExpressionStubImpl) stub).isClassRef());
}
@NotNull
@Override
public KotlinNameReferenceExpressionStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
StringRef referencedName = dataStream.readName();
return new KotlinNameReferenceExpressionStubImpl(parentStub, referencedName);
boolean isClassRef = dataStream.readBoolean();
return new KotlinNameReferenceExpressionStubImpl(parentStub, referencedName, isClassRef);
}
}
@@ -16,9 +16,11 @@
package org.jetbrains.kotlin.psi.stubs.impl;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.psi.KtNameReferenceExpression;
import org.jetbrains.kotlin.psi.stubs.KotlinNameReferenceExpressionStub;
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
@@ -27,10 +29,26 @@ public class KotlinNameReferenceExpressionStubImpl extends KotlinStubBaseImpl<Kt
KotlinNameReferenceExpressionStub {
@NotNull
private final StringRef referencedName;
private final boolean myClassRef;
public KotlinNameReferenceExpressionStubImpl(StubElement parent, @NotNull StringRef referencedName) {
super(parent, KtStubElementTypes.REFERENCE_EXPRESSION);
this.referencedName = referencedName;
myClassRef = false;
}
public KotlinNameReferenceExpressionStubImpl(
@Nullable StubElement<?> parent,
@NotNull StringRef referencedName,
boolean myClassRef
) {
super(parent, KtStubElementTypes.REFERENCE_EXPRESSION);
this.referencedName = referencedName;
this.myClassRef = myClassRef;
}
public boolean isClassRef() {
return myClassRef;
}
@NotNull