[LL FIR] LLFirTargetResolver: add default implementation to withFile and withRegularClassImpl
To drop redundant implementations in resolvers ^KT-60728
This commit is contained in:
committed by
Space Team
parent
de48a51711
commit
32e3b67416
+25
-20
@@ -54,36 +54,41 @@ private class LLFirAnnotationArgumentsTargetResolver(
|
||||
firResolveContextCollector = firResolveContextCollector,
|
||||
)
|
||||
|
||||
override fun withScript(firScript: FirScript, action: () -> Unit) {
|
||||
super.withScript(firScript) {
|
||||
transformer.firResolveContextCollector?.let { collector ->
|
||||
collector.addDeclarationContext(firScript, transformer.context)
|
||||
}
|
||||
|
||||
private inline fun actionWithContextCollector(
|
||||
noinline action: () -> Unit,
|
||||
crossinline collect: (FirResolveContextCollector, BodyResolveContext) -> Unit,
|
||||
): () -> Unit {
|
||||
val collector = transformer.firResolveContextCollector ?: return action
|
||||
return {
|
||||
collect(collector, transformer.context)
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
super.withFile(firFile) {
|
||||
transformer.firResolveContextCollector?.let { collector ->
|
||||
collector.addFileContext(firFile, transformer.context.towerDataContext)
|
||||
}
|
||||
|
||||
action()
|
||||
override fun withScript(firScript: FirScript, action: () -> Unit) {
|
||||
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
||||
collector.addDeclarationContext(firScript, context)
|
||||
}
|
||||
|
||||
super.withScript(firScript, actionWithCollector)
|
||||
}
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
||||
collector.addFileContext(firFile, context.towerDataContext)
|
||||
}
|
||||
|
||||
super.withFile(firFile, actionWithCollector)
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
super.withRegularClassImpl(firClass) {
|
||||
transformer.firResolveContextCollector?.let { collector ->
|
||||
collector.addDeclarationContext(firClass, transformer.context)
|
||||
}
|
||||
|
||||
action()
|
||||
val actionWithCollector = actionWithContextCollector(action) { collector, context ->
|
||||
collector.addDeclarationContext(firClass, context)
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
super.withRegularClassImpl(firClass, actionWithCollector)
|
||||
}
|
||||
|
||||
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
|
||||
|
||||
+2
-6
@@ -91,16 +91,12 @@ private class LLFirCompilerRequiredAnnotationsTargetResolver(
|
||||
get() = transformer.annotationTransformer.computationSession as LLFirCompilerRequiredAnnotationsComputationSession
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
transformer.annotationTransformer.withFileAndFileScopes(firFile) {
|
||||
action()
|
||||
}
|
||||
transformer.annotationTransformer.withFileAndFileScopes(firFile, action)
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
transformer.annotationTransformer.withRegularClass(firClass) {
|
||||
action()
|
||||
}
|
||||
transformer.annotationTransformer.withRegularClass(firClass, action)
|
||||
}
|
||||
|
||||
override fun doResolveWithoutLock(target: FirElementWithResolveState): Boolean {
|
||||
|
||||
-10
@@ -47,21 +47,11 @@ private class LLFirExpectActualMatchingTargetResolver(
|
||||
}
|
||||
}
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
|
||||
if (target !is FirMemberDeclaration) return
|
||||
if (!target.canHaveExpectCounterPart()) return
|
||||
transformer.transformMemberDeclaration(target)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun FirMemberDeclaration.canHaveExpectCounterPart(): Boolean = when (this) {
|
||||
|
||||
+1
-11
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveT
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
||||
import org.jetbrains.kotlin.fir.FirElementWithResolveState
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
@@ -36,17 +35,8 @@ private class LLFirCompanionGenerationTargetResolver(
|
||||
) : LLFirTargetResolver(target, lockProvider, FirResolvePhase.COMPANION_GENERATION) {
|
||||
private val transformer: FirCompanionGenerationTransformer = FirCompanionGenerationTransformer(session)
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
|
||||
if (target !is FirRegularClass) return
|
||||
transformer.generateAndUpdateCompanion(target)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-13
@@ -9,8 +9,6 @@ import org.jetbrains.kotlin.analysis.low.level.api.fir.api.targets.LLFirResolveT
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.file.builder.LLFirLockProvider
|
||||
import org.jetbrains.kotlin.fir.FirElementWithResolveState
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirResolveContextCollector
|
||||
@@ -33,17 +31,7 @@ private class LLFirSealedClassInheritorsDesignatedResolver(
|
||||
target: LLFirResolveTarget,
|
||||
lockProvider: LLFirLockProvider,
|
||||
) : LLFirTargetResolver(target, lockProvider, FirResolvePhase.SEALED_CLASS_INHERITORS) {
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
override fun doLazyResolveUnderLock(target: FirElementWithResolveState) {
|
||||
// just update the phase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-4
@@ -91,10 +91,6 @@ private class LLFirStatusTargetResolver(
|
||||
) : LLFirTargetResolver(target, lockProvider, FirResolvePhase.STATUS, isJumpingPhase = false) {
|
||||
private val transformer = Transformer(session, scopeSession)
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
doResolveWithoutLock(firClass)
|
||||
|
||||
-4
@@ -87,10 +87,6 @@ private class LLFirSuperTypeTargetResolver(
|
||||
}
|
||||
}
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
override fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
supertypeResolver.withClass(firClass) {
|
||||
|
||||
+6
-2
@@ -28,14 +28,18 @@ internal abstract class LLFirTargetResolver(
|
||||
|
||||
val nestedClassesStack: List<FirRegularClass> get() = _nestedClassesStack.toList()
|
||||
|
||||
protected abstract fun withFile(firFile: FirFile, action: () -> Unit)
|
||||
protected open fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
protected open fun withScript(firScript: FirScript, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
protected abstract fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit)
|
||||
protected open fun withRegularClassImpl(firClass: FirRegularClass, action: () -> Unit) {
|
||||
action()
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION_ERROR")
|
||||
protected fun withRegularClass(firClass: FirRegularClass, action: () -> Unit) {
|
||||
|
||||
+1
-3
@@ -81,9 +81,7 @@ private class LLFirTypeTargetResolver(
|
||||
}
|
||||
|
||||
override fun withFile(firFile: FirFile, action: () -> Unit) {
|
||||
transformer.withFileScope(firFile) {
|
||||
action()
|
||||
}
|
||||
transformer.withFileScope(firFile, action)
|
||||
}
|
||||
|
||||
@Deprecated("Should never be called directly, only for override purposes, please use withRegularClass", level = DeprecationLevel.ERROR)
|
||||
|
||||
Reference in New Issue
Block a user