KT-21974 Editor color scheme option for Kotlin typealias names (#1457)

This commit is contained in:
Toshiaki Kameyama
2018-01-05 01:39:39 +09:00
committed by Dmitry Jemerov
parent 06903f803b
commit 266b40b654
6 changed files with 27 additions and 0 deletions
@@ -74,6 +74,7 @@ options.kotlin.attribute.descriptor.kdoc.tag=Comments//KDoc//KDoc tag
options.kotlin.attribute.descriptor.kdoc.value=Comments//KDoc//Link in KDoc tag
options.kotlin.attribute.descriptor.object=Classes and Interfaces//Object
options.kotlin.attribute.descriptor.enumEntry=Classes and Interfaces//Enum entry
options.kotlin.attribute.descriptor.typeAlias=Classes and Interfaces//Type alias
options.kotlin.attribute.descriptor.var=Properties and Variables//Var (mutable variable, parameter or property)
options.kotlin.attribute.descriptor.local.variable=Properties and Variables//Local variable or value
options.kotlin.attribute.descriptor.captured.variable=Properties and Variables//Variables and values captured in a closure
@@ -59,6 +59,7 @@ public class KotlinHighlightingColors {
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_ENTRY = createTextAttributesKey("KOTLIN_ENUM_ENTRY", DefaultLanguageHighlighterColors.INSTANCE_FIELD);
public static final TextAttributesKey TYPE_ALIAS = createTextAttributesKey("KOTLIN_TYPE_ALIAS", CLASS);
// variable kinds
public static final TextAttributesKey MUTABLE_VARIABLE = createTextAttributesKey("KOTLIN_MUTABLE_VARIABLE");
@@ -57,6 +57,9 @@ internal class TypeKindHighlightingVisitor(holder: AnnotationHolder, bindingCont
else if (referenceTarget is TypeParameterDescriptor) {
highlightName(expression, TYPE_PARAMETER)
}
else if (referenceTarget is TypeAliasDescriptor) {
highlightName(expression, TYPE_ALIAS)
}
}
}
@@ -92,6 +95,16 @@ internal class TypeKindHighlightingVisitor(holder: AnnotationHolder, bindingCont
super.visitClassOrObject(classOrObject)
}
override fun visitTypeAlias(typeAlias: KtTypeAlias) {
val identifier = typeAlias.nameIdentifier
val descriptor = bindingContext.get(BindingContext.TYPE_ALIAS, typeAlias)
if (identifier != null && descriptor != null) {
if (applyHighlighterExtensions(identifier, descriptor)) return
highlightName(identifier, TYPE_ALIAS)
}
super.visitTypeAlias(typeAlias)
}
override fun visitDynamicType(type: KtDynamicType) {
// Do nothing: 'dynamic' is highlighted as a keyword
}
@@ -89,6 +89,9 @@ var <PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAG
<KEYWORD>interface</KEYWORD> <TRAIT>FunctionLike</TRAIT> {
<BUILTIN_ANNOTATION>operator</BUILTIN_ANNOTATION> <KEYWORD>fun</KEYWORD> <FUNCTION_DECLARATION>invoke</FUNCTION_DECLARATION>() = <NUMBER>1</NUMBER>
}
<KEYWORD>typealias</KEYWORD> <TYPE_ALIAS>Predicate</TYPE_ALIAS><<TYPE_PARAMETER>T</TYPE_PARAMETER>> = (<TYPE_PARAMETER>T</TYPE_PARAMETER>) -> <CLASS>Boolean</CLASS>
<KEYWORD>fun</KEYWORD> <FUNCTION_DECLARATION>baz</FUNCTION_DECLARATION>(<PARAMETER>p</PARAMETER>: <TYPE_ALIAS>Predicate</TYPE_ALIAS><<CLASS>Int</CLASS>>) = <PARAMETER><VARIABLE_AS_FUNCTION_CALL>p</VARIABLE_AS_FUNCTION_CALL></PARAMETER>(<NUMBER>42</NUMBER>)
"""
}
@@ -143,6 +146,7 @@ var <PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAG
KotlinBundle.message("options.kotlin.attribute.descriptor.annotation") to KotlinHighlightingColors.ANNOTATION,
KotlinBundle.message("options.kotlin.attribute.descriptor.object") to KotlinHighlightingColors.OBJECT,
KotlinBundle.message("options.kotlin.attribute.descriptor.enumEntry") to KotlinHighlightingColors.ENUM_ENTRY,
KotlinBundle.message("options.kotlin.attribute.descriptor.typeAlias") to KotlinHighlightingColors.TYPE_ALIAS,
KotlinBundle.message("options.kotlin.attribute.descriptor.var") to KotlinHighlightingColors.MUTABLE_VARIABLE,
KotlinBundle.message("options.kotlin.attribute.descriptor.local.variable") to KotlinHighlightingColors.LOCAL_VARIABLE,
OptionsBundle.message("options.java.attribute.descriptor.parameter") to KotlinHighlightingColors.PARAMETER,
+2
View File
@@ -0,0 +1,2 @@
typealias <info textAttributesKey="KOTLIN_TYPE_ALIAS">Predicate</info><<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>> = (<info textAttributesKey="KOTLIN_TYPE_PARAMETER">T</info>) -> <info textAttributesKey="KOTLIN_CLASS">Boolean</info>
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">baz</info>(<info textAttributesKey="KOTLIN_PARAMETER">p</info>: <info textAttributesKey="KOTLIN_TYPE_ALIAS">Predicate</info><<info textAttributesKey="KOTLIN_CLASS">Int</info>>) = <info textAttributesKey="KOTLIN_PARAMETER"><info textAttributesKey="KOTLIN_VARIABLE_AS_FUNCTION">p</info></info>(42)
@@ -126,6 +126,12 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
doTest(fileName);
}
@TestMetadata("TypeAlias.kt")
public void testTypeAlias() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/TypeAlias.kt");
doTest(fileName);
}
@TestMetadata("TypesAndAnnotations.kt")
public void testTypesAndAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/TypesAndAnnotations.kt");