Optimal type mapping modes for UAST
As shown in (DEFALUT | GENERIC_ARGUMENT)_UAST, UAST's PsiType mapping needs an automatic expansion of type alias. This commit makes utils that generate optimal type mapping modes for return / parameter to consider if this is used for UAST. In that case, utils will set `mapTypeAliases` true so that typealias (even inside type arguments) can be expanded properly.
This commit is contained in:
committed by
Ilya Kirillov
parent
485fad1951
commit
e89a387cd4
+13
-8
@@ -9,23 +9,26 @@ import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
|||||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||||
|
|
||||||
fun TypeSystemCommonBackendContext.getOptimalModeForValueParameter(
|
fun TypeSystemCommonBackendContext.getOptimalModeForValueParameter(
|
||||||
type: KotlinTypeMarker
|
type: KotlinTypeMarker,
|
||||||
): TypeMappingMode = getOptimalModeForSignaturePart(type, canBeUsedInSupertypePosition = true)
|
isForUast: Boolean = false,
|
||||||
|
): TypeMappingMode = getOptimalModeForSignaturePart(type, canBeUsedInSupertypePosition = true, isForUast)
|
||||||
|
|
||||||
fun TypeSystemCommonBackendContext.getOptimalModeForReturnType(
|
fun TypeSystemCommonBackendContext.getOptimalModeForReturnType(
|
||||||
type: KotlinTypeMarker,
|
type: KotlinTypeMarker,
|
||||||
isAnnotationMethod: Boolean
|
isAnnotationMethod: Boolean,
|
||||||
|
isForUast: Boolean = false,
|
||||||
): TypeMappingMode {
|
): TypeMappingMode {
|
||||||
return if (isAnnotationMethod)
|
return if (isAnnotationMethod)
|
||||||
TypeMappingMode.VALUE_FOR_ANNOTATION
|
TypeMappingMode.VALUE_FOR_ANNOTATION
|
||||||
else
|
else
|
||||||
getOptimalModeForSignaturePart(type, canBeUsedInSupertypePosition = false)
|
getOptimalModeForSignaturePart(type, canBeUsedInSupertypePosition = false, isForUast)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(TypeMappingModeInternals::class)
|
@OptIn(TypeMappingModeInternals::class)
|
||||||
private fun TypeSystemCommonBackendContext.getOptimalModeForSignaturePart(
|
private fun TypeSystemCommonBackendContext.getOptimalModeForSignaturePart(
|
||||||
type: KotlinTypeMarker,
|
type: KotlinTypeMarker,
|
||||||
canBeUsedInSupertypePosition: Boolean
|
canBeUsedInSupertypePosition: Boolean,
|
||||||
|
isForUast: Boolean = false,
|
||||||
): TypeMappingMode {
|
): TypeMappingMode {
|
||||||
if (type.argumentsCount() == 0) return TypeMappingMode.DEFAULT
|
if (type.argumentsCount() == 0) return TypeMappingMode.DEFAULT
|
||||||
|
|
||||||
@@ -33,7 +36,7 @@ private fun TypeSystemCommonBackendContext.getOptimalModeForSignaturePart(
|
|||||||
if (isInlineClassType && shouldUseUnderlyingType(type)) {
|
if (isInlineClassType && shouldUseUnderlyingType(type)) {
|
||||||
val underlyingType = computeUnderlyingType(type)
|
val underlyingType = computeUnderlyingType(type)
|
||||||
if (underlyingType != null) {
|
if (underlyingType != null) {
|
||||||
return getOptimalModeForSignaturePart(underlyingType, canBeUsedInSupertypePosition).dontWrapInlineClassesMode()
|
return getOptimalModeForSignaturePart(underlyingType, canBeUsedInSupertypePosition, isForUast).dontWrapInlineClassesMode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,15 +48,17 @@ private fun TypeSystemCommonBackendContext.getOptimalModeForSignaturePart(
|
|||||||
|
|
||||||
val invariantArgumentMode =
|
val invariantArgumentMode =
|
||||||
if (canBeUsedInSupertypePosition)
|
if (canBeUsedInSupertypePosition)
|
||||||
getOptimalModeForSignaturePart(type, canBeUsedInSupertypePosition = false)
|
getOptimalModeForSignaturePart(type, canBeUsedInSupertypePosition = false, isForUast)
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|
||||||
return TypeMappingMode(
|
return TypeMappingMode(
|
||||||
skipDeclarationSiteWildcards = !canBeUsedInSupertypePosition,
|
skipDeclarationSiteWildcards = !canBeUsedInSupertypePosition,
|
||||||
skipDeclarationSiteWildcardsIfPossible = true,
|
skipDeclarationSiteWildcardsIfPossible = true,
|
||||||
|
genericArgumentMode = if (isForUast) TypeMappingMode.GENERIC_ARGUMENT_UAST else null,
|
||||||
genericContravariantArgumentMode = contravariantArgumentMode,
|
genericContravariantArgumentMode = contravariantArgumentMode,
|
||||||
genericInvariantArgumentMode = invariantArgumentMode,
|
genericInvariantArgumentMode = invariantArgumentMode,
|
||||||
needInlineClassWrapping = !isInlineClassType
|
needInlineClassWrapping = !isInlineClassType,
|
||||||
|
mapTypeAliases = isForUast
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user