FunctionsHighlightingVisitor: cleanup after J2K, remove overlaid highlighting of function calls
This commit is contained in:
+22
-25
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors.*
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
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.model.VariableAsFunctionResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||||
|
|
||||||
class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingContext: BindingContext) :
|
class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingContext: BindingContext) :
|
||||||
AfterAnalysisHighlightingVisitor(holder, bindingContext) {
|
AfterAnalysisHighlightingVisitor(holder, bindingContext) {
|
||||||
|
|
||||||
override fun visitNamedFunction(function: KtNamedFunction) {
|
override fun visitNamedFunction(function: KtNamedFunction) {
|
||||||
val nameIdentifier = function.nameIdentifier
|
function.nameIdentifier?.let { holder.highlightName(it, FUNCTION_DECLARATION) }
|
||||||
if (nameIdentifier != null) {
|
|
||||||
NameHighlighter.highlightName(holder, nameIdentifier, KotlinHighlightingColors.FUNCTION_DECLARATION)
|
|
||||||
}
|
|
||||||
|
|
||||||
super.visitNamedFunction(function)
|
super.visitNamedFunction(function)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitSuperTypeCallEntry(call: KtSuperTypeCallEntry) {
|
override fun visitSuperTypeCallEntry(call: KtSuperTypeCallEntry) {
|
||||||
val calleeExpression = call.calleeExpression
|
val calleeExpression = call.calleeExpression
|
||||||
val typeRef = calleeExpression.typeReference
|
val typeElement = calleeExpression.typeReference?.typeElement
|
||||||
if (typeRef != null) {
|
if (typeElement is KtUserType) {
|
||||||
val typeElement = typeRef.typeElement
|
typeElement.referenceExpression?.let { holder.highlightName(it, CONSTRUCTOR_CALL) }
|
||||||
if (typeElement is KtUserType) {
|
|
||||||
val nameExpression = typeElement.referenceExpression
|
|
||||||
if (nameExpression != null) {
|
|
||||||
NameHighlighter.highlightName(holder, nameExpression, KotlinHighlightingColors.CONSTRUCTOR_CALL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
super.visitSuperTypeCallEntry(call)
|
super.visitSuperTypeCallEntry(call)
|
||||||
}
|
}
|
||||||
@@ -62,28 +54,33 @@ class FunctionsHighlightingVisitor(holder: AnnotationHolder, bindingContext: Bin
|
|||||||
val calleeDescriptor = resolvedCall.resultingDescriptor
|
val calleeDescriptor = resolvedCall.resultingDescriptor
|
||||||
|
|
||||||
if (calleeDescriptor.isDynamic()) {
|
if (calleeDescriptor.isDynamic()) {
|
||||||
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.DYNAMIC_FUNCTION_CALL)
|
holder.highlightName(callee, DYNAMIC_FUNCTION_CALL)
|
||||||
}
|
}
|
||||||
else if (resolvedCall is VariableAsFunctionResolvedCall) {
|
else if (resolvedCall is VariableAsFunctionResolvedCall) {
|
||||||
val container = calleeDescriptor.containingDeclaration
|
val container = calleeDescriptor.containingDeclaration
|
||||||
val containedInFunctionClassOrSubclass = container is ClassDescriptor && container.defaultType.isFunctionTypeOrSubtype
|
val containedInFunctionClassOrSubclass = container is ClassDescriptor && container.defaultType.isFunctionTypeOrSubtype
|
||||||
NameHighlighter.highlightName(holder, callee, if (containedInFunctionClassOrSubclass)
|
holder.highlightName(callee, if (containedInFunctionClassOrSubclass)
|
||||||
KotlinHighlightingColors.VARIABLE_AS_FUNCTION_CALL
|
VARIABLE_AS_FUNCTION_CALL
|
||||||
else
|
else
|
||||||
KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL)
|
VARIABLE_AS_FUNCTION_LIKE_CALL)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (calleeDescriptor is ConstructorDescriptor) {
|
if (calleeDescriptor is ConstructorDescriptor) {
|
||||||
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.CONSTRUCTOR_CALL)
|
holder.highlightName(callee, CONSTRUCTOR_CALL)
|
||||||
}
|
}
|
||||||
else if (calleeDescriptor is FunctionDescriptor) {
|
else if (calleeDescriptor is FunctionDescriptor) {
|
||||||
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.FUNCTION_CALL)
|
val color = when {
|
||||||
if (DescriptorUtils.isTopLevelDeclaration(calleeDescriptor)) {
|
calleeDescriptor.extensionReceiverParameter != null ->
|
||||||
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.PACKAGE_FUNCTION_CALL)
|
EXTENSION_FUNCTION_CALL
|
||||||
}
|
|
||||||
if (calleeDescriptor.extensionReceiverParameter != null) {
|
DescriptorUtils.isTopLevelDeclaration(calleeDescriptor) ->
|
||||||
NameHighlighter.highlightName(holder, callee, KotlinHighlightingColors.EXTENSION_FUNCTION_CALL)
|
PACKAGE_FUNCTION_CALL
|
||||||
|
|
||||||
|
else ->
|
||||||
|
FUNCTION_CALL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
holder.highlightName(callee, color)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,4 +39,8 @@ object NameHighlighter {
|
|||||||
holder.createInfoAnnotation(textRange, null).textAttributes = attributesKey
|
holder.createInfoAnnotation(textRange, null).textAttributes = attributesKey
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun AnnotationHolder.highlightName(element: PsiElement, attributesKey: TextAttributesKey) {
|
||||||
|
NameHighlighter.highlightName(this, element, attributesKey)
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -7,5 +7,5 @@ package testing
|
|||||||
|
|
||||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">testing</info>(<info textAttributesKey="KOTLIN_PARAMETER">t1</info>: <info textAttributesKey="KOTLIN_CLASS">Test</info>, <info textAttributesKey="KOTLIN_PARAMETER">t2</info>: <info textAttributesKey="KOTLIN_CLASS">Test</info>): <info textAttributesKey="KOTLIN_CLASS">Test</info> {
|
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">testing</info>(<info textAttributesKey="KOTLIN_PARAMETER">t1</info>: <info textAttributesKey="KOTLIN_CLASS">Test</info>, <info textAttributesKey="KOTLIN_PARAMETER">t2</info>: <info textAttributesKey="KOTLIN_CLASS">Test</info>): <info textAttributesKey="KOTLIN_CLASS">Test</info> {
|
||||||
if (<info textAttributesKey="KOTLIN_PARAMETER">t1</info> != <info textAttributesKey="KOTLIN_PARAMETER">t2</info>) return <info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_ENUM_ENTRY">FIRST</info>
|
if (<info textAttributesKey="KOTLIN_PARAMETER">t1</info> != <info textAttributesKey="KOTLIN_PARAMETER">t2</info>) return <info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_ENUM_ENTRY">FIRST</info>
|
||||||
return <info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL"><info textAttributesKey="KOTLIN_FUNCTION_CALL">testing</info></info>(<info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_ENUM_ENTRY">FIRST</info>, <info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_ENUM_ENTRY">SECOND</info>)
|
return <info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL">testing</info>(<info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_ENUM_ENTRY">FIRST</info>, <info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_ENUM_ENTRY">SECOND</info>)
|
||||||
}
|
}
|
||||||
+2
-2
@@ -10,8 +10,8 @@ fun <info textAttributesKey="KOTLIN_CLASS">Int</info>.<info textAttributesKey="K
|
|||||||
|
|
||||||
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">open</info> class <info textAttributesKey="KOTLIN_CLASS">Container</info> {
|
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">open</info> class <info textAttributesKey="KOTLIN_CLASS">Container</info> {
|
||||||
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">open</info> fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">member</info>() {
|
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">open</info> fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">member</info>() {
|
||||||
<info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL"><info textAttributesKey="KOTLIN_FUNCTION_CALL">global</info></info>()
|
<info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL">global</info>()
|
||||||
5.<info textAttributesKey="KOTLIN_EXTENSION_FUNCTION_CALL"><info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL"><info textAttributesKey="KOTLIN_FUNCTION_CALL">ext</info></info></info>()
|
5.<info textAttributesKey="KOTLIN_EXTENSION_FUNCTION_CALL">ext</info>()
|
||||||
<info textAttributesKey="KOTLIN_FUNCTION_CALL">member</info>()
|
<info textAttributesKey="KOTLIN_FUNCTION_CALL">member</info>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,5 +3,5 @@ fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>(<info textA
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">bar</info>() {
|
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">bar</info>() {
|
||||||
<info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL"><info textAttributesKey="KOTLIN_FUNCTION_CALL">foo</info></info>(1, <info textAttributesKey="KOTLIN_NAMED_ARGUMENT">p2 =</info> "")
|
<info textAttributesKey="KOTLIN_PACKAGE_FUNCTION_CALL">foo</info>(1, <info textAttributesKey="KOTLIN_NAMED_ARGUMENT">p2 =</info> "")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user