From e72a06bdf40089f5871ab45a307cc40f9faf6ea9 Mon Sep 17 00:00:00 2001 From: Guillaume Darmont Date: Thu, 25 Jun 2020 12:23:29 +0200 Subject: [PATCH] Add specific highlight for Enum class #KT-39844 Fixed --- .../idea/highlighter/TypeKindHighlightingVisitor.kt | 1 + .../kotlin/idea/fir/highlighter/HighlightingUtils.kt | 1 + .../idea/highlighter/KotlinHighlightingColors.java | 1 + idea/resources-en/messages/KotlinBundle.properties | 1 + .../kotlin/idea/highlighter/KotlinColorSettingsPage.kt | 3 ++- idea/testData/highlighter/Annotations.kt | 4 ++-- idea/testData/highlighter/Enums.kt | 10 +++++----- 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt index 7b4624367c3..57497d914be 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/TypeKindHighlightingVisitor.kt @@ -114,6 +114,7 @@ internal class TypeKindHighlightingVisitor(holder: AnnotationHolder, bindingCont ClassKind.INTERFACE -> TRAIT ClassKind.ANNOTATION_CLASS -> ANNOTATION ClassKind.OBJECT -> OBJECT + ClassKind.ENUM_CLASS -> ENUM ClassKind.ENUM_ENTRY -> ENUM_ENTRY else -> if (descriptor.modality === Modality.ABSTRACT) ABSTRACT_CLASS else CLASS } diff --git a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/highlighter/HighlightingUtils.kt b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/highlighter/HighlightingUtils.kt index 8c8d7fa45c7..d13e9d28dd7 100644 --- a/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/highlighter/HighlightingUtils.kt +++ b/idea/idea-fir/src/org/jetbrains/kotlin/idea/fir/highlighter/HighlightingUtils.kt @@ -59,6 +59,7 @@ internal fun textAttributesKeyForTypeDeclaration(declaration: PsiElement): TextA fun textAttributesForClass(klass: KtClass): TextAttributesKey = when { klass.isInterface() -> Colors.TRAIT klass.isAnnotation() -> Colors.ANNOTATION + klass.isEnum() -> Colors.ENUM klass is KtEnumEntry -> Colors.ENUM_ENTRY klass.isAbstract() -> Colors.ABSTRACT_CLASS else -> Colors.CLASS diff --git a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java index 21c1a435028..df848af568a 100644 --- a/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java +++ b/idea/idea-frontend-independent/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java @@ -49,6 +49,7 @@ public class KotlinHighlightingColors { public static final TextAttributesKey TRAIT = createTextAttributesKey("KOTLIN_TRAIT", DefaultLanguageHighlighterColors.INTERFACE_NAME); public static final TextAttributesKey ANNOTATION = createTextAttributesKey("KOTLIN_ANNOTATION", JavaHighlightingColors.ANNOTATION_NAME_ATTRIBUTES); public static final TextAttributesKey OBJECT = createTextAttributesKey("KOTLIN_OBJECT", CLASS); + public static final TextAttributesKey ENUM = createTextAttributesKey("KOTLIN_ENUM", JavaHighlightingColors.ENUM_NAME_ATTRIBUTES); public static final TextAttributesKey ENUM_ENTRY = createTextAttributesKey("KOTLIN_ENUM_ENTRY", DefaultLanguageHighlighterColors.STATIC_FIELD); public static final TextAttributesKey TYPE_ALIAS = createTextAttributesKey("KOTLIN_TYPE_ALIAS", CLASS); diff --git a/idea/resources-en/messages/KotlinBundle.properties b/idea/resources-en/messages/KotlinBundle.properties index 816409a6119..001a1f51f14 100644 --- a/idea/resources-en/messages/KotlinBundle.properties +++ b/idea/resources-en/messages/KotlinBundle.properties @@ -593,6 +593,7 @@ highlighter.descriptor.text.label=Label highlighter.descriptor.text.local.variable=Properties and Variables//Local variable or value highlighter.descriptor.text.named.argument=Named argument highlighter.descriptor.text.object=Classes and Interfaces//Object +highlighter.descriptor.text.enum=Classes and Interfaces//Enum highlighter.descriptor.text.package.fun.call=Functions//Package-level function call highlighter.descriptor.text.package.property.custom.property.declaration=Properties and Variables//Package-level property with custom property declarations highlighter.descriptor.text.package.property=Properties and Variables//Package-level property diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt index a9acef96966..fd63a8e046b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt @@ -90,7 +90,7 @@ var globalCounte object Obj -enum class E { A, B } +enum class E { A, B } interface FunctionLike { operator fun invoke() = 1 @@ -163,6 +163,7 @@ var globalCounte KotlinBundle.message("highlighter.descriptor.text.annotation") to KotlinHighlightingColors.ANNOTATION, KotlinBundle.message("highlighter.descriptor.text.annotation.attribute.name") to KotlinHighlightingColors.ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES, KotlinBundle.message("highlighter.descriptor.text.object") to KotlinHighlightingColors.OBJECT, + KotlinBundle.message("highlighter.descriptor.text.enum") to KotlinHighlightingColors.ENUM, KotlinBundle.message("highlighter.descriptor.text.enumEntry") to KotlinHighlightingColors.ENUM_ENTRY, KotlinBundle.message("highlighter.descriptor.text.typeAlias") to KotlinHighlightingColors.TYPE_ALIAS, KotlinBundle.message("highlighter.descriptor.text.var") to KotlinHighlightingColors.MUTABLE_VARIABLE, diff --git a/idea/testData/highlighter/Annotations.kt b/idea/testData/highlighter/Annotations.kt index a088ba160aa..df98831958b 100644 --- a/idea/testData/highlighter/Annotations.kt +++ b/idea/testData/highlighter/Annotations.kt @@ -1,8 +1,8 @@ // IGNORE_FIR // EXPECTED_DUPLICATED_HIGHLIGHTING -@Target(AnnotationTarget.CLASS, AnnotationTarget.EXPRESSION) -@Retention(AnnotationRetention.SOURCE) +@Target(AnnotationTarget.CLASS, AnnotationTarget.EXPRESSION) +@Retention(AnnotationRetention.SOURCE) annotation class Ann @Ann class A diff --git a/idea/testData/highlighter/Enums.kt b/idea/testData/highlighter/Enums.kt index 6196d43fcb9..cecf5986a6e 100644 --- a/idea/testData/highlighter/Enums.kt +++ b/idea/testData/highlighter/Enums.kt @@ -1,16 +1,16 @@ package testing -enum class Test { +enum class Test { FIRST, SECOND } -enum class Type(val id: Int) { +enum class Type(val id: Int) { FIRST(1), SECOND(2) } -fun testing(t1: Test, t2: Test): Test { - if (t1 != t2) return Test.FIRST - return testing(Test.FIRST, Test.SECOND) +fun testing(t1: Test, t2: Test): Test { + if (t1 != t2) return Test.FIRST + return testing(Test.FIRST, Test.SECOND) } \ No newline at end of file