Smart cast of value / implicit receiver: two different colors
This commit is contained in:
@@ -138,6 +138,7 @@ options.kotlin.attribute.descriptor.constructor.call=Constructor call
|
||||
options.kotlin.attribute.descriptor.variable.as.function.call=Variable as function call
|
||||
options.kotlin.attribute.descriptor.variable.as.function.like.call=Variable as function-like call
|
||||
options.kotlin.attribute.descriptor.smart.cast=Smart-cast value
|
||||
options.kotlin.attribute.descriptor.smart.cast.receiver=Smart-cast implicit receiver
|
||||
options.kotlin.attribute.descriptor.label=Label
|
||||
change.to.function.invocation=Change to function invocation
|
||||
migrate.sure=Replace sure() calls by !! in project
|
||||
|
||||
+1
@@ -83,6 +83,7 @@ public class KotlinHighlightingColors {
|
||||
// other
|
||||
public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("KOTLIN_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
|
||||
public static final TextAttributesKey SMART_CAST_VALUE = createTextAttributesKey("KOTLIN_SMART_CAST_VALUE");
|
||||
public static final TextAttributesKey SMART_CAST_RECEIVER = createTextAttributesKey("KOTLIN_SMART_CAST_RECEIVER");
|
||||
public static final TextAttributesKey LABEL = createTextAttributesKey("KOTLIN_LABEL");
|
||||
public static final TextAttributesKey DEBUG_INFO = createTextAttributesKey("KOTLIN_DEBUG_INFO");
|
||||
public static final TextAttributesKey RESOLVED_TO_ERROR = createTextAttributesKey("KOTLIN_RESOLVED_TO_ERROR");
|
||||
|
||||
+11
-7
@@ -69,16 +69,20 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
|
||||
@Override
|
||||
public void visitExpression(@NotNull KtExpression expression) {
|
||||
KotlinType 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))
|
||||
.setTextAttributes(KotlinHighlightingColors.SMART_CAST_RECEIVER);
|
||||
}
|
||||
|
||||
KotlinType smartCast = bindingContext.get(SMARTCAST, expression);
|
||||
if (smartCast != null) {
|
||||
holder.createInfoAnnotation(expression, "Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast)).setTextAttributes(
|
||||
KotlinHighlightingColors.SMART_CAST_VALUE);
|
||||
}
|
||||
smartCast = bindingContext.get(IMPLICIT_RECEIVER_SMARTCAST, expression);
|
||||
if (smartCast != null) {
|
||||
holder.createInfoAnnotation(expression, "Implicit receiver smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast)).setTextAttributes(
|
||||
KotlinHighlightingColors.SMART_CAST_VALUE);
|
||||
holder.createInfoAnnotation(expression, "Smart cast to " +
|
||||
DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast))
|
||||
.setTextAttributes(KotlinHighlightingColors.SMART_CAST_VALUE);
|
||||
}
|
||||
|
||||
super.visitExpression(expression);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
<option name="BACKGROUND" value="223c23" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_SMART_CAST_RECEIVER">
|
||||
<value>
|
||||
<option name="BACKGROUND" value="223c23" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_LABEL">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="467cda" />
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
<option name="BACKGROUND" value="dbffdb" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_SMART_CAST_RECEIVER">
|
||||
<value>
|
||||
<option name="BACKGROUND" value="dbffdb" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_LABEL">
|
||||
<value>
|
||||
<option name="FOREGROUND" value="4a86e8" />
|
||||
|
||||
@@ -63,6 +63,12 @@ public class KotlinColorSettingsPage : ColorSettingsPage {
|
||||
}
|
||||
}
|
||||
|
||||
fun Int?.bar() {
|
||||
if (this != null) {
|
||||
println(<SMART_CAST_RECEIVER>toString</SMART_CAST_RECEIVER>())
|
||||
}
|
||||
}
|
||||
|
||||
var <PROPERTY_WITH_BACKING_FIELD><PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAGE_PROPERTY></PROPERTY_WITH_BACKING_FIELD> : Int = 5
|
||||
<KEYWORD>get</KEYWORD>() {
|
||||
return <BACKING_FIELD_VARIABLE><LOCAL_VARIABLE><MUTABLE_VARIABLE>field</MUTABLE_VARIABLE></LOCAL_VARIABLE></BACKING_FIELD_VARIABLE>
|
||||
@@ -146,6 +152,7 @@ var <PROPERTY_WITH_BACKING_FIELD><PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCount
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.variable.as.function.like.call") to KotlinHighlightingColors.VARIABLE_AS_FUNCTION_LIKE_CALL,
|
||||
OptionsBundle.message("options.java.attribute.descriptor.bad.character") to KotlinHighlightingColors.BAD_CHARACTER,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast") to KotlinHighlightingColors.SMART_CAST_VALUE,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast.receiver") to KotlinHighlightingColors.SMART_CAST_RECEIVER,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.label") to KotlinHighlightingColors.LABEL)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
class <info textAttributesKey="KOTLIN_CLASS">My</info>(val <info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_PARAMETER"><info textAttributesKey="KOTLIN_PROPERTY_WITH_BACKING_FIELD">x</info></info></info>: <info textAttributesKey="KOTLIN_CLASS">Int</info>?)
|
||||
|
||||
fun <info textAttributesKey="KOTLIN_CLASS">My</info>?.<info textAttributesKey="KOTLIN_FUNCTION_DECLARATION">foo</info>(): <info textAttributesKey="KOTLIN_CLASS">Int</info> {
|
||||
if (this == null || <info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_SMART_CAST_RECEIVER">x</info></info> == null) return 42
|
||||
return <info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_SMART_CAST_RECEIVER"><info textAttributesKey="KOTLIN_SMART_CAST_VALUE">x</info></info></info>
|
||||
}
|
||||
@@ -89,6 +89,12 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SmartCast.kt")
|
||||
public void testSmartCast() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/SmartCast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Todo.kt")
|
||||
public void testTodo() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/Todo.kt");
|
||||
|
||||
Reference in New Issue
Block a user