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) {
|
if (referenceTarget instanceof ClassDescriptor) {
|
||||||
highlightClassByKind((ClassDescriptor) referenceTarget, expression);
|
highlightName(expression, textAttributesKeyForClass((ClassDescriptor) referenceTarget));
|
||||||
}
|
}
|
||||||
else if (referenceTarget instanceof TypeParameterDescriptor) {
|
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
|
@Override
|
||||||
public void visitTypeParameter(@NotNull JetTypeParameter parameter) {
|
public void visitTypeParameter(@NotNull JetTypeParameter parameter) {
|
||||||
PsiElement identifier = parameter.getNameIdentifier();
|
PsiElement identifier = parameter.getNameIdentifier();
|
||||||
if (identifier != null) {
|
if (identifier != null) {
|
||||||
JetPsiChecker.highlightName(holder, identifier, JetHighlightingColors.TYPE_PARAMETER);
|
highlightName(identifier, JetHighlightingColors.TYPE_PARAMETER);
|
||||||
}
|
}
|
||||||
super.visitTypeParameter(parameter);
|
super.visitTypeParameter(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitEnumEntry(@NotNull JetEnumEntry enumEntry) {
|
||||||
|
// Do nothing, the name was already highlighted in visitObjectDeclarationName
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitClass(@NotNull JetClass klass) {
|
public void visitClass(@NotNull JetClass klass) {
|
||||||
PsiElement identifier = klass.getNameIdentifier();
|
PsiElement identifier = klass.getNameIdentifier();
|
||||||
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, klass);
|
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, klass);
|
||||||
if (identifier != null && classDescriptor != null) {
|
if (identifier != null && classDescriptor != null) {
|
||||||
highlightClassByKind(classDescriptor, identifier);
|
highlightName(identifier, textAttributesKeyForClass(classDescriptor));
|
||||||
}
|
}
|
||||||
super.visitClass(klass);
|
super.visitClass(klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void highlightClassByKind(@NotNull ClassDescriptor classDescriptor, @NotNull PsiElement whatToHighlight) {
|
private void highlightName(@NotNull PsiElement whatToHighlight, @NotNull TextAttributesKey textAttributesKey) {
|
||||||
TextAttributesKey textAttributes;
|
JetPsiChecker.highlightName(holder, whatToHighlight, textAttributesKey);
|
||||||
switch (classDescriptor.getKind()) {
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static TextAttributesKey textAttributesKeyForClass(@NotNull ClassDescriptor descriptor) {
|
||||||
|
switch (descriptor.getKind()) {
|
||||||
case TRAIT:
|
case TRAIT:
|
||||||
textAttributes = JetHighlightingColors.TRAIT;
|
return JetHighlightingColors.TRAIT;
|
||||||
break;
|
|
||||||
case ANNOTATION_CLASS:
|
case ANNOTATION_CLASS:
|
||||||
textAttributes = JetHighlightingColors.ANNOTATION;
|
return JetHighlightingColors.ANNOTATION;
|
||||||
break;
|
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:
|
default:
|
||||||
textAttributes = classDescriptor.getModality() == Modality.ABSTRACT
|
return descriptor.getModality() == Modality.ABSTRACT
|
||||||
? JetHighlightingColors.ABSTRACT_CLASS
|
? JetHighlightingColors.ABSTRACT_CLASS
|
||||||
: JetHighlightingColors.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");
|
doTest("idea/testData/highlighter/JavaTypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Object.kt")
|
||||||
|
public void testObject() throws Exception {
|
||||||
|
doTest("idea/testData/highlighter/Object.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("TypesAndAnnotations.kt")
|
@TestMetadata("TypesAndAnnotations.kt")
|
||||||
public void testTypesAndAnnotations() throws Exception {
|
public void testTypesAndAnnotations() throws Exception {
|
||||||
doTest("idea/testData/highlighter/TypesAndAnnotations.kt");
|
doTest("idea/testData/highlighter/TypesAndAnnotations.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user