Minor changes on code review

This commit is contained in:
Valentin Kipyatkov
2016-11-02 19:22:13 +03:00
parent 6d3dd5d9b7
commit 6a3597fa0f
3 changed files with 25 additions and 16 deletions
@@ -16,6 +16,7 @@
package org.jetbrains.kotlin.idea.completion
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.completion.*
import com.intellij.codeInsight.completion.impl.BetterPrefixMatcher
import com.intellij.codeInsight.lookup.LookupElement
@@ -202,18 +203,24 @@ class BasicCompletionSession(
val contextVariableTypesForSmartCompletion = withCollectRequiredContextVariableTypes(::completeWithSmartCompletion)
val contextVariableTypesForReferenceVariants = withCollectRequiredContextVariableTypes { lookupElementFactory ->
if (prefix.isEmpty() || callTypeAndReceiver.receiver != null) {
addReferenceVariantElements(lookupElementFactory, descriptorKindFilter)
}
else if (prefix[0].isLowerCase()) {
addReferenceVariantElements(lookupElementFactory, USUALLY_START_LOWER_CASE.intersect(descriptorKindFilter))
flushToResultSet()
addReferenceVariantElements(lookupElementFactory, USUALLY_START_UPPER_CASE.intersect(descriptorKindFilter))
}
else {
addReferenceVariantElements(lookupElementFactory, USUALLY_START_UPPER_CASE.intersect(descriptorKindFilter))
flushToResultSet()
addReferenceVariantElements(lookupElementFactory, USUALLY_START_LOWER_CASE.intersect(descriptorKindFilter))
when {
prefix.isEmpty()
|| callTypeAndReceiver.receiver != null
|| CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE == CodeInsightSettings.NONE -> {
addReferenceVariantElements(lookupElementFactory, descriptorKindFilter)
}
prefix[0].isLowerCase() -> {
addReferenceVariantElements(lookupElementFactory, USUALLY_START_LOWER_CASE.intersect(descriptorKindFilter))
flushToResultSet()
addReferenceVariantElements(lookupElementFactory, USUALLY_START_UPPER_CASE.intersect(descriptorKindFilter))
}
else -> {
addReferenceVariantElements(lookupElementFactory, USUALLY_START_UPPER_CASE.intersect(descriptorKindFilter))
flushToResultSet()
addReferenceVariantElements(lookupElementFactory, USUALLY_START_LOWER_CASE.intersect(descriptorKindFilter))
}
}
referenceVariantsCollector!!.collectingFinished()
}
@@ -119,6 +119,7 @@ class BasicLookupElementFactory(
): LookupElement {
val declarationLazy by lazy { DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) }
//TODO: try JavaClassDescriptor?
if (descriptor is ClassifierDescriptor &&
declarationLazy is PsiClass &&
declarationLazy !is KtLightClass) {
@@ -74,6 +74,8 @@ class ReferenceVariantsCollector(
return variants
}
private val GET_SET_PREFIXES = listOf("get", "set", "ge", "se", "g", "s")
private fun doCollectReferenceVariants(descriptorKindFilter: DescriptorKindFilter): ReferenceVariants {
val completeExtensionsFromIndices = descriptorKindFilter.kindMask.and(DescriptorKindFilter.CALLABLES_MASK) != 0
&& DescriptorKindExclude.Extensions !in descriptorKindFilter.excludes
@@ -97,10 +99,9 @@ class ReferenceVariantsCollector(
var variants = getReferenceVariants(descriptorKindFilter, descriptorNameFilter.toNameFilter())
val getOrSetPrefix = listOf("get", "set", "ge", "se", "g", "s").firstOrNull { prefix.startsWith(it) }
val additionalPropertyNameFilter: ((String) -> Boolean)? = run {
getOrSetPrefix?.let { prefixMatcher.cloneWithPrefix(prefix.removePrefix(getOrSetPrefix).decapitalizeSmart()).asStringNameFilter() }
}
val getOrSetPrefix = GET_SET_PREFIXES.firstOrNull { prefix.startsWith(it) }
val additionalPropertyNameFilter: ((String) -> Boolean)? = getOrSetPrefix
?.let { prefixMatcher.cloneWithPrefix(prefix.removePrefix(getOrSetPrefix).decapitalizeSmart()).asStringNameFilter() }
if (additionalPropertyNameFilter != null) {
variants += getReferenceVariants(descriptorKindFilter.intersect(DescriptorKindFilter.VARIABLES),
additionalPropertyNameFilter.toNameFilter())