FIR LC: revisit when to add fields to companion and/or containing class
This commit is contained in:
committed by
Ilya Kirillov
parent
89d1a6bc0f
commit
63fb00fa21
+8
-2
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtClassBody
|
|||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||||
import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub
|
import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.applyIf
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.ifFalse
|
import org.jetbrains.kotlin.utils.addToStdlib.ifFalse
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
|
import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
|
||||||
|
|
||||||
@@ -101,7 +102,9 @@ internal abstract class FirLightClassForClassOrObjectSymbol(
|
|||||||
analyzeWithSymbolAsContext(this) {
|
analyzeWithSymbolAsContext(this) {
|
||||||
getDeclaredMemberScope().getCallableSymbols()
|
getDeclaredMemberScope().getCallableSymbols()
|
||||||
.filterIsInstance<KtPropertySymbol>()
|
.filterIsInstance<KtPropertySymbol>()
|
||||||
.filter { it.hasJvmFieldAnnotation() || it.hasJvmStaticAnnotation() || it is KtKotlinPropertySymbol && it.isConst }
|
.applyIf(isInterface) {
|
||||||
|
filter { it.hasJvmFieldAnnotation() || it.isConst }
|
||||||
|
}
|
||||||
.mapTo(result) {
|
.mapTo(result) {
|
||||||
FirLightFieldForPropertySymbol(
|
FirLightFieldForPropertySymbol(
|
||||||
propertySymbol = it,
|
propertySymbol = it,
|
||||||
@@ -109,7 +112,7 @@ internal abstract class FirLightClassForClassOrObjectSymbol(
|
|||||||
containingClass = this@FirLightClassForClassOrObjectSymbol,
|
containingClass = this@FirLightClassForClassOrObjectSymbol,
|
||||||
lightMemberOrigin = null,
|
lightMemberOrigin = null,
|
||||||
isTopLevel = false,
|
isTopLevel = false,
|
||||||
forceStatic = !it.hasJvmStaticAnnotation(),
|
forceStatic = true,
|
||||||
takePropertyVisibility = true
|
takePropertyVisibility = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -117,6 +120,9 @@ internal abstract class FirLightClassForClassOrObjectSymbol(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val KtPropertySymbol.isConst: Boolean
|
||||||
|
get() = (this as? KtKotlinPropertySymbol)?.isConst == true
|
||||||
|
|
||||||
private val _containingFile: PsiFile? by lazyPub {
|
private val _containingFile: PsiFile? by lazyPub {
|
||||||
|
|
||||||
val kotlinOrigin = kotlinOrigin ?: return@lazyPub null
|
val kotlinOrigin = kotlinOrigin ?: return@lazyPub null
|
||||||
|
|||||||
+4
-1
@@ -246,7 +246,10 @@ internal open class FirLightClassForSymbol(
|
|||||||
val propertySymbols = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
|
val propertySymbols = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
|
||||||
.filterIsInstance<KtPropertySymbol>()
|
.filterIsInstance<KtPropertySymbol>()
|
||||||
.applyIf(classOrObjectSymbol.isCompanionObject) {
|
.applyIf(classOrObjectSymbol.isCompanionObject) {
|
||||||
filterNot { it.hasJvmFieldAnnotation() || it is KtKotlinPropertySymbol && it.isConst }
|
// All fields for companion object of classes are generated to the containing class
|
||||||
|
// For interfaces, only @JvmField-annotated properties are generated to the containing class
|
||||||
|
// Probably, the same should work for const vals but it doesn't at the moment (see KT-28294)
|
||||||
|
filter { containingClass?.isInterface == true && !it.hasJvmFieldAnnotation() }
|
||||||
}
|
}
|
||||||
val propertyGroups = propertySymbols.groupBy { it.isFromPrimaryConstructor }
|
val propertyGroups = propertySymbols.groupBy { it.isFromPrimaryConstructor }
|
||||||
|
|
||||||
|
|||||||
+3
@@ -7,6 +7,9 @@ public abstract interface TraitClassObjectField /* TraitClassObjectField*/ {
|
|||||||
|
|
||||||
|
|
||||||
public static final class Companion /* TraitClassObjectField.Companion*/ {
|
public static final class Companion /* TraitClassObjectField.Companion*/ {
|
||||||
|
@org.jetbrains.annotations.Nullable()
|
||||||
|
private final java.lang.String x = "" /* initializer type: java.lang.String */;
|
||||||
|
|
||||||
@org.jetbrains.annotations.Nullable()
|
@org.jetbrains.annotations.Nullable()
|
||||||
private final java.lang.String y;
|
private final java.lang.String y;
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -7,6 +7,8 @@ public final class SmartSet /* SmartSet*/<T> extends kotlin.collections.Abstrac
|
|||||||
|
|
||||||
private int size;
|
private int size;
|
||||||
|
|
||||||
|
private static final int ARRAY_THRESHOLD;
|
||||||
|
|
||||||
@kotlin.jvm.JvmStatic()
|
@kotlin.jvm.JvmStatic()
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public static final <T> SmartSet<T> create();// <T> create()
|
public static final <T> SmartSet<T> create();// <T> create()
|
||||||
@@ -30,8 +32,6 @@ public final class SmartSet /* SmartSet*/<T> extends kotlin.collections.Abstrac
|
|||||||
|
|
||||||
|
|
||||||
public static final class Companion /* SmartSet.Companion*/ {
|
public static final class Companion /* SmartSet.Companion*/ {
|
||||||
private final int ARRAY_THRESHOLD;
|
|
||||||
|
|
||||||
@kotlin.jvm.JvmStatic()
|
@kotlin.jvm.JvmStatic()
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public final <T> SmartSet<T> create();// <T> create()
|
public final <T> SmartSet<T> create();// <T> create()
|
||||||
@@ -42,4 +42,4 @@ public static final class Companion /* SmartSet.Companion*/ {
|
|||||||
|
|
||||||
private Companion();// .ctor()
|
private Companion();// .ctor()
|
||||||
|
|
||||||
}}
|
}}
|
||||||
+6
-6
@@ -2,16 +2,16 @@ public final class ClassObjectField /* ClassObjectField*/ {
|
|||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public static final ClassObjectField.Companion Companion;
|
public static final ClassObjectField.Companion Companion;
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.Nullable()
|
||||||
|
private static final java.lang.String y;
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.Nullable()
|
||||||
|
public static final java.lang.String x;
|
||||||
|
|
||||||
public ClassObjectField();// .ctor()
|
public ClassObjectField();// .ctor()
|
||||||
|
|
||||||
|
|
||||||
public static final class Companion /* ClassObjectField.Companion*/ {
|
public static final class Companion /* ClassObjectField.Companion*/ {
|
||||||
@org.jetbrains.annotations.Nullable()
|
|
||||||
private final java.lang.String x;
|
|
||||||
|
|
||||||
@org.jetbrains.annotations.Nullable()
|
|
||||||
private final java.lang.String y;
|
|
||||||
|
|
||||||
@org.jetbrains.annotations.Nullable()
|
@org.jetbrains.annotations.Nullable()
|
||||||
public final java.lang.String getX();// getX()
|
public final java.lang.String getX();// getX()
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ public static final class Companion /* A.Companion*/ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract interface B /* B*/ {
|
public abstract interface B /* B*/ {
|
||||||
|
@kotlin.jvm.JvmField()
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public static final java.util.Collection<?> a;
|
||||||
|
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public static final B.Companion Companion;
|
public static final B.Companion Companion;
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
public final class C /* C*/ {
|
public final class C /* C*/ {
|
||||||
@kotlin.jvm.JvmStatic()
|
@kotlin.jvm.JvmStatic()
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public java.lang.String x;
|
public static java.lang.String x;
|
||||||
|
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public static final C.Companion Companion;
|
public static final C.Companion Companion;
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public static java.lang.String c1;
|
||||||
|
|
||||||
|
@org.jetbrains.annotations.NotNull()
|
||||||
|
public static java.lang.String c;
|
||||||
|
|
||||||
@kotlin.jvm.JvmStatic()
|
@kotlin.jvm.JvmStatic()
|
||||||
public static final void foo();// foo()
|
public static final void foo();// foo()
|
||||||
|
|
||||||
@@ -20,10 +26,6 @@ public final class C /* C*/ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Companion /* C.Companion*/ {
|
public static final class Companion /* C.Companion*/ {
|
||||||
@kotlin.jvm.JvmStatic()
|
|
||||||
@org.jetbrains.annotations.NotNull()
|
|
||||||
private java.lang.String x;
|
|
||||||
|
|
||||||
@kotlin.jvm.JvmStatic()
|
@kotlin.jvm.JvmStatic()
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
public final java.lang.String getC(I);// getC(I)
|
public final java.lang.String getC(I);// getC(I)
|
||||||
|
|||||||
@@ -80,6 +80,12 @@ public final class Foo /* Foo*/ {
|
|||||||
|
|
||||||
public java.lang.String internalVarPrivateSet;
|
public java.lang.String internalVarPrivateSet;
|
||||||
|
|
||||||
|
public static final int f1;
|
||||||
|
|
||||||
|
public static final int prop3;
|
||||||
|
|
||||||
|
public static int prop7;
|
||||||
|
|
||||||
@org.jetbrains.annotations.NotNull()
|
@org.jetbrains.annotations.NotNull()
|
||||||
protected final java.lang.String getProtectedLateinitVar();// getProtectedLateinitVar()
|
protected final java.lang.String getProtectedLateinitVar();// getProtectedLateinitVar()
|
||||||
|
|
||||||
@@ -191,12 +197,6 @@ public final class Foo /* Foo*/ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Companion /* Foo.Companion*/ {
|
public static final class Companion /* Foo.Companion*/ {
|
||||||
private final int f1;
|
|
||||||
|
|
||||||
private final int prop3;
|
|
||||||
|
|
||||||
private int prop7;
|
|
||||||
|
|
||||||
private Companion();// .ctor()
|
private Companion();// .ctor()
|
||||||
|
|
||||||
public final int getF1();// getF1()
|
public final int getF1();// getF1()
|
||||||
|
|||||||
Reference in New Issue
Block a user