[Low Level FIR] encapsulate the work with lazy transformers to a class
This commit is contained in:
+20
-17
@@ -16,10 +16,11 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.project.structure.llFirMo
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.llFirSession
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirFileAnnotationsResolveTransformer
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirFirProviderInterceptor
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LazyTransformerFactory
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirLazyTransformerExecutor
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.checkCanceled
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.findSourceNonLocalFirDeclaration
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.withFirEntry
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.buildErrorWithAttachment
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
@@ -157,6 +158,7 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
||||
if (checkPCE) checkCanceled()
|
||||
firFile.transform<FirElement, Any?>(FirImportResolveTransformer(firFile.moduleData.session), null)
|
||||
firFile.replaceResolvePhase(FirResolvePhase.IMPORTS)
|
||||
|
||||
}
|
||||
|
||||
private fun lazyResolveFileDeclarationWithoutLock(
|
||||
@@ -186,25 +188,24 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
||||
currentPhase = currentPhase.next
|
||||
if (checkPCE) checkCanceled()
|
||||
|
||||
val transformersToApply = designations.mapNotNull {
|
||||
val needToResolve = it.declaration.resolvePhase < currentPhase
|
||||
if (needToResolve) {
|
||||
LazyTransformerFactory.createLazyTransformer(
|
||||
val transformersToApply = designations.filter { designation ->
|
||||
designation.declaration.resolvePhase < currentPhase
|
||||
}
|
||||
|
||||
if (transformersToApply.isEmpty()) continue
|
||||
|
||||
moduleComponents.globalResolveComponents.phaseRunner.runPhaseWithCustomResolve(currentPhase) {
|
||||
for (curDesignation in transformersToApply) {
|
||||
LLFirLazyTransformerExecutor.execute(
|
||||
phase = currentPhase,
|
||||
designation = it,
|
||||
designation = curDesignation,
|
||||
scopeSession = scopeSession,
|
||||
phaseRunner = moduleComponents.globalResolveComponents.phaseRunner,
|
||||
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
||||
towerDataContextCollector = collector,
|
||||
firProviderInterceptor = null,
|
||||
checkPCE = checkPCE,
|
||||
)
|
||||
} else null
|
||||
}
|
||||
if (transformersToApply.isEmpty()) continue
|
||||
|
||||
moduleComponents.globalResolveComponents.phaseRunner.runPhaseWithCustomResolve(currentPhase) {
|
||||
for (currentTransformer in transformersToApply) {
|
||||
currentTransformer.transformDeclaration(moduleComponents.globalResolveComponents.phaseRunner)
|
||||
}
|
||||
}
|
||||
firFile.replaceResolvePhase(currentPhase)
|
||||
@@ -373,15 +374,16 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
||||
currentPhase = currentPhase.next
|
||||
if (checkPCE) checkCanceled()
|
||||
|
||||
LazyTransformerFactory.createLazyTransformer(
|
||||
LLFirLazyTransformerExecutor.execute(
|
||||
phase = currentPhase,
|
||||
designation = designation,
|
||||
scopeSession = scopeSession,
|
||||
phaseRunner = moduleComponents.globalResolveComponents.phaseRunner,
|
||||
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
||||
towerDataContextCollector = null,
|
||||
firProviderInterceptor = null,
|
||||
checkPCE = checkPCE,
|
||||
).transformDeclaration(moduleComponents.globalResolveComponents.phaseRunner)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,15 +410,16 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
||||
currentPhase = currentPhase.next
|
||||
if (checkPCE) checkCanceled()
|
||||
|
||||
LazyTransformerFactory.createLazyTransformer(
|
||||
LLFirLazyTransformerExecutor.execute(
|
||||
phase = currentPhase,
|
||||
designation = designation,
|
||||
scopeSession = scopeSession,
|
||||
phaseRunner = moduleComponents.globalResolveComponents.phaseRunner,
|
||||
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
||||
towerDataContextCollector = towerDataContextCollector,
|
||||
firProviderInterceptor = firProviderInterceptor,
|
||||
checkPCE = checkPCE,
|
||||
).transformDeclaration(moduleComponents.globalResolveComponents.phaseRunner)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.analysis.low.level.api.fir.transformers
|
||||
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.LLFirPhaseRunner
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.FirDeclarationDesignationWithFile
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirProviderInterceptor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirTowerDataContextCollector
|
||||
|
||||
internal class LLFirLazyTransformerExecutor {
|
||||
companion object {
|
||||
fun execute(
|
||||
phase: FirResolvePhase,
|
||||
designation: FirDeclarationDesignationWithFile,
|
||||
scopeSession: ScopeSession,
|
||||
phaseRunner: LLFirPhaseRunner,
|
||||
lockProvider: LLFirLockProvider,
|
||||
towerDataContextCollector: FirTowerDataContextCollector?,
|
||||
firProviderInterceptor: FirProviderInterceptor?,
|
||||
checkPCE: Boolean
|
||||
) {
|
||||
|
||||
val lazyTransformer = LazyTransformerFactory.createLazyTransformer(
|
||||
phase,
|
||||
designation,
|
||||
scopeSession,
|
||||
lockProvider,
|
||||
towerDataContextCollector,
|
||||
firProviderInterceptor,
|
||||
checkPCE
|
||||
)
|
||||
lazyTransformer.transformDeclaration(phaseRunner)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user