[low level fir] use correct FirModuleData for declarations provided by FirJavaFacade
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.analysis.low.level.api.fir.sessions
|
||||
|
||||
import org.jetbrains.kotlin.analysis.utils.errors.requireIsInstance
|
||||
import org.jetbrains.kotlin.fir.BuiltinTypes
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.deserialization.ModuleDataProvider
|
||||
import org.jetbrains.kotlin.fir.java.FirJavaFacade
|
||||
import org.jetbrains.kotlin.load.java.JavaClassFinder
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClass
|
||||
import org.jetbrains.kotlin.load.java.structure.classId
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.VirtualFileBoundJavaClass
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
internal class LLFirJavaFacadeForBinaries(
|
||||
session: FirSession,
|
||||
builtinTypes: BuiltinTypes,
|
||||
classFinder: JavaClassFinder,
|
||||
private val binaryDependenciesModuleDataProvider: ModuleDataProvider,
|
||||
) : FirJavaFacade(session, builtinTypes, classFinder) {
|
||||
override fun getModuleDataForClass(javaClass: JavaClass): FirModuleData {
|
||||
requireIsInstance<VirtualFileBoundJavaClass>(javaClass)
|
||||
val path = getBinaryPath(javaClass)
|
||||
return binaryDependenciesModuleDataProvider.getModuleData(path)
|
||||
?: error("No module data found for ${javaClass.classId} with path $path")
|
||||
}
|
||||
|
||||
private fun getBinaryPath(javaClass: VirtualFileBoundJavaClass): Path {
|
||||
val virtualFile = javaClass.virtualFile
|
||||
?: error("no virtual file for ${javaClass.classId}")
|
||||
val path = virtualFile.path
|
||||
return Paths.get(path)
|
||||
}
|
||||
}
|
||||
+17
-18
@@ -41,7 +41,7 @@ import org.jetbrains.kotlin.fir.extensions.FirPredicateBasedProvider
|
||||
import org.jetbrains.kotlin.fir.extensions.FirRegisteredPluginAnnotations
|
||||
import org.jetbrains.kotlin.fir.extensions.FirSwitchableExtensionDeclarationsSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.extensions.predicate.DeclarationPredicate
|
||||
import org.jetbrains.kotlin.fir.java.FirJavaFacade
|
||||
import org.jetbrains.kotlin.fir.java.FirJavaFacadeForSource
|
||||
import org.jetbrains.kotlin.fir.java.JavaSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.java.deserialization.JvmClassFileBasedSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.FirDependenciesSymbolProvider
|
||||
@@ -188,7 +188,7 @@ internal object LLFirSessionFactory {
|
||||
switchableExtensionDeclarationsSymbolProvider,
|
||||
JavaSymbolProvider(
|
||||
this,
|
||||
FirJavaFacade(
|
||||
FirJavaFacadeForSource(
|
||||
this, moduleData, project.createJavaClassFinder(contentScope)
|
||||
)
|
||||
),
|
||||
@@ -226,8 +226,6 @@ internal object LLFirSessionFactory {
|
||||
val kotlinScopeProvider = FirKotlinScopeProvider(::wrapScopeWithJvmMapped)
|
||||
register(FirKotlinScopeProvider::class, kotlinScopeProvider)
|
||||
|
||||
val mainModuleData = KtModuleBasedModuleData(sourceModule).apply { bindSession(this@session) }
|
||||
|
||||
val moduleDataProvider = createModuleDataProviderWithLibraryDependencies(sourceModule, this)
|
||||
val classFileBasedSymbolProvider = JvmClassFileBasedSymbolProvider(
|
||||
this@session,
|
||||
@@ -235,8 +233,11 @@ internal object LLFirSessionFactory {
|
||||
kotlinScopeProvider = kotlinScopeProvider,
|
||||
packagePartProvider = project.createPackagePartProviderForLibrary(searchScope),
|
||||
kotlinClassFinder = VirtualFileFinderFactory.getInstance(project).create(searchScope),
|
||||
javaFacade = FirJavaFacade(
|
||||
this@session, mainModuleData, project.createJavaClassFinder(searchScope)
|
||||
javaFacade = LLFirJavaFacadeForBinaries(
|
||||
this@session,
|
||||
builtinTypes,
|
||||
project.createJavaClassFinder(searchScope),
|
||||
moduleDataProvider
|
||||
)
|
||||
)
|
||||
val symbolProvider =
|
||||
@@ -281,18 +282,12 @@ internal object LLFirSessionFactory {
|
||||
fun createBuiltinsAndCloneableSession(
|
||||
project: Project,
|
||||
builtinTypes: BuiltinTypes,
|
||||
stdlibModule: KtModule,
|
||||
languageVersionSettings: LanguageVersionSettings = LanguageVersionSettingsImpl.DEFAULT,
|
||||
configureSession: (LLFirSession.() -> Unit)? = null,
|
||||
): LLFirBuiltinsAndCloneableSession {
|
||||
return LLFirBuiltinsAndCloneableSession(project, builtinTypes).apply session@{
|
||||
val moduleData = FirModuleDataImpl(
|
||||
Name.special("<builtins module>"),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
emptyList(),
|
||||
JvmPlatforms.unspecifiedJvmPlatform,
|
||||
JvmPlatformAnalyzerServices
|
||||
).apply {
|
||||
val moduleData = KtModuleBasedModuleData(stdlibModule).apply {
|
||||
bindSession(this@session)
|
||||
}
|
||||
registerIdeComponents(project)
|
||||
@@ -376,15 +371,19 @@ internal object LLFirSessionFactory {
|
||||
val librariesSearchScope = ProjectScope.getLibrariesScope(project)
|
||||
.intersectWith(GlobalSearchScope.notScope(libraryModule.contentScope)) // <all libraries scope> - <current library scope>
|
||||
add(builtinsAndCloneableSession.symbolProvider)
|
||||
val libraryDependenciesModuleDataProvider = createModuleDataProviderWithLibraryDependencies(module, this@session)
|
||||
add(
|
||||
JvmClassFileBasedSymbolProvider(
|
||||
this@session,
|
||||
moduleDataProvider = createModuleDataProviderWithLibraryDependencies(module, this@session),
|
||||
moduleDataProvider = libraryDependenciesModuleDataProvider,
|
||||
kotlinScopeProvider = scopeProvider,
|
||||
packagePartProvider = project.createPackagePartProviderForLibrary(librariesSearchScope),
|
||||
kotlinClassFinder = VirtualFileFinderFactory.getInstance(project).create(librariesSearchScope),
|
||||
javaFacade = FirJavaFacade(
|
||||
this@session, moduleData, project.createJavaClassFinder(librariesSearchScope)
|
||||
javaFacade = LLFirJavaFacadeForBinaries(
|
||||
this@session,
|
||||
builtinTypes,
|
||||
project.createJavaClassFinder(librariesSearchScope),
|
||||
libraryDependenciesModuleDataProvider
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -422,7 +421,7 @@ internal object LLFirSessionFactory {
|
||||
provider.symbolProvider,
|
||||
JavaSymbolProvider(
|
||||
this,
|
||||
FirJavaFacade(
|
||||
FirJavaFacadeForSource(
|
||||
this, moduleData, project.createJavaClassFinder(contentScope)
|
||||
)
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user