More diagnostics for EA-85926 and EA-77163

This commit is contained in:
Dmitry Jemerov
2016-11-21 19:09:38 +01:00
parent 2d2f439a78
commit f9f590d270
3 changed files with 14 additions and 2 deletions
@@ -86,7 +86,11 @@ class FileScopeFactory(
val packageView = moduleDescriptor.getPackage(file.packageFqName)
val packageFragment = topLevelDescriptorProvider.getPackageFragment(file.packageFqName)
?: error("Could not find fragment ${file.packageFqName} for file ${file.name}")
if (packageFragment == null) {
// TODO J2K and change return type of diagnoseMissingPackageFragment() to Nothing
(topLevelDescriptorProvider as? LazyClassContext)?.declarationProviderFactory?.diagnoseMissingPackageFragment(file)
error("Could not find fragment ${file.packageFqName} for file ${file.name}")
}
fun createImportResolver(indexedImports: IndexedImports, trace: BindingTrace, excludedImports: List<FqName>? = null) =
LazyImportResolver(
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.stubindex
import com.intellij.openapi.components.ServiceManager
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiManager
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.util.CachedValueProvider
import com.intellij.psi.util.CachedValuesManager
@@ -42,6 +43,7 @@ class SubpackagesIndexService(private val project: Project) {
// a map from any existing package (in kotlin) to a set of subpackages (not necessarily direct) containing files
private val allPackageFqNames = hashSetOf<FqName>()
private val fqNameByPrefix = MultiMap.createSet<FqName, FqName>()
private val oocbCount = PsiManager.getInstance(project).modificationTracker.outOfCodeBlockModificationCount
init {
for (fqNameAsString in allPackageFqNames) {
@@ -80,6 +82,8 @@ class SubpackagesIndexService(private val project: Project) {
return existingSubPackagesShortNames.map { fqName.child(it) }
}
override fun toString() = "SubpackagesIndex: OOCB on creation $oocbCount, all packages size ${allPackageFqNames.size}"
}
companion object {
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.idea.stubindex.resolve
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
import org.jetbrains.kotlin.idea.stubindex.SubpackagesIndexService
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.lazy.data.KtClassLikeInfo
@@ -56,9 +57,12 @@ class PluginDeclarationProviderFactory(
override fun diagnoseMissingPackageFragment(file: KtFile) {
val packageFqName = file.packageFqName
val subpackagesIndex = SubpackagesIndexService.getInstance(project)
throw IllegalStateException("Cannot find package fragment for file ${file.name} with package $packageFqName, " +
"vFile ${file.virtualFile}, nonIndexed ${file in nonIndexedFiles} " +
"packageExists=${PackageIndexUtil.packageExists(packageFqName, indexedFilesScope, project)}")
"packageExists=${PackageIndexUtil.packageExists(packageFqName, indexedFilesScope, project)} in $indexedFilesScope," +
"SPI.packageExists=${subpackagesIndex.packageExists(packageFqName)} SPI=$subpackagesIndex " +
"OOCB count ${file.manager.modificationTracker.outOfCodeBlockModificationCount}}")
}
// trying to diagnose org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException in completion