diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties
index bb7f15142e2..08f11d02632 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties
@@ -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
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java
index 92502fe2fb0..6c2d55d88e2 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinHighlightingColors.java
@@ -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");
diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.java
index a1942d45cb8..f0ad6bd9c1f 100644
--- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.java
+++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/VariablesHighlightingVisitor.java
@@ -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);
}
diff --git a/idea/resources/colorScheme/Darcula_Kotlin.xml b/idea/resources/colorScheme/Darcula_Kotlin.xml
index 2f2a87f3207..02bd5b202ce 100644
--- a/idea/resources/colorScheme/Darcula_Kotlin.xml
+++ b/idea/resources/colorScheme/Darcula_Kotlin.xml
@@ -30,6 +30,11 @@
+
diff --git a/idea/resources/colorScheme/Default_Kotlin.xml b/idea/resources/colorScheme/Default_Kotlin.xml
index ff12f870d95..51f38eaebb1 100644
--- a/idea/resources/colorScheme/Default_Kotlin.xml
+++ b/idea/resources/colorScheme/Default_Kotlin.xml
@@ -30,6 +30,11 @@
+
+
+
+
+
diff --git a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt
index e2aeae9b911..be553c62b09 100644
--- a/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/highlighter/KotlinColorSettingsPage.kt
@@ -63,6 +63,12 @@ public class KotlinColorSettingsPage : ColorSettingsPage {
}
}
+fun Int?.bar() {
+ if (this != null) {
+ println(toString())
+ }
+}
+
var globalCounter : Int = 5
get() {
return field
@@ -146,6 +152,7 @@ var 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)
}
diff --git a/idea/testData/highlighter/SmartCast.kt b/idea/testData/highlighter/SmartCast.kt
new file mode 100644
index 00000000000..5532732ad04
--- /dev/null
+++ b/idea/testData/highlighter/SmartCast.kt
@@ -0,0 +1,6 @@
+class My(val x: Int?)
+
+fun My?.foo(): Int {
+ if (this == null || x == null) return 42
+ return x
+}
diff --git a/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java
index aa59800f683..a2e93df4a62 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/highlighter/HighlightingTestGenerated.java
@@ -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");