Simplify boolean == true / false is no longer applicable on flexible boolean #KT-15087 Fixed
This commit is contained in:
+2
-1
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.lexer.KtTokens.*
|
|||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
|
import org.jetbrains.kotlin.resolve.CompileTimeConstantUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
import org.jetbrains.kotlin.resolve.calls.callUtil.getType
|
||||||
|
import org.jetbrains.kotlin.types.isFlexible
|
||||||
|
|
||||||
class SimplifyBooleanWithConstantsInspection : IntentionBasedInspection<KtBinaryExpression>(SimplifyBooleanWithConstantsIntention::class)
|
class SimplifyBooleanWithConstantsInspection : IntentionBasedInspection<KtBinaryExpression>(SimplifyBooleanWithConstantsIntention::class)
|
||||||
|
|
||||||
@@ -136,7 +137,7 @@ class SimplifyBooleanWithConstantsIntention : SelfTargetingOffsetIndependentInte
|
|||||||
|
|
||||||
private fun KtExpression?.hasBooleanType(): Boolean {
|
private fun KtExpression?.hasBooleanType(): Boolean {
|
||||||
val type = this?.getType(this.analyze()) ?: return false
|
val type = this?.getType(this.analyze()) ?: return false
|
||||||
return KotlinBuiltIns.isBoolean(type)
|
return KotlinBuiltIns.isBoolean(type) && !type.isFlexible()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KtExpression.canBeReducedToBooleanConstant(constant: Boolean? = null): Boolean {
|
private fun KtExpression.canBeReducedToBooleanConstant(constant: Boolean? = null): Boolean {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class FromJava {
|
||||||
|
static Boolean foo() {
|
||||||
|
return Boolean.TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
fun bar() = <caret>FromJava.foo() == true
|
||||||
@@ -12939,6 +12939,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("flexibleBoolean.kt")
|
||||||
|
public void testFlexibleBoolean() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyBooleanWithConstants/flexibleBoolean.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("inapplicableNoConstants.kt")
|
@TestMetadata("inapplicableNoConstants.kt")
|
||||||
public void testInapplicableNoConstants() throws Exception {
|
public void testInapplicableNoConstants() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyBooleanWithConstants/inapplicableNoConstants.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/simplifyBooleanWithConstants/inapplicableNoConstants.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user