From ac19cc9376500bd9d4bd47c3c21351c489d4e28f Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 29 Nov 2018 12:07:19 +0300 Subject: [PATCH] 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 --- .../kotlin/asJava/classes/ultraLightField.kt | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt index 4a8bff5d899..3d8d5e1ff1b 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/classes/ultraLightField.kt @@ -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