Minor code refactoring
This commit is contained in:
committed by
valentin
parent
f4924299dd
commit
7d6542854b
@@ -38,40 +38,43 @@ public object TipsManager{
|
||||
val parent = expression.getParent()
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
|
||||
val inPositionForCompletionWithReceiver = parent is JetCallExpression
|
||||
|| parent is JetQualifiedExpression
|
||||
|| parent is JetBinaryExpression
|
||||
if (receiverExpression != null && inPositionForCompletionWithReceiver) {
|
||||
val isInfixCall = parent is JetBinaryExpression
|
||||
fun filterIfInfix(descriptor: DeclarationDescriptor)
|
||||
= if (isInfixCall) descriptor is SimpleFunctionDescriptor && descriptor.getValueParameters().size == 1 else true
|
||||
if (receiverExpression != null) {
|
||||
val inPositionForCompletionWithReceiver = parent is JetCallExpression
|
||||
|| parent is JetQualifiedExpression
|
||||
|| parent is JetBinaryExpression
|
||||
if (inPositionForCompletionWithReceiver) {
|
||||
val isInfixCall = parent is JetBinaryExpression
|
||||
fun filterIfInfix(descriptor: DeclarationDescriptor)
|
||||
= if (isInfixCall) descriptor is SimpleFunctionDescriptor && descriptor.getValueParameters().size == 1 else true
|
||||
|
||||
// Process as call expression
|
||||
val descriptors = HashSet<DeclarationDescriptor>()
|
||||
// Process as call expression
|
||||
val descriptors = HashSet<DeclarationDescriptor>()
|
||||
|
||||
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
||||
if (qualifier != null) {
|
||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||
qualifier.scope.getAllDescriptors().filterTo(descriptors, ::filterIfInfix)
|
||||
}
|
||||
|
||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||
if (expressionType != null && !expressionType.isError()) {
|
||||
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
|
||||
for (variant in AutoCastUtils.getAutoCastVariants(receiverValue, context, dataFlowInfo)) {
|
||||
variant.getMemberScope().getAllDescriptors().filterTo(descriptors) { filterIfInfix(it) && !it.isExtension }
|
||||
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
|
||||
if (qualifier != null) {
|
||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||
qualifier.scope.getAllDescriptors().filterTo(descriptors, ::filterIfInfix)
|
||||
}
|
||||
|
||||
JetScopeUtils.getAllExtensions(resolutionScope).filterTo(descriptors) {
|
||||
ExpressionTypingUtils.checkIsExtensionCallable(receiverValue, it, isInfixCall, context, dataFlowInfo)
|
||||
}
|
||||
}
|
||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||
if (expressionType != null && !expressionType.isError()) {
|
||||
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
|
||||
val dataFlowInfo = context.getDataFlowInfo(expression)
|
||||
|
||||
return descriptors
|
||||
for (variant in AutoCastUtils.getAutoCastVariants(receiverValue, context, dataFlowInfo)) {
|
||||
variant.getMemberScope().getAllDescriptors().filterTo(descriptors) { filterIfInfix(it) && !it.isExtension }
|
||||
}
|
||||
|
||||
JetScopeUtils.getAllExtensions(resolutionScope).filterTo(descriptors) {
|
||||
ExpressionTypingUtils.checkIsExtensionCallable(receiverValue, it, isInfixCall, context, dataFlowInfo)
|
||||
}
|
||||
}
|
||||
|
||||
return descriptors
|
||||
}
|
||||
}
|
||||
else if (parent is JetImportDirective || parent is JetPackageDirective) {
|
||||
|
||||
if (parent is JetImportDirective || parent is JetPackageDirective) {
|
||||
return excludeNonPackageDescriptors(resolutionScope.getAllDescriptors())
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user