[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.sessions.llFirSession
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.transformers.LLFirFileAnnotationsResolveTransformer
|
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.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.checkCanceled
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.findSourceNonLocalFirDeclaration
|
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.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.analysis.utils.errors.shouldIjPlatformExceptionBeRethrown
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.declarations.*
|
import org.jetbrains.kotlin.fir.declarations.*
|
||||||
@@ -157,6 +158,7 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
|||||||
if (checkPCE) checkCanceled()
|
if (checkPCE) checkCanceled()
|
||||||
firFile.transform<FirElement, Any?>(FirImportResolveTransformer(firFile.moduleData.session), null)
|
firFile.transform<FirElement, Any?>(FirImportResolveTransformer(firFile.moduleData.session), null)
|
||||||
firFile.replaceResolvePhase(FirResolvePhase.IMPORTS)
|
firFile.replaceResolvePhase(FirResolvePhase.IMPORTS)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun lazyResolveFileDeclarationWithoutLock(
|
private fun lazyResolveFileDeclarationWithoutLock(
|
||||||
@@ -186,25 +188,24 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
|||||||
currentPhase = currentPhase.next
|
currentPhase = currentPhase.next
|
||||||
if (checkPCE) checkCanceled()
|
if (checkPCE) checkCanceled()
|
||||||
|
|
||||||
val transformersToApply = designations.mapNotNull {
|
val transformersToApply = designations.filter { designation ->
|
||||||
val needToResolve = it.declaration.resolvePhase < currentPhase
|
designation.declaration.resolvePhase < currentPhase
|
||||||
if (needToResolve) {
|
}
|
||||||
LazyTransformerFactory.createLazyTransformer(
|
|
||||||
|
if (transformersToApply.isEmpty()) continue
|
||||||
|
|
||||||
|
moduleComponents.globalResolveComponents.phaseRunner.runPhaseWithCustomResolve(currentPhase) {
|
||||||
|
for (curDesignation in transformersToApply) {
|
||||||
|
LLFirLazyTransformerExecutor.execute(
|
||||||
phase = currentPhase,
|
phase = currentPhase,
|
||||||
designation = it,
|
designation = curDesignation,
|
||||||
scopeSession = scopeSession,
|
scopeSession = scopeSession,
|
||||||
|
phaseRunner = moduleComponents.globalResolveComponents.phaseRunner,
|
||||||
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
||||||
towerDataContextCollector = collector,
|
towerDataContextCollector = collector,
|
||||||
firProviderInterceptor = null,
|
firProviderInterceptor = null,
|
||||||
checkPCE = checkPCE,
|
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)
|
firFile.replaceResolvePhase(currentPhase)
|
||||||
@@ -373,15 +374,16 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
|||||||
currentPhase = currentPhase.next
|
currentPhase = currentPhase.next
|
||||||
if (checkPCE) checkCanceled()
|
if (checkPCE) checkCanceled()
|
||||||
|
|
||||||
LazyTransformerFactory.createLazyTransformer(
|
LLFirLazyTransformerExecutor.execute(
|
||||||
phase = currentPhase,
|
phase = currentPhase,
|
||||||
designation = designation,
|
designation = designation,
|
||||||
scopeSession = scopeSession,
|
scopeSession = scopeSession,
|
||||||
|
phaseRunner = moduleComponents.globalResolveComponents.phaseRunner,
|
||||||
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
||||||
towerDataContextCollector = null,
|
towerDataContextCollector = null,
|
||||||
firProviderInterceptor = null,
|
firProviderInterceptor = null,
|
||||||
checkPCE = checkPCE,
|
checkPCE = checkPCE,
|
||||||
).transformDeclaration(moduleComponents.globalResolveComponents.phaseRunner)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -408,15 +410,16 @@ internal class LLFirModuleLazyDeclarationResolver(val moduleComponents: LLFirMod
|
|||||||
currentPhase = currentPhase.next
|
currentPhase = currentPhase.next
|
||||||
if (checkPCE) checkCanceled()
|
if (checkPCE) checkCanceled()
|
||||||
|
|
||||||
LazyTransformerFactory.createLazyTransformer(
|
LLFirLazyTransformerExecutor.execute(
|
||||||
phase = currentPhase,
|
phase = currentPhase,
|
||||||
designation = designation,
|
designation = designation,
|
||||||
scopeSession = scopeSession,
|
scopeSession = scopeSession,
|
||||||
|
phaseRunner = moduleComponents.globalResolveComponents.phaseRunner,
|
||||||
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
lockProvider = moduleComponents.globalResolveComponents.lockProvider,
|
||||||
towerDataContextCollector = towerDataContextCollector,
|
towerDataContextCollector = towerDataContextCollector,
|
||||||
firProviderInterceptor = firProviderInterceptor,
|
firProviderInterceptor = firProviderInterceptor,
|
||||||
checkPCE = checkPCE,
|
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