[FIR]: sealed hierarchy processor for IDE
From now on sealed declarations get resolved with the help of FirIdeSealedHierarchyProcessor. This change entails correct IDE side check for sealed when exhaustiveness.
This commit is contained in:
+1
-11
@@ -44,14 +44,4 @@ abstract class FirAbstractPhaseTransformer<D>(
|
||||
"File ${file.name} and transformer ${this::class} have inconsistent sessions"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun FirFile.runResolve(toPhase: FirResolvePhase, fromPhase: FirResolvePhase = FirResolvePhase.RAW_FIR) {
|
||||
val scopeSession = ScopeSession()
|
||||
var currentPhase = fromPhase
|
||||
while (currentPhase < toPhase) {
|
||||
currentPhase = currentPhase.next
|
||||
val phaseProcessor = currentPhase.createTransformerBasedProcessorByPhase(session, scopeSession)
|
||||
phaseProcessor.processFile(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
-38
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.fir.resolve.transformers
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
import org.jetbrains.kotlin.fir.visitors.compose
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
|
||||
/*
|
||||
* This processor is needed only for IDE until there won't be proper IDE implementation
|
||||
* for detecting sealed inheritors in multiple files
|
||||
*/
|
||||
class FirLegacySealedClassInheritorsProcessor(session: FirSession, scopeSession: ScopeSession) : FirTransformerBasedResolveProcessor(session, scopeSession) {
|
||||
override val transformer = FirLegacySealedClassInheritorsTransformer()
|
||||
}
|
||||
|
||||
class FirLegacySealedClassInheritorsTransformer : FirTransformer<Nothing?>() {
|
||||
override fun <E : FirElement> transformElement(element: E, data: Nothing?): CompositeTransformResult<E> {
|
||||
throw IllegalStateException("Should not be there")
|
||||
}
|
||||
|
||||
override fun transformFile(file: FirFile, data: Nothing?): CompositeTransformResult<FirDeclaration> {
|
||||
val sealedClassInheritorsMap = mutableMapOf<FirRegularClass, MutableList<ClassId>>()
|
||||
file.accept(FirSealedClassInheritorsProcessor.InheritorsCollector, sealedClassInheritorsMap)
|
||||
if (sealedClassInheritorsMap.isEmpty()) return file.compose()
|
||||
return file.transform(FirSealedClassInheritorsProcessor.InheritorsTransformer(sealedClassInheritorsMap), null)
|
||||
}
|
||||
}
|
||||
+1
-11
@@ -41,17 +41,7 @@ fun createAllCompilerResolveProcessors(
|
||||
}
|
||||
}
|
||||
|
||||
fun createAllTransformerBasedResolveProcessors(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession? = null,
|
||||
pluginPhasesEnabled: Boolean = false,
|
||||
): List<FirTransformerBasedResolveProcessor> {
|
||||
return createAllResolveProcessors(scopeSession, pluginPhasesEnabled) {
|
||||
createTransformerBasedProcessorByPhase(session, it)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T : FirResolveProcessor> createAllResolveProcessors(
|
||||
inline fun <T : FirResolveProcessor> createAllResolveProcessors(
|
||||
scopeSession: ScopeSession? = null,
|
||||
pluginPhasesEnabled: Boolean,
|
||||
creator: FirResolvePhase.(ScopeSession) -> T
|
||||
|
||||
+1
-23
@@ -40,29 +40,7 @@ fun FirResolvePhase.createCompilerProcessorByPhase(
|
||||
}
|
||||
}
|
||||
|
||||
fun FirResolvePhase.createTransformerBasedProcessorByPhase(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
): FirTransformerBasedResolveProcessor {
|
||||
return when (this) {
|
||||
RAW_FIR -> throw IllegalStateException("Raw FIR building phase does not have a transformer")
|
||||
ANNOTATIONS_FOR_PLUGINS -> FirPluginAnnotationsResolveProcessor(session, scopeSession)
|
||||
CLASS_GENERATION -> FirDummyTransformerBasedProcessor(session, scopeSession) // TODO: remove
|
||||
IMPORTS -> FirImportResolveProcessor(session, scopeSession)
|
||||
SUPER_TYPES -> FirSupertypeResolverProcessor(session, scopeSession)
|
||||
SEALED_CLASS_INHERITORS -> FirLegacySealedClassInheritorsProcessor(session, scopeSession)
|
||||
TYPES -> FirTypeResolveProcessor(session, scopeSession)
|
||||
ARGUMENTS_OF_PLUGIN_ANNOTATIONS -> FirAnnotationArgumentsResolveProcessor(session, scopeSession)
|
||||
EXTENSION_STATUS_UPDATE -> FirTransformerBasedExtensionStatusProcessor(session, scopeSession)
|
||||
STATUS -> FirStatusResolveProcessor(session, scopeSession)
|
||||
CONTRACTS -> FirContractResolveProcessor(session, scopeSession)
|
||||
NEW_MEMBERS_GENERATION -> FirDummyTransformerBasedProcessor(session, scopeSession) // TODO: remove
|
||||
IMPLICIT_TYPES_BODY_RESOLVE -> FirImplicitTypeBodyResolveProcessor(session, scopeSession)
|
||||
BODY_RESOLVE -> FirBodyResolveProcessor(session, scopeSession)
|
||||
}
|
||||
}
|
||||
|
||||
private class FirDummyTransformerBasedProcessor(
|
||||
class FirDummyTransformerBasedProcessor(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
) : FirTransformerBasedResolveProcessor(session, scopeSession) {
|
||||
|
||||
Reference in New Issue
Block a user