[FIR] Map Class to KClass in java annotations
This commit is contained in:
committed by
Mikhail Glukhikh
parent
282a295d43
commit
b63257345b
@@ -106,11 +106,12 @@ internal fun JavaClassifierType.toFirResolvedTypeRef(
|
||||
|
||||
internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
session: FirSession,
|
||||
javaTypeParameterStack: JavaTypeParameterStack
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
forAnnotationValueParameter: Boolean = false
|
||||
): ConeKotlinType {
|
||||
return when (this) {
|
||||
is JavaClassifierType -> {
|
||||
toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack, forAnnotationValueParameter = forAnnotationValueParameter)
|
||||
}
|
||||
is JavaPrimitiveType -> {
|
||||
val primitiveType = type
|
||||
@@ -123,7 +124,7 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
classId.toConeKotlinType(emptyArray(), isNullable = false)
|
||||
}
|
||||
is JavaArrayType -> {
|
||||
toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack, forAnnotationValueParameter)
|
||||
}
|
||||
is JavaWildcardType -> bound?.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack) ?: run {
|
||||
StandardClassIds.Any.toConeFlexibleType(emptyArray())
|
||||
@@ -137,12 +138,13 @@ internal fun JavaType?.toConeKotlinTypeWithoutEnhancement(
|
||||
|
||||
private fun JavaArrayType.toConeKotlinTypeWithoutEnhancement(
|
||||
session: FirSession,
|
||||
javaTypeParameterStack: JavaTypeParameterStack
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
forAnnotationValueParameter: Boolean = false
|
||||
): ConeFlexibleType {
|
||||
val componentType = componentType
|
||||
return if (componentType !is JavaPrimitiveType) {
|
||||
val classId = StandardClassIds.Array
|
||||
val argumentType = componentType.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
val argumentType = componentType.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack, forAnnotationValueParameter)
|
||||
classId.toConeFlexibleType(
|
||||
arrayOf(argumentType),
|
||||
typeArgumentsForUpper = arrayOf(ConeKotlinTypeProjectionOut(argumentType))
|
||||
@@ -166,12 +168,24 @@ private fun ClassId.toConeFlexibleType(
|
||||
private fun JavaClassifierType.toConeKotlinTypeWithoutEnhancement(
|
||||
session: FirSession,
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
forTypeParameterBounds: Boolean = false
|
||||
forTypeParameterBounds: Boolean = false,
|
||||
forAnnotationValueParameter: Boolean = false
|
||||
): ConeKotlinType {
|
||||
val lowerBound = toConeKotlinTypeForFlexibleBound(session, javaTypeParameterStack, isLowerBound = true, forTypeParameterBounds)
|
||||
val lowerBound = toConeKotlinTypeForFlexibleBound(
|
||||
session,
|
||||
javaTypeParameterStack,
|
||||
isLowerBound = true,
|
||||
forTypeParameterBounds,
|
||||
forAnnotationValueParameter = forAnnotationValueParameter
|
||||
)
|
||||
val upperBound =
|
||||
toConeKotlinTypeForFlexibleBound(
|
||||
session, javaTypeParameterStack, isLowerBound = false, forTypeParameterBounds, lowerBound
|
||||
session,
|
||||
javaTypeParameterStack,
|
||||
isLowerBound = false,
|
||||
forTypeParameterBounds,
|
||||
lowerBound,
|
||||
forAnnotationValueParameter = forAnnotationValueParameter
|
||||
)
|
||||
|
||||
return if (isRaw) ConeRawType(lowerBound, upperBound) else ConeFlexibleType(lowerBound, upperBound)
|
||||
@@ -272,12 +286,17 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
||||
javaTypeParameterStack: JavaTypeParameterStack,
|
||||
isLowerBound: Boolean,
|
||||
forTypeParameterBounds: Boolean,
|
||||
lowerBound: ConeLookupTagBasedType? = null
|
||||
lowerBound: ConeLookupTagBasedType? = null,
|
||||
forAnnotationValueParameter: Boolean = false
|
||||
): ConeLookupTagBasedType {
|
||||
return when (val classifier = classifier) {
|
||||
is JavaClass -> {
|
||||
//val classId = classifier.classId!!
|
||||
var classId = JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!) ?: classifier.classId!!
|
||||
var classId = if (forAnnotationValueParameter) {
|
||||
JavaToKotlinClassMap.mapJavaToKotlinIncludingClassMapping(classifier.fqName!!)
|
||||
} else {
|
||||
JavaToKotlinClassMap.mapJavaToKotlin(classifier.fqName!!)
|
||||
} ?: classifier.classId!!
|
||||
|
||||
if (isLowerBound) {
|
||||
classId = classId.readOnlyToMutable() ?: classId
|
||||
|
||||
+7
-2
@@ -47,7 +47,8 @@ internal class EnhancementSignatureParts(
|
||||
internal fun enhance(
|
||||
session: FirSession,
|
||||
jsr305State: Jsr305State,
|
||||
predefined: TypeEnhancementInfo? = null
|
||||
predefined: TypeEnhancementInfo? = null,
|
||||
forAnnotationValueParameter: Boolean = false
|
||||
): PartEnhancementResult {
|
||||
val qualifiers = computeIndexedQualifiersForOverride(session, jsr305State)
|
||||
|
||||
@@ -57,7 +58,11 @@ internal class EnhancementSignatureParts(
|
||||
}
|
||||
}
|
||||
|
||||
val typeWithoutEnhancement = current.type.toConeKotlinTypeWithoutEnhancement(session, javaTypeParameterStack)
|
||||
val typeWithoutEnhancement = current.type.toConeKotlinTypeWithoutEnhancement(
|
||||
session,
|
||||
javaTypeParameterStack,
|
||||
forAnnotationValueParameter
|
||||
)
|
||||
val containsFunctionN = typeWithoutEnhancement.contains {
|
||||
if (it is ConeClassErrorType) false
|
||||
else {
|
||||
|
||||
+7
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.java.enhancement
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
@@ -289,7 +290,12 @@ class FirSignatureEnhancement(
|
||||
parameterContainer = ownerParameter,
|
||||
methodContext = memberContext,
|
||||
typeInSignature = TypeInSignature.ValueParameter(hasReceiver, index)
|
||||
).enhance(session, jsr305State, predefinedEnhancementInfo?.parametersInfo?.getOrNull(index))
|
||||
).enhance(
|
||||
session,
|
||||
jsr305State,
|
||||
predefinedEnhancementInfo?.parametersInfo?.getOrNull(index),
|
||||
forAnnotationValueParameter = owner.classKind == ClassKind.ANNOTATION_CLASS
|
||||
)
|
||||
val firResolvedTypeRef = signatureParts.type
|
||||
val defaultValueExpression = when (val defaultValue = ownerParameter.getDefaultValueFromAnnotation()) {
|
||||
NullDefaultValue -> buildConstExpression(null, FirConstKind.Null, null)
|
||||
|
||||
Reference in New Issue
Block a user