Migrate utils to check/alter TypeMappingMode according to suppress wildcard annotations
^KT-61734
This commit is contained in:
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_WILDCARD_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.firstOverridden
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
@@ -35,6 +34,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSystemCommonBackendContext
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.suppressWildcardsMode
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
|
||||
import org.jetbrains.kotlin.types.checker.convertVariance
|
||||
import org.jetbrains.kotlin.types.getEffectiveVariance
|
||||
@@ -91,31 +91,6 @@ private val METHODS_WITH_DECLARATION_SITE_WILDCARDS = setOf(
|
||||
FqNames.mutableMap.child("putAll")
|
||||
)
|
||||
|
||||
fun TypeMappingMode.updateArgumentModeFromAnnotations(
|
||||
type: KotlinTypeMarker, typeSystem: TypeSystemCommonBackendContext
|
||||
): TypeMappingMode {
|
||||
type.suppressWildcardsMode(typeSystem)?.let {
|
||||
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = it,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
needInlineClassWrapping = needInlineClassWrapping,
|
||||
mapTypeAliases = mapTypeAliases
|
||||
)
|
||||
}
|
||||
|
||||
if (with(typeSystem) { type.hasAnnotation(JVM_WILDCARD_ANNOTATION_FQ_NAME) }) {
|
||||
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = false,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
fallbackMode = this,
|
||||
needInlineClassWrapping = needInlineClassWrapping,
|
||||
mapTypeAliases = mapTypeAliases
|
||||
)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
internal fun extractTypeMappingModeFromAnnotation(
|
||||
callableDescriptor: CallableDescriptor?,
|
||||
outerType: KotlinType,
|
||||
@@ -150,12 +125,6 @@ private fun DeclarationDescriptor.suppressWildcardsMode(): Boolean? =
|
||||
it.annotations.findAnnotation(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME)
|
||||
}.firstOrNull()?.suppressWildcardsMode()
|
||||
|
||||
private fun KotlinTypeMarker.suppressWildcardsMode(typeSystem: TypeSystemCommonBackendContext): Boolean? =
|
||||
with(typeSystem) {
|
||||
if (hasAnnotation(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME))
|
||||
getAnnotationFirstArgumentValue(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME) as? Boolean ?: true
|
||||
else null
|
||||
}
|
||||
|
||||
private fun AnnotationDescriptor.suppressWildcardsMode(): Boolean? =
|
||||
allValueArguments.values.firstOrNull()?.value as? Boolean ?: true
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@file:JvmName("TypeMappingUtil")
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
|
||||
import org.jetbrains.kotlin.name.JvmStandardClassIds
|
||||
import org.jetbrains.kotlin.name.JvmStandardClassIds.JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
|
||||
fun TypeMappingMode.updateArgumentModeFromAnnotations(
|
||||
type: KotlinTypeMarker, typeSystem: TypeSystemCommonBackendContext
|
||||
): TypeMappingMode {
|
||||
type.suppressWildcardsMode(typeSystem)?.let {
|
||||
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = it,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
needInlineClassWrapping = needInlineClassWrapping,
|
||||
mapTypeAliases = mapTypeAliases
|
||||
)
|
||||
}
|
||||
|
||||
if (with(typeSystem) { type.hasAnnotation(JvmStandardClassIds.JVM_WILDCARD_ANNOTATION_FQ_NAME) }) {
|
||||
return TypeMappingMode.createWithConstantDeclarationSiteWildcardsMode(
|
||||
skipDeclarationSiteWildcards = false,
|
||||
isForAnnotationParameter = isForAnnotationParameter,
|
||||
fallbackMode = this,
|
||||
needInlineClassWrapping = needInlineClassWrapping,
|
||||
mapTypeAliases = mapTypeAliases
|
||||
)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
fun KotlinTypeMarker.suppressWildcardsMode(typeSystem: TypeSystemCommonBackendContext): Boolean? =
|
||||
with(typeSystem) {
|
||||
if (hasAnnotation(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME))
|
||||
getAnnotationFirstArgumentValue(JVM_SUPPRESS_WILDCARDS_ANNOTATION_FQ_NAME) as? Boolean ?: true
|
||||
else null
|
||||
}
|
||||
-1
@@ -20,7 +20,6 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.sun.tools.javac.code.BoundKind
|
||||
import com.sun.tools.javac.tree.JCTree
|
||||
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
|
||||
import org.jetbrains.kotlin.codegen.state.updateArgumentModeFromAnnotations
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.kapt3.base.javac.kaptError
|
||||
import org.jetbrains.kotlin.kapt3.base.mapJList
|
||||
|
||||
Reference in New Issue
Block a user