Made styles for properties cascading, and therefore easier to tune.

This commit is contained in:
Evgeny Gerashchenko
2012-03-30 19:59:38 +04:00
parent 06e27d7a8c
commit 80c70616f0
3 changed files with 22 additions and 44 deletions
@@ -134,13 +134,9 @@ public class JetColorSettingsPage implements ColorSettingsPage {
new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR),
new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), 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", JetHighlightingColors.NAMESPACE_PROPERTY),
new AttributesDescriptor("Namespace property with backing field", JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD), new AttributesDescriptor("Property with backing field", JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD),
new AttributesDescriptor("Namespace property backing field access", JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS), new AttributesDescriptor("Property backing field access", JetHighlightingColors.BACKING_FIELD_ACCESS),
new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY), new AttributesDescriptor("Extension property", JetHighlightingColors.EXTENSION_PROPERTY),
new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER), new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER),
@@ -181,33 +181,19 @@ public class JetHighlightingColors {
CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes() 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( public static final TextAttributesKey NAMESPACE_PROPERTY = TextAttributesKey.createTextAttributesKey(
"KOTLIN_NAMESPACE_PROPERTY", "KOTLIN_NAMESPACE_PROPERTY",
CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes()
); );
public static final TextAttributesKey NAMESPACE_PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey( public static final TextAttributesKey PROPERTY_WITH_BACKING_FIELD = TextAttributesKey.createTextAttributesKey(
"KOTLIN_NAMESPACE_PROPERTY_WITH_BACKING_FIELD", "KOTLIN_PROPERTY_WITH_BACKING_FIELD",
TextAttributes.fromFlyweight(CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() new TextAttributes(null, null, INSTANCE_PROPERTY.getDefaultAttributes().getForegroundColor(), EffectType.LINE_UNDERSCORE, 0)
.getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor( );
CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) );
public static final TextAttributesKey NAMESPACE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey( public static final TextAttributesKey BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey(
"KOTLIN_NAMESPACE_BACKING_FIELD_ACCESS", "KOTLIN_BACKING_FIELD_ACCESS",
CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes() new TextAttributes()
); );
public static final TextAttributesKey EXTENSION_PROPERTY = TextAttributesKey.createTextAttributesKey( public static final TextAttributesKey EXTENSION_PROPERTY = TextAttributesKey.createTextAttributesKey(
@@ -46,14 +46,9 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
} }
boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor; boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor;
putPropertyAnnotation(expression, namespace, false);
if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) { if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
holder.createInfoAnnotation(expression, null).setTextAttributes( holder.createInfoAnnotation(expression, null).setTextAttributes(JetHighlightingColors.BACKING_FIELD_ACCESS);
(namespace ?
JetHighlightingColors.NAMESPACE_BACKING_FIELD_ACCESS :
JetHighlightingColors.INSTANCE_BACKING_FIELD_ACCESS)
);
} else {
putPropertyAnnotation(expression, namespace, false);
} }
} }
@@ -88,15 +83,16 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
} }
private void putPropertyAnnotation(@NotNull PsiElement elementToHighlight, boolean namespace, boolean withBackingField) { private void putPropertyAnnotation(@NotNull PsiElement elementToHighlight, boolean namespace, boolean withBackingField) {
holder.createInfoAnnotation( holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(
elementToHighlight, namespace
"This property has a backing field") ? JetHighlightingColors.NAMESPACE_PROPERTY
.setTextAttributes(withBackingField ? : JetHighlightingColors.INSTANCE_PROPERTY
(namespace );
? JetHighlightingColors.NAMESPACE_PROPERTY_WITH_BACKING_FIELD if (withBackingField) {
: JetHighlightingColors.INSTANCE_PROPERTY_WITH_BACKING_FIELD) : holder.createInfoAnnotation(
(namespace elementToHighlight,
? JetHighlightingColors.NAMESPACE_PROPERTY "This property has a backing field")
: JetHighlightingColors.INSTANCE_PROPERTY)); .setTextAttributes(JetHighlightingColors.PROPERTY_WITH_BACKING_FIELD);
}
} }
} }