Minor code refactorings in TipsManager
This commit is contained in:
committed by
valentin
parent
726f49b3f8
commit
f43a9968ba
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.codeInsight
|
package org.jetbrains.jet.plugin.codeInsight
|
||||||
|
|
||||||
import com.google.common.base.Predicate
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*
|
import org.jetbrains.jet.lang.descriptors.*
|
||||||
import org.jetbrains.jet.lang.psi.*
|
import org.jetbrains.jet.lang.psi.*
|
||||||
import org.jetbrains.jet.lang.psi.psiUtil.*
|
import org.jetbrains.jet.lang.psi.psiUtil.*
|
||||||
@@ -37,11 +36,11 @@ public object TipsManager{
|
|||||||
public fun getReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext): Collection<DeclarationDescriptor> {
|
public fun getReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext): Collection<DeclarationDescriptor> {
|
||||||
val receiverExpression = expression.getReceiverExpression()
|
val receiverExpression = expression.getReceiverExpression()
|
||||||
val parent = expression.getParent()
|
val parent = expression.getParent()
|
||||||
|
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||||
|
|
||||||
val inPositionForCompletionWithReceiver = parent is JetCallExpression || parent is JetQualifiedExpression
|
val inPositionForCompletionWithReceiver = parent is JetCallExpression || parent is JetQualifiedExpression
|
||||||
if (receiverExpression != null && inPositionForCompletionWithReceiver) {
|
if (receiverExpression != null && inPositionForCompletionWithReceiver) {
|
||||||
// Process as call expression
|
// Process as call expression
|
||||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
|
||||||
|
|
||||||
val descriptors = HashSet<DeclarationDescriptor>()
|
val descriptors = HashSet<DeclarationDescriptor>()
|
||||||
|
|
||||||
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
||||||
@@ -53,29 +52,20 @@ public object TipsManager{
|
|||||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||||
if (expressionType != null && !expressionType.isError()) {
|
if (expressionType != null && !expressionType.isError()) {
|
||||||
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
|
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
|
||||||
|
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||||
|
|
||||||
val info = context.getDataFlowInfo(expression)
|
for (variant in AutoCastUtils.getAutoCastVariants(receiverValue, context, dataFlowInfo)) {
|
||||||
|
|
||||||
val variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariants(receiverValue, context, info)
|
|
||||||
|
|
||||||
for (variant in variantsForExplicitReceiver) {
|
|
||||||
descriptors.addAll(variant.getMemberScope().getAllDescriptors())
|
descriptors.addAll(variant.getMemberScope().getAllDescriptors())
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptors.addAll(externalCallableExtensions(resolutionScope, receiverValue, context, info))
|
JetScopeUtils.getAllExtensions(resolutionScope).filterTo(descriptors) {
|
||||||
|
ExpressionTypingUtils.checkIsExtensionCallable(receiverValue, it, context, dataFlowInfo)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return descriptors
|
return descriptors
|
||||||
}
|
}
|
||||||
else {
|
else if (parent is JetImportDirective || parent is JetPackageDirective) {
|
||||||
return getVariantsNoReceiver(expression, context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun getVariantsNoReceiver(expression: JetExpression, context: BindingContext): Collection<DeclarationDescriptor> {
|
|
||||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
|
||||||
val parent = expression.getParent()
|
|
||||||
if (parent is JetImportDirective || parent is JetPackageDirective) {
|
|
||||||
return excludeNonPackageDescriptors(resolutionScope.getAllDescriptors())
|
return excludeNonPackageDescriptors(resolutionScope.getAllDescriptors())
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -89,7 +79,9 @@ public object TipsManager{
|
|||||||
|
|
||||||
descriptorsSet.addAll(resolutionScope.getAllDescriptors())
|
descriptorsSet.addAll(resolutionScope.getAllDescriptors())
|
||||||
|
|
||||||
return excludeNotCallableExtensions(descriptorsSet, resolutionScope, context, context.getDataFlowInfo(expression))
|
descriptorsSet.excludeNotCallableExtensions(resolutionScope, context, context.getDataFlowInfo(expression))
|
||||||
|
|
||||||
|
return descriptorsSet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,16 +91,19 @@ public object TipsManager{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>, scope: JetScope, context: BindingContext, dataFlowInfo: DataFlowInfo): Collection<DeclarationDescriptor> {
|
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>, scope: JetScope, context: BindingContext, dataFlowInfo: DataFlowInfo): Collection<DeclarationDescriptor> {
|
||||||
val implicitReceivers = scope.getImplicitReceiversHierarchy()
|
val set = HashSet(descriptors)
|
||||||
|
set.excludeNotCallableExtensions(scope, context, dataFlowInfo)
|
||||||
|
return set
|
||||||
|
}
|
||||||
|
|
||||||
val descriptorsSet = HashSet(descriptors)
|
private fun MutableSet<DeclarationDescriptor>.excludeNotCallableExtensions(scope: JetScope, context: BindingContext, dataFlowInfo: DataFlowInfo) {
|
||||||
descriptorsSet.removeAll(JetScopeUtils.getAllExtensions(scope).filter { callable ->
|
val implicitReceivers = scope.getImplicitReceiversHierarchy()
|
||||||
|
removeAll(JetScopeUtils.getAllExtensions(scope).filter { callable ->
|
||||||
if (callable.getReceiverParameter() == null)
|
if (callable.getReceiverParameter() == null)
|
||||||
false
|
false
|
||||||
else
|
else
|
||||||
implicitReceivers.none { ExpressionTypingUtils.checkIsExtensionCallable(it.getValue(), callable, context, dataFlowInfo) }
|
implicitReceivers.none { ExpressionTypingUtils.checkIsExtensionCallable(it.getValue(), callable, context, dataFlowInfo) }
|
||||||
})
|
})
|
||||||
return descriptorsSet
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun excludeNonPackageDescriptors(descriptors: Collection<DeclarationDescriptor>): Collection<DeclarationDescriptor> {
|
private fun excludeNonPackageDescriptors(descriptors: Collection<DeclarationDescriptor>): Collection<DeclarationDescriptor> {
|
||||||
@@ -124,10 +119,4 @@ public object TipsManager{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun externalCallableExtensions(externalScope: JetScope, receiverValue: ReceiverValue, context: BindingContext, dataFlowInfo: DataFlowInfo): Collection<CallableDescriptor> {
|
|
||||||
return JetScopeUtils.getAllExtensions(externalScope).filter {
|
|
||||||
ExpressionTypingUtils.checkIsExtensionCallable(receiverValue, it, context, dataFlowInfo)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user