[lc] KotlinAsJavaSupportBase: reduce number of findModule calls
^KT-50241
This commit is contained in:
+21
-26
@@ -37,11 +37,11 @@ abstract class KotlinAsJavaSupportBase<TModule>(protected val project: Project)
|
||||
return when {
|
||||
facadeFiles.none(KtFile::hasTopLevelCallables) -> null
|
||||
facadeFiles.none(KtFile::isCompiled) -> {
|
||||
createInstanceOfLightFacade(facadeFqName, facadeFiles, module) to outOfBlockModificationTracker(file, module)
|
||||
createInstanceOfLightFacade(facadeFqName, facadeFiles) to outOfBlockModificationTracker(file)
|
||||
}
|
||||
|
||||
facadeFiles.all(KtFile::isCompiled) -> {
|
||||
createInstanceOfDecompiledLightFacade(facadeFqName, facadeFiles, module) to librariesTracker(file, module)
|
||||
createInstanceOfDecompiledLightFacade(facadeFqName, facadeFiles) to librariesTracker(file)
|
||||
}
|
||||
|
||||
else -> error("Source and compiled files are mixed: $facadeFiles")
|
||||
@@ -52,25 +52,21 @@ abstract class KotlinAsJavaSupportBase<TModule>(protected val project: Project)
|
||||
protected abstract fun facadeIsApplicable(module: TModule, file: KtFile): Boolean
|
||||
protected abstract val TModule.contentSearchScope: GlobalSearchScope
|
||||
|
||||
protected abstract fun createInstanceOfLightFacade(facadeFqName: FqName, files: List<KtFile>, module: TModule): KtLightClassForFacade
|
||||
protected abstract fun createInstanceOfDecompiledLightFacade(
|
||||
facadeFqName: FqName,
|
||||
files: List<KtFile>,
|
||||
module: TModule,
|
||||
): KtLightClassForFacade?
|
||||
|
||||
protected open fun outOfBlockModificationTracker(element: PsiElement, module: TModule): ModificationTracker {
|
||||
return projectWideOutOfBlockModificationTracker()
|
||||
}
|
||||
|
||||
protected open fun librariesTracker(element: PsiElement, module: TModule): ModificationTracker {
|
||||
return projectWideOutOfBlockModificationTracker()
|
||||
}
|
||||
protected abstract fun createInstanceOfLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade
|
||||
protected abstract fun createInstanceOfDecompiledLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade?
|
||||
|
||||
protected open fun projectWideOutOfBlockModificationTracker(): ModificationTracker {
|
||||
return KotlinModificationTrackerService.getInstance(project).outOfBlockModificationTracker
|
||||
}
|
||||
|
||||
protected open fun outOfBlockModificationTracker(element: PsiElement): ModificationTracker {
|
||||
return projectWideOutOfBlockModificationTracker()
|
||||
}
|
||||
|
||||
protected open fun librariesTracker(element: PsiElement): ModificationTracker {
|
||||
return projectWideOutOfBlockModificationTracker()
|
||||
}
|
||||
|
||||
override fun getLightFacade(file: KtFile): KtLightClassForFacade? = ifValid(file) {
|
||||
CachedValuesManager.getCachedValue(file) {
|
||||
val (facade, tracker) = createLightFacade(file) ?: (null to projectWideOutOfBlockModificationTracker())
|
||||
@@ -79,7 +75,7 @@ abstract class KotlinAsJavaSupportBase<TModule>(protected val project: Project)
|
||||
}
|
||||
|
||||
override fun createFacadeForSyntheticFile(file: KtFile): KtLightClassForFacade {
|
||||
return createInstanceOfLightFacade(file.javaFileFacadeFqName, listOf(file), file.findModule())
|
||||
return createInstanceOfLightFacade(file.javaFileFacadeFqName, listOf(file))
|
||||
}
|
||||
|
||||
override fun getFacadeClassesInPackage(packageFqName: FqName, scope: GlobalSearchScope): Collection<KtLightClassForFacade> {
|
||||
@@ -119,14 +115,13 @@ abstract class KotlinAsJavaSupportBase<TModule>(protected val project: Project)
|
||||
if (classOrObject.shouldNotBeVisibleAsLightClass()) return null
|
||||
|
||||
val containingFile = classOrObject.containingKtFile
|
||||
val module = containingFile.findModule()
|
||||
when (declarationLocation(containingFile, module)) {
|
||||
when (declarationLocation(containingFile)) {
|
||||
DeclarationLocation.ProjectSources -> {
|
||||
return createInstanceOfLightClass(classOrObject, module) to outOfBlockModificationTracker(classOrObject, module)
|
||||
return createInstanceOfLightClass(classOrObject) to outOfBlockModificationTracker(classOrObject)
|
||||
}
|
||||
|
||||
DeclarationLocation.LibraryClasses -> {
|
||||
return createInstanceOfDecompiledLightClass(classOrObject, module) to librariesTracker(classOrObject, module)
|
||||
return createInstanceOfDecompiledLightClass(classOrObject) to librariesTracker(classOrObject)
|
||||
}
|
||||
|
||||
DeclarationLocation.LibrarySources -> {
|
||||
@@ -138,22 +133,22 @@ abstract class KotlinAsJavaSupportBase<TModule>(protected val project: Project)
|
||||
guardedRun { getLightClass(it) }
|
||||
}
|
||||
|
||||
return value to librariesTracker(classOrObject, module)
|
||||
return value to librariesTracker(classOrObject)
|
||||
}
|
||||
|
||||
null -> Unit
|
||||
}
|
||||
|
||||
if (containingFile.analysisContext != null || containingFile.originalFile.virtualFile != null) {
|
||||
return createInstanceOfLightClass(classOrObject, module) to outOfBlockModificationTracker(classOrObject, module)
|
||||
return createInstanceOfLightClass(classOrObject) to outOfBlockModificationTracker(classOrObject)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
protected abstract fun createInstanceOfLightClass(classOrObject: KtClassOrObject, module: TModule): KtLightClass?
|
||||
protected abstract fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject, module: TModule): KtLightClass?
|
||||
protected abstract fun declarationLocation(file: KtFile, module: TModule): DeclarationLocation?
|
||||
protected abstract fun createInstanceOfLightClass(classOrObject: KtClassOrObject): KtLightClass?
|
||||
protected abstract fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject): KtLightClass?
|
||||
protected abstract fun declarationLocation(file: KtFile): DeclarationLocation?
|
||||
|
||||
protected enum class DeclarationLocation {
|
||||
ProjectSources, LibraryClasses, LibrarySources,
|
||||
|
||||
+10
-13
@@ -89,43 +89,40 @@ class SymbolKotlinAsJavaSupport(project: Project) : KotlinAsJavaSupportBase<KtMo
|
||||
|
||||
override fun KtFile.findModule(): KtModule = getKtModule(project)
|
||||
|
||||
override fun declarationLocation(file: KtFile, module: KtModule): DeclarationLocation? = when (module) {
|
||||
override fun declarationLocation(file: KtFile): DeclarationLocation? = when (file.getKtModule(project)) {
|
||||
is KtSourceModule -> DeclarationLocation.ProjectSources
|
||||
is KtLibraryModule -> DeclarationLocation.LibraryClasses
|
||||
is KtLibrarySourceModule -> DeclarationLocation.LibrarySources
|
||||
else -> null
|
||||
}
|
||||
|
||||
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject, module: KtModule): KtLightClass? {
|
||||
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject): KtLightClass? {
|
||||
return DecompiledLightClassesFactory.getLightClassForDecompiledClassOrObject(classOrObject, project)
|
||||
}
|
||||
|
||||
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject, module: KtModule): KtLightClass? {
|
||||
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject): KtLightClass? {
|
||||
return createSymbolLightClassNoCache(classOrObject)
|
||||
}
|
||||
|
||||
override fun createInstanceOfDecompiledLightFacade(
|
||||
facadeFqName: FqName,
|
||||
files: List<KtFile>,
|
||||
module: KtModule,
|
||||
): KtLightClassForFacade? = DecompiledLightClassesFactory.createLightFacadeForDecompiledKotlinFile(project, facadeFqName, files)
|
||||
override fun createInstanceOfDecompiledLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade? {
|
||||
return DecompiledLightClassesFactory.createLightFacadeForDecompiledKotlinFile(project, facadeFqName, files)
|
||||
}
|
||||
|
||||
override fun projectWideOutOfBlockModificationTracker(): ModificationTracker {
|
||||
return project.createProjectWideOutOfBlockModificationTracker()
|
||||
}
|
||||
|
||||
override fun outOfBlockModificationTracker(element: PsiElement, module: KtModule): ModificationTracker {
|
||||
override fun outOfBlockModificationTracker(element: PsiElement): ModificationTracker {
|
||||
return project.createProjectWideOutOfBlockModificationTracker()
|
||||
}
|
||||
|
||||
override fun librariesTracker(element: PsiElement, module: KtModule): ModificationTracker {
|
||||
override fun librariesTracker(element: PsiElement): ModificationTracker {
|
||||
return project.createAllLibrariesModificationTracker()
|
||||
}
|
||||
|
||||
override fun createInstanceOfLightFacade(
|
||||
facadeFqName: FqName,
|
||||
files: List<KtFile>,
|
||||
module: KtModule,
|
||||
): KtLightClassForFacade = analyzeForLightClasses(files.first()) {
|
||||
SymbolLightClassForFacade(facadeFqName, files)
|
||||
}
|
||||
@@ -136,8 +133,8 @@ class SymbolKotlinAsJavaSupport(project: Project) : KotlinAsJavaSupportBase<KtMo
|
||||
|
||||
override fun getScriptClasses(scriptFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> = error("Should not be called")
|
||||
|
||||
override fun getKotlinInternalClasses(fqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> =
|
||||
emptyList() //TODO Implement if necessary for symbol
|
||||
//TODO Implement if necessary for symbol
|
||||
override fun getKotlinInternalClasses(fqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> = emptyList()
|
||||
|
||||
override fun findFilesForFacade(facadeFqName: FqName, searchScope: GlobalSearchScope): Collection<KtFile> {
|
||||
return project.createDeclarationProvider(searchScope).findFilesForFacade(facadeFqName)
|
||||
|
||||
@@ -38,11 +38,11 @@ class CliKotlinAsJavaSupport(project: Project, private val traceHolder: CliTrace
|
||||
|
||||
override fun KtFile.findModule(): KtFile = this
|
||||
|
||||
override fun createInstanceOfDecompiledLightFacade(facadeFqName: FqName, files: List<KtFile>, module: KtFile): KtLightClassForFacade? {
|
||||
override fun createInstanceOfDecompiledLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade? {
|
||||
error("Should not be called")
|
||||
}
|
||||
|
||||
override fun createInstanceOfLightFacade(facadeFqName: FqName, files: List<KtFile>, module: KtFile): KtLightClassForFacade {
|
||||
override fun createInstanceOfLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade {
|
||||
return LightClassGenerationSupport.getInstance(files.first().project).createUltraLightClassForFacade(facadeFqName, files)
|
||||
}
|
||||
|
||||
@@ -117,12 +117,9 @@ class CliKotlinAsJavaSupport(project: Project, private val traceHolder: CliTrace
|
||||
}
|
||||
|
||||
override fun createFacadeForSyntheticFile(file: KtFile): KtLightClassForFacade = error("Should not be called")
|
||||
override fun declarationLocation(file: KtFile, module: KtFile): DeclarationLocation = DeclarationLocation.ProjectSources
|
||||
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject, module: KtFile): KtLightClass? {
|
||||
error("Should not be called")
|
||||
}
|
||||
|
||||
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject, module: KtFile): KtLightClass? {
|
||||
override fun declarationLocation(file: KtFile): DeclarationLocation = DeclarationLocation.ProjectSources
|
||||
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject): KtLightClass = error("Should not be called")
|
||||
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject): KtLightClass {
|
||||
return LightClassGenerationSupport.getInstance(classOrObject.project).createUltraLightClass(classOrObject)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user