Do not limit scope when searching in index by default
This commit is contained in:
committed by
Ilya Chernikov
parent
478ae96e50
commit
8e700cdb10
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.asJava.defaultImplsChild
|
||||
import org.jetbrains.kotlin.fileClasses.javaFileFacadeFqName
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinClassShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFileFacadeShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.util.*
|
||||
@@ -51,12 +52,13 @@ class KotlinShortNamesCache(private val project: Project) : PsiShortNamesCache()
|
||||
* Return class names form kotlin sources in given scope which should be visible as Java classes.
|
||||
*/
|
||||
override fun getClassesByName(name: String, scope: GlobalSearchScope): Array<PsiClass> {
|
||||
val effectiveScope = KotlinSourceFilterScope.sourcesAndLibraries(scope, project)
|
||||
val allFqNames = HashSet<FqName?>()
|
||||
|
||||
KotlinClassShortNameIndex.getInstance().get(name, project, scope)
|
||||
KotlinClassShortNameIndex.getInstance().get(name, project, effectiveScope)
|
||||
.mapTo(allFqNames) { it.fqName }
|
||||
|
||||
KotlinFileFacadeShortNameIndex.INSTANCE.get(name, project, scope)
|
||||
KotlinFileFacadeShortNameIndex.INSTANCE.get(name, project, effectiveScope)
|
||||
.mapTo(allFqNames) { it.javaFileFacadeFqName }
|
||||
|
||||
val result = ArrayList<PsiClass>()
|
||||
@@ -70,7 +72,7 @@ class KotlinShortNamesCache(private val project: Project) : PsiShortNamesCache()
|
||||
|
||||
val fqNameToSearch = if (isInterfaceDefaultImpl) fqName.defaultImplsChild() else fqName
|
||||
|
||||
val psiClass = JavaElementFinder.getInstance(project).findClass(fqNameToSearch.asString(), scope)
|
||||
val psiClass = JavaElementFinder.getInstance(project).findClass(fqNameToSearch.asString(), effectiveScope)
|
||||
if (psiClass != null) {
|
||||
result.add(psiClass)
|
||||
}
|
||||
|
||||
+4
-13
@@ -85,10 +85,7 @@ private fun findCandidateDeclarationsInIndex(
|
||||
|
||||
val containingClass = DescriptorUtils.getParentOfType(referencedDescriptor, ClassDescriptor::class.java, false)
|
||||
if (containingClass != null) {
|
||||
return if (scriptsScope != null)
|
||||
KotlinFullClassNameIndex.getInstance().getNoScopeWrap(containingClass.fqNameSafe.asString(), project, scope)
|
||||
else
|
||||
KotlinFullClassNameIndex.getInstance().get(containingClass.fqNameSafe.asString(), project, scope)
|
||||
return KotlinFullClassNameIndex.getInstance().get(containingClass.fqNameSafe.asString(), project, scope)
|
||||
}
|
||||
|
||||
val topLevelDeclaration = DescriptorUtils.getParentOfType(referencedDescriptor, PropertyDescriptor::class.java, false)
|
||||
@@ -98,18 +95,12 @@ private fun findCandidateDeclarationsInIndex(
|
||||
if (!DescriptorUtils.isTopLevelDeclaration(topLevelDeclaration)) return emptyList()
|
||||
|
||||
val fqName = topLevelDeclaration.fqNameSafe.asString()
|
||||
when (topLevelDeclaration) {
|
||||
return when (topLevelDeclaration) {
|
||||
is FunctionDescriptor -> {
|
||||
return if (scriptsScope != null)
|
||||
KotlinTopLevelFunctionFqnNameIndex.getInstance().getNoScopeWrap(fqName, project, scope)
|
||||
else
|
||||
KotlinTopLevelFunctionFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
KotlinTopLevelFunctionFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
}
|
||||
is PropertyDescriptor -> {
|
||||
return if (scriptsScope != null)
|
||||
KotlinTopLevelPropertyFqnNameIndex.getInstance().getNoScopeWrap(fqName, project, scope)
|
||||
else
|
||||
KotlinTopLevelPropertyFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
KotlinTopLevelPropertyFqnNameIndex.getInstance().get(fqName, project, scope)
|
||||
}
|
||||
else -> error("Referenced non local declaration that is not inside top level function, property of class:\n $referencedDescriptor")
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class KotlinAnnotationsIndex extends StringStubIndexExtension<KtAnnotatio
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtAnnotationEntry> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtAnnotationEntry.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtAnnotationEntry.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -48,6 +48,6 @@ public class KotlinClassShortNameIndex extends StringStubIndexExtension<KtClassO
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtClassOrObject> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtClassOrObject.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtClassOrObject.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -47,6 +47,6 @@ public class KotlinExactPackagesIndex extends StringStubIndexExtension<KtFile> {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtFile> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtFile.class);
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtFile.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ class KotlinFileFacadeClassByPackageIndex private constructor() : StringStubInde
|
||||
override fun getKey(): StubIndexKey<String, KtFile> = KEY
|
||||
|
||||
override fun get(key: String, project: Project, scope: GlobalSearchScope) =
|
||||
StubIndex.getElements(KEY, key, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtFile::class.java)
|
||||
StubIndex.getElements(KEY, key, project, scope, KtFile::class.java)
|
||||
|
||||
companion object {
|
||||
private val KEY = KotlinIndexUtil.createIndexKey(KotlinFileFacadeClassByPackageIndex::class.java)
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ class KotlinFileFacadeFqNameIndex private constructor() : StringStubIndexExtensi
|
||||
override fun getKey(): StubIndexKey<String, KtFile> = KEY
|
||||
|
||||
override fun get(key: String, project: Project, scope: GlobalSearchScope) =
|
||||
StubIndex.getElements(KEY, key, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtFile::class.java)
|
||||
StubIndex.getElements(KEY, key, project, scope, KtFile::class.java)
|
||||
|
||||
companion object {
|
||||
private val KEY = KotlinIndexUtil.createIndexKey(KotlinFileFacadeFqNameIndex::class.java)
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ class KotlinFileFacadeShortNameIndex private constructor() : StringStubIndexExte
|
||||
override fun getKey(): StubIndexKey<String, KtFile> = KEY
|
||||
|
||||
override fun get(key: String, project: Project, scope: GlobalSearchScope) =
|
||||
StubIndex.getElements(KEY, key, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtFile::class.java)
|
||||
StubIndex.getElements(KEY, key, project, scope, KtFile::class.java)
|
||||
|
||||
companion object {
|
||||
private val KEY = KotlinIndexUtil.createIndexKey(KotlinFileFacadeShortNameIndex::class.java)
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ class KotlinFilePartClassIndex private constructor() : StringStubIndexExtension<
|
||||
override fun getKey(): StubIndexKey<String, KtFile> = KEY
|
||||
|
||||
override fun get(key: String, project: Project, scope: GlobalSearchScope) =
|
||||
StubIndex.getElements(KEY, key, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtFile::class.java)
|
||||
StubIndex.getElements(KEY, key, project, scope, KtFile::class.java)
|
||||
|
||||
companion object {
|
||||
private val KEY = KotlinIndexUtil.createIndexKey(KotlinFilePartClassIndex::class.java)
|
||||
|
||||
-6
@@ -48,12 +48,6 @@ public class KotlinFullClassNameIndex extends StringStubIndexExtension<KtClassOr
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtClassOrObject> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtClassOrObject.class);
|
||||
}
|
||||
|
||||
// temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt)
|
||||
@NotNull
|
||||
public Collection<KtClassOrObject> getNoScopeWrap(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtClassOrObject.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinFunctionShortNameIndex extends StringStubIndexExtension<KtNam
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtNamedFunction> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtNamedFunction.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtNamedFunction.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinProbablyNothingFunctionShortNameIndex extends StringStubIndex
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtNamedFunction> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtNamedFunction.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtNamedFunction.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinProbablyNothingPropertyShortNameIndex extends StringStubIndex
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtProperty> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtProperty.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtProperty.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinPropertyShortNameIndex extends StringStubIndexExtension<KtPro
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtProperty> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtProperty.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtProperty.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class KotlinScriptFqnIndex private constructor() : StringStubIndexExtension<KtSc
|
||||
override fun getKey() = KEY
|
||||
|
||||
override fun get(fqName: String, project: Project, scope: GlobalSearchScope): Collection<KtScript> {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtScript::class.java)
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtScript::class.java)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+1
-1
@@ -47,6 +47,6 @@ public class KotlinSuperClassIndex extends StringStubIndexExtension<KtClassOrObj
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtClassOrObject> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtClassOrObject.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtClassOrObject.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinTopLevelClassByPackageIndex extends StringStubIndexExtension<
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtClassOrObject> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtClassOrObject.class);
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtClassOrObject.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ class KotlinTopLevelExtensionsByReceiverTypeIndex private constructor() : String
|
||||
override fun getKey() = KEY
|
||||
|
||||
override fun get(s: String, project: Project, scope: GlobalSearchScope)
|
||||
= StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtCallableDeclaration::class.java)
|
||||
= StubIndex.getElements(KEY, s, project, scope, KtCallableDeclaration::class.java)
|
||||
|
||||
companion object {
|
||||
private val KEY = KotlinIndexUtil.createIndexKey<String, KtCallableDeclaration>(KotlinTopLevelExtensionsByReceiverTypeIndex::class.java)
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinTopLevelFunctionByPackageIndex extends StringStubIndexExtensi
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtNamedFunction> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtNamedFunction.class);
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtNamedFunction.class);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class KotlinTopLevelFunctionFqnNameIndex extends StringStubIndexExtension
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtNamedFunction> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtNamedFunction.class);
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtNamedFunction.class);
|
||||
}
|
||||
|
||||
// temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt)
|
||||
|
||||
+1
-1
@@ -46,6 +46,6 @@ public class KotlinTopLevelPropertyByPackageIndex extends StringStubIndexExtensi
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtProperty> get(@NotNull String fqName, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, fqName, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtProperty.class);
|
||||
return StubIndex.getElements(KEY, fqName, project, scope, KtProperty.class);
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -47,12 +47,6 @@ public class KotlinTopLevelPropertyFqnNameIndex extends StringStubIndexExtension
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<KtProperty> get(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, KotlinSourceFilterScope.sourcesAndLibraries(scope, project), KtProperty.class);
|
||||
}
|
||||
|
||||
// temporary hack, see comments in findCandidateDeclarationsInIndex (findDecompiledDeclaration.kt)
|
||||
@NotNull
|
||||
public Collection<KtProperty> getNoScopeWrap(@NotNull String s, @NotNull Project project, @NotNull GlobalSearchScope scope) {
|
||||
return StubIndex.getElements(KEY, s, project, scope, KtProperty.class);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.asJava.LightClassUtil
|
||||
import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinAnnotationsIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.KotlinSourceFilterScope
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
|
||||
@@ -106,7 +107,8 @@ class KotlinAnnotatedElementsSearcher : QueryExecutor<PsiModifierListOwner, Anno
|
||||
return runReadAction(fun(): Collection<PsiElement> {
|
||||
if (useScope is GlobalSearchScope) {
|
||||
val name = annClass.name ?: return emptyList()
|
||||
return KotlinAnnotationsIndex.getInstance().get(name, annClass.project, useScope)
|
||||
val scope = KotlinSourceFilterScope.sourcesAndLibraries(useScope, annClass.project)
|
||||
return KotlinAnnotationsIndex.getInstance().get(name, annClass.project, scope)
|
||||
}
|
||||
|
||||
return (useScope as LocalSearchScope).scope.flatMap { it.collectDescendantsOfType<KtAnnotationEntry>() }
|
||||
|
||||
Reference in New Issue
Block a user