From 5863111124baea8fa4a9275b8ca651a652a8d654 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Fri, 30 Mar 2012 20:25:06 +0400 Subject: [PATCH] Replaced "local var" and "local val" styles with "local variable" and "mutable variable/parameter/property". --- .../highlighter/JetColorSettingsPage.java | 5 +- .../highlighter/JetHighlightingColors.java | 10 +-- .../VariablesHighlightingVisitor.java | 64 +++++++++++-------- 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java index 450be1cc166..b3ceb75d972 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetColorSettingsPage.java @@ -129,9 +129,10 @@ public class JetColorSettingsPage implements ColorSettingsPage { new AttributesDescriptor("Trait", JetHighlightingColors.TRAIT), new AttributesDescriptor("Annotation", JetHighlightingColors.ANNOTATION), + new AttributesDescriptor("Mutable variable, parameter or property", JetHighlightingColors.MUTABLE_VARIABLE), + + new AttributesDescriptor("Local variable", JetHighlightingColors.LOCAL_VARIABLE), new AttributesDescriptor("Closure or anonymous object bound variable", JetHighlightingColors.WRAPPED_INTO_REF), - new AttributesDescriptor("Read-only local variable (val)", JetHighlightingColors.LOCAL_VAL), - new AttributesDescriptor("Mutable local variable (var)", JetHighlightingColors.LOCAL_VAR), new AttributesDescriptor("Instance property", JetHighlightingColors.INSTANCE_PROPERTY), new AttributesDescriptor("Namespace property", JetHighlightingColors.NAMESPACE_PROPERTY), diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java index ddae95925df..59a8e5e27c6 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetHighlightingColors.java @@ -161,14 +161,14 @@ public class JetHighlightingColors { CodeInsightColors.ANNOTATION_NAME_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey LOCAL_VAL = TextAttributesKey.createTextAttributesKey( - "KOTLIN_LOCAL_VAL", + public static final TextAttributesKey LOCAL_VARIABLE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_LOCAL_VARIABLE", CodeInsightColors.LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() ); - public static final TextAttributesKey LOCAL_VAR = TextAttributesKey.createTextAttributesKey( - "KOTLIN_LOCAL_VAR", - CodeInsightColors.REASSIGNED_LOCAL_VARIABLE_ATTRIBUTES.getDefaultAttributes() + public static final TextAttributesKey MUTABLE_VARIABLE = TextAttributesKey.createTextAttributesKey( + "KOTLIN_MUTABLE_VARIABLE", + new TextAttributes(null, null, Color.BLACK, EffectType.LINE_UNDERSCORE, 0) ); public static final TextAttributesKey WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey( diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java index b53c1ff8ee0..59ac567f2a1 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/VariablesHighlightingVisitor.java @@ -23,10 +23,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; import org.jetbrains.jet.lang.descriptors.LocalVariableDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; -import org.jetbrains.jet.lang.psi.JetElement; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.lang.psi.JetProperty; -import org.jetbrains.jet.lang.psi.JetSimpleNameExpression; +import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.types.JetType; @@ -37,9 +34,17 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { super(holder, bindingContext); } + @Override + public void visitJetElement(@NotNull JetElement element) { + element.acceptChildren(this); + } + @Override public void visitSimpleNameExpression(@NotNull JetSimpleNameExpression expression) { DeclarationDescriptor target = bindingContext.get(REFERENCE_TARGET, expression); + if (target == null) { + return; + } if (target instanceof ValueParameterDescriptor) { ValueParameterDescriptor parameterDescriptor = (ValueParameterDescriptor) target; if (Boolean.TRUE.equals(bindingContext.get(AUTO_CREATED_IT, parameterDescriptor))) { @@ -52,28 +57,16 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { super.visitSimpleNameExpression(expression); } - private void highlightVariable(@NotNull PsiElement elementToHighlight, DeclarationDescriptor descriptor) { - if (descriptor instanceof LocalVariableDescriptor) { - LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; - if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { - holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( - JetHighlightingColors.WRAPPED_INTO_REF); - } - holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes( - variableDescriptor.isVar() ? - JetHighlightingColors.LOCAL_VAR : - JetHighlightingColors.LOCAL_VAL); - } + @Override + public void visitProperty(@NotNull JetProperty property) { + visitVariableDeclaration(property); + super.visitProperty(property); } @Override - public void visitProperty(@NotNull JetProperty property) { - DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property); - PsiElement nameIdentifier = property.getNameIdentifier(); - if (nameIdentifier != null) { - highlightVariable(nameIdentifier, declarationDescriptor); - } - super.visitProperty(property); + public void visitParameter(JetParameter parameter) { + visitVariableDeclaration(parameter); + super.visitParameter(parameter); } @Override @@ -86,8 +79,27 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor { super.visitExpression(expression); } - @Override - public void visitJetElement(@NotNull JetElement element) { - element.acceptChildren(this); + private void visitVariableDeclaration(JetNamedDeclaration declaration) { + DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, declaration); + PsiElement nameIdentifier = declaration.getNameIdentifier(); + if (nameIdentifier != null && declarationDescriptor != null) { + highlightVariable(nameIdentifier, declarationDescriptor); + } + } + + private void highlightVariable(@NotNull PsiElement elementToHighlight, @NotNull DeclarationDescriptor descriptor) { + if (descriptor instanceof VariableDescriptor) { + if (((VariableDescriptor)descriptor).isVar()) { + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.MUTABLE_VARIABLE); + } + } + if (descriptor instanceof LocalVariableDescriptor) { + LocalVariableDescriptor variableDescriptor = (LocalVariableDescriptor) descriptor; + if (Boolean.TRUE.equals(bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor))) { + holder.createInfoAnnotation(elementToHighlight, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes( + JetHighlightingColors.WRAPPED_INTO_REF); + } + holder.createInfoAnnotation(elementToHighlight, null).setTextAttributes(JetHighlightingColors.LOCAL_VARIABLE); + } } }