From aec5ae5dd4e331768911f748f837fb6fd3692ee0 Mon Sep 17 00:00:00 2001 From: Zack Grannan Date: Mon, 14 Apr 2014 15:26:53 -0700 Subject: [PATCH] Added IfThenToDoubleBangIntention --- .../jet/generators/tests/GenerateTests.kt | 1 + .../after.kt.template | 1 + .../before.kt.template | 1 + .../description.html | 6 ++ idea/src/META-INF/plugin.xml | 5 + .../jetbrains/jet/plugin/JetBundle.properties | 3 + .../intentions/IfThenToDoubleBangIntention.kt | 101 ++++++++++++++++++ .../acceptableEmptyElseBlockForStatement.kt | 9 ++ ...eptableEmptyElseBlockForStatement.kt.after | 4 + .../acceptableEmptyThenBlockForStatement.kt | 9 ++ ...eptableEmptyThenBlockForStatement.kt.after | 4 + ...ableWithoutElseBlockForStatementWithFun.kt | 8 ++ ...thoutElseBlockForStatementWithFun.kt.after | 6 ++ ...ableWithoutElseBlockForStatementWithVal.kt | 7 ++ ...thoutElseBlockForStatementWithVal.kt.after | 4 + .../blockHasMoreThanOneStatement.kt | 13 +++ .../blockUsesDifferentVar.kt | 14 +++ .../conditionComparesNullWithNull.kt | 11 ++ .../conditionInvalidBinaryExp.kt | 14 +++ .../conditionNotBinaryExpr.kt | 17 +++ .../doesNotinlineValueIfUsedMoreThanOnce.kt | 15 +++ ...sNotinlineValueIfUsedMoreThanOnce.kt.after | 10 ++ .../doesNotinlineValueOutsideOfScope.kt | 14 +++ .../doesNotinlineValueOutsideOfScope.kt.after | 10 ++ .../ifThenToDoubleBang/emptyCondition.kt | 11 ++ .../ifThenToDoubleBang/emptyElseBlock.kt | 11 ++ .../ifThenToDoubleBang/emptyThenBlock.kt | 10 ++ .../ifAndElseBothInBlocks.kt | 14 +++ .../ifAndElseBothInBlocks.kt.after | 8 ++ .../ifAndElseNotInBlocks.kt | 12 +++ .../ifAndElseNotInBlocks.kt.after | 8 ++ .../ifThenToDoubleBang/ifAsExpression.kt | 14 +++ .../ifAsExpression.kt.after | 8 ++ .../ifThenToDoubleBang/lhsEqualsNull.kt | 12 +++ .../ifThenToDoubleBang/lhsEqualsNull.kt.after | 8 ++ .../ifThenToDoubleBang/lhsNotEqualsNull.kt | 12 +++ .../lhsNotEqualsNull.kt.after | 8 ++ .../ifThenToDoubleBang/missingElseClause.kt | 9 ++ .../ifThenToDoubleBang/missingThenClause.kt | 9 ++ .../ifThenToDoubleBang/noCondition.kt | 10 ++ .../ifThenToDoubleBang/noNullInCondition.kt | 12 +++ .../notApplicableForFunction.kt | 12 +++ .../notApplicableForLocalVar.kt | 13 +++ .../ifThenToDoubleBang/nullBranchAlsoNull.kt | 11 ++ .../otherBlockHasMoreThanOneStatement.kt | 13 +++ .../ifThenToDoubleBang/rhsEqualsNull.kt | 12 +++ .../ifThenToDoubleBang/rhsEqualsNull.kt.after | 8 ++ .../ifThenToDoubleBang/rhsNotEqualsNull.kt | 12 +++ .../rhsNotEqualsNull.kt.after | 8 ++ .../ifThenToDoubleBang/thenAndElseBothNull.kt | 11 ++ .../ifThenToDoubleBang/throwByFqName.kt | 10 ++ .../ifThenToDoubleBang/throwByFqName.kt.after | 8 ++ ...unacceptableEmptyElseBlockForExpression.kt | 10 ++ ...unacceptableEmptyThenBlockForExpression.kt | 10 ++ .../willNotInlineClassProperty.kt | 9 ++ .../willNotInlineClassProperty.kt.after | 9 ++ .../AbstractCodeTransformationTest.java | 4 + 57 files changed, 623 insertions(+) create mode 100644 idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/after.kt.template create mode 100644 idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/before.kt.template create mode 100644 idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/description.html create mode 100644 idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/blockHasMoreThanOneStatement.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/blockUsesDifferentVar.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/conditionComparesNullWithNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/conditionInvalidBinaryExp.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/conditionNotBinaryExpr.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/emptyCondition.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/emptyElseBlock.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/emptyThenBlock.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/missingElseClause.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/missingThenClause.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/noCondition.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/noNullInCondition.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForFunction.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForLocalVar.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/nullBranchAlsoNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/otherBlockHasMoreThanOneStatement.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/thenAndElseBothNull.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt.after create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyElseBlockForExpression.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyThenBlockForExpression.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt create mode 100644 idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt.after diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 18a6e267388..652537ede45 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -343,6 +343,7 @@ fun main(args: Array) { testClass(javaClass()) { model("intentions/branched/doubleBangToIfThen", testMethod = "doTestDoubleBangToIfThen") + model("intentions/branched/ifThenToDoubleBang", testMethod = "doTestIfThenToDoubleBang") model("intentions/branched/elvisToIfThen", testMethod = "doTestElvisToIfThen") model("intentions/branched/ifThenToElvis", testMethod = "doTestIfThenToElvis") model("intentions/branched/safeAccessToIfThen", testMethod = "doTestSafeAccessToIfThen") diff --git a/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/after.kt.template b/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/after.kt.template new file mode 100644 index 00000000000..5d8181f0686 --- /dev/null +++ b/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/after.kt.template @@ -0,0 +1 @@ +foo(maybeSomething!!) diff --git a/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/before.kt.template b/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/before.kt.template new file mode 100644 index 00000000000..512b442a380 --- /dev/null +++ b/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/before.kt.template @@ -0,0 +1 @@ +foo(if (maybeSomething != null) maybeSomething else throw KotlinNullPointerException()) diff --git a/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/description.html b/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/description.html new file mode 100644 index 00000000000..1adad0ae72c --- /dev/null +++ b/idea/resources/intentionDescriptions/IfThenToDoubleBangIntention/description.html @@ -0,0 +1,6 @@ + + + Converts an if-then expression that checks if a value is null to an equivalent expression + using the '!!' operator. + + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 39c9933604c..cc28417f9f4 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -499,6 +499,11 @@ Kotlin + + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.IfThenToDoubleBangIntention + Kotlin + + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.ElvisToIfThenIntention Kotlin diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index cc4da0ed0ac..81085b66d7c 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -225,6 +225,9 @@ double.bang.to.if.then.exception.text=Expression ''{0}'' must not be null double.bang.to.if.then.choose.exception=Choose Exception Class double.bang.to.if.then=Replace '!!' expression with 'if' expression double.bang.to.if.then.family=Replace '!!' Expression With 'if' Expression +if.then.to.double.bang=Replace 'if' expression with '!!' expression +if.then.to.double.bang.replace.exception=Replace 'if' expression with '!!' expression (will remove Exception) +if.then.to.double.bang.family=Replace 'if' expression With '!!' Expression elvis.to.if.then=Replace elvis expression with 'if' expression elvis.to.if.then.family=Replace Elvis Expression With 'if' Expression if.then.to.elvis=Replace 'if' expression with elvis expression diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt new file mode 100644 index 00000000000..726d4d4892a --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfThenToDoubleBangIntention.kt @@ -0,0 +1,101 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import com.intellij.openapi.editor.Editor +import org.jetbrains.jet.lang.psi.JetIfExpression +import org.jetbrains.jet.lang.psi.JetBinaryExpression +import org.jetbrains.jet.lexer.JetTokens +import org.jetbrains.jet.plugin.intentions.branchedTransformations.evaluatesTo +import org.jetbrains.jet.plugin.intentions.branchedTransformations.comparesNonNullToNull +import org.jetbrains.jet.plugin.intentions.branchedTransformations.getNonNullExpression +import org.jetbrains.jet.plugin.intentions.branchedTransformations.replace +import org.jetbrains.jet.plugin.intentions.branchedTransformations.isStableVariable +import org.jetbrains.jet.lang.psi.JetPostfixExpression +import org.jetbrains.jet.plugin.intentions.branchedTransformations.inlineBaseExpressionIfApplicableWithPrompt +import org.jetbrains.jet.plugin.intentions.branchedTransformations.extractExpressionIfSingle +import org.jetbrains.jet.lang.psi.JetThrowExpression +import org.jetbrains.jet.plugin.JetBundle +import org.jetbrains.jet.plugin.intentions.branchedTransformations.isNullExpressionOrEmptyBlock +import org.jetbrains.jet.plugin.intentions.branchedTransformations.isStatement +import org.jetbrains.jet.plugin.intentions.branchedTransformations.throwsNullPointerExceptionWithNoArguments + + +public class IfThenToDoubleBangIntention : JetSelfTargetingIntention("if.then.to.double.bang", javaClass()) { + + override fun isApplicableTo(element: JetIfExpression): Boolean { + val condition = element.getCondition() + val thenClause = element.getThen() + val elseClause = element.getElse() + + if (condition !is JetBinaryExpression || !condition.comparesNonNullToNull()) return false + + val expression = condition.getNonNullExpression() + + if (expression == null) return false + + val token = condition.getOperationToken() + if (token != JetTokens.EQEQ && token != JetTokens.EXCLEQ) return false + + val throwExpression = + when (token) { + JetTokens.EQEQ -> thenClause?.extractExpressionIfSingle() + JetTokens.EXCLEQ -> elseClause?.extractExpressionIfSingle() + else -> throw IllegalStateException("Token must be either '!=' or '==' ") + } as? JetThrowExpression + + if (throwExpression == null) return false + + val matchingClause = + when (token) { + JetTokens.EQEQ -> elseClause + JetTokens.EXCLEQ -> thenClause + else -> throw IllegalStateException("Token must be either '!=' or '==' ") + } + + val matchesAsStatement = element.isStatement() && (matchingClause?.isNullExpressionOrEmptyBlock() ?: true) + val matches = matchesAsStatement || (matchingClause?.evaluatesTo(expression) ?: false && expression.isStableVariable()) + + if (matches) { + val message = + if (throwExpression.throwsNullPointerExceptionWithNoArguments()) { + JetBundle.message("if.then.to.double.bang") + } + else { + // Warn that custom exception will be overwritten by intention action + JetBundle.message("if.then.to.double.bang.replace.exception") + } + + setText(message) + return true + } + else { + return false + } + } + + override fun applyTo(element: JetIfExpression, editor: Editor) { + val condition = element.getCondition() as JetBinaryExpression + + val expression = checkNotNull(condition.getNonNullExpression(), "condition must contain non null expression") + val resultingExprString = expression.getText() + "!!" + val result = element.replace(resultingExprString) as JetPostfixExpression + + result.inlineBaseExpressionIfApplicableWithPrompt(editor) + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt new file mode 100644 index 00000000000..3c3a34f104e --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +fun main(args: Array) { + val foo: String? = "foo" + if (foo == null) { + throw NullPointerException() + } + else { + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt.after new file mode 100644 index 00000000000..ffad6179d63 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyElseBlockForStatement.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun main(args: Array) { + "foo"!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt new file mode 100644 index 00000000000..05fd0e101c7 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +fun main(args: Array) { + val foo: String? = "foo" + if (foo != null) { + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt.after new file mode 100644 index 00000000000..ffad6179d63 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableEmptyThenBlockForStatement.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun main(args: Array) { + "foo"!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt new file mode 100644 index 00000000000..1c13b9edc97 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun foo(): Any? = "foo" + +fun main(args: Array) { + if (foo() == null) { + throw KotlinNullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt.after new file mode 100644 index 00000000000..fe3b8fdffb8 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithFun.kt.after @@ -0,0 +1,6 @@ +// WITH_RUNTIME +fun foo(): Any? = "foo" + +fun main(args: Array) { + foo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt new file mode 100644 index 00000000000..229fd96b15e --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +fun main(args: Array) { + val foo: String? = "foo" + if (foo == null) { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt.after new file mode 100644 index 00000000000..ffad6179d63 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/acceptableWithoutElseBlockForStatementWithVal.kt.after @@ -0,0 +1,4 @@ +// WITH_RUNTIME +fun main(args: Array) { + "foo"!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/blockHasMoreThanOneStatement.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/blockHasMoreThanOneStatement.kt new file mode 100644 index 00000000000..76f824e1a4b --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/blockHasMoreThanOneStatement.kt @@ -0,0 +1,13 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = null + + if (foo != null) { + print ("Hello") + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/blockUsesDifferentVar.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/blockUsesDifferentVar.kt new file mode 100644 index 00000000000..070718561b0 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/blockUsesDifferentVar.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo = null + val a = "a" + + if (foo != null) { + a + } + else { + throw NullPointerException() + } + +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/conditionComparesNullWithNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/conditionComparesNullWithNull.kt new file mode 100644 index 00000000000..a50e26966eb --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/conditionComparesNullWithNull.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = "foo" + if (null == null) { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/conditionInvalidBinaryExp.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/conditionInvalidBinaryExp.kt new file mode 100644 index 00000000000..8822e66b74b --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/conditionInvalidBinaryExp.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false + +fun T.compareTo(a: T): Int = 0 + +fun main(args: Array) { + val foo = null + if (foo > null) { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/conditionNotBinaryExpr.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/conditionNotBinaryExpr.kt new file mode 100644 index 00000000000..1325e4988ef --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/conditionNotBinaryExpr.kt @@ -0,0 +1,17 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +// ERROR: Type mismatch.
Required:kotlin.Boolean
Found:kotlin.Int
+// ERROR: Condition must be of type kotlin.Boolean, but is of type kotlin.Int +// ERROR: Infix call corresponds to a dot-qualified call 'foo.times(10)' which is not allowed on a nullable receiver 'foo'. Use ?.-qualified call instead + +fun String?.times(a: Int): Boolean = a == 0 + +fun main(args: Array) { + val foo: Int? = 4 + if (foo * 10) { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt new file mode 100644 index 00000000000..5e51472089f --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt @@ -0,0 +1,15 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + print(foo) + if (foo != null) { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt.after new file mode 100644 index 00000000000..70504aa3c62 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueIfUsedMoreThanOnce.kt.after @@ -0,0 +1,10 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + print(foo) + foo!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt new file mode 100644 index 00000000000..3723c97e398 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +val x = maybeFoo() + +fun main(args: Array) { + if (x != null) { + x + } else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt.after new file mode 100644 index 00000000000..2a21da1d5a0 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/doesNotinlineValueOutsideOfScope.kt.after @@ -0,0 +1,10 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +val x = maybeFoo() + +fun main(args: Array) { + x!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/emptyCondition.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/emptyCondition.kt new file mode 100644 index 00000000000..96e4dac05a4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/emptyCondition.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo = "foo" + if () { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/emptyElseBlock.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/emptyElseBlock.kt new file mode 100644 index 00000000000..4d07cd4e04b --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/emptyElseBlock.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = null + if (foo != null) { + foo + } + else { + + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/emptyThenBlock.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/emptyThenBlock.kt new file mode 100644 index 00000000000..30080506697 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/emptyThenBlock.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = "foo" + if (foo == null) { + } + else { + foo + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt new file mode 100644 index 00000000000..e060d322c99 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + if (foo != null) { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt.after new file mode 100644 index 00000000000..077fdef6df4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseBothInBlocks.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt new file mode 100644 index 00000000000..598056c02e4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + if (foo != null) + foo + else + throw NullPointerException() +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt.after new file mode 100644 index 00000000000..077fdef6df4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAndElseNotInBlocks.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt new file mode 100644 index 00000000000..283d1b87945 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt @@ -0,0 +1,14 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + val x = if (foo == null) { + throw KotlinNullPointerException() + } + else { + foo + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt.after new file mode 100644 index 00000000000..26476f892a9 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/ifAsExpression.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val x = maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt new file mode 100644 index 00000000000..3f125bf634b --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + if (foo == null) + throw NullPointerException() + else + foo +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt.after new file mode 100644 index 00000000000..077fdef6df4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsEqualsNull.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt new file mode 100644 index 00000000000..9cdc7fa2b72 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + if (foo != null) + foo + else + throw NullPointerException("'foo' must not be null") +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt.after new file mode 100644 index 00000000000..077fdef6df4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/lhsNotEqualsNull.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/missingElseClause.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/missingElseClause.kt new file mode 100644 index 00000000000..8164fafff31 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/missingElseClause.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = "foo" + if (foo == null) { + null + } +} + diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/missingThenClause.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/missingThenClause.kt new file mode 100644 index 00000000000..cd46c98eada --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/missingThenClause.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = "foo" + if (foo == null) + else { + foo + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/noCondition.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/noCondition.kt new file mode 100644 index 00000000000..92aa62d49d0 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/noCondition.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +// ERROR: Type mismatch.
Required:kotlin.Boolean
Found:() → kotlin.String?
+// ERROR: Condition must be of type kotlin.Boolean, but is of type () -> kotlin.String? +fun main(args: Array) { + val foo: String? = "foo" + if { + foo + } else throw NullPointerException() +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/noNullInCondition.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/noNullInCondition.kt new file mode 100644 index 00000000000..6c7db8d7147 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/noNullInCondition.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo = "foo" + val bar = "bar" + if (foo == bar) { + foo + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForFunction.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForFunction.kt new file mode 100644 index 00000000000..95fe35bd60f --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForFunction.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +//IS_APPLICABLE: false +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + if (maybeFoo() == null) + maybeFoo() + else + throw NullPointerException() +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForLocalVar.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForLocalVar.kt new file mode 100644 index 00000000000..c5bea081ab4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/notApplicableForLocalVar.kt @@ -0,0 +1,13 @@ +// WITH_RUNTIME +//IS_APPLICABLE: false +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + var foo = maybeFoo() + if (foo == null) + throw NullPointerException() + else + foo +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/nullBranchAlsoNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/nullBranchAlsoNull.kt new file mode 100644 index 00000000000..6258bc26f71 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/nullBranchAlsoNull.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = "foo" + if (foo == null) { + null + } + else { + foo + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/otherBlockHasMoreThanOneStatement.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/otherBlockHasMoreThanOneStatement.kt new file mode 100644 index 00000000000..a4cd8bba130 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/otherBlockHasMoreThanOneStatement.kt @@ -0,0 +1,13 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo: String? = null + + if (foo != null) { + foo + } + else { + print ("Hello") + throw NullPointerException("'foo' must not be null") + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt new file mode 100644 index 00000000000..da023b9a123 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + if (null == foo) + throw NullPointerException() + else + foo +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt.after new file mode 100644 index 00000000000..077fdef6df4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsEqualsNull.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt new file mode 100644 index 00000000000..0039f285cdc --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt @@ -0,0 +1,12 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + val foo = maybeFoo() + if (null != foo) + foo + else + throw NullPointerException() +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt.after new file mode 100644 index 00000000000..077fdef6df4 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/rhsNotEqualsNull.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +fun maybeFoo(): String? { + return "foo" +} + +fun main(args: Array) { + maybeFoo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/thenAndElseBothNull.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/thenAndElseBothNull.kt new file mode 100644 index 00000000000..bf1ca8661ef --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/thenAndElseBothNull.kt @@ -0,0 +1,11 @@ +// WITH_RUNTIME +// IS_APPLICABLE: false +fun main(args: Array) { + val foo = null + if (foo == null) { + null + } + else { + null + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt new file mode 100644 index 00000000000..27fbf30c1c3 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME +class NullPointerException : Exception() + +fun foo(): Any? = "foo" + +fun main(args: Array) { + if (foo() == null) { + throw java.lang.NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt.after new file mode 100644 index 00000000000..bbe8a0743b3 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/throwByFqName.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +class NullPointerException : Exception() + +fun foo(): Any? = "foo" + +fun main(args: Array) { + foo()!! +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyElseBlockForExpression.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyElseBlockForExpression.kt new file mode 100644 index 00000000000..22535edbb39 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyElseBlockForExpression.kt @@ -0,0 +1,10 @@ +// IS_APPLICABLE: false +// WITH_RUNTIME +fun main(args: Array) { + val foo: String? = "foo" + val y = if (foo == null) { + throw NullPointerException() + } + else { + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyThenBlockForExpression.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyThenBlockForExpression.kt new file mode 100644 index 00000000000..3442396d4fb --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/unacceptableEmptyThenBlockForExpression.kt @@ -0,0 +1,10 @@ +// WITH_RUNTIME +// IS_APPLICABLE: FALSE +fun main(args: Array) { + val foo: String? = "foo" + val y = if (foo == null) { + } + else { + throw NullPointerException() + } +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt b/idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt new file mode 100644 index 00000000000..3501e666e0c --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +class F(a: Int?) { + val b = a + val c = if (b != null) b else throw NullPointerException() +} + +fun main(args: Array) { + F(1).c +} diff --git a/idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt.after b/idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt.after new file mode 100644 index 00000000000..d2cc9074816 --- /dev/null +++ b/idea/testData/intentions/branched/ifThenToDoubleBang/willNotInlineClassProperty.kt.after @@ -0,0 +1,9 @@ +// WITH_RUNTIME +class F(a: Int?) { + val b = a + val c = b!! +} + +fun main(args: Array) { + F(1).c +} diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java index cc33812b16f..645a8c87b6a 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java @@ -42,6 +42,10 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes doTestIntention(path, new DoubleBangToIfThenIntention()); } + public void doTestIfThenToDoubleBang(@NotNull String path) throws Exception { + doTestIntention(path, new IfThenToDoubleBangIntention()); + } + public void doTestElvisToIfThen(@NotNull String path) throws Exception { doTestIntention(path, new ElvisToIfThenIntention()); }