From 5512043ed48f61e11d85df9a52690e725e6bdcfc Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 24 May 2016 20:58:43 +0200 Subject: [PATCH] FunctionsHighlightingVisitor: cleanup after J2K, remove overlaid highlighting of function calls --- .../FunctionsHighlightingVisitor.kt | 47 +++++++++---------- .../idea/highlighter/NameHighlighter.kt | 4 ++ idea/testData/highlighter/Enums.kt | 2 +- idea/testData/highlighter/Functions.kt | 4 +- idea/testData/highlighter/NamedArguments.kt | 2 +- 5 files changed, 30 insertions(+), 29 deletions(-) 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 8fa73646730..5bcb18e0fcd 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 @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -28,29 +29,20 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic -class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingContext: BindingContext) : +class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingContext: BindingContext) : AfterAnalysisHighlightingVisitor(holder, bindingContext) { override fun visitNamedFunction(function: KtNamedFunction) { - val nameIdentifier = function.nameIdentifier - if (nameIdentifier != null) { - NameHighlighter.highlightName(holder, nameIdentifier, KotlinHighlightingColors.FUNCTION_DECLARATION) - } + function.nameIdentifier?.let { holder.highlightName(it, FUNCTION_DECLARATION) } super.visitNamedFunction(function) } override fun visitSuperTypeCallEntry(call: KtSuperTypeCallEntry) { val calleeExpression = call.calleeExpression - val typeRef = calleeExpression.typeReference - if (typeRef != null) { - val typeElement = typeRef.typeElement - if (typeElement is KtUserType) { - val nameExpression = typeElement.referenceExpression - if (nameExpression != null) { - NameHighlighter.highlightName(holder, nameExpression, KotlinHighlightingColors.CONSTRUCTOR_CALL) - } - } + val typeElement = calleeExpression.typeReference?.typeElement + if (typeElement is KtUserType) { + typeElement.referenceExpression?.let { holder.highlightName(it, CONSTRUCTOR_CALL) } } super.visitSuperTypeCallEntry(call) } @@ -62,28 +54,33 @@ class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingContext: Bin val calleeDescriptor = resolvedCall.resultingDescriptor if (calleeDescriptor.isDynamic()) { - NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL) + holder.highlightName(callee, DYNAMIC_FUNCTION_CALL) } else if (resolvedCall is VariableAsFunctionResolvedCall) { val container = calleeDescriptor.containingDeclaration val containedInFunctionClassOrSubclass = container is ClassDescriptor && container.defaultType.isFunctionTypeOrSubtype - NameHighlighter.highlightName(holder, callee, if (containedInFunctionClassOrSubclass) - KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL + holder.highlightName(callee, if (containedInFunctionClassOrSubclass) + VARIABLE_AS_FUNCTION_CALL else - KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL) + VARIABLE_AS_FUNCTION_LIKE_CALL) } else { if (calleeDescriptor is ConstructorDescriptor) { - NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.CONSTRUCTOR_CALL) + holder.highlightName(callee, CONSTRUCTOR_CALL) } else if (calleeDescriptor is FunctionDescriptor) { - NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.FUNCTION_CALL) - if (DescriptorUtils.isTopLevelDeclaration(calleeDescriptor)) { - NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.PACKAGE_FUNCTION_CALL) - } - if (calleeDescriptor.extensionReceiverParameter != null) { - NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.EXTENSION_FUNCTION_CALL) + 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/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/NameHighlighter.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/NameHighlighter.kt index 8a652600388..aa5fb388d29 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/NameHighlighter.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/NameHighlighter.kt @@ -39,4 +39,8 @@ object NameHighlighter { holder.createInfoAnnotation(textRange, null).textAttributes = attributesKey } } +} + +fun AnnotationHolder.highlightName(element: PsiElement, attributesKey: TextAttributesKey) { + NameHighlighter.highlightName(this, element, attributesKey) } \ No newline at end of file diff --git a/idea/testData/highlighter/Enums.kt b/idea/testData/highlighter/Enums.kt index 4c194cc8392..8a204c6042c 100644 --- a/idea/testData/highlighter/Enums.kt +++ b/idea/testData/highlighter/Enums.kt @@ -7,5 +7,5 @@ package testing fun testing(t1: Test, t2: Test): Test { if (t1 != t2) return Test.FIRST - return testing(Test.FIRST, Test.SECOND) + return testing(Test.FIRST, Test.SECOND) } \ No newline at end of file diff --git a/idea/testData/highlighter/Functions.kt b/idea/testData/highlighter/Functions.kt index 3a5391fe9fa..97f2ec6743e 100644 --- a/idea/testData/highlighter/Functions.kt +++ b/idea/testData/highlighter/Functions.kt @@ -10,8 +10,8 @@ fun Int.open class Container { open fun member() { - global() - 5.ext() + global() + 5.ext() member() } } diff --git a/idea/testData/highlighter/NamedArguments.kt b/idea/testData/highlighter/NamedArguments.kt index 434311d414d..efd7fa45721 100644 --- a/idea/testData/highlighter/NamedArguments.kt +++ b/idea/testData/highlighter/NamedArguments.kt @@ -3,5 +3,5 @@ fun foo(bar() { - foo(1, p2 = "") + foo(1, p2 = "") }