Added highlighting for extension properties. Fixed a couple of property-highlighting problems.
Made visitProperty() recursive to avoid skipping getters/setters parsing. Tuned style for properties with backing fields a little.
This commit is contained in:
@@ -141,6 +141,8 @@ public class JetColorSettingsPage implements ColorSettingsPage {
|
||||
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("Extension property", JetHighlightingColors.EXTENSION_PROPERTY),
|
||||
|
||||
new AttributesDescriptor("Function literal default parameter", JetHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER),
|
||||
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER),
|
||||
|
||||
@@ -185,7 +185,7 @@ public class JetHighlightingColors {
|
||||
"KOTLIN_INSTANCE_PROPERTY_WITH_BACKING_FIELD",
|
||||
TextAttributes
|
||||
.fromFlyweight(CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes()
|
||||
.getFlyweight().withEffectType(EffectType.BOLD_DOTTED_LINE).withEffectColor(
|
||||
.getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor(
|
||||
CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor()))
|
||||
);
|
||||
|
||||
@@ -202,12 +202,17 @@ public class JetHighlightingColors {
|
||||
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.BOLD_DOTTED_LINE).withEffectColor(
|
||||
.getFlyweight().withEffectType(EffectType.LINE_UNDERSCORE).withEffectColor(
|
||||
CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes().getForegroundColor())) );
|
||||
|
||||
public static final TextAttributesKey NAMESPACE_BACKING_FIELD_ACCESS = TextAttributesKey.createTextAttributesKey(
|
||||
"KOTLIN_NAMESPACE_BACKING_FIELD_ACCESS",
|
||||
CodeInsightColors.INSTANCE_FIELD_ATTRIBUTES.getDefaultAttributes()
|
||||
CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes()
|
||||
);
|
||||
|
||||
public static final TextAttributesKey EXTENSION_PROPERTY = TextAttributesKey.createTextAttributesKey(
|
||||
"KOTLIN_EXTENSION_PROPERTY",
|
||||
CodeInsightColors.STATIC_FIELD_ATTRIBUTES.getDefaultAttributes()
|
||||
);
|
||||
|
||||
public static final TextAttributesKey FUNCTION_LITERAL_DEFAULT_PARAMETER = TextAttributesKey.createTextAttributesKey(
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
@@ -34,12 +35,16 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
|
||||
@Override
|
||||
public void visitSimpleNameExpression(JetSimpleNameExpression expression) {
|
||||
// TODO highlight extension properties
|
||||
DeclarationDescriptor target = bindingContext.get(BindingContext.REFERENCE_TARGET, expression);
|
||||
if (!(target instanceof PropertyDescriptor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((PropertyDescriptor)target).getReceiverParameter() != ReceiverDescriptor.NO_RECEIVER) {
|
||||
holder.createInfoAnnotation(expression, null).setTextAttributes(
|
||||
JetHighlightingColors.EXTENSION_PROPERTY);
|
||||
}
|
||||
|
||||
boolean namespace = target.getContainingDeclaration() instanceof NamespaceDescriptor;
|
||||
if (expression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
||||
holder.createInfoAnnotation(expression, null).setTextAttributes(
|
||||
@@ -62,6 +67,8 @@ class PropertiesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
boolean namespace = propertyDescriptor.getContainingDeclaration() instanceof NamespaceDescriptor;
|
||||
putPropertyAnnotation(nameIdentifier, namespace, Boolean.TRUE.equals(backingFieldRequired));
|
||||
}
|
||||
|
||||
super.visitProperty(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user