Limit "always null" scope: only for !!, is and dot; senseless comparison rolled back; "smart constant" information for nulls #KT-10029 Fixed
This commit is contained in:
@@ -134,6 +134,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.constant=Smart constant
|
||||
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
|
||||
|
||||
+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_CONSTANT = createTextAttributesKey("KOTLIN_SMART_CONSTANT");
|
||||
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");
|
||||
|
||||
+6
@@ -76,6 +76,12 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
|
||||
.setTextAttributes(KotlinHighlightingColors.SMART_CAST_RECEIVER);
|
||||
}
|
||||
|
||||
boolean nullSmartCast = bindingContext.get(SMARTCAST_NULL, expression) == Boolean.TRUE;
|
||||
if (nullSmartCast) {
|
||||
holder.createInfoAnnotation(expression, "Always null")
|
||||
.setTextAttributes(KotlinHighlightingColors.SMART_CONSTANT);
|
||||
}
|
||||
|
||||
KotlinType smartCast = bindingContext.get(SMARTCAST, expression);
|
||||
if (smartCast != null) {
|
||||
holder.createInfoAnnotation(expression, "Smart cast to " +
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
<option name="BACKGROUND" value="223c23" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_SMART_CONSTANT">
|
||||
<value>
|
||||
<option name="BACKGROUND" value="223c23" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_SMART_CAST_RECEIVER">
|
||||
<value>
|
||||
<option name="BACKGROUND" value="223c23" />
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
<option name="BACKGROUND" value="dbffdb" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_SMART_CONSTANT">
|
||||
<value>
|
||||
<option name="BACKGROUND" value="dbffdb" />
|
||||
</value>
|
||||
</option>
|
||||
<option name="KOTLIN_SMART_CAST_RECEIVER">
|
||||
<value>
|
||||
<option name="BACKGROUND" value="dbffdb" />
|
||||
|
||||
@@ -67,6 +67,9 @@ fun Int?.bar() {
|
||||
if (this != null) {
|
||||
println(<SMART_CAST_RECEIVER>toString</SMART_CAST_RECEIVER>())
|
||||
}
|
||||
else {
|
||||
println(<SMART_CONSTANT>this</SMART_CONSTANT>.toString())
|
||||
}
|
||||
}
|
||||
|
||||
var <PROPERTY_WITH_BACKING_FIELD><PACKAGE_PROPERTY><MUTABLE_VARIABLE>globalCounter</MUTABLE_VARIABLE></PACKAGE_PROPERTY></PROPERTY_WITH_BACKING_FIELD> : Int = 5
|
||||
@@ -152,6 +155,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.constant") to KotlinHighlightingColors.SMART_CONSTANT,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.smart.cast.receiver") to KotlinHighlightingColors.SMART_CAST_RECEIVER,
|
||||
KotlinBundle.message("options.kotlin.attribute.descriptor.label") to KotlinHighlightingColors.LABEL)
|
||||
}
|
||||
|
||||
Vendored
+8
-8
@@ -4,7 +4,7 @@ fun test() {
|
||||
a.plus(1)
|
||||
}
|
||||
else {
|
||||
<warning>a</warning>?.plus(1)
|
||||
a?.plus(1)
|
||||
}
|
||||
|
||||
val out : java.io.PrintStream? = null
|
||||
@@ -28,7 +28,7 @@ fun test() {
|
||||
}
|
||||
|
||||
if (out == null) {
|
||||
<warning>out</warning>?.println()
|
||||
out?.println()
|
||||
} else {
|
||||
out.println()
|
||||
}
|
||||
@@ -84,7 +84,7 @@ fun test() {
|
||||
}
|
||||
|
||||
if (out == null) {
|
||||
<warning>out</warning>?.println()
|
||||
out?.println()
|
||||
} else {
|
||||
out.println()
|
||||
}
|
||||
@@ -131,12 +131,12 @@ fun test() {
|
||||
while (out != null) {
|
||||
out.println();
|
||||
}
|
||||
<warning>out</warning>?.println();
|
||||
out?.println();
|
||||
|
||||
val out2 : java.io.PrintStream? = null
|
||||
|
||||
while (out2 == null) {
|
||||
<warning>out2</warning>?.println();
|
||||
out2?.println();
|
||||
}
|
||||
out2.println()
|
||||
|
||||
@@ -224,7 +224,7 @@ fun f7(s : String?, t : String?) {
|
||||
}
|
||||
s?.get(0)
|
||||
if (!(s != null)) {
|
||||
<warning>s</warning>?.get(0)
|
||||
s?.get(0)
|
||||
}
|
||||
else {
|
||||
s.get(0)
|
||||
@@ -234,7 +234,7 @@ fun f7(s : String?, t : String?) {
|
||||
s.get(0)
|
||||
}
|
||||
else {
|
||||
<warning>s</warning>?.get(0)
|
||||
s?.get(0)
|
||||
}
|
||||
s?.get(0)
|
||||
t?.get(0)
|
||||
@@ -253,7 +253,7 @@ fun f7(s : String?, t : String?) {
|
||||
t?.get(0)
|
||||
}
|
||||
else {
|
||||
<warning>s</warning>?.get(0)
|
||||
s?.get(0)
|
||||
t?.get(0)
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -1,6 +1,12 @@
|
||||
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
|
||||
if (this == null) return 42
|
||||
if (<info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_SMART_CAST_RECEIVER">x</info></info> == null) {
|
||||
if (<warning textAttributesKey="WARNING_ATTRIBUTES"><info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_SMART_CONSTANT"><info textAttributesKey="KOTLIN_SMART_CAST_RECEIVER">x</info></info></info> != null</warning>) {
|
||||
<warning textAttributesKey="WARNING_ATTRIBUTES">return</warning> <info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_SMART_CAST_RECEIVER"><info textAttributesKey="KOTLIN_SMART_CAST_VALUE">x</info></info></info>
|
||||
}
|
||||
return 13
|
||||
}
|
||||
return <info textAttributesKey="KOTLIN_INSTANCE_PROPERTY"><info textAttributesKey="KOTLIN_SMART_CAST_RECEIVER"><info textAttributesKey="KOTLIN_SMART_CAST_VALUE">x</info></info></info>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user