Made highlighting for annotations valid. Renamed "Soft keyword" entry to "Built-in annotation"

This commit is contained in:
Evgeny Gerashchenko
2012-03-29 23:16:35 +04:00
parent 7efc1bcb5c
commit f8618fb9b1
4 changed files with 30 additions and 28 deletions
@@ -98,7 +98,7 @@ public class JetColorSettingsPage implements ColorSettingsPage {
// TODO i18n // TODO i18n
return new AttributesDescriptor[]{ return new AttributesDescriptor[]{
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.keyword"), JetHighlightingColors.KEYWORD), 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.number"), JetHighlightingColors.NUMBER),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.string"), JetHighlightingColors.STRING), 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.type.parameter"), JetHighlightingColors.TYPE_PARAMETER),
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS), new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.abstract.class"), JetHighlightingColors.ABSTRACT_CLASS),
new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT),
new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION),
new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF), new AttributesDescriptor("Wrapped into ref", JetHighlightingColors.WRAPPED_INTO_REF),
@@ -31,8 +31,8 @@ public class JetHighlightingColors {
SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()
); );
public static final TextAttributesKey SOFT_KEYWORD = TextAttributesKey.createTextAttributesKey( public static final TextAttributesKey BUILTIN_ANNOTATION = TextAttributesKey.createTextAttributesKey(
"KOTLIN_SOFT_KEYWORD", "KOTLIN_BUILTIN_ANNOTATION",
SyntaxHighlighterColors.KEYWORD.getDefaultAttributes() SyntaxHighlighterColors.KEYWORD.getDefaultAttributes()
); );
@@ -156,6 +156,11 @@ public class JetHighlightingColors {
CodeInsightColors.INTERFACE_NAME_ATTRIBUTES.getDefaultAttributes() CodeInsightColors.INTERFACE_NAME_ATTRIBUTES.getDefaultAttributes()
); );
public static final TextAttributesKey ANNOTATION = TextAttributesKey.createTextAttributesKey(
"KOTLIN_ANNOTATION",
CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes()
);
// TODO review: is it needed? // TODO review: is it needed?
public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey(
"KOTLIN_WRAPPED_INTO_REF", "KOTLIN_WRAPPED_INTO_REF",
@@ -24,7 +24,6 @@ import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ApplicationManager;
import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement; import com.intellij.psi.impl.source.tree.LeafPsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
@@ -37,20 +36,11 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor {
public void visitElement(PsiElement element) { public void visitElement(PsiElement element) {
if (element instanceof LeafPsiElement) { if (element instanceof LeafPsiElement) {
if (JetTokens.SOFT_KEYWORDS.contains(((LeafPsiElement) element).getElementType())) { 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 @Override
public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) { public void visitFunctionLiteralExpression(JetFunctionLiteralExpression expression) {
if (ApplicationManager.getApplication().isUnitTestMode()) return; if (ApplicationManager.getApplication().isUnitTestMode()) return;
@@ -65,16 +55,4 @@ class SoftKeywordsHighlightingVisitor extends HighlightingVisitor {
holder.createInfoAnnotation(arrowNode, null).setTextAttributes(JetHighlightingColors.FUNCTION_LITERAL_BRACES); 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);
}
}
}
}
} }
@@ -34,6 +34,20 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor {
super(holder); 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) { private void visitNameExpression(JetExpression expression) {
PsiReference ref = expression.getReference(); PsiReference ref = expression.getReference();
if (ref == null) return; if (ref == null) return;
@@ -77,8 +91,12 @@ class TypeKindHighlightingVisitor extends HighlightingVisitor {
textAttributes = JetHighlightingColors.TRAIT; textAttributes = JetHighlightingColors.TRAIT;
} else { } else {
JetModifierList modifierList = klass.getModifierList(); JetModifierList modifierList = klass.getModifierList();
if (modifierList != null && modifierList.hasModifier(JetTokens.ABSTRACT_KEYWORD)) { if (modifierList != null) {
textAttributes = JetHighlightingColors.ABSTRACT_CLASS; 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); Annotation annotation = holder.createInfoAnnotation(whatToHighlight, null);