Refactoring

This commit is contained in:
Valentin Kipyatkov
2016-10-27 12:10:13 +03:00
parent 6c17fa7736
commit f6a73e756e
3 changed files with 10 additions and 13 deletions
@@ -165,10 +165,6 @@ class BasicCompletionSession(
filter = filter.exclude(DescriptorKindExclude.TopLevelPackages)
}
if (callTypeAndReceiver.shouldCompleteCallableExtensions()) {
filter = filter.exclude(TopLevelExtensionsExclude) // completed via indices
}
filter
}
@@ -116,7 +116,7 @@ abstract class CompletionSession(
parameters.position.containingFile,
parameters.offset,
kotlinIdentifierPartPattern or singleCharPattern('@'),
kotlinIdentifierStartPattern)
kotlinIdentifierStartPattern)!!
protected val prefixMatcher = CamelHumpMatcher(prefix)
@@ -303,6 +303,14 @@ abstract class CompletionSession(
nameExpression: KtSimpleNameExpression,
runtimeReceiver: ExpressionReceiver? = null
): ReferenceVariants {
val completeExtensionsFromIndices = descriptorKindFilter.kindMask.and(DescriptorKindFilter.CALLABLES_MASK) != 0
&& callTypeAndReceiver !is CallTypeAndReceiver.IMPORT_DIRECTIVE
@Suppress("NAME_SHADOWING")
val descriptorKindFilter = if (completeExtensionsFromIndices)
descriptorKindFilter exclude TopLevelExtensionsExclude // handled via indices
else
descriptorKindFilter
fun getReferenceVariants(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
return referenceVariantsHelper.getReferenceVariants(
nameExpression,
@@ -327,7 +335,7 @@ abstract class CompletionSession(
}
var notImportedExtensions: Collection<CallableDescriptor> = emptyList()
if (callTypeAndReceiver.shouldCompleteCallableExtensions()) {
if (completeExtensionsFromIndices) {
val indicesHelper = indicesHelper(true)
val nameFilter = if (additionalPropertyNameFilter != null)
descriptorNameFilter or additionalPropertyNameFilter
@@ -434,11 +442,6 @@ abstract class CompletionSession(
}
}
protected fun CallTypeAndReceiver<*, *>.shouldCompleteCallableExtensions(): Boolean {
return callType.descriptorKindFilter.kindMask.and(DescriptorKindFilter.CALLABLES_MASK) != 0
&& this !is CallTypeAndReceiver.IMPORT_DIRECTIVE
}
protected fun withCollectRequiredContextVariableTypes(action: (LookupElementFactory) -> Unit): Collection<FuzzyType> {
val provider = CollectRequiredTypesContextVariablesProvider()
val lookupElementFactory = createLookupElementFactory(provider)
@@ -47,8 +47,6 @@ class SmartCompletionSession(
// we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes
var filter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude
filter = filter exclude TopLevelExtensionsExclude // handled via indices
if (smartCompletion?.expectedInfos?.filterFunctionExpected()?.isNotEmpty() ?: false) {
// if function type is expected we need classes to obtain their constructors
filter = filter.withKinds(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)