From 4261e4a5cc626b13e5005d9b87b712c1a2a8924e Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 25 May 2016 13:11:12 +0200 Subject: [PATCH] VariablesHighlightingVisitor: cleanup after J2K --- .../VariablesHighlightingVisitor.kt | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt index a119dc94f1b..df2f95790d2 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor +import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingColors.* import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.BindingContext @@ -35,8 +36,9 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon override fun visitSimpleNameExpression(expression: KtSimpleNameExpression) { val target = bindingContext.get(REFERENCE_TARGET, expression) ?: return if (target is ValueParameterDescriptor) { - if (java.lang.Boolean.TRUE == bindingContext.get(AUTO_CREATED_IT, target)) { - holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").textAttributes = KotlinHighlightingColors.FUNCTION_LITERAL_DEFAULT_PARAMETER + if (bindingContext.get(AUTO_CREATED_IT, target) == true) { + holder.createInfoAnnotation(expression, "Automatically declared based on the expected type") + .textAttributes = FUNCTION_LITERAL_DEFAULT_PARAMETER } } @@ -60,35 +62,35 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon private fun getSmartCastTarget(expression: KtExpression): PsiElement { var target: PsiElement = expression if (target is KtParenthesizedExpression) { - target = KtPsiUtil.deparenthesize(target as KtParenthesizedExpression?) ?: expression + target = KtPsiUtil.deparenthesize(target) ?: expression } - if (target is KtIfExpression) { - target = target.ifKeyword + return when (target) { + is KtIfExpression -> target.ifKeyword + is KtWhenExpression -> target.whenKeyword + is KtBinaryExpression -> target.operationReference + else -> target } - else if (target is KtWhenExpression) { - target = target.whenKeyword - } - else if (target is KtBinaryExpression) { - target = target.operationReference - } - return target } override fun visitExpression(expression: KtExpression) { val implicitSmartCast = bindingContext.get(IMPLICIT_RECEIVER_SMARTCAST, expression) if (implicitSmartCast != null) { - holder.createInfoAnnotation(expression, "Implicit receiver smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(implicitSmartCast)).textAttributes = KotlinHighlightingColors.SMART_CAST_RECEIVER + holder.createInfoAnnotation(expression, + "Implicit receiver smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(implicitSmartCast)) + .textAttributes = SMART_CAST_RECEIVER } - val nullSmartCast = bindingContext.get(SMARTCAST_NULL, expression) === java.lang.Boolean.TRUE + val nullSmartCast = bindingContext.get(SMARTCAST_NULL, expression) == true if (nullSmartCast) { - holder.createInfoAnnotation(expression, "Always null").textAttributes = KotlinHighlightingColors.SMART_CONSTANT + holder.createInfoAnnotation(expression, "Always null") + .textAttributes = SMART_CONSTANT } val smartCast = bindingContext.get(SMARTCAST, expression) if (smartCast != null) { holder.createInfoAnnotation(getSmartCastTarget(expression), - "Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast)).textAttributes = KotlinHighlightingColors.SMART_CAST_VALUE + "Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast)) + .textAttributes = SMART_CAST_VALUE } super.visitExpression(expression) @@ -106,12 +108,12 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon if (descriptor is VariableDescriptor) { if (descriptor.isDynamic()) { - NameHighlighter.highlightName(holder, elementToHighlight, KotlinHighlightingColors.DYNAMIC_PROPERTY_CALL) + holder.highlightName(elementToHighlight, DYNAMIC_PROPERTY_CALL) return } if (descriptor.isVar) { - NameHighlighter.highlightName(holder, elementToHighlight, KotlinHighlightingColors.MUTABLE_VARIABLE) + holder.highlightName(elementToHighlight, MUTABLE_VARIABLE) } if (bindingContext.get(CAPTURED_IN_CLOSURE, descriptor) == CaptureKind.NOT_INLINE) { @@ -119,15 +121,15 @@ internal class VariablesHighlightingVisitor(holder: AnnotationHolder, bindingCon "Wrapped into a reference object to be modified when captured in a closure" else "Value captured in a closure" - holder.createInfoAnnotation(elementToHighlight, msg).textAttributes = KotlinHighlightingColors.WRAPPED_INTO_REF + holder.createInfoAnnotation(elementToHighlight, msg).textAttributes = WRAPPED_INTO_REF } if (descriptor is LocalVariableDescriptor) { - NameHighlighter.highlightName(holder, elementToHighlight, KotlinHighlightingColors.LOCAL_VARIABLE) + NameHighlighter.highlightName(holder, elementToHighlight, LOCAL_VARIABLE) } if (descriptor is ValueParameterDescriptor) { - NameHighlighter.highlightName(holder, elementToHighlight, KotlinHighlightingColors.PARAMETER) + NameHighlighter.highlightName(holder, elementToHighlight, PARAMETER) } } }