Extract kotlinType property in KtUltraLightField

It's gonna be used in the later commits

Also simplify a bit related code in `_type` initializer:
it seems safe just to map `kotlinType` as is for all non-trivial cases,
also note that all of them are actually generated without generic signature
This commit is contained in:
Denis Zharkov
2018-11-29 12:07:19 +03:00
parent efc39c6137
commit ac19cc9376
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.resolve.jvm.annotations.TRANSIENT_ANNOTATION_FQ_NAME
import org.jetbrains.kotlin.resolve.jvm.annotations.VOLATILE_ANNOTATION_FQ_NAME
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
import org.jetbrains.kotlin.types.KotlinType
internal open class KtUltraLightField(
protected val declaration: KtNamedDeclaration,
@@ -60,13 +61,11 @@ internal open class KtUltraLightField(
override fun getLanguage(): Language = KotlinLanguage.INSTANCE
private val _type: PsiType by lazyPub {
fun nonExistent() = JavaPsiFacade.getElementFactory(project).createTypeFromText("error.NonExistentClass", declaration)
val propertyDescriptor: PropertyDescriptor? by lazyPub {
declaration.resolve() as? PropertyDescriptor
}
private val propertyDescriptor: PropertyDescriptor? by lazyPub {
declaration.resolve() as? PropertyDescriptor
}
private val kotlinType: KotlinType? by lazyPub {
when {
declaration is KtProperty && declaration.hasDelegate() ->
propertyDescriptor
@@ -74,17 +73,25 @@ internal open class KtUltraLightField(
val context = LightClassGenerationSupport.getInstance(project).analyze(declaration)
PropertyCodegen.getDelegateTypeForProperty(declaration, it, context)
}
?.let { it.asPsiType(support, TypeMappingMode.getOptimalModeForValueParameter(it), this) }
declaration is KtObjectDeclaration ->
(declaration.resolve() as? ClassDescriptor)?.defaultType
declaration is KtEnumEntry -> {
(containingClass.kotlinOrigin.resolve() as? ClassDescriptor)?.defaultType
}
else -> {
declaration.getKotlinType()
}
}
}
private val _type: PsiType by lazyPub {
fun nonExistent() = JavaPsiFacade.getElementFactory(project).createTypeFromText("error.NonExistentClass", declaration)
when {
(declaration is KtProperty && declaration.hasDelegate()) || declaration is KtEnumEntry || declaration is KtObjectDeclaration ->
kotlinType?.asPsiType(support, TypeMappingMode.DEFAULT, this)
?.let(TypeConversionUtil::erasure)
?: nonExistent()
declaration is KtObjectDeclaration ->
KtLightClassForSourceDeclaration.create(declaration)?.let { JavaPsiFacade.getElementFactory(project).createType(it) }
?: nonExistent()
declaration is KtEnumEntry -> {
(containingClass.kotlinOrigin.resolve() as? ClassDescriptor)
?.defaultType?.asPsiType(support, TypeMappingMode.DEFAULT, this)
?: nonExistent()
}
else -> {
val kotlinType = declaration.getKotlinType() ?: return@lazyPub PsiType.NULL
val descriptor = propertyDescriptor ?: return@lazyPub PsiType.NULL