From f2accb7b9efc9bf02d6bfcac9b6e14ffc4a6c33d Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Mon, 3 Jun 2019 20:27:35 +0700 Subject: [PATCH] Convert IfThenToElvisIntention to inspection & decrease severity to INFO #KT-16067 Fixed --- idea/resources/META-INF/plugin-common.xml | 2 +- .../IfThenToElvisIntention/after.kt.template | 1 - .../IfThenToElvisIntention/before.kt.template | 1 - .../IfThenToElvisIntention/description.html | 5 - .../IfThenToElvisInspection.kt} | 111 ++++--- .../j2k/J2KPostProcessingRegistrarImpl.kt | 4 +- .../SmartCastImpossibleInIfThenFactory.kt | 10 +- .../branched/ifThenToElvis/.inspection | 1 + .../applicableForLocalStableVar.kt | 0 .../applicableForLocalStableVar.kt.after | 0 .../blockHasMoreThanOneStatement.kt | 2 +- .../ifThenToElvis/blockUsesDifferentVar.kt | 2 +- .../ifThenToElvis/comparisonInElse.kt | 0 .../ifThenToElvis/comparisonInElse.kt.after | 0 .../conditionComparesNullWithNull.kt | 2 +- .../conditionInvalidBinaryExp.kt | 2 +- .../ifThenToElvis/conditionNotBinaryExpr.kt | 2 +- ...doesNotInlineVariableInMultiDeclaration.kt | 0 ...tInlineVariableInMultiDeclaration.kt.after | 0 .../doesNotinlineValueIfUsedMoreThanOnce.kt | 0 ...sNotinlineValueIfUsedMoreThanOnce.kt.after | 0 .../doesNotinlineValueOutsideOfScope.kt | 0 .../doesNotinlineValueOutsideOfScope.kt.after | 0 .../branched/ifThenToElvis/emptyCondition.kt | 2 +- .../branched/ifThenToElvis/emptyElseBlock.kt | 2 +- .../branched/ifThenToElvis/emptyThenBlock.kt | 2 +- .../ifThenToElvis/extensionFunctionInClass.kt | 0 .../extensionFunctionInClass.kt.after | 0 .../ifThenToElvis/ifAndElseBothInBlocks.kt | 0 .../ifAndElseBothInBlocks.kt.after | 0 .../ifThenToElvis/ifAndElseNotInBlocks.kt | 0 .../ifAndElseNotInBlocks.kt.after | 0 .../branched/ifThenToElvis/ifAsExpression.kt | 0 .../ifThenToElvis/ifAsExpression.kt.after | 0 .../ifThenToElvis/ifAsPartOfExpression.kt | 0 .../ifAsPartOfExpression.kt.after | 0 .../ifThenToElvis/ifToElvisSwallowComments.kt | 0 .../ifToElvisSwallowComments.kt.after | 0 .../ifThenToElvis/implicitReceiver.kt | 0 .../ifThenToElvis/implicitReceiver.kt.after | 0 .../ifThenToElvis/inspectionData/expected.xml | 101 ++++++ .../inspectionData/inspections.test | 2 + .../branched/ifThenToElvis/isCheck.kt | 0 .../branched/ifThenToElvis/isCheck.kt.after | 0 .../ifThenToElvis/isCheckForNullableType.kt | 2 +- .../ifThenToElvis/isCheckForUnrelatedType.kt | 2 +- .../ifThenToElvis/isCheckWithSelector.kt | 0 .../isCheckWithSelector.kt.after | 0 .../ifThenToElvis/isCheckWithSelectorChain.kt | 0 .../isCheckWithSelectorChain.kt.after | 0 .../branched/ifThenToElvis/kt19666.kt | 0 .../branched/ifThenToElvis/kt19666.kt.after | 0 .../branched/ifThenToElvis/lhsEqualsNull.kt | 0 .../ifThenToElvis/lhsEqualsNull.kt.after | 0 .../ifThenToElvis/lhsNotEqualsNull.kt | 0 .../ifThenToElvis/lhsNotEqualsNull.kt.after | 0 .../ifThenToElvis/missingElseClause.kt | 2 +- .../ifThenToElvis/missingThenClause.kt | 2 +- .../branched/ifThenToElvis/noCondition.kt | 2 +- .../ifThenToElvis/noNullInCondition.kt | 2 +- .../ifThenToElvis/notApplicableForFunction.kt | 2 +- .../notApplicableForLocalUnstableVar.kt | 2 +- .../notApplicableForSimpleKotlinNPE.kt | 2 +- .../notApplicableForSimpleNPE.kt | 2 +- .../branched/ifThenToElvis/notIsCheck.kt | 0 .../ifThenToElvis/notIsCheck.kt.after | 0 .../ifThenToElvis/nullBranchAlsoNull.kt | 2 +- .../ifThenToElvis/nullCheckWithSelector.kt | 0 .../nullCheckWithSelector.kt.after | 0 .../nullCheckWithSelectorCall.kt | 0 .../nullCheckWithSelectorCall.kt.after | 0 .../nullCheckWithSelectorCallChain.kt | 0 .../nullCheckWithSelectorCallChain.kt.after | 0 .../nullableResultWithImplicitReceiver.kt | 2 +- .../branched/ifThenToElvis/nullableThen.kt | 2 +- .../otherBlockHasMoreThanOneStatement.kt | 2 +- .../branched/ifThenToElvis/replaceWithLet.kt | 0 .../ifThenToElvis/replaceWithLet.kt.after | 0 .../replaceWithLetAndRenameIt.kt | 0 .../replaceWithLetAndRenameIt.kt.after | 0 .../ifThenToElvis/replaceWithLetInMember.kt | 0 .../replaceWithLetInMember.kt.after | 0 .../replaceWithLetInMemberWithIs.kt | 0 .../replaceWithLetInMemberWithIs.kt.after | 0 .../branched/ifThenToElvis/rhsEqualsNull.kt | 0 .../ifThenToElvis/rhsEqualsNull.kt.after | 0 .../ifThenToElvis/rhsNotEqualsNull.kt | 0 .../ifThenToElvis/rhsNotEqualsNull.kt.after | 0 .../ifThenToElvis/thenAndElseBothNull.kt | 2 +- .../ifThenToElvis/throwsNPEwithArgument.kt | 0 .../throwsNPEwithArgument.kt.after | 0 .../branched/ifThenToElvis/unitResult.kt | 2 +- .../willNotInlineClassProperty.kt | 0 .../willNotInlineClassProperty.kt.after | 0 .../branched/ifThenToElvis/.intention | 1 - .../ifThenToElvis/inspectionData/expected.xml | 90 ------ .../inspectionData/inspections.test | 2 - .../codeInsight/InspectionTestGenerated.java | 10 +- .../LocalInspectionTestGenerated.java | 296 ++++++++++++++++++ .../intentions/IntentionTestGenerated.java | 296 ------------------ .../nj2k/postProcessing/J2kPostProcessor.kt | 4 +- 101 files changed, 498 insertions(+), 487 deletions(-) delete mode 100644 idea/resources/intentionDescriptions/IfThenToElvisIntention/after.kt.template delete mode 100644 idea/resources/intentionDescriptions/IfThenToElvisIntention/before.kt.template delete mode 100644 idea/resources/intentionDescriptions/IfThenToElvisIntention/description.html rename idea/src/org/jetbrains/kotlin/idea/{intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt => inspections/branchedTransformations/IfThenToElvisInspection.kt} (62%) create mode 100644 idea/testData/inspectionsLocal/branched/ifThenToElvis/.inspection rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/applicableForLocalStableVar.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/applicableForLocalStableVar.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt (90%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/blockUsesDifferentVar.kt (86%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/comparisonInElse.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/comparisonInElse.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/conditionComparesNullWithNull.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/conditionInvalidBinaryExp.kt (88%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/conditionNotBinaryExpr.kt (94%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/emptyCondition.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/emptyElseBlock.kt (84%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/emptyThenBlock.kt (86%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/extensionFunctionInClass.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/extensionFunctionInClass.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAndElseBothInBlocks.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAndElseBothInBlocks.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAndElseNotInBlocks.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAndElseNotInBlocks.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAsExpression.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAsExpression.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAsPartOfExpression.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifAsPartOfExpression.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifToElvisSwallowComments.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/ifToElvisSwallowComments.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/implicitReceiver.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/implicitReceiver.kt.after (100%) create mode 100644 idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/expected.xml create mode 100644 idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/inspections.test rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheck.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheck.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheckForNullableType.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheckForUnrelatedType.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheckWithSelector.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheckWithSelector.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheckWithSelectorChain.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/isCheckWithSelectorChain.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/kt19666.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/kt19666.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/lhsEqualsNull.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/lhsEqualsNull.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/lhsNotEqualsNull.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/lhsNotEqualsNull.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/missingElseClause.kt (82%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/missingThenClause.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/noCondition.kt (84%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/noNullInCondition.kt (86%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/notApplicableForFunction.kt (87%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt (92%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/notApplicableForSimpleNPE.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/notIsCheck.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/notIsCheck.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullBranchAlsoNull.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullCheckWithSelector.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullCheckWithSelector.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullCheckWithSelectorCall.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullCheckWithSelectorCall.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt (85%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/nullableThen.kt (82%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt (90%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLet.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLet.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLetInMember.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLetInMember.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/rhsEqualsNull.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/rhsEqualsNull.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/rhsNotEqualsNull.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/rhsNotEqualsNull.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/thenAndElseBothNull.kt (84%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/throwsNPEwithArgument.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/throwsNPEwithArgument.kt.after (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/unitResult.kt (87%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/willNotInlineClassProperty.kt (100%) rename idea/testData/{intentions => inspectionsLocal}/branched/ifThenToElvis/willNotInlineClassProperty.kt.after (100%) delete mode 100644 idea/testData/intentions/branched/ifThenToElvis/.intention delete mode 100644 idea/testData/intentions/branched/ifThenToElvis/inspectionData/expected.xml delete mode 100644 idea/testData/intentions/branched/ifThenToElvis/inspectionData/inspections.test diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index c4fce455b04..e4f83738640 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -1738,7 +1738,7 @@ language="kotlin" /> - - -This intention converts an if expression to an expression using an elvis operator (if applicable). - - diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToElvisInspection.kt similarity index 62% rename from idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt rename to idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToElvisInspection.kt index 87a6bd129e1..326a56944c2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/IfThenToElvisIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToElvisInspection.kt @@ -1,79 +1,65 @@ /* - * Copyright 2010-2015 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. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions +package org.jetbrains.kotlin.idea.inspections.branchedTransformations import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInspection.ui.MultipleCheckboxOptionsPanel import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.TextRange +import com.intellij.psi.PsiElement import org.jetbrains.kotlin.KtNodeTypes import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.core.replaced -import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection -import org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection -import org.jetbrains.kotlin.idea.intentions.SelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.inspections.AbstractApplicabilityBasedInspection import org.jetbrains.kotlin.idea.intentions.branchedTransformations.* import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset +import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression import org.jetbrains.kotlin.resolve.calls.callUtil.getType import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode +import javax.swing.JComponent -class IfThenToElvisInspection : IntentionBasedInspection( - IfThenToElvisIntention::class, - { it -> it.isUsedAsExpression(it.analyze(BodyResolveMode.PARTIAL_WITH_CFA)) } -) { - override fun inspectionTarget(element: KtIfExpression) = element.ifKeyword +class IfThenToElvisInspection( + @JvmField var highlightStatement: Boolean = false +) : AbstractApplicabilityBasedInspection(KtIfExpression::class.java) { + override fun inspectionText(element: KtIfExpression): String = "If-Then foldable to '?:'" - override fun problemHighlightType(element: KtIfExpression): ProblemHighlightType = - if (element.shouldBeTransformed()) super.problemHighlightType(element) else ProblemHighlightType.INFORMATION -} + override val defaultFixText: String = INTENTION_TEXT -class IfThenToElvisIntention : SelfTargetingOffsetIndependentIntention(KtIfExpression::class.java, intentionText) { + override fun isApplicable(element: KtIfExpression): Boolean = isApplicableTo(element, expressionShouldBeStable = true) - override fun isApplicableTo(element: KtIfExpression): Boolean = isApplicableTo(element, expressionShouldBeStable = true) + override fun inspectionHighlightType(element: KtIfExpression): ProblemHighlightType = + if (element.shouldBeTransformed() && (highlightStatement || element.isUsedAsExpression(element.analyze(BodyResolveMode.PARTIAL_WITH_CFA)))) + super.inspectionHighlightType(element) + else + ProblemHighlightType.INFORMATION - override fun startInWriteAction() = false + override fun applyTo(element: PsiElement, project: Project, editor: Editor?) { + convert( + element as KtIfExpression, + editor + ) + } - override fun applyTo(element: KtIfExpression, editor: Editor?) = convert(element, editor) + override fun inspectionRange(element: KtIfExpression): TextRange? = TextRange( + element.ifKeyword.startOffset, + element.condition?.endOffset ?: element.ifKeyword.endOffset + ).shiftLeft(element.startOffset) + + override fun createOptionsPanel(): JComponent? = MultipleCheckboxOptionsPanel(this).also { + it.addCheckbox("Report also on statement", "highlightStatement") + } companion object { - private fun KtExpression.isNullOrBlockExpression(): Boolean { - val innerExpression = this.unwrapBlockOrParenthesis() - return innerExpression is KtBlockExpression || innerExpression.node.elementType == KtNodeTypes.NULL - } - - private fun IfThenToSelectData.clausesReplaceableByElvis(): Boolean = - when { - baseClause == null || negatedClause == null || negatedClause.isNullOrBlockExpression() -> - false - negatedClause is KtThrowExpression && negatedClause.throwsNullPointerExceptionWithNoArguments() -> - false - baseClause.evaluatesTo(receiverExpression) -> - true - baseClause.anyArgumentEvaluatesTo(receiverExpression) -> - true - hasImplicitReceiverReplaceableBySafeCall() || baseClause.hasFirstReceiverOf(receiverExpression) -> - !baseClause.hasNullableType(context) - else -> - false - } - - val intentionText = "Replace 'if' expression with elvis expression" + const val INTENTION_TEXT = "Replace 'if' expression with elvis expression" fun convert(element: KtIfExpression, editor: Editor?) { val ifThenToSelectData = element.buildSelectTransformationData() ?: return @@ -114,5 +100,26 @@ class IfThenToElvisIntention : SelfTargetingOffsetIndependentIntention + false + negatedClause is KtThrowExpression && negatedClause.throwsNullPointerExceptionWithNoArguments() -> + false + baseClause.evaluatesTo(receiverExpression) -> + true + baseClause.anyArgumentEvaluatesTo(receiverExpression) -> + true + hasImplicitReceiverReplaceableBySafeCall() || baseClause.hasFirstReceiverOf(receiverExpression) -> + !baseClause.hasNullableType(context) + else -> + false + } } -} +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/j2k/J2KPostProcessingRegistrarImpl.kt b/idea/src/org/jetbrains/kotlin/idea/j2k/J2KPostProcessingRegistrarImpl.kt index 96d2bf7403f..2e4d3e88cde 100644 --- a/idea/src/org/jetbrains/kotlin/idea/j2k/J2KPostProcessingRegistrarImpl.kt +++ b/idea/src/org/jetbrains/kotlin/idea/j2k/J2KPostProcessingRegistrarImpl.kt @@ -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.IfThenToElvisInspection 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.isTrivialStatementBody import org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix import org.jetbrains.kotlin.idea.quickfix.RemoveUselessCastFix @@ -96,7 +96,7 @@ object J2KPostProcessingRegistrarImpl : J2KPostProcessingRegistrar { } registerInspectionBasedProcessing(IfThenToSafeAccessInspection()) - registerIntentionBasedProcessing(IfThenToElvisIntention()) + registerInspectionBasedProcessing(IfThenToElvisInspection(true)) registerInspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()) registerInspectionBasedProcessing(ReplaceGetOrSetInspection()) registerInspectionBasedProcessing(AddOperatorModifierInspection()) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SmartCastImpossibleInIfThenFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SmartCastImpossibleInIfThenFactory.kt index bab5ab5977f..3a6464cf1d2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SmartCastImpossibleInIfThenFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SmartCastImpossibleInIfThenFactory.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -9,8 +9,8 @@ import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToElvisInspection import org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention import org.jetbrains.kotlin.psi.KtContainerNodeForControlStructureBody import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtIfExpression @@ -32,9 +32,9 @@ object SmartCastImpossibleInIfThenFactory : KotlinIntentionActionsFactory() { ), createQuickFix( ifExpression, - { IfThenToElvisIntention.intentionText }, - { IfThenToElvisIntention.isApplicableTo(it, expressionShouldBeStable = false) }, - { ifExpr, _, editor -> IfThenToElvisIntention.convert(ifExpr, editor) } + { IfThenToElvisInspection.INTENTION_TEXT }, + { IfThenToElvisInspection.isApplicableTo(it, expressionShouldBeStable = false) }, + { ifExpr, _, editor -> IfThenToElvisInspection.convert(ifExpr, editor) } ) ) } diff --git a/idea/testData/inspectionsLocal/branched/ifThenToElvis/.inspection b/idea/testData/inspectionsLocal/branched/ifThenToElvis/.inspection new file mode 100644 index 00000000000..79b16636a2f --- /dev/null +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToElvisInspection \ No newline at end of file diff --git a/idea/testData/intentions/branched/ifThenToElvis/applicableForLocalStableVar.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/applicableForLocalStableVar.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/applicableForLocalStableVar.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/applicableForLocalStableVar.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/applicableForLocalStableVar.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/applicableForLocalStableVar.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/applicableForLocalStableVar.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/applicableForLocalStableVar.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt similarity index 90% rename from idea/testData/intentions/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt index 3e463b646da..2a253096810 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun doSomething(a: T) {} fun main(args: Array) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/blockUsesDifferentVar.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/blockUsesDifferentVar.kt similarity index 86% rename from idea/testData/intentions/branched/ifThenToElvis/blockUsesDifferentVar.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/blockUsesDifferentVar.kt index 72f13d277af..852733322fb 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/blockUsesDifferentVar.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/blockUsesDifferentVar.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo = null val a = "a" diff --git a/idea/testData/intentions/branched/ifThenToElvis/comparisonInElse.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/comparisonInElse.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/comparisonInElse.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/comparisonInElse.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/comparisonInElse.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/comparisonInElse.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/comparisonInElse.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/comparisonInElse.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/conditionComparesNullWithNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionComparesNullWithNull.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/conditionComparesNullWithNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionComparesNullWithNull.kt index e9474fc929e..6bedeeffffb 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/conditionComparesNullWithNull.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionComparesNullWithNull.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = "foo" if (null == null) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/conditionInvalidBinaryExp.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionInvalidBinaryExp.kt similarity index 88% rename from idea/testData/intentions/branched/ifThenToElvis/conditionInvalidBinaryExp.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionInvalidBinaryExp.kt index d4c091bf323..dcb96d98e37 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/conditionInvalidBinaryExp.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionInvalidBinaryExp.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none operator fun T.compareTo(a: T): Int = 0 fun main(args: Array) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/conditionNotBinaryExpr.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionNotBinaryExpr.kt similarity index 94% rename from idea/testData/intentions/branched/ifThenToElvis/conditionNotBinaryExpr.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionNotBinaryExpr.kt index 83c3f524995..49fcab73173 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/conditionNotBinaryExpr.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionNotBinaryExpr.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // ERROR: Type mismatch: inferred type is Int but Boolean was expected // ERROR: Type mismatch: inferred type is Int but Boolean was expected // ERROR: Operator call corresponds to a dot-qualified call 'foo.times(10)' which is not allowed on a nullable receiver 'foo'. diff --git a/idea/testData/intentions/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/emptyCondition.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyCondition.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/emptyCondition.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyCondition.kt index 3258b218fcf..3fe9ff19c8c 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/emptyCondition.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyCondition.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo = "foo" val bar = "foo" diff --git a/idea/testData/intentions/branched/ifThenToElvis/emptyElseBlock.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyElseBlock.kt similarity index 84% rename from idea/testData/intentions/branched/ifThenToElvis/emptyElseBlock.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyElseBlock.kt index 1864b505085..24e7db0ba4a 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/emptyElseBlock.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyElseBlock.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = null if (foo != null) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/emptyThenBlock.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyThenBlock.kt similarity index 86% rename from idea/testData/intentions/branched/ifThenToElvis/emptyThenBlock.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyThenBlock.kt index 0efaf8748bf..28de900f125 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/emptyThenBlock.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyThenBlock.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = "foo" val bar = "bar" diff --git a/idea/testData/intentions/branched/ifThenToElvis/extensionFunctionInClass.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/extensionFunctionInClass.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/extensionFunctionInClass.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/extensionFunctionInClass.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/extensionFunctionInClass.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/extensionFunctionInClass.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/extensionFunctionInClass.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/extensionFunctionInClass.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseBothInBlocks.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseBothInBlocks.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseBothInBlocks.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseBothInBlocks.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAndElseNotInBlocks.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseNotInBlocks.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAndElseNotInBlocks.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseNotInBlocks.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAndElseNotInBlocks.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseNotInBlocks.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAndElseNotInBlocks.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseNotInBlocks.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAsExpression.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsExpression.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAsExpression.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsExpression.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAsExpression.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsExpression.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAsExpression.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsExpression.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAsPartOfExpression.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsPartOfExpression.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAsPartOfExpression.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsPartOfExpression.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifAsPartOfExpression.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsPartOfExpression.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifAsPartOfExpression.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsPartOfExpression.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifToElvisSwallowComments.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifToElvisSwallowComments.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifToElvisSwallowComments.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifToElvisSwallowComments.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/ifToElvisSwallowComments.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/ifToElvisSwallowComments.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/ifToElvisSwallowComments.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/ifToElvisSwallowComments.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/implicitReceiver.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/implicitReceiver.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/implicitReceiver.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/implicitReceiver.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/implicitReceiver.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/implicitReceiver.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/implicitReceiver.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/implicitReceiver.kt.after diff --git a/idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/expected.xml b/idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/expected.xml new file mode 100644 index 00000000000..7e1777b5a4b --- /dev/null +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/expected.xml @@ -0,0 +1,101 @@ + + + ifAsPartOfExpression.kt + 8 + light_idea_test_case + ifAsPartOfExpression + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + comparisonInElse.kt + 8 + light_idea_test_case + comparisonInElse + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + willNotInlineClassProperty.kt + 3 + light_idea_test_case + willNotInlineClassProperty + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + applicableForLocalStableVar.kt + 8 + light_idea_test_case + applicableForLocalStableVar + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + nullCheckWithSelector.kt + 4 + light_idea_test_case + nullCheckWithSelector + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + nullCheckWithSelectorCall.kt + 5 + light_idea_test_case + nullCheckWithSelectorCall + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + implicitReceiver.kt + 2 + light_idea_test_case + implicitReceiver + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + nullCheckWithSelectorCallChain.kt + 5 + light_idea_test_case + nullCheckWithSelectorCallChain + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + extensionFunctionInClass.kt + 5 + light_idea_test_case + extensionFunctionInClass + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + doesNotInlineVariableInMultiDeclaration.kt + 7 + light_idea_test_case + doesNotInlineVariableInMultiDeclaration + + If-Then foldable to '?:' + If-Then foldable to '?:' + + + ifAsExpression.kt + 8 + light_idea_test_case + ifAsExpression + + If-Then foldable to '?:' + If-Then foldable to '?:' + + diff --git a/idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/inspections.test b/idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/inspections.test new file mode 100644 index 00000000000..5a880dbab9e --- /dev/null +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/inspections.test @@ -0,0 +1,2 @@ +// INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToElvisInspection +// WITH_RUNTIME diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheck.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheck.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/isCheck.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheck.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheck.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheck.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/isCheck.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheck.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheckForNullableType.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForNullableType.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/isCheckForNullableType.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForNullableType.kt index 22dc7735be9..53937ea1190 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/isCheckForNullableType.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForNullableType.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun foo(x: CharSequence?) { val y = if (x is String?) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheckForUnrelatedType.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForUnrelatedType.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/isCheckForUnrelatedType.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForUnrelatedType.kt index d5995260f0a..9248eaa92e5 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/isCheckForUnrelatedType.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForUnrelatedType.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none interface A interface B diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelector.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelector.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelector.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelector.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelector.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelector.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelector.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelector.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelectorChain.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelectorChain.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelectorChain.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelectorChain.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelectorChain.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelectorChain.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelectorChain.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelectorChain.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/kt19666.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/kt19666.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/kt19666.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/kt19666.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/kt19666.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/kt19666.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/kt19666.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/kt19666.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsEqualsNull.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsEqualsNull.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsEqualsNull.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsEqualsNull.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/lhsNotEqualsNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsNotEqualsNull.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/lhsNotEqualsNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsNotEqualsNull.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/lhsNotEqualsNull.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsNotEqualsNull.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/lhsNotEqualsNull.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsNotEqualsNull.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/missingElseClause.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/missingElseClause.kt similarity index 82% rename from idea/testData/intentions/branched/ifThenToElvis/missingElseClause.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/missingElseClause.kt index 3c6d197adb6..df4a840c668 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/missingElseClause.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/missingElseClause.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = "foo" if (foo == null) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/missingThenClause.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/missingThenClause.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/missingThenClause.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/missingThenClause.kt index d4a46e007d9..fd61a2b5f6a 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/missingThenClause.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/missingThenClause.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = "foo" val bar = "bar" diff --git a/idea/testData/intentions/branched/ifThenToElvis/noCondition.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/noCondition.kt similarity index 84% rename from idea/testData/intentions/branched/ifThenToElvis/noCondition.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/noCondition.kt index 4328f8a0770..bdee24d96ed 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/noCondition.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/noCondition.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = "foo" val bar = "bar" diff --git a/idea/testData/intentions/branched/ifThenToElvis/noNullInCondition.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/noNullInCondition.kt similarity index 86% rename from idea/testData/intentions/branched/ifThenToElvis/noNullInCondition.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/noNullInCondition.kt index 1fe611daf90..8095acf762d 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/noNullInCondition.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/noNullInCondition.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo = "foo" val bar = "bar" diff --git a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForFunction.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForFunction.kt similarity index 87% rename from idea/testData/intentions/branched/ifThenToElvis/notApplicableForFunction.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForFunction.kt index 44f4a4f982b..bb558eddd75 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForFunction.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForFunction.kt @@ -1,4 +1,4 @@ -//IS_APPLICABLE: false +// PROBLEM: none fun maybeFoo(): String? { return "foo" } diff --git a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt similarity index 92% rename from idea/testData/intentions/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt index ebb2b11cba0..4d8c8bb9fea 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt @@ -1,5 +1,5 @@ // WITH_RUNTIME -// IS_APPLICABLE: false +// PROBLEM: none fun maybeFoo(): String? { return "foo" } diff --git a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt index 6a1e90b294e..7111348dcb6 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun main(args: Array) { val t: String? = "abc" diff --git a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleNPE.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleNPE.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleNPE.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleNPE.kt index ef6fc01b6dd..1b4dd4e556d 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleNPE.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleNPE.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none // WITH_RUNTIME fun main(args: Array) { val t: String? = "abc" diff --git a/idea/testData/intentions/branched/ifThenToElvis/notIsCheck.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notIsCheck.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/notIsCheck.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/notIsCheck.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/notIsCheck.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/notIsCheck.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/notIsCheck.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/notIsCheck.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullBranchAlsoNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullBranchAlsoNull.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/nullBranchAlsoNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullBranchAlsoNull.kt index 11da5e88dfe..fac1308fefe 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/nullBranchAlsoNull.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullBranchAlsoNull.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo: String? = "foo" if (foo == null) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelector.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelector.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelector.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelector.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelector.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelector.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelector.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelector.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCall.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCall.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCall.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCall.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCall.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCall.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCall.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCall.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt similarity index 85% rename from idea/testData/intentions/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt index cec960ba1da..0c2d641c791 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none class Something { fun nullable(): Int? = null diff --git a/idea/testData/intentions/branched/ifThenToElvis/nullableThen.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableThen.kt similarity index 82% rename from idea/testData/intentions/branched/ifThenToElvis/nullableThen.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableThen.kt index 9b11a10d2df..2e8b98f5410 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/nullableThen.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableThen.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun foo(p: String?): String? { return if (p != null) p.bar() else "a" diff --git a/idea/testData/intentions/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt similarity index 90% rename from idea/testData/intentions/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt index 3149eb67e73..71de720f317 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun doSomething(a: T) {} fun main(args: Array) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLet.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLet.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLet.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLet.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLet.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLet.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLet.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLet.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMember.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMember.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMember.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMember.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMember.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMember.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMember.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMember.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/rhsEqualsNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsEqualsNull.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/rhsEqualsNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsEqualsNull.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/rhsEqualsNull.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsEqualsNull.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/rhsEqualsNull.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsEqualsNull.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/rhsNotEqualsNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsNotEqualsNull.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/rhsNotEqualsNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsNotEqualsNull.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/rhsNotEqualsNull.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsNotEqualsNull.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/rhsNotEqualsNull.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsNotEqualsNull.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/thenAndElseBothNull.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/thenAndElseBothNull.kt similarity index 84% rename from idea/testData/intentions/branched/ifThenToElvis/thenAndElseBothNull.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/thenAndElseBothNull.kt index 3bc679de523..a0264c87c4d 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/thenAndElseBothNull.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/thenAndElseBothNull.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none fun main(args: Array) { val foo = null if (foo == null) { diff --git a/idea/testData/intentions/branched/ifThenToElvis/throwsNPEwithArgument.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/throwsNPEwithArgument.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/throwsNPEwithArgument.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/throwsNPEwithArgument.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/throwsNPEwithArgument.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/throwsNPEwithArgument.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/throwsNPEwithArgument.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/throwsNPEwithArgument.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/unitResult.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/unitResult.kt similarity index 87% rename from idea/testData/intentions/branched/ifThenToElvis/unitResult.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/unitResult.kt index 03392306602..bc8f3f519a6 100644 --- a/idea/testData/intentions/branched/ifThenToElvis/unitResult.kt +++ b/idea/testData/inspectionsLocal/branched/ifThenToElvis/unitResult.kt @@ -1,4 +1,4 @@ -// IS_APPLICABLE: false +// PROBLEM: none open class Some { fun bar() {} diff --git a/idea/testData/intentions/branched/ifThenToElvis/willNotInlineClassProperty.kt b/idea/testData/inspectionsLocal/branched/ifThenToElvis/willNotInlineClassProperty.kt similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/willNotInlineClassProperty.kt rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/willNotInlineClassProperty.kt diff --git a/idea/testData/intentions/branched/ifThenToElvis/willNotInlineClassProperty.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToElvis/willNotInlineClassProperty.kt.after similarity index 100% rename from idea/testData/intentions/branched/ifThenToElvis/willNotInlineClassProperty.kt.after rename to idea/testData/inspectionsLocal/branched/ifThenToElvis/willNotInlineClassProperty.kt.after diff --git a/idea/testData/intentions/branched/ifThenToElvis/.intention b/idea/testData/intentions/branched/ifThenToElvis/.intention deleted file mode 100644 index 835cc19e7a9..00000000000 --- a/idea/testData/intentions/branched/ifThenToElvis/.intention +++ /dev/null @@ -1 +0,0 @@ -org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisIntention diff --git a/idea/testData/intentions/branched/ifThenToElvis/inspectionData/expected.xml b/idea/testData/intentions/branched/ifThenToElvis/inspectionData/expected.xml deleted file mode 100644 index 2c37332c12e..00000000000 --- a/idea/testData/intentions/branched/ifThenToElvis/inspectionData/expected.xml +++ /dev/null @@ -1,90 +0,0 @@ - - - willNotInlineClassProperty.kt - 3 - light_idea_test_case - - If-Then foldable to '?:'. - Replace 'if' expression with elvis expression - - - ifAsExpression.kt - 8 - light_idea_test_case - - If-Then foldable to '?:'. - Replace 'if' expression with elvis expression - - - ifAsPartOfExpression.kt - 8 - light_idea_test_case - - If-Then foldable to '?:'. - Replace 'if' expression with elvis expression - - - doesNotInlineVariableInMultiDeclaration.kt - 7 - light_idea_test_case - - If-Then foldable to '?:'. - Replace 'if' expression with elvis expression - - - nullCheckWithSelector.kt - 4 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - - nullCheckWithSelectorCall.kt - 5 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - - nullCheckWithSelectorCallChain.kt - 5 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - - comparisonInElse.kt - 8 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - - implicitReceiver.kt - 2 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - - applicableForLocalStableVar.kt - 8 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - - extensionFunctionInClass.kt - 5 - light_idea_test_case - - If-Then foldable to '?:' - Replace 'if' expression with elvis expression - - diff --git a/idea/testData/intentions/branched/ifThenToElvis/inspectionData/inspections.test b/idea/testData/intentions/branched/ifThenToElvis/inspectionData/inspections.test deleted file mode 100644 index 316e8697da5..00000000000 --- a/idea/testData/intentions/branched/ifThenToElvis/inspectionData/inspections.test +++ /dev/null @@ -1,2 +0,0 @@ -// INSPECTION_CLASS: org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.IfThenToElvisInspection -// WITH_RUNTIME diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java index e931ad44745..5328542b56d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/InspectionTestGenerated.java @@ -31,11 +31,6 @@ public class InspectionTestGenerated extends AbstractInspectionTest { KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/intentions"), Pattern.compile("^(inspections\\.test)$"), TargetBackend.ANY); } - @TestMetadata("branched/ifThenToElvis/inspectionData/inspections.test") - public void testBranched_ifThenToElvis_inspectionData_Inspections_test() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/inspectionData/inspections.test"); - } - @TestMetadata("convertToStringTemplate/inspectionData/inspections.test") public void testConvertToStringTemplate_inspectionData_Inspections_test() throws Exception { runTest("idea/testData/intentions/convertToStringTemplate/inspectionData/inspections.test"); @@ -467,6 +462,11 @@ public class InspectionTestGenerated extends AbstractInspectionTest { KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/inspectionsLocal"), Pattern.compile("^(inspections\\.test)$"), TargetBackend.ANY); } + @TestMetadata("branched/ifThenToElvis/inspectionData/inspections.test") + public void testBranched_ifThenToElvis_inspectionData_Inspections_test() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData/inspections.test"); + } + @TestMetadata("branched/ifThenToSafeAccess/inspectionData/inspections.test") public void testBranched_ifThenToSafeAccess_inspectionData_Inspections_test() throws Exception { runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/inspections.test"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 0efd48e8ce9..08fa66fbbcc 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -180,6 +180,302 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/branched"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); } + @TestMetadata("idea/testData/inspectionsLocal/branched/ifThenToElvis") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class IfThenToElvis extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInIfThenToElvis() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/branched/ifThenToElvis"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + + @TestMetadata("applicableForLocalStableVar.kt") + public void testApplicableForLocalStableVar() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/applicableForLocalStableVar.kt"); + } + + @TestMetadata("blockHasMoreThanOneStatement.kt") + public void testBlockHasMoreThanOneStatement() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt"); + } + + @TestMetadata("blockUsesDifferentVar.kt") + public void testBlockUsesDifferentVar() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/blockUsesDifferentVar.kt"); + } + + @TestMetadata("comparisonInElse.kt") + public void testComparisonInElse() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/comparisonInElse.kt"); + } + + @TestMetadata("conditionComparesNullWithNull.kt") + public void testConditionComparesNullWithNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionComparesNullWithNull.kt"); + } + + @TestMetadata("conditionInvalidBinaryExp.kt") + public void testConditionInvalidBinaryExp() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionInvalidBinaryExp.kt"); + } + + @TestMetadata("conditionNotBinaryExpr.kt") + public void testConditionNotBinaryExpr() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/conditionNotBinaryExpr.kt"); + } + + @TestMetadata("doesNotInlineVariableInMultiDeclaration.kt") + public void testDoesNotInlineVariableInMultiDeclaration() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt"); + } + + @TestMetadata("doesNotinlineValueIfUsedMoreThanOnce.kt") + public void testDoesNotinlineValueIfUsedMoreThanOnce() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt"); + } + + @TestMetadata("doesNotinlineValueOutsideOfScope.kt") + public void testDoesNotinlineValueOutsideOfScope() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt"); + } + + @TestMetadata("emptyCondition.kt") + public void testEmptyCondition() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyCondition.kt"); + } + + @TestMetadata("emptyElseBlock.kt") + public void testEmptyElseBlock() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyElseBlock.kt"); + } + + @TestMetadata("emptyThenBlock.kt") + public void testEmptyThenBlock() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/emptyThenBlock.kt"); + } + + @TestMetadata("extensionFunctionInClass.kt") + public void testExtensionFunctionInClass() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/extensionFunctionInClass.kt"); + } + + @TestMetadata("ifAndElseBothInBlocks.kt") + public void testIfAndElseBothInBlocks() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseBothInBlocks.kt"); + } + + @TestMetadata("ifAndElseNotInBlocks.kt") + public void testIfAndElseNotInBlocks() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAndElseNotInBlocks.kt"); + } + + @TestMetadata("ifAsExpression.kt") + public void testIfAsExpression() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsExpression.kt"); + } + + @TestMetadata("ifAsPartOfExpression.kt") + public void testIfAsPartOfExpression() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/ifAsPartOfExpression.kt"); + } + + @TestMetadata("ifToElvisSwallowComments.kt") + public void testIfToElvisSwallowComments() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/ifToElvisSwallowComments.kt"); + } + + @TestMetadata("implicitReceiver.kt") + public void testImplicitReceiver() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/implicitReceiver.kt"); + } + + @TestMetadata("isCheck.kt") + public void testIsCheck() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheck.kt"); + } + + @TestMetadata("isCheckForNullableType.kt") + public void testIsCheckForNullableType() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForNullableType.kt"); + } + + @TestMetadata("isCheckForUnrelatedType.kt") + public void testIsCheckForUnrelatedType() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckForUnrelatedType.kt"); + } + + @TestMetadata("isCheckWithSelector.kt") + public void testIsCheckWithSelector() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelector.kt"); + } + + @TestMetadata("isCheckWithSelectorChain.kt") + public void testIsCheckWithSelectorChain() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/isCheckWithSelectorChain.kt"); + } + + @TestMetadata("kt19666.kt") + public void testKt19666() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/kt19666.kt"); + } + + @TestMetadata("lhsEqualsNull.kt") + public void testLhsEqualsNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsEqualsNull.kt"); + } + + @TestMetadata("lhsNotEqualsNull.kt") + public void testLhsNotEqualsNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/lhsNotEqualsNull.kt"); + } + + @TestMetadata("missingElseClause.kt") + public void testMissingElseClause() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/missingElseClause.kt"); + } + + @TestMetadata("missingThenClause.kt") + public void testMissingThenClause() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/missingThenClause.kt"); + } + + @TestMetadata("noCondition.kt") + public void testNoCondition() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/noCondition.kt"); + } + + @TestMetadata("noNullInCondition.kt") + public void testNoNullInCondition() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/noNullInCondition.kt"); + } + + @TestMetadata("notApplicableForFunction.kt") + public void testNotApplicableForFunction() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForFunction.kt"); + } + + @TestMetadata("notApplicableForLocalUnstableVar.kt") + public void testNotApplicableForLocalUnstableVar() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt"); + } + + @TestMetadata("notApplicableForSimpleKotlinNPE.kt") + public void testNotApplicableForSimpleKotlinNPE() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt"); + } + + @TestMetadata("notApplicableForSimpleNPE.kt") + public void testNotApplicableForSimpleNPE() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/notApplicableForSimpleNPE.kt"); + } + + @TestMetadata("notIsCheck.kt") + public void testNotIsCheck() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/notIsCheck.kt"); + } + + @TestMetadata("nullBranchAlsoNull.kt") + public void testNullBranchAlsoNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/nullBranchAlsoNull.kt"); + } + + @TestMetadata("nullCheckWithSelector.kt") + public void testNullCheckWithSelector() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelector.kt"); + } + + @TestMetadata("nullCheckWithSelectorCall.kt") + public void testNullCheckWithSelectorCall() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCall.kt"); + } + + @TestMetadata("nullCheckWithSelectorCallChain.kt") + public void testNullCheckWithSelectorCallChain() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt"); + } + + @TestMetadata("nullableResultWithImplicitReceiver.kt") + public void testNullableResultWithImplicitReceiver() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt"); + } + + @TestMetadata("nullableThen.kt") + public void testNullableThen() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/nullableThen.kt"); + } + + @TestMetadata("otherBlockHasMoreThanOneStatement.kt") + public void testOtherBlockHasMoreThanOneStatement() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt"); + } + + @TestMetadata("replaceWithLet.kt") + public void testReplaceWithLet() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLet.kt"); + } + + @TestMetadata("replaceWithLetAndRenameIt.kt") + public void testReplaceWithLetAndRenameIt() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt"); + } + + @TestMetadata("replaceWithLetInMember.kt") + public void testReplaceWithLetInMember() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMember.kt"); + } + + @TestMetadata("replaceWithLetInMemberWithIs.kt") + public void testReplaceWithLetInMemberWithIs() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt"); + } + + @TestMetadata("rhsEqualsNull.kt") + public void testRhsEqualsNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsEqualsNull.kt"); + } + + @TestMetadata("rhsNotEqualsNull.kt") + public void testRhsNotEqualsNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/rhsNotEqualsNull.kt"); + } + + @TestMetadata("thenAndElseBothNull.kt") + public void testThenAndElseBothNull() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/thenAndElseBothNull.kt"); + } + + @TestMetadata("throwsNPEwithArgument.kt") + public void testThrowsNPEwithArgument() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/throwsNPEwithArgument.kt"); + } + + @TestMetadata("unitResult.kt") + public void testUnitResult() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/unitResult.kt"); + } + + @TestMetadata("willNotInlineClassProperty.kt") + public void testWillNotInlineClassProperty() throws Exception { + runTest("idea/testData/inspectionsLocal/branched/ifThenToElvis/willNotInlineClassProperty.kt"); + } + + @TestMetadata("idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InspectionData extends AbstractLocalInspectionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInInspectionData() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/branched/ifThenToElvis/inspectionData"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); + } + } + } + @TestMetadata("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 79d5de6d4d3..e749862fd69 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -2289,302 +2289,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest { } } - @TestMetadata("idea/testData/intentions/branched/ifThenToElvis") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class IfThenToElvis extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInIfThenToElvis() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/branched/ifThenToElvis"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - - @TestMetadata("applicableForLocalStableVar.kt") - public void testApplicableForLocalStableVar() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/applicableForLocalStableVar.kt"); - } - - @TestMetadata("blockHasMoreThanOneStatement.kt") - public void testBlockHasMoreThanOneStatement() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/blockHasMoreThanOneStatement.kt"); - } - - @TestMetadata("blockUsesDifferentVar.kt") - public void testBlockUsesDifferentVar() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/blockUsesDifferentVar.kt"); - } - - @TestMetadata("comparisonInElse.kt") - public void testComparisonInElse() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/comparisonInElse.kt"); - } - - @TestMetadata("conditionComparesNullWithNull.kt") - public void testConditionComparesNullWithNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/conditionComparesNullWithNull.kt"); - } - - @TestMetadata("conditionInvalidBinaryExp.kt") - public void testConditionInvalidBinaryExp() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/conditionInvalidBinaryExp.kt"); - } - - @TestMetadata("conditionNotBinaryExpr.kt") - public void testConditionNotBinaryExpr() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/conditionNotBinaryExpr.kt"); - } - - @TestMetadata("doesNotInlineVariableInMultiDeclaration.kt") - public void testDoesNotInlineVariableInMultiDeclaration() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/doesNotInlineVariableInMultiDeclaration.kt"); - } - - @TestMetadata("doesNotinlineValueIfUsedMoreThanOnce.kt") - public void testDoesNotinlineValueIfUsedMoreThanOnce() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueIfUsedMoreThanOnce.kt"); - } - - @TestMetadata("doesNotinlineValueOutsideOfScope.kt") - public void testDoesNotinlineValueOutsideOfScope() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/doesNotinlineValueOutsideOfScope.kt"); - } - - @TestMetadata("emptyCondition.kt") - public void testEmptyCondition() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/emptyCondition.kt"); - } - - @TestMetadata("emptyElseBlock.kt") - public void testEmptyElseBlock() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/emptyElseBlock.kt"); - } - - @TestMetadata("emptyThenBlock.kt") - public void testEmptyThenBlock() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/emptyThenBlock.kt"); - } - - @TestMetadata("extensionFunctionInClass.kt") - public void testExtensionFunctionInClass() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/extensionFunctionInClass.kt"); - } - - @TestMetadata("ifAndElseBothInBlocks.kt") - public void testIfAndElseBothInBlocks() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/ifAndElseBothInBlocks.kt"); - } - - @TestMetadata("ifAndElseNotInBlocks.kt") - public void testIfAndElseNotInBlocks() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/ifAndElseNotInBlocks.kt"); - } - - @TestMetadata("ifAsExpression.kt") - public void testIfAsExpression() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/ifAsExpression.kt"); - } - - @TestMetadata("ifAsPartOfExpression.kt") - public void testIfAsPartOfExpression() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/ifAsPartOfExpression.kt"); - } - - @TestMetadata("ifToElvisSwallowComments.kt") - public void testIfToElvisSwallowComments() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/ifToElvisSwallowComments.kt"); - } - - @TestMetadata("implicitReceiver.kt") - public void testImplicitReceiver() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/implicitReceiver.kt"); - } - - @TestMetadata("isCheck.kt") - public void testIsCheck() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/isCheck.kt"); - } - - @TestMetadata("isCheckForNullableType.kt") - public void testIsCheckForNullableType() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/isCheckForNullableType.kt"); - } - - @TestMetadata("isCheckForUnrelatedType.kt") - public void testIsCheckForUnrelatedType() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/isCheckForUnrelatedType.kt"); - } - - @TestMetadata("isCheckWithSelector.kt") - public void testIsCheckWithSelector() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelector.kt"); - } - - @TestMetadata("isCheckWithSelectorChain.kt") - public void testIsCheckWithSelectorChain() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/isCheckWithSelectorChain.kt"); - } - - @TestMetadata("kt19666.kt") - public void testKt19666() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/kt19666.kt"); - } - - @TestMetadata("lhsEqualsNull.kt") - public void testLhsEqualsNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/lhsEqualsNull.kt"); - } - - @TestMetadata("lhsNotEqualsNull.kt") - public void testLhsNotEqualsNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/lhsNotEqualsNull.kt"); - } - - @TestMetadata("missingElseClause.kt") - public void testMissingElseClause() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/missingElseClause.kt"); - } - - @TestMetadata("missingThenClause.kt") - public void testMissingThenClause() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/missingThenClause.kt"); - } - - @TestMetadata("noCondition.kt") - public void testNoCondition() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/noCondition.kt"); - } - - @TestMetadata("noNullInCondition.kt") - public void testNoNullInCondition() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/noNullInCondition.kt"); - } - - @TestMetadata("notApplicableForFunction.kt") - public void testNotApplicableForFunction() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/notApplicableForFunction.kt"); - } - - @TestMetadata("notApplicableForLocalUnstableVar.kt") - public void testNotApplicableForLocalUnstableVar() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/notApplicableForLocalUnstableVar.kt"); - } - - @TestMetadata("notApplicableForSimpleKotlinNPE.kt") - public void testNotApplicableForSimpleKotlinNPE() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleKotlinNPE.kt"); - } - - @TestMetadata("notApplicableForSimpleNPE.kt") - public void testNotApplicableForSimpleNPE() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/notApplicableForSimpleNPE.kt"); - } - - @TestMetadata("notIsCheck.kt") - public void testNotIsCheck() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/notIsCheck.kt"); - } - - @TestMetadata("nullBranchAlsoNull.kt") - public void testNullBranchAlsoNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/nullBranchAlsoNull.kt"); - } - - @TestMetadata("nullCheckWithSelector.kt") - public void testNullCheckWithSelector() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelector.kt"); - } - - @TestMetadata("nullCheckWithSelectorCall.kt") - public void testNullCheckWithSelectorCall() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCall.kt"); - } - - @TestMetadata("nullCheckWithSelectorCallChain.kt") - public void testNullCheckWithSelectorCallChain() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/nullCheckWithSelectorCallChain.kt"); - } - - @TestMetadata("nullableResultWithImplicitReceiver.kt") - public void testNullableResultWithImplicitReceiver() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/nullableResultWithImplicitReceiver.kt"); - } - - @TestMetadata("nullableThen.kt") - public void testNullableThen() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/nullableThen.kt"); - } - - @TestMetadata("otherBlockHasMoreThanOneStatement.kt") - public void testOtherBlockHasMoreThanOneStatement() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/otherBlockHasMoreThanOneStatement.kt"); - } - - @TestMetadata("replaceWithLet.kt") - public void testReplaceWithLet() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/replaceWithLet.kt"); - } - - @TestMetadata("replaceWithLetAndRenameIt.kt") - public void testReplaceWithLetAndRenameIt() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/replaceWithLetAndRenameIt.kt"); - } - - @TestMetadata("replaceWithLetInMember.kt") - public void testReplaceWithLetInMember() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMember.kt"); - } - - @TestMetadata("replaceWithLetInMemberWithIs.kt") - public void testReplaceWithLetInMemberWithIs() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/replaceWithLetInMemberWithIs.kt"); - } - - @TestMetadata("rhsEqualsNull.kt") - public void testRhsEqualsNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/rhsEqualsNull.kt"); - } - - @TestMetadata("rhsNotEqualsNull.kt") - public void testRhsNotEqualsNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/rhsNotEqualsNull.kt"); - } - - @TestMetadata("thenAndElseBothNull.kt") - public void testThenAndElseBothNull() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/thenAndElseBothNull.kt"); - } - - @TestMetadata("throwsNPEwithArgument.kt") - public void testThrowsNPEwithArgument() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/throwsNPEwithArgument.kt"); - } - - @TestMetadata("unitResult.kt") - public void testUnitResult() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/unitResult.kt"); - } - - @TestMetadata("willNotInlineClassProperty.kt") - public void testWillNotInlineClassProperty() throws Exception { - runTest("idea/testData/intentions/branched/ifThenToElvis/willNotInlineClassProperty.kt"); - } - - @TestMetadata("idea/testData/intentions/branched/ifThenToElvis/inspectionData") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class InspectionData extends AbstractIntentionTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); - } - - public void testAllFilesPresentInInspectionData() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/branched/ifThenToElvis/inspectionData"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true); - } - } - } - @TestMetadata("idea/testData/intentions/branched/ifWhen") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/J2kPostProcessor.kt b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/J2kPostProcessor.kt index ef5ec1c06c6..92d1f9d4877 100644 --- a/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/J2kPostProcessor.kt +++ b/nj2k/nj2k-services/src/org/jetbrains/kotlin/nj2k/postProcessing/J2kPostProcessor.kt @@ -22,12 +22,12 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference import org.jetbrains.kotlin.idea.core.util.EDT import org.jetbrains.kotlin.idea.formatter.commitAndUnblockDocument import org.jetbrains.kotlin.idea.inspections.* +import org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToElvisInspection 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.isNullExpression import org.jetbrains.kotlin.idea.intentions.branchedTransformations.isTrivialStatementBody import org.jetbrains.kotlin.idea.quickfix.* @@ -149,7 +149,7 @@ private val processings: List = listOf( inspectionBasedProcessing(IfThenToSafeAccessInspection()), inspectionBasedProcessing(IfThenToSafeAccessInspection()), - intentionBasedProcessing(IfThenToElvisIntention()), + inspectionBasedProcessing(IfThenToElvisInspection(true)), inspectionBasedProcessing(SimplifyNegatedBinaryExpressionInspection()), inspectionBasedProcessing(ReplaceGetOrSetInspection()), inspectionBasedProcessing(AddOperatorModifierInspection()),