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:
@@ -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.TRANSIENT_ANNOTATION_FQ_NAME
|
||||||
import org.jetbrains.kotlin.resolve.jvm.annotations.VOLATILE_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.resolve.jvm.diagnostics.JvmDeclarationOriginKind
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
internal open class KtUltraLightField(
|
internal open class KtUltraLightField(
|
||||||
protected val declaration: KtNamedDeclaration,
|
protected val declaration: KtNamedDeclaration,
|
||||||
@@ -60,13 +61,11 @@ internal open class KtUltraLightField(
|
|||||||
|
|
||||||
override fun getLanguage(): Language = KotlinLanguage.INSTANCE
|
override fun getLanguage(): Language = KotlinLanguage.INSTANCE
|
||||||
|
|
||||||
private val _type: PsiType by lazyPub {
|
private val propertyDescriptor: PropertyDescriptor? by lazyPub {
|
||||||
fun nonExistent() = JavaPsiFacade.getElementFactory(project).createTypeFromText("error.NonExistentClass", declaration)
|
declaration.resolve() as? PropertyDescriptor
|
||||||
|
}
|
||||||
val propertyDescriptor: PropertyDescriptor? by lazyPub {
|
|
||||||
declaration.resolve() as? PropertyDescriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private val kotlinType: KotlinType? by lazyPub {
|
||||||
when {
|
when {
|
||||||
declaration is KtProperty && declaration.hasDelegate() ->
|
declaration is KtProperty && declaration.hasDelegate() ->
|
||||||
propertyDescriptor
|
propertyDescriptor
|
||||||
@@ -74,17 +73,25 @@ internal open class KtUltraLightField(
|
|||||||
val context = LightClassGenerationSupport.getInstance(project).analyze(declaration)
|
val context = LightClassGenerationSupport.getInstance(project).analyze(declaration)
|
||||||
PropertyCodegen.getDelegateTypeForProperty(declaration, it, context)
|
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)
|
?.let(TypeConversionUtil::erasure)
|
||||||
?: nonExistent()
|
?: 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 -> {
|
else -> {
|
||||||
val kotlinType = declaration.getKotlinType() ?: return@lazyPub PsiType.NULL
|
val kotlinType = declaration.getKotlinType() ?: return@lazyPub PsiType.NULL
|
||||||
val descriptor = propertyDescriptor ?: return@lazyPub PsiType.NULL
|
val descriptor = propertyDescriptor ?: return@lazyPub PsiType.NULL
|
||||||
|
|||||||
Reference in New Issue
Block a user