From 80c70616f04c7f85bbb7c8a516809ebf07644261 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 19:59:38 +0400 Subject: [PATCH] Made styles for properties cascading, and therefore easier to tune. --- .../highlighter/JetColorSettingsPage.java | 8 ++--- .../highlighter/JetHighlightingColors.java | 28 +++++------------ .../PropertiesHighlightingVisitor.java | 30 ++++++++----------- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 7539696df3c..450be1cc166 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -134,13 +134,9 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), - new AttributesDescriptor("Instance property with backing field", JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD), - new AttributesDescriptor("Instance property backing field access", JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS), - new AttributesDescriptor("Namespace property", JetHighlightingColors.NAMESPACE_PROPERTY), - new AttributesDescriptor("Namespace property with backing field", JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD), - new AttributesDescriptor("Namespace property backing field access", JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS), - + new AttributesDescriptor("Property with backing field", JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD), + new AttributesDescriptor("Property backing field access", JetHighlightingColors.BACKING_FIELD_ACCESS), new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY), new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index 5161be6dac3..ddae95925df 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -181,33 +181,19 @@ public class JetHighlightingColors { CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey INSTANCE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_INSTANCE_PROPERTY_WITH_BACKING_FIELD", - TextAttributes - .fromFlyweight(CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() - .getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( - CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) - ); - - public static final TextAttributesKey INSTANCE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( - "KOTLIN_INSTANCE_BACKING_FIELD_ACCESS", - CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() - ); - public static final TextAttributesKey NAMESPACE_PROPERTY = TextAttributesKey.createTextAttributesKey( "KOTLIN_NAMESPACE_PROPERTY", CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey NAMESPACE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( - "KOTLIN_NAMESPACE_PROPERTY_WITH_BACKING_FIELD", - TextAttributes.fromFlyweight(CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() - .getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( - CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) ); + public static final TextAttributesKey PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( + "KOTLIN_PROPERTY_WITH_BACKING_FIELD", + new TextAttributes(null, null, INSTANCE_PROPERTY.getDefaultAttributes().getForegroundColor(), EffectType.LINE_UNDERSCORE, 0) +); - public static final TextAttributesKey NAMESPACE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( - "KOTLIN_NAMESPACE_BACKING_FIELD_ACCESS", - CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() + public static final TextAttributesKey BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( + "KOTLIN_BACKING_FIELD_ACCESS", + new TextAttributes() ); public static final TextAttributesKey EXTENSION_PROPERTY = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java index bf2b740394d..f12ed88d807 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/PropertiesHighlightingVisitor.java @@ -46,14 +46,9 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor; + putPropertyAnnotation(expression, namespace, false); if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { - holder.createInfoAnnotation(expression, null).setTextAttributes( - (namespace ? - JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS : - JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS) - ); - } else { - putPropertyAnnotation(expression, namespace, false); + holder.createInfoAnnotation(expression, null).setTextAttributes(JetHighlightingColors.BACKING_FIELD_ACCESS); } } @@ -88,15 +83,16 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { } private void putPropertyAnnotation(@NotNull PsiElement elementToHighlight, boolean namespace, boolean withBackingField) { - holder.createInfoAnnotation( - elementToHighlight, - "This property has a backing field") - .setTextAttributes(withBackingField ? - (namespace - ? JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD - : JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD) : - (namespace - ? JetHighlightingColors.NAMESPACE_PROPERTY - : JetHighlightingColors.INSTANCE_PROPERTY)); + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes( + namespace + ? JetHighlightingColors.NAMESPACE_PROPERTY + : JetHighlightingColors.INSTANCE_PROPERTY + ); + if (withBackingField) { + holder.createInfoAnnotation( + elementToHighlight, + "This property has a backing field") + .setTextAttributes(JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD); + } } }