FIR LC: populate delegate fields

This commit is contained in:
Jinseong Jeon
2021-10-18 15:35:46 -07:00
committed by Ilya Kirillov
parent 71e7cfb036
commit 693564084a
2 changed files with 20 additions and 5 deletions
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtNonErrorClassType
import org.jetbrains.kotlin.analysis.api.types.KtType
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.light.classes.symbol.*
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.*
@@ -287,7 +288,8 @@ internal fun FirLightClassBase.createField(
property.modality == Modality.ABSTRACT -> false
property.isHiddenOrSynthetic(project) -> false
property.isLateInit -> true
//TODO Fix it when KtFirConstructorValueParameterSymbol be ready
property.isDelegatedProperty -> true
property.isFromPrimaryConstructor -> true
property.psi.let { it == null || it is KtParameter } -> true
property.hasJvmSyntheticAnnotation(AnnotationUseSiteTarget.FIELD) -> false
else -> property.hasBackingField
@@ -296,10 +298,15 @@ internal fun FirLightClassBase.createField(
if (!hasBackingField(declaration)) return
val isDelegated = (declaration as? KtKotlinPropertySymbol)?.isDelegatedProperty == true
val fieldName = nameGenerator.generateUniqueFieldName(
declaration.name.asString() + (if (isDelegated) JvmAbi.DELEGATED_PROPERTY_NAME_SUFFIX else "")
)
result.add(
FirLightFieldForPropertySymbol(
propertySymbol = declaration,
fieldName = nameGenerator.generateUniqueFieldName(declaration.name.asString()),
fieldName = fieldName,
containingClass = this,
lightMemberOrigin = null,
isTopLevel = isTopLevel,
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.analysis.api.symbols.KtKotlinPropertySymbol
import org.jetbrains.kotlin.analysis.api.symbols.KtPropertySymbol
import org.jetbrains.kotlin.analysis.api.symbols.markers.KtLiteralConstantValue
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.psi.KtProperty
internal class FirLightFieldForPropertySymbol(
private val propertySymbol: KtPropertySymbol,
@@ -29,9 +30,16 @@ internal class FirLightFieldForPropertySymbol(
private val _returnedType: PsiType by lazyPub {
analyzeWithSymbolAsContext(propertySymbol) {
propertySymbol.annotatedType.type.asPsiType(this@FirLightFieldForPropertySymbol)
?: this@FirLightFieldForPropertySymbol.nonExistentType()
}
val isDelegated = (propertySymbol as? KtKotlinPropertySymbol)?.isDelegatedProperty == true
when {
isDelegated ->
(kotlinOrigin as? KtProperty)?.delegateExpression?.let {
it.getKtType()?.asPsiType(this@FirLightFieldForPropertySymbol)
}
else ->
propertySymbol.annotatedType.type.asPsiType(this@FirLightFieldForPropertySymbol)
}
} ?: nonExistentType()
}
private val _isDeprecated: Boolean by lazyPub {