[Analysis API] Provide sessions in 'LLFirModuleData' for dependencies
Normally, 'bindSession()' is called on a 'FirModuleData' right after its instantiation to make it fully initialized. For source sessions, this is done directly during the session creation. However, module data created for dependencies (see 'LLFirModuleData.dependencies' & friends) stay uninitialized, breaking 'collectAllDependentSourceSessionsTo()'.
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
@@ -58,16 +57,16 @@ abstract class FirModuleData : FirSessionComponent {
|
||||
open val capabilities: FirModuleCapabilities
|
||||
get() = FirModuleCapabilities.Empty
|
||||
|
||||
private var _session: FirSession? = null
|
||||
val session: FirSession
|
||||
get() = _session
|
||||
?: error("module data ${this::class.simpleName}:${name} not bound to session")
|
||||
protected var boundSession: FirSession? = null
|
||||
private set
|
||||
|
||||
abstract val session: FirSession
|
||||
|
||||
fun bindSession(session: FirSession) {
|
||||
if (_session != null) {
|
||||
if (boundSession != null) {
|
||||
error("module data already bound to $this")
|
||||
}
|
||||
_session = session
|
||||
boundSession = session
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
@@ -84,7 +83,11 @@ class FirModuleDataImpl(
|
||||
override val analyzerServices: PlatformDependentAnalyzerServices,
|
||||
override val capabilities: FirModuleCapabilities = FirModuleCapabilities.Empty,
|
||||
override val isCommon: Boolean = platform.isCommon(),
|
||||
) : FirModuleData()
|
||||
) : FirModuleData() {
|
||||
override val session: FirSession
|
||||
get() = boundSession
|
||||
?: error("module data ${this::class.simpleName}:${name} not bound to session")
|
||||
}
|
||||
|
||||
val FirSession.nullableModuleData: FirModuleData? by FirSession.nullableSessionComponentAccessor()
|
||||
val FirSession.moduleData: FirModuleData
|
||||
|
||||
Reference in New Issue
Block a user