Merge pull request #450 from wutalman/assert_to_if
KT-4576: (Bug fix) Intention to transform an if an AssertionError throw into an assert
This commit is contained in:
@@ -28,6 +28,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
|||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||||
import org.jetbrains.jet.lang.psi.JetIfExpression
|
import org.jetbrains.jet.lang.psi.JetIfExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
|
||||||
|
|
||||||
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>(
|
public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<JetCallExpression>(
|
||||||
"convert.assert.to.if.with.throw", javaClass()) {
|
"convert.assert.to.if.with.throw", javaClass()) {
|
||||||
@@ -98,6 +99,11 @@ public class ConvertAssertToIfWithThrowIntention : JetSelfTargetingIntention<Jet
|
|||||||
simplifier.applyTo(ifCondition, editor)
|
simplifier.applyTo(ifCondition, editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
element.replace(ifExpression)
|
val parent = element.getParent()
|
||||||
|
if (parent is JetDotQualifiedExpression) {
|
||||||
|
parent.replace(ifExpression)
|
||||||
|
} else {
|
||||||
|
element.replace(ifExpression)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo() {
|
||||||
|
kotlin.<caret>assert(true, "text")
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
fun foo() {
|
||||||
|
if (!true) {
|
||||||
|
throw AssertionError("text")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3556,6 +3556,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
doTestConvertAssertToIfWithThrowIntention("idea/testData/intentions/convertAssertToIf/booleanConditionWithVariables.kt");
|
doTestConvertAssertToIfWithThrowIntention("idea/testData/intentions/convertAssertToIf/booleanConditionWithVariables.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dotQualifiedCall.kt")
|
||||||
|
public void testDotQualifiedCall() throws Exception {
|
||||||
|
doTestConvertAssertToIfWithThrowIntention("idea/testData/intentions/convertAssertToIf/dotQualifiedCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("functionCallCondition.kt")
|
@TestMetadata("functionCallCondition.kt")
|
||||||
public void testFunctionCallCondition() throws Exception {
|
public void testFunctionCallCondition() throws Exception {
|
||||||
doTestConvertAssertToIfWithThrowIntention("idea/testData/intentions/convertAssertToIf/functionCallCondition.kt");
|
doTestConvertAssertToIfWithThrowIntention("idea/testData/intentions/convertAssertToIf/functionCallCondition.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user