Fixed highlighting for enum and object names in code

#KT-8134 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-06-23 18:28:14 +03:00
parent 2bd1362be6
commit c689af142a
9 changed files with 37 additions and 29 deletions
@@ -30,7 +30,15 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
}
public R visitClass(@NotNull JetClass klass, D data) {
return visitNamedDeclaration(klass, data);
return visitClassOrObject(klass, data);
}
public R visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, D data) {
return visitClassOrObject(declaration, data);
}
public R visitClassOrObject(@NotNull JetClassOrObject classOrObject, D data) {
return visitNamedDeclaration(classOrObject, data);
}
public R visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, D data) {
@@ -402,10 +410,6 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
return visitJetElement(condition, data);
}
public R visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, D data) {
return visitNamedDeclaration(declaration, data);
}
public R visitObjectDeclarationName(@NotNull JetObjectDeclarationName declarationName, D data) {
return visitExpression(declarationName, data);
}
@@ -33,6 +33,10 @@ public class JetVisitorVoid extends JetVisitor<Void, Void> {
super.visitClass(klass, null);
}
public void visitClassOrObject(@NotNull JetClassOrObject classOrObject) {
super.visitClassOrObject(classOrObject, null);
}
public void visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor) {
super.visitSecondaryConstructor(constructor, null);
}
@@ -448,6 +452,12 @@ public class JetVisitorVoid extends JetVisitor<Void, Void> {
return null;
}
@Override
public final Void visitClassOrObject(@NotNull JetClassOrObject classOrObject, Void data) {
visitClassOrObject(classOrObject);
return null;
}
@Override
public final Void visitSecondaryConstructor(@NotNull JetSecondaryConstructor constructor, Void data) {
visitSecondaryConstructor(constructor);
@@ -154,7 +154,7 @@ public class LazyTopDownAnalyzer {
fileScope.forceResolveImport(importDirective)
}
private fun visitClassOrObject(classOrObject: JetClassOrObject) {
override fun visitClassOrObject(classOrObject: JetClassOrObject) {
val descriptor = lazyDeclarationResolver!!.getClassDescriptor(classOrObject) as ClassDescriptorWithResolutionScopes
c.getDeclaredClasses().put(classOrObject, descriptor)
@@ -133,6 +133,7 @@ options.kotlin.attribute.descriptor.kdoc.comment=KDoc comment
options.kotlin.attribute.descriptor.kdoc.tag=KDoc tag
options.kotlin.attribute.descriptor.kdoc.value=Link in KDoc tag
options.kotlin.attribute.descriptor.object=Object
options.kotlin.attribute.descriptor.enumEntry=Enum entry
options.kotlin.attribute.descriptor.annotation=Annotation
options.kotlin.attribute.descriptor.var=Var (mutable variable, parameter or property)
options.kotlin.attribute.descriptor.local.variable=Local variable or value
@@ -55,6 +55,7 @@ public class JetHighlightingColors {
public static final TextAttributesKey TRAIT = createTextAttributesKey("KOTLIN_TRAIT", CodeInsightColors.INTERFACE_NAME_ATTRIBUTES);
public static final TextAttributesKey ANNOTATION = createTextAttributesKey("KOTLIN_ANNOTATION");
public static final TextAttributesKey OBJECT = createTextAttributesKey("KOTLIN_OBJECT", CLASS);
public static final TextAttributesKey ENUM_ENTRY = createTextAttributesKey("KOTLIN_ENUM_ENTRY", CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES);
// variable kinds
public static final TextAttributesKey MUTABLE_VARIABLE = createTextAttributesKey("KOTLIN_MUTABLE_VARIABLE");
@@ -62,14 +62,6 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
JetPsiChecker.highlightName(holder, toHighlight, JetHighlightingColors.ANNOTATION);
}
@Override
public void visitObjectDeclarationName(@NotNull JetObjectDeclarationName declaration) {
PsiElement nameIdentifier = declaration.getNameIdentifier();
if (nameIdentifier != null) {
highlightName(nameIdentifier, JetHighlightingColors.CLASS);
}
}
@Override
public void visitTypeParameter(@NotNull JetTypeParameter parameter) {
PsiElement identifier = parameter.getNameIdentifier();
@@ -80,18 +72,13 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
}
@Override
public void visitEnumEntry(@NotNull JetEnumEntry enumEntry) {
// Do nothing, the name was already highlighted in visitObjectDeclarationName
}
@Override
public void visitClass(@NotNull JetClass klass) {
PsiElement identifier = klass.getNameIdentifier();
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, klass);
public void visitClassOrObject(@NotNull JetClassOrObject classOrObject) {
PsiElement identifier = classOrObject.getNameIdentifier();
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, classOrObject);
if (identifier != null && classDescriptor != null) {
highlightName(identifier, textAttributesKeyForClass(classDescriptor));
}
super.visitClass(klass);
super.visitClassOrObject(classOrObject);
}
@Override
@@ -113,7 +100,7 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
case OBJECT:
return JetHighlightingColors.OBJECT;
case ENUM_ENTRY:
return JetHighlightingColors.INSTANCE_PROPERTY;
return JetHighlightingColors.ENUM_ENTRY;
default:
return descriptor.getModality() == Modality.ABSTRACT
? JetHighlightingColors.ABSTRACT_CLASS
@@ -82,6 +82,10 @@ public class JetColorSettingsPage implements ColorSettingsPage {
"\n" +
"<KEYWORD>public</KEYWORD> <KEYWORD>abstract</KEYWORD> class <ABSTRACT_CLASS>Abstract</ABSTRACT_CLASS> {\n" +
"}\n" +
"\n" +
"<KEYWORD>object</KEYWORD> <OBJECT>Obj</OBJECT>\n" +
"\n" +
"<KEYWORD>enum</KEYWORD> <KEYWORD>class</KEYWORD> <CLASS>E</CLASS> { <ENUM_ENTRY>A</ENUM_ENTRY> }\n" +
" Bad character: \\n\n";
}
@@ -137,6 +141,7 @@ public class JetColorSettingsPage implements ColorSettingsPage {
new AttributesDescriptor("Interface", JetHighlightingColors.TRAIT),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.annotation"), JetHighlightingColors.ANNOTATION),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.object"), JetHighlightingColors.OBJECT),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.enumEntry"), JetHighlightingColors.ENUM_ENTRY),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.var"), JetHighlightingColors.MUTABLE_VARIABLE),
+4 -4
View File
@@ -1,11 +1,11 @@
package testing
<info textAttributesKey="KOTLIN_BUILTIN_ANNOTATION">enum</info> class <info textAttributesKey="KOTLIN_CLASS">Test</info> {
<info textAttributesKey="KOTLIN_CLASS">FIRST</info>,
<info textAttributesKey="KOTLIN_CLASS">SECOND</info>
<info textAttributesKey="KOTLIN_ENUM_ENTRY">FIRST</info>,
<info textAttributesKey="KOTLIN_ENUM_ENTRY">SECOND</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_INSTANCE_PROPERTY">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_INSTANCE_PROPERTY">FIRST</info>, <info textAttributesKey="KOTLIN_CLASS">Test</info>.<info textAttributesKey="KOTLIN_INSTANCE_PROPERTY">SECOND</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>)
}
+1 -1
View File
@@ -1,6 +1,6 @@
package testing
object <info textAttributesKey="KOTLIN_CLASS">O</info> {
object <info textAttributesKey="KOTLIN_OBJECT">O</info> {
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>() = 42
}