Made highlighting for annotations valid. Renamed "Soft keyword" entry to "Built-in annotation"
This commit is contained in:
@@ -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),
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user