Vars modified in closures are marked with a MUST_BE_WRAPPED_IN_A_REF key
This commit is contained in:
@@ -97,6 +97,15 @@ public class JetHighlighter extends SyntaxHighlighterBase {
|
||||
JET_AUTO_CAST_EXPRESSION = TextAttributesKey.createTextAttributesKey("JET.AUTO.CAST.EXPRESSION", clone);
|
||||
}
|
||||
|
||||
public static final TextAttributesKey JET_WRAPPED_INTO_REF;
|
||||
|
||||
static {
|
||||
TextAttributes attributes = new TextAttributes();
|
||||
attributes.setEffectType(EffectType.LINE_UNDERSCORE);
|
||||
attributes.setEffectColor(Color.BLACK);
|
||||
JET_WRAPPED_INTO_REF = TextAttributesKey.createTextAttributesKey("JET.WRAPPED.INTO.REF", attributes);
|
||||
}
|
||||
|
||||
public static final TextAttributesKey JET_AUTOCREATED_IT;
|
||||
|
||||
static {
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.jetbrains.jet.plugin.annotations;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.ProblemHighlightType;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
@@ -117,9 +118,28 @@ public class JetPsiChecker implements Annotator {
|
||||
holder.createInfoAnnotation(expression, "Automatically declared based on the expected type").setTextAttributes(JetHighlighter.JET_AUTOCREATED_IT);
|
||||
}
|
||||
}
|
||||
|
||||
markVariableAsWrappedIfNeeded(expression.getNode(), target);
|
||||
super.visitSimpleNameExpression(expression);
|
||||
}
|
||||
|
||||
private void markVariableAsWrappedIfNeeded(ASTNode node, DeclarationDescriptor target) {
|
||||
if (target instanceof VariableDescriptor) {
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) target;
|
||||
if (bindingContext.get(MUST_BE_WRAPPED_IN_A_REF, variableDescriptor)) {
|
||||
holder.createInfoAnnotation(node, "Wrapped into a ref-object to be modifier when captured in a closure").setTextAttributes(JetHighlighter.JET_WRAPPED_INTO_REF);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitProperty(JetProperty property) {
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, property);
|
||||
markVariableAsWrappedIfNeeded(property.getNameIdentifier().getNode(), declarationDescriptor);
|
||||
super.visitProperty(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitExpression(JetExpression expression) {
|
||||
JetType autoCast = bindingContext.get(AUTOCAST, expression);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
fun notContainsBreak() {
|
||||
var <info>a</info> = 1
|
||||
val v = {
|
||||
<info>a</info> = 2
|
||||
}
|
||||
|
||||
var <info>x</info> = 1
|
||||
val b = object {
|
||||
fun foo() {
|
||||
<info>x</info> = 2
|
||||
}
|
||||
}
|
||||
|
||||
var <info>y</info> = 1
|
||||
fun foo() {
|
||||
<info>y</info> = 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user