[FIR] Introduce utility for creating ConeClassLikeLookupTagImpl from ClassId
`classId.toLookupTag()` looks much cleaner than `ConeClassLikeLookupTagImpl(classId)`
This commit is contained in:
committed by
Space Team
parent
6c449e29cd
commit
125b773205
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.fir.declarations.utils.effectiveVisibility
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.java.declarations.*
|
||||
import org.jetbrains.kotlin.fir.java.enhancement.FirSignatureEnhancement
|
||||
import org.jetbrains.kotlin.fir.types.constructType
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
@@ -463,7 +462,7 @@ abstract class FirJavaFacade(
|
||||
resolvePhase = FirResolvePhase.ANALYZED_DEPENDENCIES
|
||||
origin = javaOrigin(javaField.isFromSource)
|
||||
}.apply {
|
||||
containingClassForStaticMemberAttr = ConeClassLikeLookupTagImpl(classId)
|
||||
containingClassForStaticMemberAttr = classId.toLookupTag()
|
||||
// TODO: check if this works properly with annotations that take the enum class as an argument
|
||||
setAnnotationsFromJava(session, javaField, javaTypeParameterStack)
|
||||
}
|
||||
@@ -500,7 +499,7 @@ abstract class FirJavaFacade(
|
||||
}
|
||||
}.apply {
|
||||
if (javaField.isStatic) {
|
||||
containingClassForStaticMemberAttr = ConeClassLikeLookupTagImpl(classId)
|
||||
containingClassForStaticMemberAttr = classId.toLookupTag()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -555,7 +554,7 @@ abstract class FirJavaFacade(
|
||||
}
|
||||
}.apply {
|
||||
if (javaMethod.isStatic) {
|
||||
containingClassForStaticMemberAttr = ConeClassLikeLookupTagImpl(classId)
|
||||
containingClassForStaticMemberAttr = classId.toLookupTag()
|
||||
}
|
||||
if (containingClass.isRecord && valueParameters.isEmpty() && containingClass.recordComponents.any { it.name == methodName }) {
|
||||
isJavaRecordComponent = true
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.java.enhancement.readOnlyToMutable
|
||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
@@ -24,9 +23,6 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
private fun ClassId.toLookupTag(): ConeClassLikeLookupTag =
|
||||
ConeClassLikeLookupTagImpl(this)
|
||||
|
||||
private fun ClassId.toConeFlexibleType(
|
||||
typeArguments: Array<out ConeTypeProjection>,
|
||||
typeArgumentsForUpper: Array<out ConeTypeProjection>,
|
||||
@@ -186,7 +182,7 @@ private fun JavaClassifierType.toConeKotlinTypeForFlexibleBound(
|
||||
classId = classId.readOnlyToMutable() ?: classId
|
||||
}
|
||||
|
||||
val lookupTag = ConeClassLikeLookupTagImpl(classId)
|
||||
val lookupTag = classId.toLookupTag()
|
||||
// When converting type parameter bounds we should not attempt to load any classes, as this may trigger
|
||||
// enhancement of type parameter bounds on some other class that depends on this one. Also, in case of raw
|
||||
// types specifically there could be an infinite recursion on the type parameter itself.
|
||||
|
||||
+3
-4
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.fir.references.builder.buildResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.getClassDeclaredPropertySymbols
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
@@ -36,7 +35,7 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko
|
||||
private fun loadAnnotation(
|
||||
annotationClassId: ClassId, result: MutableList<FirAnnotation>,
|
||||
): KotlinJvmBinaryClass.AnnotationArgumentVisitor {
|
||||
val lookupTag = ConeClassLikeLookupTagImpl(annotationClassId)
|
||||
val lookupTag = annotationClassId.toLookupTag()
|
||||
|
||||
return object : KotlinJvmBinaryClass.AnnotationArgumentVisitor {
|
||||
private val argumentMap = mutableMapOf<Name, FirExpression>()
|
||||
@@ -48,7 +47,7 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko
|
||||
}
|
||||
|
||||
private fun ClassLiteralValue.toFirClassReferenceExpression(): FirClassReferenceExpression {
|
||||
val resolvedClassTypeRef = ConeClassLikeLookupTagImpl(classId).toDefaultResolvedTypeRef()
|
||||
val resolvedClassTypeRef = classId.toLookupTag().toDefaultResolvedTypeRef()
|
||||
return buildClassReferenceExpression {
|
||||
classTypeRef = resolvedClassTypeRef
|
||||
typeRef = buildResolvedTypeRef {
|
||||
@@ -83,7 +82,7 @@ internal class AnnotationsLoader(private val session: FirSession, private val ko
|
||||
|
||||
typeRef = buildResolvedTypeRef {
|
||||
type = ConeClassLikeTypeImpl(
|
||||
ConeClassLikeLookupTagImpl(this@toEnumEntryReferenceExpression),
|
||||
this@toEnumEntryReferenceExpression.toLookupTag(),
|
||||
emptyArray(),
|
||||
isNullable = false
|
||||
)
|
||||
|
||||
+1
-1
@@ -489,7 +489,7 @@ class FirSignatureEnhancement(
|
||||
else -> return null
|
||||
}
|
||||
return ConeClassLikeTypeImpl(
|
||||
ConeClassLikeLookupTagImpl(purelyImplementedClassId),
|
||||
purelyImplementedClassId.toLookupTag(),
|
||||
parametersAsTypeProjections.toTypedArray(),
|
||||
isNullable = false
|
||||
)
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassifierLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.load.java.typeEnhancement.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -136,13 +135,13 @@ private fun ConeClassifierLookupTag.enhanceMutability(
|
||||
MutabilityQualifier.READ_ONLY -> {
|
||||
val readOnlyId = classId.mutableToReadOnly()
|
||||
if (position == TypeComponentPosition.FLEXIBLE_LOWER && readOnlyId != null) {
|
||||
return ConeClassLikeLookupTagImpl(readOnlyId)
|
||||
return readOnlyId.toLookupTag()
|
||||
}
|
||||
}
|
||||
MutabilityQualifier.MUTABLE -> {
|
||||
val mutableId = classId.readOnlyToMutable()
|
||||
if (position == TypeComponentPosition.FLEXIBLE_UPPER && mutableId != null) {
|
||||
return ConeClassLikeLookupTagImpl(mutableId)
|
||||
return mutableId.toLookupTag()
|
||||
}
|
||||
}
|
||||
null -> {}
|
||||
|
||||
@@ -154,7 +154,7 @@ private fun buildEnumCall(session: FirSession, classId: ClassId?, entryName: Nam
|
||||
if (classId != null) {
|
||||
this.typeRef = buildResolvedTypeRef {
|
||||
type = ConeClassLikeTypeImpl(
|
||||
ConeClassLikeLookupTagImpl(classId),
|
||||
classId.toLookupTag(),
|
||||
emptyArray(),
|
||||
isNullable = false
|
||||
)
|
||||
@@ -174,7 +174,7 @@ private fun List<JavaAnnotationArgument>.mapJavaTargetArguments(session: FirSess
|
||||
resultSet.mapTo(arguments) { buildEnumCall(session, classId, Name.identifier(it.name)) }
|
||||
varargElementType = buildResolvedTypeRef {
|
||||
type = ConeClassLikeTypeImpl(
|
||||
ConeClassLikeLookupTagImpl(classId),
|
||||
classId.toLookupTag(),
|
||||
emptyArray(),
|
||||
isNullable = false,
|
||||
ConeAttributes.Empty
|
||||
@@ -221,7 +221,7 @@ private fun JavaAnnotation.toFirAnnotationCall(
|
||||
StandardClassIds.Annotations.Java.Documented -> StandardClassIds.Annotations.MustBeDocumented
|
||||
StandardClassIds.Annotations.Java.Deprecated -> StandardClassIds.Annotations.Deprecated
|
||||
else -> classId
|
||||
}?.let(::ConeClassLikeLookupTagImpl)
|
||||
}?.toLookupTag()
|
||||
annotationTypeRef = if (lookupTag != null) {
|
||||
buildResolvedTypeRef {
|
||||
type = ConeClassLikeTypeImpl(lookupTag, emptyArray(), isNullable = false)
|
||||
|
||||
Reference in New Issue
Block a user