Data flow values for Elvis / parenthesized expressions, smart casts on them

This commit is contained in:
Mikhail Glukhikh
2015-12-08 16:50:04 +03:00
parent 745a3aeeac
commit d024045638
10 changed files with 160 additions and 16 deletions
@@ -67,6 +67,27 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
super.visitParameter(parameter);
}
@NotNull
private static PsiElement getSmartCastTarget(@NotNull KtExpression expression) {
PsiElement target = expression;
if (target instanceof KtParenthesizedExpression) {
target = KtPsiUtil.deparenthesize((KtParenthesizedExpression) target);
if (target == null) {
target = expression;
}
}
if (target instanceof KtIfExpression) {
target = ((KtIfExpression) target).getIfKeyword();
}
else if (target instanceof KtWhenExpression) {
target = ((KtWhenExpression) target).getWhenKeyword();
}
else if (target instanceof KtBinaryExpression) {
target = ((KtBinaryExpression) target).getOperationReference();
}
return target;
}
@Override
public void visitExpression(@NotNull KtExpression expression) {
KotlinType implicitSmartCast = bindingContext.get(IMPLICIT_RECEIVER_SMARTCAST, expression);
@@ -84,14 +105,8 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
KotlinType smartCast = bindingContext.get(SMARTCAST, expression);
if (smartCast != null) {
PsiElement target = expression;
if (expression instanceof KtIfExpression) {
target = ((KtIfExpression) expression).getIfKeyword();
}
else if (expression instanceof KtWhenExpression) {
target = ((KtWhenExpression) expression).getWhenKeyword();
}
holder.createInfoAnnotation(target, "Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast))
holder.createInfoAnnotation(getSmartCastTarget(expression),
"Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast))
.setTextAttributes(KotlinHighlightingColors.SMART_CAST_VALUE);
}