[FIR] Use stubs for creating lazy bodies of backing field initializer
Ninth step for ^KT-52615 Merge-request: KT-MR-8756 Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
This commit is contained in:
@@ -1705,7 +1705,7 @@ open class RawFirBuilder(
|
|||||||
|
|
||||||
private fun KtDeclarationWithInitializer.toInitializerExpression() =
|
private fun KtDeclarationWithInitializer.toInitializerExpression() =
|
||||||
runIf(hasInitializer()) {
|
runIf(hasInitializer()) {
|
||||||
buildOrLazyExpression(initializer?.toFirSourceElement()) {
|
buildOrLazyExpression(null) {
|
||||||
initializer.toFirExpression("Should have initializer")
|
initializer.toFirExpression("Should have initializer")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,11 +62,19 @@ public class KtBackingField extends KtDeclarationStub<KotlinBackingFieldStub>
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public KtExpression getInitializer() {
|
public KtExpression getInitializer() {
|
||||||
|
KotlinBackingFieldStub stub = getStub();
|
||||||
|
if (stub != null && !stub.hasInitializer()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
return PsiTreeUtil.getNextSiblingOfType(getEqualsToken(), KtExpression.class);
|
return PsiTreeUtil.getNextSiblingOfType(getEqualsToken(), KtExpression.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasInitializer() {
|
public boolean hasInitializer() {
|
||||||
|
KotlinBackingFieldStub stub = getStub();
|
||||||
|
if (stub != null) {
|
||||||
|
return stub.hasInitializer();
|
||||||
|
}
|
||||||
return getInitializer() != null;
|
return getInitializer() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ object KotlinStubVersions {
|
|||||||
// Though only kotlin declarations (no code in the bodies) are stubbed, please do increase this version
|
// 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.
|
// 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.
|
// 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 = 145
|
const val SOURCE_STUB_VERSION = 146
|
||||||
|
|
||||||
// Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed
|
// 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).
|
// or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder).
|
||||||
|
|||||||
@@ -127,7 +127,9 @@ interface KotlinPropertyAccessorStub : StubElement<KtPropertyAccessor> {
|
|||||||
fun hasBlockBody(): Boolean
|
fun hasBlockBody(): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface KotlinBackingFieldStub : StubElement<KtBackingField>
|
interface KotlinBackingFieldStub : StubElement<KtBackingField> {
|
||||||
|
fun hasInitializer(): Boolean
|
||||||
|
}
|
||||||
|
|
||||||
interface KotlinPropertyStub : KotlinCallableStubBase<KtProperty> {
|
interface KotlinPropertyStub : KotlinCallableStubBase<KtProperty> {
|
||||||
fun isVar(): Boolean
|
fun isVar(): Boolean
|
||||||
|
|||||||
+6
-3
@@ -34,15 +34,18 @@ public class KtBackingFieldElementType extends KtStubElementType<KotlinBackingFi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KotlinBackingFieldStub createStub(@NotNull KtBackingField psi, StubElement parentStub) {
|
public KotlinBackingFieldStub createStub(@NotNull KtBackingField psi, StubElement parentStub) {
|
||||||
return new KotlinBackingFieldStubImpl(parentStub);
|
return new KotlinBackingFieldStubImpl(parentStub, psi.hasInitializer());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void serialize(@NotNull KotlinBackingFieldStub stub, @NotNull StubOutputStream dataStream) throws IOException {}
|
public void serialize(@NotNull KotlinBackingFieldStub stub, @NotNull StubOutputStream dataStream) throws IOException {
|
||||||
|
dataStream.writeBoolean(stub.hasInitializer());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public KotlinBackingFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
public KotlinBackingFieldStub deserialize(@NotNull StubInputStream dataStream, StubElement parentStub) throws IOException {
|
||||||
return new KotlinBackingFieldStubImpl(parentStub);
|
boolean hasInitializer = dataStream.readBoolean();
|
||||||
|
return new KotlinBackingFieldStubImpl(parentStub, hasInitializer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -23,7 +23,14 @@ import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes;
|
|||||||
|
|
||||||
public class KotlinBackingFieldStubImpl extends KotlinStubBaseImpl<KtBackingField>
|
public class KotlinBackingFieldStubImpl extends KotlinStubBaseImpl<KtBackingField>
|
||||||
implements KotlinBackingFieldStub {
|
implements KotlinBackingFieldStub {
|
||||||
public KotlinBackingFieldStubImpl(StubElement<?> parent) {
|
private final boolean hasInitializer;
|
||||||
|
public KotlinBackingFieldStubImpl(StubElement<?> parent, boolean hasInitializer) {
|
||||||
super(parent, KtStubElementTypes.BACKING_FIELD);
|
super(parent, KtStubElementTypes.BACKING_FIELD);
|
||||||
|
this.hasInitializer = hasInitializer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasInitializer() {
|
||||||
|
return hasInitializer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user