From f8618fb9b1a15809f9fbf97fcb85528209471236 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 23:16:35 +0400 Subject: [PATCH] Made highlighting for annotations valid. Renamed "Soft keyword" entry to "Built-in annotation" --- .../highlighter/JetColorSettingsPage.java | 3 ++- .../highlighter/JetHighlightingColors.java | 9 +++++-- .../SoftKeywordsHighlightingVisitor.java | 24 +------------------ .../TypeKindHighlightingVisitor.java | 22 +++++++++++++++-- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 8c5d66d661a..1a705153847 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -98,7 +98,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { // TODO i18n return new AttributesDescriptor[]{ new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.keyword"), JetHighlightingColors.KEYWORD), - new AttributesDescriptor("Soft keyword", JetHighlightingColors.SOFT_KEYWORD), + new AttributesDescriptor("Built-in annotation", JetHighlightingColors.BUILTIN_ANNOTATION), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.number"), JetHighlightingColors.NUMBER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), @@ -127,6 +127,7 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.type.parameter"), JetHighlightingColors.TYPE_PARAMETER), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS), new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), + new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION), new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index d035acadc2a..c135138e569 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -31,8 +31,8 @@ public class JetHighlightingColors { SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); - public static final TextAttributesKey SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_SOFT_KEYWORD", + public static final TextAttributesKey BUILTIN_ANNOTATION = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BUILTIN_ANNOTATION", SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() ); @@ -156,6 +156,11 @@ public class JetHighlightingColors { CodeInsightColors.INTERFACE_NAME_ATTRIBUTES.getDefaultAttributes() ); + public static final TextAttributesKey ANNOTATION = TextAttributesKey.createTextAttributesKey( + "KOTLIN_ANNOTATION", + CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes() + ); + // TODO review: is it needed? public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( "KOTLIN_WRAPPED_INTO_REF", diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java index 27f90d405c9..4dacbfc30cf 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/SoftKeywordsHighlightingVisitor.java @@ -24,7 +24,6 @@ import com.intellij.lang.annotation.AnnotationHolder; import com.intellij.openapi.application.ApplicationManager; import com.intellij.psi.PsiElement; import com.intellij.psi.impl.source.tree.LeafPsiElement; -import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetTokens; @@ -37,20 +36,11 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { public void visitElement(PsiElement element) { if (element instanceof LeafPsiElement) { if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) { - holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); + holder.createInfoAnnotation(element, null).setTextAttributes(JetHighlightingColors.KEYWORD); } } } - @Override - public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { - JetTypeReference typeReference = annotationEntry.getTypeReference(); - if (typeReference != null) { - JetTypeElement typeElement = typeReference.getTypeElement(); - markAnnotationIdentifiers(typeElement, holder); - } - } - @Override public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { if (ApplicationManager.getApplication().isUnitTestMode()) return; @@ -65,16 +55,4 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor { holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES); } } - - private static void markAnnotationIdentifiers(JetTypeElement typeElement, @NotNull AnnotationHolder holder) { - if (typeElement instanceof JetUserType) { - JetUserType userType = (JetUserType) typeElement; - if (userType.getQualifier() == null) { - JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); - if (referenceExpression != null) { - holder.createInfoAnnotation(referenceExpression.getNode(), "Annotation").setTextAttributes(JetHighlightingColors.SOFT_KEYWORD); - } - } - } - } } diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java index 53d89a91639..a72c6a1b857 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/TypeKindHighlightingVisitor.java @@ -34,6 +34,20 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { super(holder); } + @Override + public void visitAnnotationEntry(JetAnnotationEntry annotationEntry) { + JetTypeReference typeReference = annotationEntry.getTypeReference(); + if (typeReference == null) return; + JetTypeElement typeElement = typeReference.getTypeElement(); + if (!(typeElement instanceof JetUserType)) return; + JetUserType userType = (JetUserType)typeElement; + if (userType.getQualifier() != null) return; + JetSimpleNameExpression referenceExpression = userType.getReferenceExpression(); + if (referenceExpression != null) { + holder.createInfoAnnotation(referenceExpression.getNode(), null).setTextAttributes(JetHighlightingColors.ANNOTATION); + } + } + private void visitNameExpression(JetExpression expression) { PsiReference ref = expression.getReference(); if (ref == null) return; @@ -77,8 +91,12 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor { textAttributes = JetHighlightingColors.TRAIT; } else { JetModifierList modifierList = klass.getModifierList(); - if (modifierList != null && modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { - textAttributes = JetHighlightingColors.ABSTRACT_CLASS; + if (modifierList != null) { + if (modifierList.hasModifier(JetTokens.ANNOTATION_KEYWORD)) { + textAttributes = JetHighlightingColors.ANNOTATION; + } else if (modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { + textAttributes = JetHighlightingColors.ABSTRACT_CLASS; + } } } Annotation annotation = holder.createInfoAnnotation(whatToHighlight, null);