Fix highlighting for objects and enum entries
JetObjectDeclarationName is now highlighted with KOTLIN_CLASS
This commit is contained in:
@@ -41,47 +41,65 @@ class TypeKindHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
}
|
||||
|
||||
if (referenceTarget instanceof ClassDescriptor) {
|
||||
highlightClassByKind((ClassDescriptor) referenceTarget, expression);
|
||||
highlightName(expression, textAttributesKeyForClass((ClassDescriptor) referenceTarget));
|
||||
}
|
||||
else if (referenceTarget instanceof TypeParameterDescriptor) {
|
||||
JetPsiChecker.highlightName(holder, expression, JetHighlightingColors.TYPE_PARAMETER);
|
||||
highlightName(expression, JetHighlightingColors.TYPE_PARAMETER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
if (identifier != null) {
|
||||
JetPsiChecker.highlightName(holder, identifier, JetHighlightingColors.TYPE_PARAMETER);
|
||||
highlightName(identifier, JetHighlightingColors.TYPE_PARAMETER);
|
||||
}
|
||||
super.visitTypeParameter(parameter);
|
||||
}
|
||||
|
||||
@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);
|
||||
if (identifier != null && classDescriptor != null) {
|
||||
highlightClassByKind(classDescriptor, identifier);
|
||||
highlightName(identifier, textAttributesKeyForClass(classDescriptor));
|
||||
}
|
||||
super.visitClass(klass);
|
||||
}
|
||||
|
||||
private void highlightClassByKind(@NotNull ClassDescriptor classDescriptor, @NotNull PsiElement whatToHighlight) {
|
||||
TextAttributesKey textAttributes;
|
||||
switch (classDescriptor.getKind()) {
|
||||
private void highlightName(@NotNull PsiElement whatToHighlight, @NotNull TextAttributesKey textAttributesKey) {
|
||||
JetPsiChecker.highlightName(holder, whatToHighlight, textAttributesKey);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static TextAttributesKey textAttributesKeyForClass(@NotNull ClassDescriptor descriptor) {
|
||||
switch (descriptor.getKind()) {
|
||||
case TRAIT:
|
||||
textAttributes = JetHighlightingColors.TRAIT;
|
||||
break;
|
||||
return JetHighlightingColors.TRAIT;
|
||||
case ANNOTATION_CLASS:
|
||||
textAttributes = JetHighlightingColors.ANNOTATION;
|
||||
break;
|
||||
return JetHighlightingColors.ANNOTATION;
|
||||
case OBJECT:
|
||||
case ENUM_ENTRY:
|
||||
// Treat object accesses as variables to simulate the old behaviour (when variables were created for objects)
|
||||
return JetHighlightingColors.INSTANCE_PROPERTY;
|
||||
default:
|
||||
textAttributes = classDescriptor.getModality() == Modality.ABSTRACT
|
||||
? JetHighlightingColors.ABSTRACT_CLASS
|
||||
: JetHighlightingColors.CLASS;
|
||||
return descriptor.getModality() == Modality.ABSTRACT
|
||||
? JetHighlightingColors.ABSTRACT_CLASS
|
||||
: JetHighlightingColors.CLASS;
|
||||
}
|
||||
JetPsiChecker.highlightName(holder, whatToHighlight, textAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package testing
|
||||
|
||||
object <info textAttributesKey="KOTLIN_CLASS">O</info> {
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>() = 42
|
||||
}
|
||||
|
||||
fun <info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">testing</info>() {
|
||||
<info textAttributesKey="KOTLIN_INSTANCE_PROPERTY">O</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">foo</info>()
|
||||
val <info textAttributesKey="KOTLIN_LOCAL_VARIABLE">o</info> = <info textAttributesKey="KOTLIN_INSTANCE_PROPERTY">O</info>
|
||||
<info textAttributesKey="KOTLIN_LOCAL_VARIABLE">o</info>.<info textAttributesKey="KOTLIN_FUNCTION_CALL">foo</info>()
|
||||
}
|
||||
@@ -52,6 +52,11 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
|
||||
doTest("idea/testData/highlighter/JavaTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("Object.kt")
|
||||
public void testObject() throws Exception {
|
||||
doTest("idea/testData/highlighter/Object.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TypesAndAnnotations.kt")
|
||||
public void testTypesAndAnnotations() throws Exception {
|
||||
doTest("idea/testData/highlighter/TypesAndAnnotations.kt");
|
||||
|
||||
Reference in New Issue
Block a user