@@ -7,6 +7,8 @@ import com.intellij.openapi.editor.colors.TextAttributesKey
7
7
import com.intellij.openapi.editor.markup.TextAttributes
8
8
import com.intellij.psi.PsiElement
9
9
import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors
10
+ import org.jetbrains.kotlin.lexer.KtKeywordToken
11
+ import org.jetbrains.kotlin.lexer.KtSingleValueToken
10
12
import org.jetbrains.kotlin.psi.KtOperationReferenceExpression
11
13
12
14
internal val KOTLIN_INFIX_FUN : TextAttributesKey =
@@ -15,28 +17,43 @@ internal val KOTLIN_INFIX_FUN: TextAttributesKey =
15
17
KotlinHighlightingColors .FUNCTION_CALL
16
18
)
17
19
18
- internal val KOTLIN_OPERATOR_FUN : TextAttributesKey =
20
+ internal val KOTLIN_KEYWORD_OPERATOR_FUN : TextAttributesKey =
19
21
TextAttributesKey .createTextAttributesKey(
20
- " CUSTOM_KOTLIN_OPERATOR_FUN " ,
22
+ " CUSTOM_KOTLIN_KEYWORD_OPERATOR_FUN " ,
21
23
KotlinHighlightingColors .KEYWORD
22
24
)
23
25
26
+ internal val KOTLIN_MATH_OPERATOR_FUN : TextAttributesKey =
27
+ TextAttributesKey .createTextAttributesKey(
28
+ " CUSTOM_KOTLIN_MATH_OPERATOR_FUN" ,
29
+ KotlinHighlightingColors .OPERATOR_SIGN
30
+ )
31
+
24
32
/* *
25
33
* @author Edoardo Luppi
26
34
*/
27
35
private class KotlinAnnotator : Annotator {
28
36
private val globalScheme = EditorColorsManager .getInstance().globalScheme
29
37
private val infixFunAttributes = globalScheme.getAttributes(KOTLIN_INFIX_FUN )
30
- private val operatorFunAttributes = globalScheme.getAttributes(KOTLIN_OPERATOR_FUN )
38
+ private val keywordOperatorFunAttributes = globalScheme.getAttributes(KOTLIN_KEYWORD_OPERATOR_FUN )
39
+ private val mathOperatorFunAttributes = globalScheme.getAttributes(KOTLIN_MATH_OPERATOR_FUN )
31
40
32
41
override fun annotate (element : PsiElement , annotationHolder : AnnotationHolder ) {
33
- if (element !is KtOperationReferenceExpression ) return
34
-
35
- val textAttributes =
36
- if (element.isConventionOperator()) operatorFunAttributes
37
- else infixFunAttributes
42
+ if (element is KtOperationReferenceExpression ) {
43
+ getTextAttributes(element)?.let {
44
+ annotationHolder.setTextAttributes(element, it)
45
+ }
46
+ }
47
+ }
38
48
39
- annotationHolder.setTextAttributes(element, textAttributes)
49
+ private fun getTextAttributes (expr : KtOperationReferenceExpression ): TextAttributes ? {
50
+ val operationSignTokenType = expr.operationSignTokenType
51
+ return when {
52
+ ! expr.isConventionOperator() -> infixFunAttributes
53
+ operationSignTokenType is KtKeywordToken -> keywordOperatorFunAttributes
54
+ operationSignTokenType is KtSingleValueToken -> mathOperatorFunAttributes
55
+ else -> null
56
+ }
40
57
}
41
58
42
59
private fun AnnotationHolder.setTextAttributes (
0 commit comments