FIR LC: use optimal type mapping mode for value parameter

This commit is contained in:
Jinseong Jeon
2021-11-03 23:09:45 -07:00
committed by Ilya Kirillov
parent 6d150fb7a5
commit d3c34fa200
7 changed files with 35 additions and 9 deletions
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.light.classes.symbol
import com.intellij.psi.*
import org.jetbrains.kotlin.asJava.classes.lazyPub
import org.jetbrains.kotlin.analysis.api.symbols.KtValueParameterSymbol
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
import org.jetbrains.kotlin.psi.KtParameter
internal abstract class FirLightParameterBaseForSymbol(
@@ -39,17 +40,22 @@ internal abstract class FirLightParameterBaseForSymbol(
parameterSymbol.annotatedType.type
)
}
}
else NullabilityType.Unknown
} else NullabilityType.Unknown
}
override fun getNameIdentifier(): PsiIdentifier = _identifier
private val _type by lazyPub {
val convertedType = analyzeWithSymbolAsContext(parameterSymbol) {
parameterSymbol.annotatedType.type.asPsiType(this@FirLightParameterBaseForSymbol)
?: this@FirLightParameterBaseForSymbol.nonExistentType()
}
val ktType = parameterSymbol.annotatedType.type
val typeMappingMode = when {
ktType.isSuspendFunctionType -> TypeMappingMode.DEFAULT
// TODO: extract type mapping mode from annotation?
// TODO: methods with declaration site wildcards?
else -> ktType.getOptimalModeForValueParameter()
}
ktType.asPsiType(this@FirLightParameterBaseForSymbol, typeMappingMode)
} ?: nonExistentType()
if (parameterSymbol.isVararg) {
PsiEllipsisType(convertedType, convertedType.annotationProvider)
} else convertedType
@@ -72,8 +72,7 @@ internal class FirLightParameterForReceiver private constructor(
private val _type: PsiType by lazyPub {
analyzeWithSymbolAsContext(context) {
receiverTypeAndAnnotations.type.asPsiType(this@FirLightParameterForReceiver)
?: this@FirLightParameterForReceiver.nonExistentType()
}
} ?: nonExistentType()
}
override fun getType(): PsiType = _type