Code refactoring
This commit is contained in:
+45
-32
@@ -261,31 +261,40 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
resultSet: CompletionResultSet)
|
resultSet: CompletionResultSet)
|
||||||
: CompletionSessionBase(configuration, parameters, resultSet) {
|
: CompletionSessionBase(configuration, parameters, resultSet) {
|
||||||
|
|
||||||
public enum class CompletionKind(val classKindFilter: ((ClassKind) -> Boolean)?) {
|
private enum class CompletionKind(
|
||||||
KEYWORDS_ONLY(classKindFilter = null),
|
val descriptorKindFilter: DescriptorKindFilter?,
|
||||||
NAMED_ARGUMENTS_ONLY(classKindFilter = null),
|
val classKindFilter: ((ClassKind) -> Boolean)?
|
||||||
ALL(classKindFilter = { it != ClassKind.ENUM_ENTRY }),
|
) {
|
||||||
TYPES(classKindFilter = { it != ClassKind.ENUM_ENTRY }),
|
ALL(
|
||||||
ANNOTATION_TYPES(classKindFilter = { it == ClassKind.ANNOTATION_CLASS }),
|
descriptorKindFilter = DescriptorKindFilter(DescriptorKindFilter.ALL_KINDS_MASK),
|
||||||
ANNOTATION_TYPES_OR_PARAMETER_NAME(classKindFilter = { it == ClassKind.ANNOTATION_CLASS }),
|
classKindFilter = { it != ClassKind.ENUM_ENTRY }
|
||||||
PARAMETER_NAME(classKindFilter = null)
|
),
|
||||||
|
|
||||||
|
TYPES(
|
||||||
|
descriptorKindFilter = DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude DescriptorKindExclude.EnumEntry,
|
||||||
|
classKindFilter = { it != ClassKind.ENUM_ENTRY }
|
||||||
|
),
|
||||||
|
|
||||||
|
ANNOTATION_TYPES(
|
||||||
|
descriptorKindFilter = ANNOTATION_TYPES_FILTER,
|
||||||
|
classKindFilter = { it == ClassKind.ANNOTATION_CLASS }
|
||||||
|
),
|
||||||
|
|
||||||
|
ANNOTATION_TYPES_OR_PARAMETER_NAME(
|
||||||
|
descriptorKindFilter = ANNOTATION_TYPES_FILTER,
|
||||||
|
classKindFilter = { it == ClassKind.ANNOTATION_CLASS }
|
||||||
|
),
|
||||||
|
|
||||||
|
KEYWORDS_ONLY(descriptorKindFilter = null, classKindFilter = null),
|
||||||
|
|
||||||
|
NAMED_ARGUMENTS_ONLY(descriptorKindFilter = null, classKindFilter = null),
|
||||||
|
|
||||||
|
PARAMETER_NAME(descriptorKindFilter = null, classKindFilter = null)
|
||||||
}
|
}
|
||||||
|
|
||||||
public val completionKind: CompletionKind = calcCompletionKind()
|
private val completionKind = calcCompletionKind()
|
||||||
|
|
||||||
protected override val descriptorKindFilter = when (completionKind) {
|
override val descriptorKindFilter = completionKind.descriptorKindFilter
|
||||||
CompletionKind.TYPES ->
|
|
||||||
DescriptorKindFilter(DescriptorKindFilter.CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude DescriptorKindExclude.EnumEntry
|
|
||||||
|
|
||||||
CompletionKind.ANNOTATION_TYPES, CompletionKind.ANNOTATION_TYPES_OR_PARAMETER_NAME ->
|
|
||||||
DescriptorKindFilter(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude
|
|
||||||
|
|
||||||
CompletionKind.ALL ->
|
|
||||||
DescriptorKindFilter(DescriptorKindFilter.ALL_KINDS_MASK)
|
|
||||||
|
|
||||||
CompletionKind.NAMED_ARGUMENTS_ONLY, CompletionKind.KEYWORDS_ONLY, CompletionKind.PARAMETER_NAME ->
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
private val parameterNameAndTypeCompletion = if (shouldCompleteParameterNameAndType())
|
private val parameterNameAndTypeCompletion = if (shouldCompleteParameterNameAndType())
|
||||||
ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
|
ParameterNameAndTypeCompletion(collector, lookupElementFactory, prefixMatcher, resolutionFacade)
|
||||||
@@ -428,15 +437,6 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
NamedArgumentCompletion.complete(position, collector, bindingContext)
|
NamedArgumentCompletion.complete(position, collector, bindingContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
private object NonAnnotationClassifierExclude : DescriptorKindExclude {
|
|
||||||
override fun matches(descriptor: DeclarationDescriptor): Boolean {
|
|
||||||
return if (descriptor is ClassDescriptor)
|
|
||||||
descriptor.getKind() != ClassKind.ANNOTATION_CLASS
|
|
||||||
else
|
|
||||||
descriptor !is ClassifierDescriptor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addNonImported(completionKind: CompletionKind) {
|
private fun addNonImported(completionKind: CompletionKind) {
|
||||||
if (completionKind == CompletionKind.ALL) {
|
if (completionKind == CompletionKind.ALL) {
|
||||||
collector.addDescriptorElements(getTopLevelExtensions(), suppressAutoInsertion = true)
|
collector.addDescriptorElements(getTopLevelExtensions(), suppressAutoInsertion = true)
|
||||||
@@ -454,13 +454,26 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
|||||||
|
|
||||||
parameterNameAndTypeCompletion?.addFromAllClasses(parameters, indicesHelper)
|
parameterNameAndTypeCompletion?.addFromAllClasses(parameters, indicesHelper)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private companion object {
|
||||||
|
object NonAnnotationClassifierExclude : DescriptorKindExclude {
|
||||||
|
override fun matches(descriptor: DeclarationDescriptor): Boolean {
|
||||||
|
return if (descriptor is ClassDescriptor)
|
||||||
|
descriptor.getKind() != ClassKind.ANNOTATION_CLASS
|
||||||
|
else
|
||||||
|
descriptor !is ClassifierDescriptor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val ANNOTATION_TYPES_FILTER = DescriptorKindFilter(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK or DescriptorKindFilter.PACKAGES_MASK) exclude NonAnnotationClassifierExclude
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class SmartCompletionSession(configuration: CompletionSessionConfiguration, parameters: CompletionParameters, resultSet: CompletionResultSet)
|
class SmartCompletionSession(configuration: CompletionSessionConfiguration, parameters: CompletionParameters, resultSet: CompletionResultSet)
|
||||||
: CompletionSessionBase(configuration, parameters, resultSet) {
|
: CompletionSessionBase(configuration, parameters, resultSet) {
|
||||||
|
|
||||||
// we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes
|
// we do not include SAM-constructors because they are handled separately and adding them requires iterating of java classes
|
||||||
override val descriptorKindFilter: DescriptorKindFilter? = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude
|
override val descriptorKindFilter = DescriptorKindFilter.VALUES exclude SamConstructorDescriptorKindExclude
|
||||||
|
|
||||||
override fun doComplete() {
|
override fun doComplete() {
|
||||||
if (NamedArgumentCompletion.isOnlyNamedArgumentExpected(position)) {
|
if (NamedArgumentCompletion.isOnlyNamedArgumentExpected(position)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user