FIR LC: revisit when to add fields to companion and/or containing class

This commit is contained in:
Jinseong Jeon
2022-05-17 11:21:53 -07:00
committed by Ilya Kirillov
parent 89d1a6bc0f
commit 63fb00fa21
8 changed files with 41 additions and 23 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtClassBody
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.debugText.getDebugText
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.ifTrue
@@ -101,7 +102,9 @@ internal abstract class FirLightClassForClassOrObjectSymbol(
analyzeWithSymbolAsContext(this) {
getDeclaredMemberScope().getCallableSymbols()
.filterIsInstance<KtPropertySymbol>()
.filter { it.hasJvmFieldAnnotation() || it.hasJvmStaticAnnotation() || it is KtKotlinPropertySymbol && it.isConst }
.applyIf(isInterface) {
filter { it.hasJvmFieldAnnotation() || it.isConst }
}
.mapTo(result) {
FirLightFieldForPropertySymbol(
propertySymbol = it,
@@ -109,7 +112,7 @@ internal abstract class FirLightClassForClassOrObjectSymbol(
containingClass = this@FirLightClassForClassOrObjectSymbol,
lightMemberOrigin = null,
isTopLevel = false,
forceStatic = !it.hasJvmStaticAnnotation(),
forceStatic = 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 {
val kotlinOrigin = kotlinOrigin ?: return@lazyPub null
@@ -246,7 +246,10 @@ internal open class FirLightClassForSymbol(
val propertySymbols = classOrObjectSymbol.getDeclaredMemberScope().getCallableSymbols()
.filterIsInstance<KtPropertySymbol>()
.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 }