[FIR] Remove jvm-specific annotations from common compiler code

^KT-54596 Fixed
This commit is contained in:
Nikolay Lunyak
2023-08-10 15:44:52 +03:00
committed by Space Team
parent f7a2da8f82
commit 986f1624ec
48 changed files with 405 additions and 268 deletions
@@ -19,12 +19,11 @@ import org.jetbrains.kotlin.fir.declarations.utils.getExplicitBackingField
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.expressions.impl.FirLazyDelegatedConstructorCall
import org.jetbrains.kotlin.fir.extensions.registeredPluginAnnotations
import org.jetbrains.kotlin.fir.resolve.transformers.plugin.CompilerRequiredAnnotationsHelper
import org.jetbrains.kotlin.fir.declarations.annotationPlatformSupport
import org.jetbrains.kotlin.fir.scopes.kotlinScopeProvider
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.visitors.FirTransformer
import org.jetbrains.kotlin.fir.visitors.transformSingle
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
internal object FirLazyBodiesCalculator {
@@ -319,15 +318,12 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnno
return element
}
private val COMPILER_ANNOTATION_NAMES: Set<Name> = CompilerRequiredAnnotationsHelper.REQUIRED_ANNOTATIONS
.mapTo(mutableSetOf()) { it.shortClassName }
private fun canBeCompilerAnnotation(annotationCall: FirAnnotationCall, session: FirSession): Boolean {
val annotationTypeRef = annotationCall.annotationTypeRef
if (annotationTypeRef !is FirUserTypeRef) return false
if (session.registeredPluginAnnotations.annotations.isNotEmpty()) return true
val name = annotationTypeRef.qualifier.last().name
return name in COMPILER_ANNOTATION_NAMES
return name in session.annotationPlatformSupport.requiredAnnotationsShortClassNames
}
override fun transformResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: FirLazyAnnotationTransformerData): FirTypeRef {
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.symbols.lazyResolveToPhase
import org.jetbrains.kotlin.fir.types.FirUserTypeRef
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.forEachDependentDeclaration
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.isScriptDependentDeclaration
import org.jetbrains.kotlin.fir.declarations.annotationPlatformSupport
internal object LLFirCompilerAnnotationsLazyResolver : LLFirLazyResolver(FirResolvePhase.COMPILER_REQUIRED_ANNOTATIONS) {
override fun resolve(
@@ -197,8 +198,9 @@ private class LLFirCompilerRequiredAnnotationsTargetResolver(
fun balanceAnnotations(target: FirElementWithResolveState) {
if (target !is FirProperty) return
val backingField = target.backingField ?: return
val updatedAnnotations = transformer.annotationTransformer.extractBackingFieldAnnotationsFromProperty(
val updatedAnnotations = transformer.session.annotationPlatformSupport.extractBackingFieldAnnotationsFromProperty(
target,
transformer.session,
annotationMap[target].orEmpty(),
annotationMap[backingField].orEmpty(),
) ?: return