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