Remove FirTotalKotlinResolveInIde test with its provider as obsolete
This commit is contained in:
-108
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* 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.idea.perf
|
||||
|
||||
import com.intellij.ide.impl.ProjectUtil
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ex.ApplicationEx
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager
|
||||
import com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.psi.search.FileTypeIndex
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.intellij.testFramework.LightPlatformTestCase
|
||||
import com.intellij.testFramework.ModuleTestCase
|
||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.doFirResolveTestBench
|
||||
import org.jetbrains.kotlin.fir.java.FirJavaModuleBasedSession
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.progress
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirTotalResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.caches.project.*
|
||||
import org.jetbrains.kotlin.idea.fir.IdeFirDependenciesSymbolProvider
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.io.File
|
||||
import kotlin.test.Ignore
|
||||
|
||||
@Ignore(value = "[Simon Ogorodnik] turned off as it is suppose to be run manually")
|
||||
class FirTotalKotlinResolveInIdeTest : ModuleTestCase() {
|
||||
private val projectRootFile = File(".")
|
||||
|
||||
override fun setUpProject() {
|
||||
(ApplicationManager.getApplication() as ApplicationEx).doNotSave()
|
||||
myProject = ProjectUtil.openOrImport(projectRootFile.path, null, false)
|
||||
LightPlatformTestCase.clearUncommittedDocuments(this.project)
|
||||
this.runStartupActivities()
|
||||
(FileTypeManager.getInstance() as FileTypeManagerImpl).drainReDetectQueue()
|
||||
}
|
||||
|
||||
private lateinit var sessionProvider: FirProjectSessionProvider
|
||||
|
||||
private fun IdeaModuleInfo.createSession(): FirSession {
|
||||
val moduleInfo = this
|
||||
|
||||
return FirJavaModuleBasedSession(
|
||||
moduleInfo, sessionProvider, moduleInfo.contentScope(),
|
||||
IdeFirDependenciesSymbolProvider(moduleInfo as ModuleSourceInfo, project, sessionProvider)
|
||||
)
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
sessionProvider = FirProjectSessionProvider(project)
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
val jdkTable = ProjectJdkTable.getInstance()
|
||||
runWriteAction {
|
||||
for (sdk in jdkTable.allJdks) {
|
||||
jdkTable.removeJdk(sdk)
|
||||
}
|
||||
}
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
fun testTotalKotlin() {
|
||||
val psiManager = PsiManager.getInstance(project)
|
||||
val files = FileTypeIndex.getFiles(KotlinFileType.INSTANCE, GlobalSearchScope.projectScope(project))
|
||||
val firFiles = mutableListOf<FirFile>()
|
||||
val sessionPerModule = mutableMapOf<ModuleInfo, FirSession>()
|
||||
|
||||
println("Got vfiles: ${files.size}")
|
||||
files.mapNotNull {
|
||||
val file = psiManager.findFile(it) as? KtFile ?: return@mapNotNull null
|
||||
val moduleInfo = file.getNullableModuleInfo() as? ModuleSourceInfo ?: return@mapNotNull null
|
||||
file to moduleInfo
|
||||
}.progress("Loading FIR").forEach { (file, moduleInfo) ->
|
||||
|
||||
val session = sessionPerModule.getOrPut(moduleInfo) {
|
||||
moduleInfo.createSession()
|
||||
}
|
||||
val builder = RawFirBuilder(session, stubMode = true)
|
||||
|
||||
try {
|
||||
val firFile = builder.buildFirFile(file)
|
||||
(session.service<FirProvider>() as FirProviderImpl).recordFile(firFile)
|
||||
firFiles += firFile
|
||||
} catch (e: Exception) {
|
||||
System.err.println("Error building fir for $file")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
println("Raw fir up, files: ${firFiles.size}")
|
||||
doFirResolveTestBench(firFiles, FirTotalResolveTransformer().transformers, withProgress = true)
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 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.idea.fir
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.RawFirBuilder
|
||||
import org.jetbrains.kotlin.fir.java.FirProjectSessionProvider
|
||||
import org.jetbrains.kotlin.fir.java.JavaSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.AbstractFirSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.FirProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.impl.FirProviderImpl
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.service
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||
import org.jetbrains.kotlin.idea.caches.project.ModuleSourceInfo
|
||||
import org.jetbrains.kotlin.idea.caches.project.getModuleInfo
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinTopLevelTypeAliasFqNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtTypeAlias
|
||||
|
||||
class IdeFirDependenciesSymbolProvider(
|
||||
val moduleInfo: ModuleSourceInfo,
|
||||
val project: Project,
|
||||
private val sessionProvider: FirProjectSessionProvider
|
||||
) : AbstractFirSymbolProvider() {
|
||||
|
||||
// TODO: Our special scope here?
|
||||
private val depScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleInfo.module)
|
||||
|
||||
private val javaSymbolProvider by lazy { JavaSymbolProvider(sessionProvider.getSession(moduleInfo)!!, project, depScope) }
|
||||
|
||||
|
||||
private fun buildKotlinClassOnRequest(file: KtFile, classId: ClassId, session: FirSession): FirClassLikeSymbol<*>? {
|
||||
val impl = FirProvider.getInstance(session) as FirProviderImpl
|
||||
val classifier = impl.getClassLikeSymbolByFqName(classId)
|
||||
if (classifier != null) {
|
||||
return classifier
|
||||
}
|
||||
|
||||
val builder = RawFirBuilder(session, stubMode = true)
|
||||
impl.recordFile(builder.buildFirFile(file))
|
||||
return impl.getClassLikeSymbolByFqName(classId)
|
||||
}
|
||||
|
||||
private fun selectNearest(classesPsi: Collection<KtDeclaration>, typeAliasesPsi: Collection<KtTypeAlias>): KtDeclaration? {
|
||||
return when {
|
||||
typeAliasesPsi.isEmpty() -> classesPsi.firstOrNull()
|
||||
classesPsi.isEmpty() -> typeAliasesPsi.firstOrNull()
|
||||
else -> (classesPsi.asSequence() + typeAliasesPsi.asSequence()).minWith(Comparator { o1, o2 ->
|
||||
depScope.compare(o1.containingFile.virtualFile, o2.containingFile.virtualFile)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClassUseSiteMemberScope(classId: ClassId, useSiteSession: FirSession, scopeSession: ScopeSession): FirScope? {
|
||||
TODO("not implemented")
|
||||
}
|
||||
|
||||
private fun tryKotlin(classId: ClassId): FirClassLikeSymbol<*>? {
|
||||
return classCache.lookupCacheOrCalculate(classId) {
|
||||
val index = KotlinFullClassNameIndex.getInstance()
|
||||
|
||||
val fqNameString = classId.packageFqName.asString() + "." + classId.relativeClassName.asString()
|
||||
val classesPsi = index[fqNameString, project, depScope]
|
||||
val typeAliasesPsi = KotlinTopLevelTypeAliasFqNameIndex.getInstance()[fqNameString, project, depScope]
|
||||
|
||||
val psi = selectNearest(classesPsi, typeAliasesPsi) ?: return@lookupCacheOrCalculate null
|
||||
|
||||
val module = psi.getModuleInfo()
|
||||
if (psi.containingKtFile.isCompiled) {
|
||||
// TODO: WTF? Resolving libraries in current session
|
||||
val session = sessionProvider.getSession(moduleInfo) ?: return@lookupCacheOrCalculate null
|
||||
return@lookupCacheOrCalculate buildKotlinClassOnRequest(psi.containingKtFile, classId, session)
|
||||
}
|
||||
|
||||
val session = sessionProvider.getSession(module) ?: return@lookupCacheOrCalculate null
|
||||
session.service<FirProvider>().getClassLikeSymbolByFqName(classId)
|
||||
}
|
||||
}
|
||||
|
||||
private fun tryJava(classId: ClassId): FirClassLikeSymbol<*>? {
|
||||
return javaSymbolProvider.getClassLikeSymbolByFqName(classId)
|
||||
}
|
||||
|
||||
override fun getClassLikeSymbolByFqName(classId: ClassId): FirClassLikeSymbol<*>? {
|
||||
return tryKotlin(classId) ?: tryJava(classId)
|
||||
}
|
||||
|
||||
override fun getTopLevelCallableSymbols(packageFqName: FqName, name: Name): List<FirCallableSymbol<*>> {
|
||||
// TODO
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
override fun getClassDeclaredMemberScope(classId: ClassId): FirScope? = null
|
||||
|
||||
override fun getPackage(fqName: FqName): FqName? {
|
||||
|
||||
if (PackageIndexUtil.packageExists(fqName, depScope, project)) {
|
||||
return fqName
|
||||
}
|
||||
return javaSymbolProvider.getPackage(fqName)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user