[FIR] Move createSessionWithDependencies to FirSessionFactory
This commit is contained in:
committed by
TeamCityServer
parent
2ee54c2201
commit
99cdb86145
+1
-2
@@ -57,7 +57,6 @@ import org.jetbrains.kotlin.fir.analysis.FirAnalyzerFacade
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendClassResolver
|
||||
import org.jetbrains.kotlin.fir.backend.jvm.FirJvmBackendExtension
|
||||
import org.jetbrains.kotlin.fir.checkers.registerExtendedCommonCheckers
|
||||
import org.jetbrains.kotlin.fir.createSessionWithDependencies
|
||||
import org.jetbrains.kotlin.fir.session.FirSessionFactory
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.jvmResolveLibraries
|
||||
import org.jetbrains.kotlin.javac.JavacWrapper
|
||||
@@ -339,7 +338,7 @@ object KotlinToJVMBytecodeCompiler {
|
||||
val librariesScope = ProjectScope.getLibrariesScope(project)
|
||||
|
||||
val languageVersionSettings = moduleConfiguration.languageVersionSettings
|
||||
val session = createSessionWithDependencies(
|
||||
val session = FirSessionFactory.createSessionWithDependencies(
|
||||
Name.identifier(module.getModuleName()),
|
||||
JvmPlatforms.unspecifiedJvmPlatform,
|
||||
JvmPlatformAnalyzerServices,
|
||||
|
||||
@@ -74,6 +74,52 @@ object FirSessionFactory {
|
||||
val scope: GlobalSearchScope
|
||||
)
|
||||
|
||||
inline fun createSessionWithDependencies(
|
||||
moduleName: Name,
|
||||
platform: TargetPlatform,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
externalSessionProvider: FirProjectSessionProvider?,
|
||||
project: Project,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sourceScope: GlobalSearchScope,
|
||||
librariesScope: GlobalSearchScope,
|
||||
lookupTracker: LookupTracker?,
|
||||
getPackagePartProvider: (GlobalSearchScope) -> PackagePartProvider,
|
||||
getProviderAndScopeForIncrementalCompilation: () -> ProviderAndScopeForIncrementalCompilation?,
|
||||
dependenciesConfigurator: DependencyListForCliModule.Builder.() -> Unit = {},
|
||||
noinline sessionConfigurator: FirSessionConfigurator.() -> Unit = {},
|
||||
): FirSession {
|
||||
val dependencyList = DependencyListForCliModule.build(moduleName, platform, analyzerServices, dependenciesConfigurator)
|
||||
val sessionProvider = externalSessionProvider ?: FirProjectSessionProvider()
|
||||
createLibrarySession(
|
||||
moduleName,
|
||||
sessionProvider,
|
||||
dependencyList.moduleDataProvider,
|
||||
librariesScope,
|
||||
project,
|
||||
getPackagePartProvider(librariesScope)
|
||||
)
|
||||
|
||||
val mainModuleData = FirModuleDataImpl(
|
||||
moduleName,
|
||||
dependencyList.regularDependencies,
|
||||
dependencyList.dependsOnDependencies,
|
||||
dependencyList.friendsDependencies,
|
||||
dependencyList.platform,
|
||||
dependencyList.analyzerServices
|
||||
)
|
||||
return createJavaModuleBasedSession(
|
||||
mainModuleData,
|
||||
sessionProvider,
|
||||
sourceScope,
|
||||
project,
|
||||
providerAndScopeForIncrementalCompilation = getProviderAndScopeForIncrementalCompilation(),
|
||||
languageVersionSettings = languageVersionSettings,
|
||||
lookupTracker = lookupTracker,
|
||||
init = sessionConfigurator
|
||||
)
|
||||
}
|
||||
|
||||
fun createJavaModuleBasedSession(
|
||||
moduleData: FirModuleData,
|
||||
sessionProvider: FirProjectSessionProvider,
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.session.FirSessionFactory
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
|
||||
import org.jetbrains.kotlin.modules.Module
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun createSessionWithDependencies(
|
||||
name: Name,
|
||||
platform: TargetPlatform,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
externalSessionProvider: FirProjectSessionProvider?,
|
||||
project: Project,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sourceScope: GlobalSearchScope,
|
||||
librariesScope: GlobalSearchScope,
|
||||
lookupTracker: LookupTracker?,
|
||||
getPackagePartProvider: (GlobalSearchScope) -> PackagePartProvider,
|
||||
getProviderAndScopeForIncrementalCompilation: () -> FirSessionFactory.ProviderAndScopeForIncrementalCompilation?,
|
||||
dependenciesConfigurator: DependencyListForCliModule.Builder.() -> Unit = {},
|
||||
noinline sessionConfigurator: FirSessionFactory.FirSessionConfigurator.() -> Unit = {},
|
||||
): FirSession {
|
||||
val dependencyList = DependencyListForCliModule.build(name, platform, analyzerServices, dependenciesConfigurator)
|
||||
return createSessionWithDependenciesImpl(
|
||||
name,
|
||||
dependencyList,
|
||||
externalSessionProvider,
|
||||
project,
|
||||
languageVersionSettings,
|
||||
sourceScope,
|
||||
librariesScope,
|
||||
lookupTracker,
|
||||
getPackagePartProvider,
|
||||
getProviderAndScopeForIncrementalCompilation,
|
||||
sessionConfigurator
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(PrivateForInline::class)
|
||||
inline fun createSessionWithDependencies(
|
||||
module: Module,
|
||||
platform: TargetPlatform,
|
||||
analyzerServices: PlatformDependentAnalyzerServices,
|
||||
externalSessionProvider: FirProjectSessionProvider?,
|
||||
project: Project,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sourceScope: GlobalSearchScope,
|
||||
librariesScope: GlobalSearchScope,
|
||||
lookupTracker: LookupTracker?,
|
||||
getPackagePartProvider: (GlobalSearchScope) -> PackagePartProvider,
|
||||
getProviderAndScopeForIncrementalCompilation: () -> FirSessionFactory.ProviderAndScopeForIncrementalCompilation?,
|
||||
noinline sessionConfigurator: FirSessionFactory.FirSessionConfigurator.() -> Unit = {},
|
||||
): FirSession {
|
||||
val moduleName = Name.identifier(module.getModuleName())
|
||||
val dependencyList = DependencyListForCliModule.build(
|
||||
moduleName,
|
||||
platform,
|
||||
analyzerServices
|
||||
) {
|
||||
friendDependencies(module.getFriendPaths())
|
||||
dependencies(module.getClasspathRoots())
|
||||
}
|
||||
return createSessionWithDependenciesImpl(
|
||||
moduleName,
|
||||
dependencyList,
|
||||
externalSessionProvider,
|
||||
project,
|
||||
languageVersionSettings,
|
||||
sourceScope,
|
||||
librariesScope,
|
||||
lookupTracker,
|
||||
getPackagePartProvider,
|
||||
getProviderAndScopeForIncrementalCompilation,
|
||||
sessionConfigurator
|
||||
)
|
||||
}
|
||||
|
||||
@PrivateForInline
|
||||
inline fun createSessionWithDependenciesImpl(
|
||||
moduleName: Name,
|
||||
dependencyListForCliModule: DependencyListForCliModule,
|
||||
externalSessionProvider: FirProjectSessionProvider?,
|
||||
project: Project,
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
sourceScope: GlobalSearchScope,
|
||||
librariesScope: GlobalSearchScope,
|
||||
lookupTracker: LookupTracker?,
|
||||
getPackagePartProvider: (GlobalSearchScope) -> PackagePartProvider,
|
||||
getProviderAndScopeForIncrementalCompilation: () -> FirSessionFactory.ProviderAndScopeForIncrementalCompilation?,
|
||||
noinline sessionConfigurator: FirSessionFactory.FirSessionConfigurator.() -> Unit,
|
||||
): FirSession {
|
||||
val sessionProvider = externalSessionProvider ?: FirProjectSessionProvider()
|
||||
FirSessionFactory.createLibrarySession(
|
||||
moduleName,
|
||||
sessionProvider,
|
||||
dependencyListForCliModule.moduleDataProvider,
|
||||
librariesScope,
|
||||
project,
|
||||
getPackagePartProvider(librariesScope)
|
||||
)
|
||||
|
||||
val mainModuleData = FirModuleDataImpl(
|
||||
moduleName,
|
||||
dependencyListForCliModule.regularDependencies,
|
||||
dependencyListForCliModule.dependsOnDependencies,
|
||||
dependencyListForCliModule.friendsDependencies,
|
||||
dependencyListForCliModule.platform,
|
||||
dependencyListForCliModule.analyzerServices
|
||||
)
|
||||
return FirSessionFactory.createJavaModuleBasedSession(
|
||||
mainModuleData,
|
||||
sessionProvider,
|
||||
sourceScope,
|
||||
project,
|
||||
providerAndScopeForIncrementalCompilation = getProviderAndScopeForIncrementalCompilation(),
|
||||
languageVersionSettings = languageVersionSettings,
|
||||
lookupTracker = lookupTracker,
|
||||
init = sessionConfigurator
|
||||
)
|
||||
}
|
||||
+2
-2
@@ -15,8 +15,8 @@ import org.jetbrains.kotlin.cli.jvm.config.jvmModularRoots
|
||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||
import org.jetbrains.kotlin.fir.analysis.FirAnalyzerFacade
|
||||
import org.jetbrains.kotlin.fir.checkers.registerExtendedCommonCheckers
|
||||
import org.jetbrains.kotlin.fir.createSessionWithDependencies
|
||||
import org.jetbrains.kotlin.fir.moduleData
|
||||
import org.jetbrains.kotlin.fir.session.FirSessionFactory
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatformAnalyzerServices
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
@@ -66,7 +66,7 @@ class FirFrontendFacade(
|
||||
val librariesScope = ProjectScope.getLibrariesScope(project)
|
||||
val sourcesScope = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(project, ktFiles)
|
||||
|
||||
val session = createSessionWithDependencies(
|
||||
val session = FirSessionFactory.createSessionWithDependencies(
|
||||
Name.identifier(module.name),
|
||||
module.targetPlatform,
|
||||
module.targetPlatform.getAnalyzerServices(),
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
val scope = TopDownAnalyzerFacadeForJVM.newModuleSearchScope(
|
||||
project,
|
||||
moduleFiles.mapNotNull { it.ktFile })
|
||||
createSessionWithDependencies(
|
||||
FirSessionFactory.createSessionWithDependencies(
|
||||
Name.identifier(info.name.asString().removeSurrounding("<", ">")),
|
||||
info.platform,
|
||||
info.analyzerServices,
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.ObsoleteTestInfrastructure
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
|
||||
import org.jetbrains.kotlin.fir.session.FirSessionFactory
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartProvider
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
@@ -41,7 +42,7 @@ fun createSessionForTests(
|
||||
friendsPaths: List<Path> = emptyList(),
|
||||
getPackagePartProvider: (GlobalSearchScope) -> PackagePartProvider,
|
||||
): FirSession {
|
||||
return createSessionWithDependencies(
|
||||
return FirSessionFactory.createSessionWithDependencies(
|
||||
Name.identifier(moduleName),
|
||||
JvmPlatforms.unspecifiedJvmPlatform,
|
||||
JvmPlatformAnalyzerServices,
|
||||
|
||||
Reference in New Issue
Block a user