Refactoring: make "if-then to safe access" an inspection

This commit is contained in:
Mikhail Glukhikh
2017-12-19 15:41:09 +03:00
parent 91bcfb97c6
commit a8b01a6b00
86 changed files with 433 additions and 410 deletions
@@ -1 +0,0 @@
val result = maybeSomething?.perform(something)
@@ -1 +0,0 @@
val result = if (maybeSomething != null) maybeSomething.perform(something) else null
@@ -1,5 +0,0 @@
<html>
<body>
Converts an if-then expression to an expression that uses a safe-access operator (if applicable)
</body>
</html>
+1 -1
View File
@@ -1620,7 +1620,7 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessInspection"
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection"
displayName="If-Then foldable to '?.'"
groupPath="Kotlin"
groupName="Style issues"
@@ -14,53 +14,74 @@
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
package org.jetbrains.kotlin.idea.inspections.branchedTransformations
import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.inspections.AbstractApplicabilityBasedInspection
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.*
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
class IfThenToSafeAccessInspection : IntentionBasedInspection<KtIfExpression>(IfThenToSafeAccessIntention::class) {
override fun inspectionTarget(element: KtIfExpression) = element.ifKeyword
class IfThenToSafeAccessInspection : AbstractApplicabilityBasedInspection<KtIfExpression>() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): KtVisitorVoid =
object : KtVisitorVoid() {
override fun visitIfExpression(expression: KtIfExpression) {
super.visitIfExpression(expression)
visitTargetElement(expression, holder, isOnTheFly)
}
}
override fun problemHighlightType(element: KtIfExpression): ProblemHighlightType =
if (element.shouldBeTransformed()) super.problemHighlightType(element) else ProblemHighlightType.INFORMATION
}
class IfThenToSafeAccessIntention : SelfTargetingOffsetIndependentIntention<KtIfExpression>(
KtIfExpression::class.java, "Replace 'if' expression with safe access expression"
) {
override fun isApplicableTo(element: KtIfExpression): Boolean {
override fun isApplicable(element: KtIfExpression): Boolean {
val ifThenToSelectData = element.buildSelectTransformationData() ?: return false
if (!ifThenToSelectData.receiverExpression.isStable(ifThenToSelectData.context)) return false
if (ifThenToSelectData.baseClauseEvaluatesToReceiver()) {
text = if (ifThenToSelectData.condition is KtIsExpression) {
return ifThenToSelectData.clausesReplaceableBySafeCall()
}
override fun inspectionTarget(element: KtIfExpression) = element.ifKeyword
override fun inspectionText(element: KtIfExpression) = "Foldable if-then"
override fun inspectionHighlightType(element: KtIfExpression): ProblemHighlightType =
if (element.shouldBeTransformed()) ProblemHighlightType.GENERIC_ERROR_OR_WARNING else ProblemHighlightType.INFORMATION
override val defaultFixText = "Simplify foldable if-then"
override fun fixText(element: KtIfExpression) : String {
val ifThenToSelectData = element.buildSelectTransformationData()
return if (ifThenToSelectData?.baseClauseEvaluatesToReceiver() == true) {
if (ifThenToSelectData.condition is KtIsExpression) {
"Replace 'if' expression with safe cast expression"
}
else {
"Remove redundant 'if' expression"
}
}
return ifThenToSelectData.clausesReplaceableBySafeCall()
else {
"Replace 'if' expression with safe access expression"
}
}
override fun startInWriteAction() = false
override val startFixInWriteAction = false
override fun applyTo(element: KtIfExpression, editor: Editor?) {
val ifThenToSelectData = element.buildSelectTransformationData() ?: return
override fun applyTo(element: PsiElement, project: Project, editor: Editor?) {
val ifExpression = element.getParentOfType<KtIfExpression>(true) ?: return
val ifThenToSelectData = ifExpression.buildSelectTransformationData() ?: return
val factory = KtPsiFactory(element)
val factory = KtPsiFactory(ifExpression)
val resultExpr = runWriteAction {
val replacedBaseClause = ifThenToSelectData.replacedBaseClause(factory)
val newExpr = element.replaced(replacedBaseClause)
val newExpr = ifExpression.replaced(replacedBaseClause)
KtPsiUtil.deparenthesize(newExpr)
}
@@ -27,12 +27,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.core.setVisibility
import org.jetbrains.kotlin.idea.inspections.*
import org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection
import org.jetbrains.kotlin.idea.inspections.conventionNameCalls.ReplaceGetOrSetInspection
import org.jetbrains.kotlin.idea.intentions.*
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldIfToReturnAsymmetricallyIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldIfToReturnIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isTrivialStatementBody
import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
import org.jetbrains.kotlin.idea.quickfix.RemoveUselessCastFix
@@ -87,7 +87,7 @@ object J2KPostProcessingRegistrar {
registerIntentionBasedProcessing(FoldIfToReturnIntention()) { it.then.isTrivialStatementBody() && it.`else`.isTrivialStatementBody() }
registerIntentionBasedProcessing(FoldIfToReturnAsymmetricallyIntention()) { it.then.isTrivialStatementBody() && (KtPsiUtil.skipTrailingWhitespacesAndComments(it) as KtReturnExpression).returnedExpression.isTrivialStatementBody() }
registerIntentionBasedProcessing(IfThenToSafeAccessIntention())
registerInspectionBasedProcessing(IfThenToSafeAccessInspection())
registerIntentionBasedProcessing(IfThenToElvisIntention())
registerIntentionBasedProcessing(SimplifyNegatedBinaryExpressionIntention())
registerInspectionBasedProcessing(ReplaceGetOrSetInspection())
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun <T> doSomething(a: T) {}
fun main(args: Array<String>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
var foo: String? = "foo"
var bar: String? = "bar"
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo = "foo"
if (null == <caret>null) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
operator fun <T> T.compareTo(a: T): Int = 0
fun main(args: Array<String>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
operator fun String?.times(a: Int): Boolean = a == 0
fun main(args: Array<String>) {
@@ -7,7 +7,7 @@ fun <T> doSomething(a: T) {}
fun main(args: Array<String>) {
val foo = maybeFoo()
doSomething(foo)
if (foo != null<caret>) {
i<caret>f (foo != null) {
foo.length
}
else {
@@ -5,7 +5,7 @@ fun maybeFoo(): String? {
val x = maybeFoo()
fun main(args: Array<String>) {
if (x !=<caret> null) {
<caret>if (x != null) {
x.length
} else {
null
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo = "foo"
if (<caret>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun maybeFoo(): String? {
return "foo"
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun maybeFoo(): String? {
return "foo"
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (foo != null<caret>) {
<caret>if (foo != null) {
foo.length
}
else {
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (foo != null<caret>)
i<caret>f (foo != null)
foo.length
else
null
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
val x = if (foo == null<caret>) {
val x = <caret>if (foo == null) {
null
}
else {
@@ -5,7 +5,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/rhsNotEqualsNull.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>rhsEqualsNull.kt</file>
@@ -13,7 +13,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/rhsEqualsNull.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>noThenBlock.kt</file>
@@ -21,7 +21,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/noThenBlock.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>noElseBlock.kt</file>
@@ -29,7 +29,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/noElseBlock.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>lhsNotEqualsNull.kt</file>
@@ -37,7 +37,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/lhsNotEqualsNull.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>lhsEqualsNull.kt</file>
@@ -45,7 +45,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/lhsEqualsNull.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>ifAsExpression.kt</file>
@@ -53,7 +53,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/ifAsExpression.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>ifAndElseNotInBlocks.kt</file>
@@ -61,7 +61,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/ifAndElseNotInBlocks.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>ifAndElseBothInBlocks.kt</file>
@@ -69,7 +69,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/ifAndElseBothInBlocks.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>doesNotinlineValueOutsideOfScope.kt</file>
@@ -77,7 +77,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/doesNotInlineValueOutsideOfScope.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>doesNotinlineValueIfUsedMoreThanOnce.kt</file>
@@ -85,7 +85,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/doesNotInlineValueIfUsedMoreThanOnce.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>willNotInlineClassProperty.kt</file>
@@ -93,7 +93,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/willNotInlineClassProperty.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isCondition.kt</file>
@@ -101,7 +101,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/isCondition.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isNotCondition.kt</file>
@@ -109,7 +109,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/src/isNotCondition.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>nullCheckWithSelectorCallChain.kt</file>
@@ -117,7 +117,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/nullCheckWithSelectorCallChain.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isCheckWithSelectorChain.kt</file>
@@ -125,7 +125,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/isCheckWithSelectorChain.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>isCheckSimple.kt</file>
@@ -133,7 +133,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/isCheckSimple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe cast expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>nullCheckSimple.kt</file>
@@ -141,7 +141,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/nullCheckSimple.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Remove redundant 'if' expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>implicitReceiver.kt</file>
@@ -149,7 +149,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/implicitReceiver.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe access expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>property.kt</file>
@@ -157,7 +157,7 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/property.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Replace 'if' expression with safe cast expression</description>
<description>Foldable if-then</description>
</problem>
<problem>
<file>propertyNotNull.kt</file>
@@ -165,6 +165,6 @@
<module>light_idea_test_case</module>
<entry_point TYPE="file" FQNAME="temp:///src/propertyNotNull.kt" />
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">If-Then foldable to '?.'</problem_class>
<description>Remove redundant 'if' expression</description>
<description>Foldable if-then</description>
</problem>
</problems>
@@ -0,0 +1,2 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection
// WITH_RUNTIME
@@ -1,5 +1,5 @@
class My(val x: Int)
fun foo(arg: Any?): My? {
return if (<caret>arg is My) arg else null
return <caret>if (arg is My) arg else null
}
@@ -0,0 +1,5 @@
class My(val x: Int)
fun foo(arg: Any?): Int? {
return i<caret>f (arg is My) arg.x.hashCode() else null
}
@@ -0,0 +1 @@
fun foo(arg: Any) = <caret>if (arg is String) arg.length else null
@@ -0,0 +1 @@
fun foo(arg: Any) = <caret>if (arg !is String) null else arg.length
@@ -1,2 +1,2 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun foo(arg: Any) = if (arg !is String?<caret>) null else arg?.length
@@ -1,2 +1,2 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun foo(arg: Any) = if (arg is String?<caret>) arg?.length else null
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (foo == null<caret>)
<caret>if (foo == null)
null
else
foo.length
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (foo != null<caret>)
<caret>if (foo != null)
foo.length
else
null
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo = null
if (foo == null<caret>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo = null
if (foo != null<caret>)
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
fun main(args: Array<String>) {
val foo: String? = "foo"
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (foo != null<caret>) {
<caret>if (foo != null) {
foo.length
}
}
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: 'if' must have both main and 'else' branches if used as an expression
// ERROR: Type mismatch: inferred type is Unit but Int was expected
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
val bar: String? = null
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
val bar: String? = null
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (foo == null<caret>) else {
<caret>if (foo == null) else {
foo.length
}
}
@@ -1,4 +1,4 @@
//IS_APPLICABLE: false
// PROBLEM: none
fun maybeFoo(): String? {
return "foo"
}
@@ -1,4 +1,4 @@
//IS_APPLICABLE: false
// PROBLEM: none
fun maybeFoo(): String? {
return "foo"
}
@@ -0,0 +1,3 @@
fun foo(arg: Any?): Any? {
return <caret>if (arg != null) arg else null
}
@@ -2,7 +2,7 @@
val nullableString: String? = "abc"
val foo = if (<caret>nullableString != null) {
val foo = <caret>if (nullableString != null) {
nullableString.toUpperCase().toLowerCase()
} else {
null
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun <T> doSomething(a: T) {}
fun main(args: Array<String>) {
@@ -1,5 +1,5 @@
// IS_APPLICABLE: true
// INTENTION_TEXT: Replace 'if' expression with safe cast expression
// FIX: Replace 'if' expression with safe cast expression
interface Foo
interface Bar : Foo
@@ -1,5 +1,5 @@
// IS_APPLICABLE: true
// INTENTION_TEXT: Replace 'if' expression with safe cast expression
// FIX: Replace 'if' expression with safe cast expression
interface Foo
interface Bar : Foo
@@ -1,5 +1,5 @@
// IS_APPLICABLE: true
// INTENTION_TEXT: Remove redundant 'if' expression
// FIX: Remove redundant 'if' expression
interface Bar
@@ -1,5 +1,5 @@
// IS_APPLICABLE: true
// INTENTION_TEXT: Remove redundant 'if' expression
// FIX: Remove redundant 'if' expression
interface Bar
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
interface Foo
interface Bar : Foo {
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (null == foo<caret>)
i<caret>f (null == foo)
null
else
foo.length
@@ -4,7 +4,7 @@ fun maybeFoo(): String? {
fun main(args: Array<String>) {
val foo = maybeFoo()
if (null != foo<caret>)
<caret>if (null != foo)
foo.length
else
null
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
<caret>if (foo == null) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
// ERROR: Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type String?
fun main(args: Array<String>) {
val foo: String? = "foo"
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
if (foo == null<caret>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
if (foo != null<caret>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
if (foo == null<caret>) {
@@ -1,4 +1,4 @@
// IS_APPLICABLE: false
// PROBLEM: none
fun main(args: Array<String>) {
val foo: String? = "foo"
if (foo != null<caret>)
@@ -1,6 +1,6 @@
class F(a: Int?) {
val b = a
val c = if (b !=<caret> null) b.toString() else null
val c = i<caret>f (b != null) b.toString() else null
}
fun main(args: Array<String>) {
@@ -1 +0,0 @@
org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessIntention
@@ -1,2 +0,0 @@
// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToSafeAccessInspection
// WITH_RUNTIME
@@ -1,5 +0,0 @@
class My(val x: Int)
fun foo(arg: Any?): Int? {
return if (<caret>arg is My) arg.x.hashCode() else null
}
@@ -1 +0,0 @@
fun foo(arg: Any) = if (arg is String<caret>) arg.length else null
@@ -1 +0,0 @@
fun foo(arg: Any) = if (arg !is String<caret>) null else arg.length
@@ -1,3 +0,0 @@
fun foo(arg: Any?): Any? {
return if (<caret>arg != null) arg else null
}
@@ -44,12 +44,6 @@ public class InspectionTestGenerated extends AbstractInspectionTest {
doTest(fileName);
}
@TestMetadata("branched/ifThenToSafeAccess/inspectionData/inspections.test")
public void testBranched_ifThenToSafeAccess_inspectionData_Inspections_test() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/inspectionData/inspections.test");
doTest(fileName);
}
@TestMetadata("convertToStringTemplate/inspectionData/inspections.test")
public void testConvertToStringTemplate_inspectionData_Inspections_test() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/inspectionData/inspections.test");
@@ -488,6 +482,12 @@ public class InspectionTestGenerated extends AbstractInspectionTest {
KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/inspectionsLocal"), Pattern.compile("^(inspections\\.test)$"), TargetBackend.ANY);
}
@TestMetadata("branched/ifThenToSafeAccess/inspectionData/inspections.test")
public void testBranched_ifThenToSafeAccess_inspectionData_Inspections_test() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/inspections.test");
doTest(fileName);
}
@TestMetadata("conventionNameCalls/replaceGetOrSet/inspectionData/inspections.test")
public void testConventionNameCalls_replaceGetOrSet_inspectionData_Inspections_test() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/conventionNameCalls/replaceGetOrSet/inspectionData/inspections.test");
@@ -51,6 +51,306 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/branched")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Branched extends AbstractLocalInspectionTest {
public void testAllFilesPresentInBranched() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/branched"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class IfThenToSafeAccess extends AbstractLocalInspectionTest {
public void testAllFilesPresentInIfThenToSafeAccess() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("blockHasMoreThanOneStatement.kt")
public void testBlockHasMoreThanOneStatement() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/blockHasMoreThanOneStatement.kt");
doTest(fileName);
}
@TestMetadata("blockUsesDifferentVar.kt")
public void testBlockUsesDifferentVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/blockUsesDifferentVar.kt");
doTest(fileName);
}
@TestMetadata("conditionComparesNullWithNull.kt")
public void testConditionComparesNullWithNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionComparesNullWithNull.kt");
doTest(fileName);
}
@TestMetadata("conditionInvalidBinaryExp.kt")
public void testConditionInvalidBinaryExp() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInvalidBinaryExp.kt");
doTest(fileName);
}
@TestMetadata("conditionNotBinaryExpr.kt")
public void testConditionNotBinaryExpr() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionNotBinaryExpr.kt");
doTest(fileName);
}
@TestMetadata("doesNotinlineValueIfUsedMoreThanOnce.kt")
public void testDoesNotinlineValueIfUsedMoreThanOnce() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/doesNotinlineValueIfUsedMoreThanOnce.kt");
doTest(fileName);
}
@TestMetadata("doesNotinlineValueOutsideOfScope.kt")
public void testDoesNotinlineValueOutsideOfScope() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/doesNotinlineValueOutsideOfScope.kt");
doTest(fileName);
}
@TestMetadata("emptyCondition.kt")
public void testEmptyCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/emptyCondition.kt");
doTest(fileName);
}
@TestMetadata("emptyElseBlock.kt")
public void testEmptyElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/emptyElseBlock.kt");
doTest(fileName);
}
@TestMetadata("emptyThenBlock.kt")
public void testEmptyThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/emptyThenBlock.kt");
doTest(fileName);
}
@TestMetadata("ifAndElseBothInBlocks.kt")
public void testIfAndElseBothInBlocks() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/ifAndElseBothInBlocks.kt");
doTest(fileName);
}
@TestMetadata("ifAndElseNotInBlocks.kt")
public void testIfAndElseNotInBlocks() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/ifAndElseNotInBlocks.kt");
doTest(fileName);
}
@TestMetadata("ifAsExpression.kt")
public void testIfAsExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/ifAsExpression.kt");
doTest(fileName);
}
@TestMetadata("implicitReceiver.kt")
public void testImplicitReceiver() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver.kt");
doTest(fileName);
}
@TestMetadata("isCheckSimple.kt")
public void testIsCheckSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/isCheckSimple.kt");
doTest(fileName);
}
@TestMetadata("isCheckWithSelectorChain.kt")
public void testIsCheckWithSelectorChain() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/isCheckWithSelectorChain.kt");
doTest(fileName);
}
@TestMetadata("isCondition.kt")
public void testIsCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/isCondition.kt");
doTest(fileName);
}
@TestMetadata("isNotCondition.kt")
public void testIsNotCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/isNotCondition.kt");
doTest(fileName);
}
@TestMetadata("isNotNullable.kt")
public void testIsNotNullable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/isNotNullable.kt");
doTest(fileName);
}
@TestMetadata("isNullable.kt")
public void testIsNullable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/isNullable.kt");
doTest(fileName);
}
@TestMetadata("lhsEqualsNull.kt")
public void testLhsEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/lhsEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("lhsNotEqualsNull.kt")
public void testLhsNotEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/lhsNotEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("missingNecessaryElseClause.kt")
public void testMissingNecessaryElseClause() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/missingNecessaryElseClause.kt");
doTest(fileName);
}
@TestMetadata("missingNecessaryThenClause.kt")
public void testMissingNecessaryThenClause() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/missingNecessaryThenClause.kt");
doTest(fileName);
}
@TestMetadata("noCondition.kt")
public void testNoCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/noCondition.kt");
doTest(fileName);
}
@TestMetadata("noElseBlock.kt")
public void testNoElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/noElseBlock.kt");
doTest(fileName);
}
@TestMetadata("noElseBlockAsExpression.kt")
public void testNoElseBlockAsExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/noElseBlockAsExpression.kt");
doTest(fileName);
}
@TestMetadata("noNullInCondition.kt")
public void testNoNullInCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/noNullInCondition.kt");
doTest(fileName);
}
@TestMetadata("noNullInCondition2.kt")
public void testNoNullInCondition2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/noNullInCondition2.kt");
doTest(fileName);
}
@TestMetadata("noThenBlock.kt")
public void testNoThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/noThenBlock.kt");
doTest(fileName);
}
@TestMetadata("notApplicableForFunction.kt")
public void testNotApplicableForFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/notApplicableForFunction.kt");
doTest(fileName);
}
@TestMetadata("notApplicableForLocalVar.kt")
public void testNotApplicableForLocalVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/notApplicableForLocalVar.kt");
doTest(fileName);
}
@TestMetadata("nullCheckSimple.kt")
public void testNullCheckSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/nullCheckSimple.kt");
doTest(fileName);
}
@TestMetadata("nullCheckWithSelectorCallChain.kt")
public void testNullCheckWithSelectorCallChain() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/nullCheckWithSelectorCallChain.kt");
doTest(fileName);
}
@TestMetadata("otherBlockHasMoreThanOneStatement.kt")
public void testOtherBlockHasMoreThanOneStatement() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/otherBlockHasMoreThanOneStatement.kt");
doTest(fileName);
}
@TestMetadata("property.kt")
public void testProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/property.kt");
doTest(fileName);
}
@TestMetadata("propertyNotNull.kt")
public void testPropertyNotNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/propertyNotNull.kt");
doTest(fileName);
}
@TestMetadata("propertyWithProperty.kt")
public void testPropertyWithProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/propertyWithProperty.kt");
doTest(fileName);
}
@TestMetadata("rhsEqualsNull.kt")
public void testRhsEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/rhsEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("rhsNotEqualsNull.kt")
public void testRhsNotEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/rhsNotEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("thenAndElseBothNull.kt")
public void testThenAndElseBothNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/thenAndElseBothNull.kt");
doTest(fileName);
}
@TestMetadata("thenAndElseNotNull.kt")
public void testThenAndElseNotNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/thenAndElseNotNull.kt");
doTest(fileName);
}
@TestMetadata("unacceptableEmptyElseBlock.kt")
public void testUnacceptableEmptyElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/unacceptableEmptyElseBlock.kt");
doTest(fileName);
}
@TestMetadata("unacceptableEmptyThenBlock.kt")
public void testUnacceptableEmptyThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/unacceptableEmptyThenBlock.kt");
doTest(fileName);
}
@TestMetadata("unacceptableNoElseBlock.kt")
public void testUnacceptableNoElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/unacceptableNoElseBlock.kt");
doTest(fileName);
}
@TestMetadata("unacceptableNoThenBlock.kt")
public void testUnacceptableNoThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/unacceptableNoThenBlock.kt");
doTest(fileName);
}
@TestMetadata("willNotInlineClassProperty.kt")
public void testWillNotInlineClassProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/willNotInlineClassProperty.kt");
doTest(fileName);
}
}
}
@TestMetadata("idea/testData/inspectionsLocal/canBeVal")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1814,297 +1814,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
}
}
@TestMetadata("idea/testData/intentions/branched/ifThenToSafeAccess")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class IfThenToSafeAccess extends AbstractIntentionTest {
public void testAllFilesPresentInIfThenToSafeAccess() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/branched/ifThenToSafeAccess"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("blockHasMoreThanOneStatement.kt")
public void testBlockHasMoreThanOneStatement() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/blockHasMoreThanOneStatement.kt");
doTest(fileName);
}
@TestMetadata("blockUsesDifferentVar.kt")
public void testBlockUsesDifferentVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/blockUsesDifferentVar.kt");
doTest(fileName);
}
@TestMetadata("conditionComparesNullWithNull.kt")
public void testConditionComparesNullWithNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/conditionComparesNullWithNull.kt");
doTest(fileName);
}
@TestMetadata("conditionInvalidBinaryExp.kt")
public void testConditionInvalidBinaryExp() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/conditionInvalidBinaryExp.kt");
doTest(fileName);
}
@TestMetadata("conditionNotBinaryExpr.kt")
public void testConditionNotBinaryExpr() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/conditionNotBinaryExpr.kt");
doTest(fileName);
}
@TestMetadata("doesNotinlineValueIfUsedMoreThanOnce.kt")
public void testDoesNotinlineValueIfUsedMoreThanOnce() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/doesNotinlineValueIfUsedMoreThanOnce.kt");
doTest(fileName);
}
@TestMetadata("doesNotinlineValueOutsideOfScope.kt")
public void testDoesNotinlineValueOutsideOfScope() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/doesNotinlineValueOutsideOfScope.kt");
doTest(fileName);
}
@TestMetadata("emptyCondition.kt")
public void testEmptyCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/emptyCondition.kt");
doTest(fileName);
}
@TestMetadata("emptyElseBlock.kt")
public void testEmptyElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/emptyElseBlock.kt");
doTest(fileName);
}
@TestMetadata("emptyThenBlock.kt")
public void testEmptyThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/emptyThenBlock.kt");
doTest(fileName);
}
@TestMetadata("ifAndElseBothInBlocks.kt")
public void testIfAndElseBothInBlocks() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/ifAndElseBothInBlocks.kt");
doTest(fileName);
}
@TestMetadata("ifAndElseNotInBlocks.kt")
public void testIfAndElseNotInBlocks() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/ifAndElseNotInBlocks.kt");
doTest(fileName);
}
@TestMetadata("ifAsExpression.kt")
public void testIfAsExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/ifAsExpression.kt");
doTest(fileName);
}
@TestMetadata("implicitReceiver.kt")
public void testImplicitReceiver() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/implicitReceiver.kt");
doTest(fileName);
}
@TestMetadata("isCheckSimple.kt")
public void testIsCheckSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/isCheckSimple.kt");
doTest(fileName);
}
@TestMetadata("isCheckWithSelectorChain.kt")
public void testIsCheckWithSelectorChain() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/isCheckWithSelectorChain.kt");
doTest(fileName);
}
@TestMetadata("isCondition.kt")
public void testIsCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/isCondition.kt");
doTest(fileName);
}
@TestMetadata("isNotCondition.kt")
public void testIsNotCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/isNotCondition.kt");
doTest(fileName);
}
@TestMetadata("isNotNullable.kt")
public void testIsNotNullable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/isNotNullable.kt");
doTest(fileName);
}
@TestMetadata("isNullable.kt")
public void testIsNullable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/isNullable.kt");
doTest(fileName);
}
@TestMetadata("lhsEqualsNull.kt")
public void testLhsEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/lhsEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("lhsNotEqualsNull.kt")
public void testLhsNotEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/lhsNotEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("missingNecessaryElseClause.kt")
public void testMissingNecessaryElseClause() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/missingNecessaryElseClause.kt");
doTest(fileName);
}
@TestMetadata("missingNecessaryThenClause.kt")
public void testMissingNecessaryThenClause() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/missingNecessaryThenClause.kt");
doTest(fileName);
}
@TestMetadata("noCondition.kt")
public void testNoCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/noCondition.kt");
doTest(fileName);
}
@TestMetadata("noElseBlock.kt")
public void testNoElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/noElseBlock.kt");
doTest(fileName);
}
@TestMetadata("noElseBlockAsExpression.kt")
public void testNoElseBlockAsExpression() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/noElseBlockAsExpression.kt");
doTest(fileName);
}
@TestMetadata("noNullInCondition.kt")
public void testNoNullInCondition() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/noNullInCondition.kt");
doTest(fileName);
}
@TestMetadata("noNullInCondition2.kt")
public void testNoNullInCondition2() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/noNullInCondition2.kt");
doTest(fileName);
}
@TestMetadata("noThenBlock.kt")
public void testNoThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/noThenBlock.kt");
doTest(fileName);
}
@TestMetadata("notApplicableForFunction.kt")
public void testNotApplicableForFunction() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/notApplicableForFunction.kt");
doTest(fileName);
}
@TestMetadata("notApplicableForLocalVar.kt")
public void testNotApplicableForLocalVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/notApplicableForLocalVar.kt");
doTest(fileName);
}
@TestMetadata("nullCheckSimple.kt")
public void testNullCheckSimple() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/nullCheckSimple.kt");
doTest(fileName);
}
@TestMetadata("nullCheckWithSelectorCallChain.kt")
public void testNullCheckWithSelectorCallChain() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/nullCheckWithSelectorCallChain.kt");
doTest(fileName);
}
@TestMetadata("otherBlockHasMoreThanOneStatement.kt")
public void testOtherBlockHasMoreThanOneStatement() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/otherBlockHasMoreThanOneStatement.kt");
doTest(fileName);
}
@TestMetadata("property.kt")
public void testProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/property.kt");
doTest(fileName);
}
@TestMetadata("propertyNotNull.kt")
public void testPropertyNotNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/propertyNotNull.kt");
doTest(fileName);
}
@TestMetadata("propertyWithProperty.kt")
public void testPropertyWithProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/propertyWithProperty.kt");
doTest(fileName);
}
@TestMetadata("rhsEqualsNull.kt")
public void testRhsEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/rhsEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("rhsNotEqualsNull.kt")
public void testRhsNotEqualsNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/rhsNotEqualsNull.kt");
doTest(fileName);
}
@TestMetadata("thenAndElseBothNull.kt")
public void testThenAndElseBothNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/thenAndElseBothNull.kt");
doTest(fileName);
}
@TestMetadata("thenAndElseNotNull.kt")
public void testThenAndElseNotNull() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/thenAndElseNotNull.kt");
doTest(fileName);
}
@TestMetadata("unacceptableEmptyElseBlock.kt")
public void testUnacceptableEmptyElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/unacceptableEmptyElseBlock.kt");
doTest(fileName);
}
@TestMetadata("unacceptableEmptyThenBlock.kt")
public void testUnacceptableEmptyThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/unacceptableEmptyThenBlock.kt");
doTest(fileName);
}
@TestMetadata("unacceptableNoElseBlock.kt")
public void testUnacceptableNoElseBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/unacceptableNoElseBlock.kt");
doTest(fileName);
}
@TestMetadata("unacceptableNoThenBlock.kt")
public void testUnacceptableNoThenBlock() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/unacceptableNoThenBlock.kt");
doTest(fileName);
}
@TestMetadata("willNotInlineClassProperty.kt")
public void testWillNotInlineClassProperty() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/branched/ifThenToSafeAccess/willNotInlineClassProperty.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/branched/ifWhen")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)