[LL FIR] FirLazyBodiesCalculator: drop obsolete logic for compiler required annotations
We have custom logic on `LLFirCompilerRequiredAnnotationsTargetResolver` side
This commit is contained in:
committed by
Space Team
parent
f5f3b7fec0
commit
58a1662c02
+20
-46
@@ -22,7 +22,6 @@ 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.expressions.impl.FirSingleExpressionBlock
|
||||
import org.jetbrains.kotlin.fir.extensions.registeredPluginAnnotations
|
||||
import org.jetbrains.kotlin.fir.references.FirDelegateFieldReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.builder.buildDelegateFieldReference
|
||||
@@ -54,7 +53,7 @@ internal object FirLazyBodiesCalculator {
|
||||
}
|
||||
|
||||
fun calculateAllLazyExpressionsInFile(firFile: FirFile) {
|
||||
firFile.transformSingle(FirAllLazyAnnotationCalculatorTransformer, FirLazyAnnotationTransformerData(firFile.moduleData.session))
|
||||
firFile.transformSingle(FirAllLazyAnnotationCalculatorTransformer, firFile.moduleData.session)
|
||||
firFile.transformSingle(FirAllLazyBodiesCalculatorTransformer, persistentListOf())
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ internal object FirLazyBodiesCalculator {
|
||||
}
|
||||
|
||||
fun calculateAnnotations(firElement: FirElement, session: FirSession) {
|
||||
firElement.transformSingle(FirTargetLazyAnnotationCalculatorTransformer, FirLazyAnnotationTransformerData(session))
|
||||
firElement.transformSingle(FirTargetLazyAnnotationCalculatorTransformer, session)
|
||||
}
|
||||
|
||||
fun calculateLazyArgumentsForAnnotation(annotationCall: FirAnnotationCall, session: FirSession): FirArgumentList {
|
||||
@@ -625,29 +624,20 @@ private fun calculateLazyBodyForCodeFragment(designation: FirDesignation) {
|
||||
codeFragment.replaceBlock(newCodeFragment.block)
|
||||
}
|
||||
|
||||
private enum class FirLazyAnnotationTransformerScope {
|
||||
ALL_ANNOTATIONS,
|
||||
}
|
||||
|
||||
private data class FirLazyAnnotationTransformerData(
|
||||
val session: FirSession,
|
||||
val compilerAnnotationsOnly: FirLazyAnnotationTransformerScope = FirLazyAnnotationTransformerScope.ALL_ANNOTATIONS,
|
||||
)
|
||||
|
||||
private object FirAllLazyAnnotationCalculatorTransformer : FirLazyAnnotationTransformer() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: FirLazyAnnotationTransformerData): E {
|
||||
override fun <E : FirElement> transformElement(element: E, data: FirSession): E {
|
||||
element.transformChildren(this, data)
|
||||
return element
|
||||
}
|
||||
}
|
||||
|
||||
private object FirTargetLazyAnnotationCalculatorTransformer : FirLazyAnnotationTransformer() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: FirLazyAnnotationTransformerData): E {
|
||||
override fun <E : FirElement> transformElement(element: E, data: FirSession): E {
|
||||
element.transformChildren(this, data)
|
||||
return element
|
||||
}
|
||||
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: FirLazyAnnotationTransformerData): FirStatement {
|
||||
override fun transformRegularClass(regularClass: FirRegularClass, data: FirSession): FirStatement {
|
||||
regularClass.transformAnnotations(this, data)
|
||||
regularClass.transformTypeParameters(this, data)
|
||||
regularClass.transformSuperTypeRefs(this, data)
|
||||
@@ -658,47 +648,39 @@ private object FirTargetLazyAnnotationCalculatorTransformer : FirLazyAnnotationT
|
||||
return regularClass
|
||||
}
|
||||
|
||||
override fun transformScript(script: FirScript, data: FirLazyAnnotationTransformerData): FirScript {
|
||||
override fun transformScript(script: FirScript, data: FirSession): FirScript {
|
||||
script.transformAnnotations(this, data)
|
||||
return script
|
||||
}
|
||||
|
||||
override fun transformBlock(block: FirBlock, data: FirLazyAnnotationTransformerData): FirStatement {
|
||||
override fun transformBlock(block: FirBlock, data: FirSession): FirStatement {
|
||||
// We shouldn't process blocks because there are no lazy annotations
|
||||
return block
|
||||
}
|
||||
|
||||
override fun transformFile(file: FirFile, data: FirLazyAnnotationTransformerData): FirFile {
|
||||
override fun transformFile(file: FirFile, data: FirSession): FirFile {
|
||||
file.transformAnnotationsContainer(this, data)
|
||||
return file
|
||||
}
|
||||
}
|
||||
|
||||
private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnnotationTransformerData>() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: FirLazyAnnotationTransformerData): E {
|
||||
private abstract class FirLazyAnnotationTransformer : FirTransformer<FirSession>() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: FirSession): E {
|
||||
element.transformChildren(this, data)
|
||||
return element
|
||||
}
|
||||
|
||||
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 session.annotationPlatformSupport.requiredAnnotationsShortClassNames
|
||||
}
|
||||
|
||||
override fun transformErrorTypeRef(errorTypeRef: FirErrorTypeRef, data: FirLazyAnnotationTransformerData): FirTypeRef {
|
||||
override fun transformErrorTypeRef(errorTypeRef: FirErrorTypeRef, data: FirSession): FirTypeRef {
|
||||
visitTypeAnnotations(errorTypeRef, data)
|
||||
return super.transformErrorTypeRef(errorTypeRef, data)
|
||||
}
|
||||
|
||||
override fun transformResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: FirLazyAnnotationTransformerData): FirTypeRef {
|
||||
override fun transformResolvedTypeRef(resolvedTypeRef: FirResolvedTypeRef, data: FirSession): FirTypeRef {
|
||||
visitTypeAnnotations(resolvedTypeRef, data)
|
||||
return super.transformResolvedTypeRef(resolvedTypeRef, data)
|
||||
}
|
||||
|
||||
private fun visitTypeAnnotations(resolvedTypeRef: FirResolvedTypeRef, data: FirLazyAnnotationTransformerData) {
|
||||
private fun visitTypeAnnotations(resolvedTypeRef: FirResolvedTypeRef, data: FirSession) {
|
||||
resolvedTypeRef.coneType.forEachType { coneType ->
|
||||
for (typeArgumentAnnotation in coneType.customAnnotations) {
|
||||
typeArgumentAnnotation.accept(this, data)
|
||||
@@ -706,11 +688,9 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnno
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformAnnotationCall(annotationCall: FirAnnotationCall, data: FirLazyAnnotationTransformerData): FirStatement {
|
||||
val shouldCalculate = data.compilerAnnotationsOnly == FirLazyAnnotationTransformerScope.ALL_ANNOTATIONS ||
|
||||
canBeCompilerAnnotation(annotationCall, data.session)
|
||||
if (shouldCalculate && FirLazyBodiesCalculator.needCalculatingAnnotationCall(annotationCall)) {
|
||||
val newArgumentList = FirLazyBodiesCalculator.calculateLazyArgumentsForAnnotation(annotationCall, data.session)
|
||||
override fun transformAnnotationCall(annotationCall: FirAnnotationCall, data: FirSession): FirStatement {
|
||||
if (FirLazyBodiesCalculator.needCalculatingAnnotationCall(annotationCall)) {
|
||||
val newArgumentList = FirLazyBodiesCalculator.calculateLazyArgumentsForAnnotation(annotationCall, data)
|
||||
annotationCall.replaceArgumentList(newArgumentList)
|
||||
}
|
||||
|
||||
@@ -718,15 +698,12 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnno
|
||||
return annotationCall
|
||||
}
|
||||
|
||||
override fun transformErrorAnnotationCall(
|
||||
errorAnnotationCall: FirErrorAnnotationCall,
|
||||
data: FirLazyAnnotationTransformerData,
|
||||
): FirStatement {
|
||||
override fun transformErrorAnnotationCall(errorAnnotationCall: FirErrorAnnotationCall, data: FirSession): FirStatement {
|
||||
transformAnnotationCall(errorAnnotationCall, data)
|
||||
return errorAnnotationCall
|
||||
}
|
||||
|
||||
override fun transformExpression(expression: FirExpression, data: FirLazyAnnotationTransformerData): FirStatement {
|
||||
override fun transformExpression(expression: FirExpression, data: FirSession): FirStatement {
|
||||
if (expression is FirLazyExpression) {
|
||||
return expression
|
||||
}
|
||||
@@ -734,7 +711,7 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnno
|
||||
return super.transformExpression(expression, data)
|
||||
}
|
||||
|
||||
override fun transformBlock(block: FirBlock, data: FirLazyAnnotationTransformerData): FirStatement {
|
||||
override fun transformBlock(block: FirBlock, data: FirSession): FirStatement {
|
||||
if (block is FirLazyBlock) {
|
||||
return block
|
||||
}
|
||||
@@ -742,10 +719,7 @@ private abstract class FirLazyAnnotationTransformer : FirTransformer<FirLazyAnno
|
||||
return super.transformBlock(block, data)
|
||||
}
|
||||
|
||||
override fun transformDelegatedConstructorCall(
|
||||
delegatedConstructorCall: FirDelegatedConstructorCall,
|
||||
data: FirLazyAnnotationTransformerData,
|
||||
): FirStatement {
|
||||
override fun transformDelegatedConstructorCall(delegatedConstructorCall: FirDelegatedConstructorCall, data: FirSession): FirStatement {
|
||||
if (delegatedConstructorCall is FirLazyDelegatedConstructorCall) {
|
||||
return delegatedConstructorCall
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user