More clear naming
This commit is contained in:
+4
-4
@@ -56,16 +56,16 @@ public class ReferenceVariantsHelper(
|
||||
public fun getReferenceVariants(
|
||||
expression: JetSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
shouldCastToRuntimeType: Boolean,
|
||||
useRuntimeReceiverType: Boolean,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
return getReferenceVariantsNoVisibilityFilter(expression, kindFilter, shouldCastToRuntimeType, nameFilter).filter(visibilityFilter)
|
||||
return getReferenceVariantsNoVisibilityFilter(expression, kindFilter, useRuntimeReceiverType, nameFilter).filter(visibilityFilter)
|
||||
}
|
||||
|
||||
private fun getReferenceVariantsNoVisibilityFilter(
|
||||
expression: JetSimpleNameExpression,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
shouldCastToRuntimeType: Boolean,
|
||||
useRuntimeReceiverType: Boolean,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
val parent = expression.getParent()
|
||||
@@ -92,7 +92,7 @@ public class ReferenceVariantsHelper(
|
||||
qualifier.scope.getDescriptorsFiltered(kindFilter exclude DescriptorKindExclude.Extensions, nameFilter).filterTo(descriptors) { callType.canCall(it) }
|
||||
}
|
||||
|
||||
val expressionType = if (shouldCastToRuntimeType)
|
||||
val expressionType = if (useRuntimeReceiverType)
|
||||
getQualifierRuntimeType(receiverExpression)
|
||||
else
|
||||
context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||
|
||||
@@ -169,9 +169,9 @@ abstract class CompletionSessionBase(protected val configuration: CompletionSess
|
||||
// set is used only for completion in code fragments
|
||||
private var alreadyAddedDescriptors: Collection<DeclarationDescriptor> by Delegates.notNull()
|
||||
|
||||
protected fun getReferenceVariants(kindFilter: DescriptorKindFilter, shouldCastToRuntimeType: Boolean): Collection<DeclarationDescriptor> {
|
||||
val descriptors = referenceVariantsHelper!!.getReferenceVariants(reference!!.expression, kindFilter, shouldCastToRuntimeType, prefixMatcher.asNameFilter())
|
||||
if (!shouldCastToRuntimeType) {
|
||||
protected fun getReferenceVariants(kindFilter: DescriptorKindFilter, runtimeReceiverType: Boolean): Collection<DeclarationDescriptor> {
|
||||
val descriptors = referenceVariantsHelper!!.getReferenceVariants(reference!!.expression, kindFilter, runtimeReceiverType, prefixMatcher.asNameFilter())
|
||||
if (!runtimeReceiverType) {
|
||||
if (position.getContainingFile() is JetCodeFragment) {
|
||||
alreadyAddedDescriptors = descriptors
|
||||
}
|
||||
@@ -277,7 +277,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
|
||||
if (completionKind != CompletionKind.KEYWORDS_ONLY) {
|
||||
addReferenceVariants(kindFilter, shouldCastToRuntimeType = false)
|
||||
addReferenceVariants(kindFilter, runtimeReceiverType = false)
|
||||
}
|
||||
|
||||
val ampIndex = prefix.indexOf("@")
|
||||
@@ -319,7 +319,7 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
|
||||
if (position.getContainingFile() is JetCodeFragment) {
|
||||
flushToResultSet()
|
||||
addReferenceVariants(kindFilter, shouldCastToRuntimeType = true)
|
||||
addReferenceVariants(kindFilter, runtimeReceiverType = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,11 +355,11 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
}
|
||||
|
||||
private fun addReferenceVariants(kindFilter: DescriptorKindFilter, shouldCastToRuntimeType: Boolean) {
|
||||
private fun addReferenceVariants(kindFilter: DescriptorKindFilter, runtimeReceiverType: Boolean) {
|
||||
collector.addDescriptorElements(
|
||||
getReferenceVariants(kindFilter, shouldCastToRuntimeType),
|
||||
getReferenceVariants(kindFilter, runtimeReceiverType),
|
||||
suppressAutoInsertion = false,
|
||||
shouldCastToRuntimeType = shouldCastToRuntimeType)
|
||||
withReceiverCast = runtimeReceiverType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,14 +382,14 @@ class SmartCompletionSession(configuration: CompletionSessionConfiguration, para
|
||||
if (reference != null) {
|
||||
val filter = result.declarationFilter
|
||||
if (filter != null) {
|
||||
getReferenceVariants(DESCRIPTOR_KIND_MASK, false).forEach { collector.addElements(filter(it)) }
|
||||
getReferenceVariants(DESCRIPTOR_KIND_MASK, runtimeReceiverType = false).forEach { collector.addElements(filter(it)) }
|
||||
flushToResultSet()
|
||||
|
||||
processNonImported { collector.addElements(filter(it)) }
|
||||
flushToResultSet()
|
||||
|
||||
if (position.getContainingFile() is JetCodeFragment) {
|
||||
getReferenceVariants(DESCRIPTOR_KIND_MASK, true).forEach { collector.addElementsWithReceiverCast(filter(it)) }
|
||||
getReferenceVariants(DESCRIPTOR_KIND_MASK, runtimeReceiverType = true).forEach { collector.addElements(filter(it).map { it.withReceiverCast() }) }
|
||||
flushToResultSet()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ fun LookupElement.assignPriority(priority: ItemPriority): LookupElement {
|
||||
|
||||
fun LookupElement.suppressAutoInsertion() = AutoCompletionPolicy.NEVER_AUTOCOMPLETE.applyPolicy(this)
|
||||
|
||||
fun LookupElement.shouldCastReceiver(): LookupElement {
|
||||
fun LookupElement.withReceiverCast(): LookupElement {
|
||||
return object: LookupElementDecorator<LookupElement>(this) {
|
||||
override fun handleInsert(context: InsertionContext) {
|
||||
super.handleInsert(context)
|
||||
@@ -335,4 +335,3 @@ fun breakOrContinueExpressionItems(position: JetElement, breakOrContinue: String
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -52,18 +52,18 @@ class LookupElementsCollector(
|
||||
|
||||
public fun addDescriptorElements(descriptors: Iterable<DeclarationDescriptor>,
|
||||
suppressAutoInsertion: Boolean, // auto-insertion suppression is used for elements that require adding an import
|
||||
shouldCastToRuntimeType: Boolean = false
|
||||
withReceiverCast: Boolean = false
|
||||
) {
|
||||
for (descriptor in descriptors) {
|
||||
addDescriptorElements(descriptor, suppressAutoInsertion, shouldCastToRuntimeType)
|
||||
addDescriptorElements(descriptor, suppressAutoInsertion, withReceiverCast)
|
||||
}
|
||||
}
|
||||
|
||||
public fun addDescriptorElements(descriptor: DeclarationDescriptor, suppressAutoInsertion: Boolean, shouldCastToRuntimeType: Boolean) {
|
||||
public fun addDescriptorElements(descriptor: DeclarationDescriptor, suppressAutoInsertion: Boolean, withReceiverCast: Boolean) {
|
||||
run {
|
||||
var lookupElement = lookupElementFactory.createLookupElement(resolutionFacade, descriptor, true)
|
||||
if (shouldCastToRuntimeType) {
|
||||
lookupElement = lookupElement.shouldCastReceiver()
|
||||
if (withReceiverCast) {
|
||||
lookupElement = lookupElement.withReceiverCast()
|
||||
}
|
||||
if (suppressAutoInsertion) {
|
||||
addElementWithAutoInsertionSuppressed(lookupElement)
|
||||
@@ -140,8 +140,4 @@ class LookupElementsCollector(
|
||||
public fun addElements(elements: Iterable<LookupElement>) {
|
||||
elements.forEach { addElement(it) }
|
||||
}
|
||||
|
||||
public fun addElementsWithReceiverCast(elements: Iterable<LookupElement>) {
|
||||
elements.forEach { addElement(it.shouldCastReceiver()) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user