[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 {
|
return when {
|
||||||
facadeFiles.none(KtFile::hasTopLevelCallables) -> null
|
facadeFiles.none(KtFile::hasTopLevelCallables) -> null
|
||||||
facadeFiles.none(KtFile::isCompiled) -> {
|
facadeFiles.none(KtFile::isCompiled) -> {
|
||||||
createInstanceOfLightFacade(facadeFqName, facadeFiles, module) to outOfBlockModificationTracker(file, module)
|
createInstanceOfLightFacade(facadeFqName, facadeFiles) to outOfBlockModificationTracker(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
facadeFiles.all(KtFile::isCompiled) -> {
|
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")
|
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 fun facadeIsApplicable(module: TModule, file: KtFile): Boolean
|
||||||
protected abstract val TModule.contentSearchScope: GlobalSearchScope
|
protected abstract val TModule.contentSearchScope: GlobalSearchScope
|
||||||
|
|
||||||
protected abstract fun createInstanceOfLightFacade(facadeFqName: FqName, files: List<KtFile>, module: TModule): KtLightClassForFacade
|
protected abstract fun createInstanceOfLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade
|
||||||
protected abstract fun createInstanceOfDecompiledLightFacade(
|
protected abstract fun createInstanceOfDecompiledLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade?
|
||||||
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 open fun projectWideOutOfBlockModificationTracker(): ModificationTracker {
|
protected open fun projectWideOutOfBlockModificationTracker(): ModificationTracker {
|
||||||
return KotlinModificationTrackerService.getInstance(project).outOfBlockModificationTracker
|
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) {
|
override fun getLightFacade(file: KtFile): KtLightClassForFacade? = ifValid(file) {
|
||||||
CachedValuesManager.getCachedValue(file) {
|
CachedValuesManager.getCachedValue(file) {
|
||||||
val (facade, tracker) = createLightFacade(file) ?: (null to projectWideOutOfBlockModificationTracker())
|
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 {
|
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> {
|
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
|
if (classOrObject.shouldNotBeVisibleAsLightClass()) return null
|
||||||
|
|
||||||
val containingFile = classOrObject.containingKtFile
|
val containingFile = classOrObject.containingKtFile
|
||||||
val module = containingFile.findModule()
|
when (declarationLocation(containingFile)) {
|
||||||
when (declarationLocation(containingFile, module)) {
|
|
||||||
DeclarationLocation.ProjectSources -> {
|
DeclarationLocation.ProjectSources -> {
|
||||||
return createInstanceOfLightClass(classOrObject, module) to outOfBlockModificationTracker(classOrObject, module)
|
return createInstanceOfLightClass(classOrObject) to outOfBlockModificationTracker(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarationLocation.LibraryClasses -> {
|
DeclarationLocation.LibraryClasses -> {
|
||||||
return createInstanceOfDecompiledLightClass(classOrObject, module) to librariesTracker(classOrObject, module)
|
return createInstanceOfDecompiledLightClass(classOrObject) to librariesTracker(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
DeclarationLocation.LibrarySources -> {
|
DeclarationLocation.LibrarySources -> {
|
||||||
@@ -138,22 +133,22 @@ abstract class KotlinAsJavaSupportBase<TModule>(protected val project: Project)
|
|||||||
guardedRun { getLightClass(it) }
|
guardedRun { getLightClass(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
return value to librariesTracker(classOrObject, module)
|
return value to librariesTracker(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
null -> Unit
|
null -> Unit
|
||||||
}
|
}
|
||||||
|
|
||||||
if (containingFile.analysisContext != null || containingFile.originalFile.virtualFile != null) {
|
if (containingFile.analysisContext != null || containingFile.originalFile.virtualFile != null) {
|
||||||
return createInstanceOfLightClass(classOrObject, module) to outOfBlockModificationTracker(classOrObject, module)
|
return createInstanceOfLightClass(classOrObject) to outOfBlockModificationTracker(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun createInstanceOfLightClass(classOrObject: KtClassOrObject, module: TModule): KtLightClass?
|
protected abstract fun createInstanceOfLightClass(classOrObject: KtClassOrObject): KtLightClass?
|
||||||
protected abstract fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject, module: TModule): KtLightClass?
|
protected abstract fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject): KtLightClass?
|
||||||
protected abstract fun declarationLocation(file: KtFile, module: TModule): DeclarationLocation?
|
protected abstract fun declarationLocation(file: KtFile): DeclarationLocation?
|
||||||
|
|
||||||
protected enum class DeclarationLocation {
|
protected enum class DeclarationLocation {
|
||||||
ProjectSources, LibraryClasses, LibrarySources,
|
ProjectSources, LibraryClasses, LibrarySources,
|
||||||
|
|||||||
+10
-13
@@ -89,43 +89,40 @@ class SymbolKotlinAsJavaSupport(project: Project) : KotlinAsJavaSupportBase<KtMo
|
|||||||
|
|
||||||
override fun KtFile.findModule(): KtModule = getKtModule(project)
|
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 KtSourceModule -> DeclarationLocation.ProjectSources
|
||||||
is KtLibraryModule -> DeclarationLocation.LibraryClasses
|
is KtLibraryModule -> DeclarationLocation.LibraryClasses
|
||||||
is KtLibrarySourceModule -> DeclarationLocation.LibrarySources
|
is KtLibrarySourceModule -> DeclarationLocation.LibrarySources
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject, module: KtModule): KtLightClass? {
|
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject): KtLightClass? {
|
||||||
return DecompiledLightClassesFactory.getLightClassForDecompiledClassOrObject(classOrObject, project)
|
return DecompiledLightClassesFactory.getLightClassForDecompiledClassOrObject(classOrObject, project)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject, module: KtModule): KtLightClass? {
|
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject): KtLightClass? {
|
||||||
return createSymbolLightClassNoCache(classOrObject)
|
return createSymbolLightClassNoCache(classOrObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createInstanceOfDecompiledLightFacade(
|
override fun createInstanceOfDecompiledLightFacade(facadeFqName: FqName, files: List<KtFile>): KtLightClassForFacade? {
|
||||||
facadeFqName: FqName,
|
return DecompiledLightClassesFactory.createLightFacadeForDecompiledKotlinFile(project, facadeFqName, files)
|
||||||
files: List<KtFile>,
|
}
|
||||||
module: KtModule,
|
|
||||||
): KtLightClassForFacade? = DecompiledLightClassesFactory.createLightFacadeForDecompiledKotlinFile(project, facadeFqName, files)
|
|
||||||
|
|
||||||
override fun projectWideOutOfBlockModificationTracker(): ModificationTracker {
|
override fun projectWideOutOfBlockModificationTracker(): ModificationTracker {
|
||||||
return project.createProjectWideOutOfBlockModificationTracker()
|
return project.createProjectWideOutOfBlockModificationTracker()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun outOfBlockModificationTracker(element: PsiElement, module: KtModule): ModificationTracker {
|
override fun outOfBlockModificationTracker(element: PsiElement): ModificationTracker {
|
||||||
return project.createProjectWideOutOfBlockModificationTracker()
|
return project.createProjectWideOutOfBlockModificationTracker()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun librariesTracker(element: PsiElement, module: KtModule): ModificationTracker {
|
override fun librariesTracker(element: PsiElement): ModificationTracker {
|
||||||
return project.createAllLibrariesModificationTracker()
|
return project.createAllLibrariesModificationTracker()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createInstanceOfLightFacade(
|
override fun createInstanceOfLightFacade(
|
||||||
facadeFqName: FqName,
|
facadeFqName: FqName,
|
||||||
files: List<KtFile>,
|
files: List<KtFile>,
|
||||||
module: KtModule,
|
|
||||||
): KtLightClassForFacade = analyzeForLightClasses(files.first()) {
|
): KtLightClassForFacade = analyzeForLightClasses(files.first()) {
|
||||||
SymbolLightClassForFacade(facadeFqName, files)
|
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 getScriptClasses(scriptFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> = error("Should not be called")
|
||||||
|
|
||||||
override fun getKotlinInternalClasses(fqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> =
|
//TODO Implement if necessary for symbol
|
||||||
emptyList() //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> {
|
override fun findFilesForFacade(facadeFqName: FqName, searchScope: GlobalSearchScope): Collection<KtFile> {
|
||||||
return project.createDeclarationProvider(searchScope).findFilesForFacade(facadeFqName)
|
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 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")
|
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)
|
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 createFacadeForSyntheticFile(file: KtFile): KtLightClassForFacade = error("Should not be called")
|
||||||
override fun declarationLocation(file: KtFile, module: KtFile): DeclarationLocation = DeclarationLocation.ProjectSources
|
override fun declarationLocation(file: KtFile): DeclarationLocation = DeclarationLocation.ProjectSources
|
||||||
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject, module: KtFile): KtLightClass? {
|
override fun createInstanceOfDecompiledLightClass(classOrObject: KtClassOrObject): KtLightClass = error("Should not be called")
|
||||||
error("Should not be called")
|
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject): KtLightClass {
|
||||||
}
|
|
||||||
|
|
||||||
override fun createInstanceOfLightClass(classOrObject: KtClassOrObject, module: KtFile): KtLightClass? {
|
|
||||||
return LightClassGenerationSupport.getInstance(classOrObject.project).createUltraLightClass(classOrObject)
|
return LightClassGenerationSupport.getInstance(classOrObject.project).createUltraLightClass(classOrObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user