Performance fix for Import Member

This commit is contained in:
Valentin Kipyatkov
2016-10-25 19:37:57 +03:00
parent d9ef8aa96f
commit 8c99b0e64c
2 changed files with 48 additions and 25 deletions
@@ -206,28 +206,41 @@ class KotlinIndicesHelper(
.toSet()
}
fun getJvmCallablesByName(name: String): Collection<CallableDescriptor> {
fun processJvmCallablesByName(
name: String,
filter: (PsiMember) -> Boolean,
processor: (CallableDescriptor) -> Unit
) {
val javaDeclarations = PsiShortNamesCache.getInstance(project).getFieldsByName(name, scopeWithoutKotlin).asSequence() +
PsiShortNamesCache.getInstance(project).getMethodsByName(name, scopeWithoutKotlin).asSequence()
return javaDeclarations
.filterNot { it is KtLightElement<*,*> }
.mapNotNull { (it as PsiMember).getJavaMemberDescriptor(resolutionFacade) as? CallableDescriptor }
.filter(descriptorFilter)
.toSet()
val processed = HashSet<CallableDescriptor>()
for (javaDeclaration in javaDeclarations) {
ProgressManager.checkCanceled()
if (javaDeclaration is KtLightElement<*, *>) continue
if (!filter(javaDeclaration as PsiMember)) continue
val descriptor = javaDeclaration.getJavaMemberDescriptor(resolutionFacade) as? CallableDescriptor ?: continue
if (!processed.add(descriptor)) continue
if (!descriptorFilter(descriptor)) continue
processor(descriptor)
}
}
fun getKotlinCallablesByName(name: String): Collection<CallableDescriptor> {
val functions = KotlinFunctionShortNameIndex.getInstance().get(name, project, scope)
.asSequence()
.map { it.descriptor as? CallableDescriptor }
val properties = KotlinPropertyShortNameIndex.getInstance().get(name, project, scope)
.asSequence()
.map { it.descriptor as? CallableDescriptor }
return (functions + properties)
.filterNotNull()
.filter(descriptorFilter)
.toSet()
fun processKotlinCallablesByName(
name: String,
filter: (KtCallableDeclaration) -> Boolean,
processor: (CallableDescriptor) -> Unit
) {
val functions: Sequence<KtCallableDeclaration> = KotlinFunctionShortNameIndex.getInstance().get(name, project, scope).asSequence()
val properties: Sequence<KtCallableDeclaration> = KotlinPropertyShortNameIndex.getInstance().get(name, project, scope).asSequence()
val processed = HashSet<CallableDescriptor>()
for (declaration in functions + properties) {
ProgressManager.checkCanceled()
if (!filter(declaration)) continue
val descriptor = declaration.descriptor as? CallableDescriptor ?: continue
if (!processed.add(descriptor)) continue
if (!descriptorFilter(descriptor)) continue
processor(descriptor)
}
}
fun getKotlinClasses(nameFilter: (String) -> Boolean, kindFilter: (ClassKind) -> Boolean): Collection<ClassDescriptor> {