diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.kt index 6e4871edc98..9950622d4fe 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/FunctionsHighlightingVisitor.kt @@ -17,7 +17,9 @@ package org.jetbrains.kotlin.idea.highlighter import com.intellij.lang.annotation.AnnotationHolder +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype +import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor @@ -26,6 +28,7 @@ import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic @@ -47,44 +50,58 @@ internal class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingCon super.visitSuperTypeCallEntry(call) } + override fun visitBinaryExpression(expression: KtBinaryExpression) { + if (expression.operationReference.getIdentifier() != null) { + val resolvedCall = expression.getResolvedCall(bindingContext) + if (resolvedCall != null) { + highlightCall(expression.operationReference, resolvedCall) + } + } + super.visitBinaryExpression(expression) + } + override fun visitCallExpression(expression: KtCallExpression) { val callee = expression.calleeExpression val resolvedCall = expression.getResolvedCall(bindingContext) if (callee is KtReferenceExpression && resolvedCall != null) { - val calleeDescriptor = resolvedCall.resultingDescriptor - - if (calleeDescriptor.isDynamic()) { - holder.highlightName(callee, DYNAMIC_FUNCTION_CALL) - } - else if (resolvedCall is VariableAsFunctionResolvedCall) { - val container = calleeDescriptor.containingDeclaration - val containedInFunctionClassOrSubclass = container is ClassDescriptor && container.defaultType.isFunctionTypeOrSubtype - holder.highlightName(callee, if (containedInFunctionClassOrSubclass) - VARIABLE_AS_FUNCTION_CALL - else - VARIABLE_AS_FUNCTION_LIKE_CALL) - } - else { - if (calleeDescriptor is ConstructorDescriptor) { - holder.highlightName(callee, CONSTRUCTOR_CALL) - } - else if (calleeDescriptor is FunctionDescriptor) { - val color = when { - calleeDescriptor.extensionReceiverParameter != null -> - EXTENSION_FUNCTION_CALL - - DescriptorUtils.isTopLevelDeclaration(calleeDescriptor) -> - PACKAGE_FUNCTION_CALL - - else -> - FUNCTION_CALL - } - - holder.highlightName(callee, color) - } - } + highlightCall(callee, resolvedCall) } super.visitCallExpression(expression) } + + private fun highlightCall(callee: PsiElement, resolvedCall: ResolvedCall) { + val calleeDescriptor = resolvedCall.resultingDescriptor + + if (calleeDescriptor.isDynamic()) { + holder.highlightName(callee, DYNAMIC_FUNCTION_CALL) + } + else if (resolvedCall is VariableAsFunctionResolvedCall) { + val container = calleeDescriptor.containingDeclaration + val containedInFunctionClassOrSubclass = container is ClassDescriptor && container.defaultType.isFunctionTypeOrSubtype + holder.highlightName(callee, if (containedInFunctionClassOrSubclass) + VARIABLE_AS_FUNCTION_CALL + else + VARIABLE_AS_FUNCTION_LIKE_CALL) + } + else { + if (calleeDescriptor is ConstructorDescriptor) { + holder.highlightName(callee, CONSTRUCTOR_CALL) + } + else if (calleeDescriptor is FunctionDescriptor) { + val color = when { + calleeDescriptor.extensionReceiverParameter != null -> + EXTENSION_FUNCTION_CALL + + DescriptorUtils.isTopLevelDeclaration(calleeDescriptor) -> + PACKAGE_FUNCTION_CALL + + else -> + FUNCTION_CALL + } + + holder.highlightName(callee, color) + } + } + } } diff --git a/idea/testData/highlighter/Functions.kt b/idea/testData/highlighter/Functions.kt index 97f2ec6743e..c42a12dc2bb 100644 --- a/idea/testData/highlighter/Functions.kt +++ b/idea/testData/highlighter/Functions.kt @@ -8,10 +8,15 @@ fun global() { fun Int.ext() { } +infix fun Int.fif(y: Int) { + this * y +} + open class Container { open fun member() { global() 5.ext() member() + 5 fif 6 } }