Add static members into the list one by one

This commit is contained in:
Valentin Kipyatkov
2015-11-06 13:07:58 +03:00
parent c38039144f
commit ae9482a36c
3 changed files with 47 additions and 37 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.core.KotlinIndicesHelper
import org.jetbrains.kotlin.idea.core.targetDescriptors
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtCallableDeclaration
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtObjectDeclaration
@@ -87,23 +88,26 @@ class StaticMembersCompletion(
//TODO: better presentation for lookup elements from imports too
//TODO: from the same file
fun membersFromIndices(indicesHelper: KotlinIndicesHelper): Collection<DeclarationDescriptor> {
fun processMembersFromIndices(indicesHelper: KotlinIndicesHelper, processor: (DeclarationDescriptor) -> Unit) {
val descriptorKindFilter = DescriptorKindFilter.CALLABLES exclude DescriptorKindExclude.Extensions
val nameFilter: (String) -> Boolean = { prefixMatcher.prefixMatches(it) }
val result = ArrayList<DeclarationDescriptor>()
val filter = { declaration: KtCallableDeclaration, objectDeclaration: KtObjectDeclaration ->
!declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD) && objectDeclaration.isTopLevelOrCompanion()
}
indicesHelper.processObjectMembers(descriptorKindFilter, nameFilter, filter) {
if (it !in alreadyAdded) { //TODO: substitution
processor(it)
}
}
if (isJvmModule) {
indicesHelper.getJavaStaticMembers(descriptorKindFilter, nameFilter).filterTo(result) { it !in alreadyAdded } //TODO: substitution
indicesHelper.processJavaStaticMembers(descriptorKindFilter, nameFilter){
if (it !in alreadyAdded) { //TODO: substitution
processor(it)
}
}
}
indicesHelper.getObjectMembers(descriptorKindFilter, nameFilter) filter@ { declaration, objectDeclaration ->
!declaration.hasModifier(KtTokens.OVERRIDE_KEYWORD) && objectDeclaration.isTopLevelOrCompanion()
}.filterTo(result) {
it !in alreadyAdded //TODO: substitution
}
return result
}
private fun KtObjectDeclaration.isTopLevelOrCompanion(): Boolean {
@@ -125,8 +129,9 @@ class StaticMembersCompletion(
fun completeFromIndices(indicesHelper: KotlinIndicesHelper, collector: LookupElementsCollector) {
val factory = decoratedLookupElementFactory(ItemPriority.STATIC_MEMBER)
membersFromIndices(indicesHelper)
.flatMap { factory.createStandardLookupElementsForDescriptor(it, useReceiverTypes = true) }
.forEach { collector.addElement(it) }
processMembersFromIndices(indicesHelper) {
factory.createStandardLookupElementsForDescriptor(it, useReceiverTypes = true).forEach { collector.addElement(it) }
collector.flushToResultSet()
}
}
}
@@ -137,9 +137,12 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
if (staticMembersCompletion != null && configuration.completeStaticMembers) {
val decoratedFactory = staticMembersCompletion.decoratedLookupElementFactory(ItemPriority.STATIC_MEMBER)
staticMembersCompletion.membersFromIndices(indicesHelper(false))
.flatMap { filter(it, decoratedFactory) }
.forEach { collector.addElement(it) }
staticMembersCompletion.processMembersFromIndices(indicesHelper(false)) {
filter(it, decoratedFactory).forEach {
collector.addElement(it)
flushToResultSet()
}
}
}
}
}