Skip to content

Commit

Permalink
[kotlin] K2: Port UnfoldAssignmentToIfIntention
Browse files Browse the repository at this point in the history
^KTIJ-32031 Fixed

GitOrigin-RevId: a50320d11f09db7cc4ab304c68ef87a5b049af97
  • Loading branch information
imbananko authored and intellij-monorepo-bot committed Dec 9, 2024
1 parent 19a9301 commit 34780c2
Show file tree
Hide file tree
Showing 28 changed files with 114 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,12 @@
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>

<intentionAction>
<language>kotlin</language>
<className>org.jetbrains.kotlin.idea.codeInsight.intentions.shared.UnfoldAssignmentToIfIntention</className>
<bundleName>messages.KotlinBundle</bundleName>
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>

</extensions>
</idea-plugin>
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.

package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions
package org.jetbrains.kotlin.idea.codeInsight.intentions.shared

import com.intellij.codeInsight.intention.LowPriorityAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils
import org.jetbrains.kotlin.idea.codeinsight.utils.BranchedUnfoldingUtils
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtIfExpression
Expand All @@ -25,5 +25,5 @@ class UnfoldAssignmentToIfIntention : SelfTargetingRangeIntention<KtBinaryExpres
return TextRange(element.startOffset, right.ifKeyword.endOffset)
}

override fun applyTo(element: KtBinaryExpression, editor: Editor?) = BranchedUnfoldingUtils.unfoldAssignmentToIf(element, editor)
override fun applyTo(element: KtBinaryExpression, editor: Editor?): Unit = BranchedUnfoldingUtils.unfoldAssignmentToIf(element, editor)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,55 @@ public void testNoUnderscores() throws Exception {
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/unfolding")
public abstract static class Unfolding extends AbstractSharedK1IntentionTest {
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/unfolding/assignmentToIf")
public static class AssignmentToIf extends AbstractSharedK1IntentionTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K1;
}

private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}

@TestMetadata("innerIfTransformed.kt")
public void testInnerIfTransformed() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/innerIfTransformed.kt");
}

@TestMetadata("nestedIfs.kt")
public void testNestedIfs() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/nestedIfs.kt");
}

@TestMetadata("simpleIf.kt")
public void testSimpleIf() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIf.kt");
}

@TestMetadata("simpleIfWithAugmentedAssignment.kt")
public void testSimpleIfWithAugmentedAssignment() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithAugmentedAssignment.kt");
}

@TestMetadata("simpleIfWithBlocks.kt")
public void testSimpleIfWithBlocks() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithBlocks.kt");
}

@TestMetadata("simpleIfWithComplexAssignmentLHS.kt")
public void testSimpleIfWithComplexAssignmentLHS() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithComplexAssignmentLHS.kt");
}

@TestMetadata("simpleIfWithoutAssignment.kt")
public void testSimpleIfWithoutAssignment() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithoutAssignment.kt");
}
}

@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/unfolding/functionCallToIf")
public static class FunctionCallToIf extends AbstractSharedK1IntentionTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2800,6 +2800,55 @@ public void testNoUnderscores() throws Exception {
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/unfolding")
public abstract static class Unfolding extends AbstractSharedK2IntentionTest {
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/unfolding/assignmentToIf")
public static class AssignmentToIf extends AbstractSharedK2IntentionTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K2;
}

private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}

@TestMetadata("innerIfTransformed.kt")
public void testInnerIfTransformed() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/innerIfTransformed.kt");
}

@TestMetadata("nestedIfs.kt")
public void testNestedIfs() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/nestedIfs.kt");
}

@TestMetadata("simpleIf.kt")
public void testSimpleIf() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIf.kt");
}

@TestMetadata("simpleIfWithAugmentedAssignment.kt")
public void testSimpleIfWithAugmentedAssignment() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithAugmentedAssignment.kt");
}

@TestMetadata("simpleIfWithBlocks.kt")
public void testSimpleIfWithBlocks() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithBlocks.kt");
}

@TestMetadata("simpleIfWithComplexAssignmentLHS.kt")
public void testSimpleIfWithComplexAssignmentLHS() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithComplexAssignmentLHS.kt");
}

@TestMetadata("simpleIfWithoutAssignment.kt")
public void testSimpleIfWithoutAssignment() throws Exception {
runTest("../testData/intentions/unfolding/assignmentToIf/simpleIfWithoutAssignment.kt");
}
}

@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/unfolding/functionCallToIf")
public static class FunctionCallToIf extends AbstractSharedK2IntentionTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.codeInsight.intentions.shared.UnfoldAssignmentToIfIntention
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.

package org.jetbrains.kotlin.idea.intentions.branchedTransformations
package org.jetbrains.kotlin.idea.codeinsight.utils

import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.base.psi.copied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils
import org.jetbrains.kotlin.idea.codeinsight.utils.BranchedUnfoldingUtils
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtBinaryExpression
import org.jetbrains.kotlin.psi.KtPsiUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils
import org.jetbrains.kotlin.idea.codeinsight.utils.BranchedUnfoldingUtils
import org.jetbrains.kotlin.idea.intentions.splitPropertyDeclaration
import org.jetbrains.kotlin.psi.KtIfExpression
import org.jetbrains.kotlin.psi.KtProperty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
import org.jetbrains.kotlin.idea.codeinsight.api.classic.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils
import org.jetbrains.kotlin.idea.codeinsight.utils.BranchedUnfoldingUtils
import org.jetbrains.kotlin.idea.intentions.splitPropertyDeclaration
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiUtil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3435,55 +3435,6 @@ public void testUsedInUncheckedIfExpression() throws Exception {
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/intentions/branched/unfolding")
public abstract static class Unfolding extends AbstractK1IntentionTest {
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/intentions/branched/unfolding/assignmentToIf")
public static class AssignmentToIf extends AbstractK1IntentionTest {
@java.lang.Override
@org.jetbrains.annotations.NotNull
public final KotlinPluginMode getPluginMode() {
return KotlinPluginMode.K1;
}

private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}

@TestMetadata("innerIfTransformed.kt")
public void testInnerIfTransformed() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/innerIfTransformed.kt");
}

@TestMetadata("nestedIfs.kt")
public void testNestedIfs() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/nestedIfs.kt");
}

@TestMetadata("simpleIf.kt")
public void testSimpleIf() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/simpleIf.kt");
}

@TestMetadata("simpleIfWithAugmentedAssignment.kt")
public void testSimpleIfWithAugmentedAssignment() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/simpleIfWithAugmentedAssignment.kt");
}

@TestMetadata("simpleIfWithBlocks.kt")
public void testSimpleIfWithBlocks() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/simpleIfWithBlocks.kt");
}

@TestMetadata("simpleIfWithComplexAssignmentLHS.kt")
public void testSimpleIfWithComplexAssignmentLHS() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/simpleIfWithComplexAssignmentLHS.kt");
}

@TestMetadata("simpleIfWithoutAssignment.kt")
public void testSimpleIfWithoutAssignment() throws Exception {
runTest("testData/intentions/branched/unfolding/assignmentToIf/simpleIfWithoutAssignment.kt");
}
}

@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/intentions/branched/unfolding/assignmentToWhen")
public static class AssignmentToWhen extends AbstractK1IntentionTest {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>

<intentionAction>
<language>kotlin</language>
<className>org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.UnfoldAssignmentToIfIntention</className>
<bundleName>messages.KotlinBundle</bundleName>
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>

<intentionAction>
<language>kotlin</language>
<className>org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.UnfoldPropertyToIfIntention</className>
Expand Down

0 comments on commit 34780c2

Please sign in to comment.