Revert "[FIR]: sealed hierarchy processor for IDE"
This reverts commit e6ccdff2
This commit is contained in:
+11
-1
@@ -44,4 +44,14 @@ 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
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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)
|
||||
}
|
||||
}
|
||||
+11
-1
@@ -41,7 +41,17 @@ fun createAllCompilerResolveProcessors(
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T : FirResolveProcessor> createAllResolveProcessors(
|
||||
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(
|
||||
scopeSession: ScopeSession? = null,
|
||||
pluginPhasesEnabled: Boolean,
|
||||
creator: FirResolvePhase.(ScopeSession) -> T
|
||||
|
||||
+23
-1
@@ -40,7 +40,29 @@ fun FirResolvePhase.createCompilerProcessorByPhase(
|
||||
}
|
||||
}
|
||||
|
||||
class FirDummyTransformerBasedProcessor(
|
||||
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(
|
||||
session: FirSession,
|
||||
scopeSession: ScopeSession
|
||||
) : FirTransformerBasedResolveProcessor(session, scopeSession) {
|
||||
|
||||
Reference in New Issue
Block a user