Reformat PluginDeclarationProviderFactory
This commit is contained in:
+16
-17
@@ -36,11 +36,11 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.*
|
|||||||
import org.jetbrains.kotlin.storage.StorageManager
|
import org.jetbrains.kotlin.storage.StorageManager
|
||||||
|
|
||||||
class PluginDeclarationProviderFactory(
|
class PluginDeclarationProviderFactory(
|
||||||
private val project: Project,
|
private val project: Project,
|
||||||
private val indexedFilesScope: GlobalSearchScope,
|
private val indexedFilesScope: GlobalSearchScope,
|
||||||
private val storageManager: StorageManager,
|
private val storageManager: StorageManager,
|
||||||
private val nonIndexedFiles: Collection<KtFile>,
|
private val nonIndexedFiles: Collection<KtFile>,
|
||||||
private val moduleInfo: ModuleInfo
|
private val moduleInfo: ModuleInfo
|
||||||
) : AbstractDeclarationProviderFactory(storageManager) {
|
) : AbstractDeclarationProviderFactory(storageManager) {
|
||||||
private val fileBasedDeclarationProviderFactory = FileBasedDeclarationProviderFactory(storageManager, nonIndexedFiles)
|
private val fileBasedDeclarationProviderFactory = FileBasedDeclarationProviderFactory(storageManager, nonIndexedFiles)
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ class PluginDeclarationProviderFactory(
|
|||||||
// We're only looking for source-based declarations
|
// We're only looking for source-based declarations
|
||||||
return (moduleInfo as? IdeaModuleInfo)?.projectSourceModules()
|
return (moduleInfo as? IdeaModuleInfo)?.projectSourceModules()
|
||||||
?.any { PerModulePackageCacheService.getInstance(project).packageExists(name, it) }
|
?.any { PerModulePackageCacheService.getInstance(project).packageExists(name, it) }
|
||||||
?: false
|
?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getStubBasedPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
private fun getStubBasedPackageMemberDeclarationProvider(name: FqName): PackageMemberDeclarationProvider? {
|
||||||
@@ -77,8 +77,8 @@ class PluginDeclarationProviderFactory(
|
|||||||
|
|
||||||
private fun diagnoseMissingPackageFragmentExactPackageIndexCorruption(message: String): Nothing {
|
private fun diagnoseMissingPackageFragmentExactPackageIndexCorruption(message: String): Nothing {
|
||||||
throw IllegalStateException(
|
throw IllegalStateException(
|
||||||
"KotlinExactPackageIndex seems corrupted.\n" +
|
"KotlinExactPackageIndex seems corrupted.\n" +
|
||||||
message
|
message
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,8 @@ class PluginDeclarationProviderFactory(
|
|||||||
val packageExists = PackageIndexUtil.packageExists(fqName, indexedFilesScope, project)
|
val packageExists = PackageIndexUtil.packageExists(fqName, indexedFilesScope, project)
|
||||||
val spiPackageExists = subpackagesIndex.packageExists(fqName)
|
val spiPackageExists = subpackagesIndex.packageExists(fqName)
|
||||||
val oldPackageExists = oldPackageExists(fqName)
|
val oldPackageExists = oldPackageExists(fqName)
|
||||||
val cachedPackageExists = moduleSourceInfo?.let { ServiceManager.getService(project, PerModulePackageCacheService::class.java).packageExists(fqName, it) }
|
val cachedPackageExists =
|
||||||
|
moduleSourceInfo?.let { ServiceManager.getService(project, PerModulePackageCacheService::class.java).packageExists(fqName, it) }
|
||||||
val moduleModificationCount = moduleSourceInfo?.createModificationTracker()?.modificationCount
|
val moduleModificationCount = moduleSourceInfo?.createModificationTracker()?.modificationCount
|
||||||
|
|
||||||
val common = """
|
val common = """
|
||||||
@@ -124,8 +125,7 @@ class PluginDeclarationProviderFactory(
|
|||||||
|$common,
|
|$common,
|
||||||
|packageFqNameByTree = '${file.packageFqNameByTree}', packageDirectiveText = '${file.packageDirective?.text}'
|
|packageFqNameByTree = '${file.packageFqNameByTree}', packageDirectiveText = '${file.packageDirective?.text}'
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
"""
|
"""
|
||||||
|Cannot find package fragment '$fqName' for unspecified file:
|
|Cannot find package fragment '$fqName' for unspecified file:
|
||||||
|nonIndexedFiles = $nonIndexedFiles,
|
|nonIndexedFiles = $nonIndexedFiles,
|
||||||
@@ -135,13 +135,13 @@ class PluginDeclarationProviderFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val scopeNotEmptyAndContainsFile =
|
val scopeNotEmptyAndContainsFile =
|
||||||
indexedFilesScope != GlobalSearchScope.EMPTY_SCOPE && (file == null || file.virtualFile in indexedFilesScope)
|
indexedFilesScope != GlobalSearchScope.EMPTY_SCOPE && (file == null || file.virtualFile in indexedFilesScope)
|
||||||
when {
|
when {
|
||||||
scopeNotEmptyAndContainsFile
|
scopeNotEmptyAndContainsFile
|
||||||
&& !packageExists && oldPackageExists == false -> diagnoseMissingPackageFragmentExactPackageIndexCorruption(message)
|
&& !packageExists && oldPackageExists == false -> diagnoseMissingPackageFragmentExactPackageIndexCorruption(message)
|
||||||
|
|
||||||
scopeNotEmptyAndContainsFile
|
scopeNotEmptyAndContainsFile
|
||||||
&& packageExists && cachedPackageExists == false -> diagnoseMissingPackageFragmentPerModulePackageCacheMiss(message)
|
&& packageExists && cachedPackageExists == false -> diagnoseMissingPackageFragmentPerModulePackageCacheMiss(message)
|
||||||
|
|
||||||
else -> diagnoseMissingPackageFragmentUnknownReason(message)
|
else -> diagnoseMissingPackageFragmentUnknownReason(message)
|
||||||
}
|
}
|
||||||
@@ -157,14 +157,13 @@ class PluginDeclarationProviderFactory(
|
|||||||
private fun oldPackageExists(packageFqName: FqName): Boolean? = try {
|
private fun oldPackageExists(packageFqName: FqName): Boolean? = try {
|
||||||
var result = false
|
var result = false
|
||||||
StubIndex.getInstance().processElements<String, KtFile>(
|
StubIndex.getInstance().processElements<String, KtFile>(
|
||||||
KotlinExactPackagesIndex.getInstance().key, packageFqName.asString(), project, indexedFilesScope, KtFile::class.java
|
KotlinExactPackagesIndex.getInstance().key, packageFqName.asString(), project, indexedFilesScope, KtFile::class.java
|
||||||
) {
|
) {
|
||||||
result = true
|
result = true
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
}
|
} catch (e: Throwable) {
|
||||||
catch (e: Throwable) {
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user