[FIR] Add FirJavaElementFinder to session's components
This change allows us to use `IrInterpreter` to evaluate Kotlin's const properties that were called from Java world #KT-57802
This commit is contained in:
+6
-1
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.KtVirtualFileSourceFile
|
|||||||
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
import org.jetbrains.kotlin.asJava.finder.JavaElementFinder
|
||||||
import org.jetbrains.kotlin.fir.FirModuleData
|
import org.jetbrains.kotlin.fir.FirModuleData
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.SessionConfiguration
|
||||||
import org.jetbrains.kotlin.fir.java.FirJavaElementFinder
|
import org.jetbrains.kotlin.fir.java.FirJavaElementFinder
|
||||||
import org.jetbrains.kotlin.fir.java.FirJavaFacadeForSource
|
import org.jetbrains.kotlin.fir.java.FirJavaFacadeForSource
|
||||||
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
import org.jetbrains.kotlin.fir.session.environment.AbstractProjectEnvironment
|
||||||
@@ -62,12 +63,16 @@ open class VfsBasedProjectEnvironment(
|
|||||||
override fun getPackagePartProvider(fileSearchScope: AbstractProjectFileSearchScope): PackagePartProvider =
|
override fun getPackagePartProvider(fileSearchScope: AbstractProjectFileSearchScope): PackagePartProvider =
|
||||||
getPackagePartProviderFn(fileSearchScope.asPsiSearchScope())
|
getPackagePartProviderFn(fileSearchScope.asPsiSearchScope())
|
||||||
|
|
||||||
|
@OptIn(SessionConfiguration::class)
|
||||||
override fun registerAsJavaElementFinder(firSession: FirSession) {
|
override fun registerAsJavaElementFinder(firSession: FirSession) {
|
||||||
val psiFinderExtensionPoint = PsiElementFinder.EP.getPoint(project)
|
val psiFinderExtensionPoint = PsiElementFinder.EP.getPoint(project)
|
||||||
if (psiFinderExtensionPoint.extensionList.any { it is JavaElementFinder }) {
|
if (psiFinderExtensionPoint.extensionList.any { it is JavaElementFinder }) {
|
||||||
psiFinderExtensionPoint.unregisterExtension(JavaElementFinder::class.java)
|
psiFinderExtensionPoint.unregisterExtension(JavaElementFinder::class.java)
|
||||||
}
|
}
|
||||||
psiFinderExtensionPoint.registerExtension(FirJavaElementFinder(firSession, project), project)
|
|
||||||
|
val firJavaElementFinder = FirJavaElementFinder(firSession, project)
|
||||||
|
firSession.register(FirJavaElementFinder::class, firJavaElementFinder)
|
||||||
|
psiFinderExtensionPoint.registerExtension(firJavaElementFinder, project)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun List<VirtualFile>.toSearchScope(allowOutOfProjectRoots: Boolean) =
|
private fun List<VirtualFile>.toSearchScope(allowOutOfProjectRoots: Boolean) =
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.FirModuleData
|
import org.jetbrains.kotlin.fir.FirModuleData
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.FirSessionComponent
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
import org.jetbrains.kotlin.fir.declarations.utils.classId
|
||||||
@@ -45,10 +46,12 @@ import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
|||||||
import org.jetbrains.kotlin.resolve.jvm.KotlinFinderMarker
|
import org.jetbrains.kotlin.resolve.jvm.KotlinFinderMarker
|
||||||
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
import org.jetbrains.kotlin.utils.exceptions.errorWithAttachment
|
||||||
|
|
||||||
|
val FirSession.javaElementFinder: FirJavaElementFinder? by FirSession.nullableSessionComponentAccessor<FirJavaElementFinder>()
|
||||||
|
|
||||||
class FirJavaElementFinder(
|
class FirJavaElementFinder(
|
||||||
private val session: FirSession,
|
private val session: FirSession,
|
||||||
project: Project
|
project: Project
|
||||||
) : PsiElementFinder(), KotlinFinderMarker {
|
) : PsiElementFinder(), KotlinFinderMarker, FirSessionComponent {
|
||||||
private val psiManager = PsiManager.getInstance(project)
|
private val psiManager = PsiManager.getInstance(project)
|
||||||
|
|
||||||
private val firProviders: List<FirProvider> = buildList {
|
private val firProviders: List<FirProvider> = buildList {
|
||||||
|
|||||||
Reference in New Issue
Block a user