diff --git a/annotations/com/intellij/codeInsight/intention/annotations.xml b/annotations/com/intellij/codeInsight/intention/annotations.xml new file mode 100644 index 00000000000..016e141fc58 --- /dev/null +++ b/annotations/com/intellij/codeInsight/intention/annotations.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/after.kt.template b/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/after.kt.template new file mode 100644 index 00000000000..10d7a35ac23 --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/after.kt.template @@ -0,0 +1,5 @@ +res = if (ok) { + "ok" +} else { + "failed" +} diff --git a/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/before.kt.template b/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/before.kt.template new file mode 100644 index 00000000000..556ea2de7b6 --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/before.kt.template @@ -0,0 +1,5 @@ +if (ok) { + res = "ok" +} else { + res = "failed" +} diff --git a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToAssignmentIntention/description.html b/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToAssignmentIntention/description.html rename to idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/description.html index 9a581e4ade0..284d93bc790 100644 --- a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToAssignmentIntention/description.html +++ b/idea/resources/intentionDescriptions/FoldIfToAssignmentIntention/description.html @@ -2,4 +2,4 @@ This intention converts 'if' expression where each branch is terminated with assignment into a single assignment with 'if' expression as a right-hand side - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/after.kt.template b/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/after.kt.template new file mode 100644 index 00000000000..43f2828d3dd --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/after.kt.template @@ -0,0 +1,3 @@ +return if (ok) { + "ok" +} else "failed" diff --git a/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/before.kt.template b/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/before.kt.template new file mode 100644 index 00000000000..70d505e1637 --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/before.kt.template @@ -0,0 +1,4 @@ +if (ok) { + return "ok" +} +return "failed" diff --git a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToReturnAsymmetricallyIntention/description.html b/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToReturnAsymmetricallyIntention/description.html rename to idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/description.html index d1df2972fb1..f2cbb9388f8 100644 --- a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToReturnAsymmetricallyIntention/description.html +++ b/idea/resources/intentionDescriptions/FoldIfToReturnAsymmetricallyIntention/description.html @@ -2,4 +2,4 @@ This intention converts single-branch 'if' expression immediately followed by 'return' into a single 'return' with 'if' expression as an argument - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/FoldIfToReturnIntention/after.kt.template b/idea/resources/intentionDescriptions/FoldIfToReturnIntention/after.kt.template new file mode 100644 index 00000000000..d930f801a5f --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldIfToReturnIntention/after.kt.template @@ -0,0 +1,5 @@ +return if (ok) { + "ok" +} else { + "failed" +} diff --git a/idea/resources/intentionDescriptions/FoldIfToReturnIntention/before.kt.template b/idea/resources/intentionDescriptions/FoldIfToReturnIntention/before.kt.template new file mode 100644 index 00000000000..ed1dec6fcc2 --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldIfToReturnIntention/before.kt.template @@ -0,0 +1,5 @@ +if (ok) { + return "ok" +} else { + return "failed" +} diff --git a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToReturnIntention/description.html b/idea/resources/intentionDescriptions/FoldIfToReturnIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToReturnIntention/description.html rename to idea/resources/intentionDescriptions/FoldIfToReturnIntention/description.html index e700394d8ff..74dc1dd7d5c 100644 --- a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldIfToReturnIntention/description.html +++ b/idea/resources/intentionDescriptions/FoldIfToReturnIntention/description.html @@ -2,4 +2,4 @@ This intention converts 'if' expression where each branch is terminated with 'return' into a single 'return' with 'if' expression as a right-hand side - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/after.kt.template b/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/after.kt.template new file mode 100644 index 00000000000..25effcc8557 --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/after.kt.template @@ -0,0 +1,5 @@ +res = when (n) { + 1 -> "one" + 2 -> "two" + else -> "many" +} diff --git a/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/before.kt.template b/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/before.kt.template new file mode 100644 index 00000000000..419247f332d --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/before.kt.template @@ -0,0 +1,5 @@ +when (n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = "many" +} diff --git a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldWhenToAssignmentIntention/description.html b/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldWhenToAssignmentIntention/description.html rename to idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/description.html index d90211f6b50..b22cfe66113 100644 --- a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldWhenToAssignmentIntention/description.html +++ b/idea/resources/intentionDescriptions/FoldWhenToAssignmentIntention/description.html @@ -2,4 +2,4 @@ This intention converts 'when' expression where each branch is terminated with assignment into a single assignment with 'when' expression as right-hand side - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/after.kt.template b/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/after.kt.template new file mode 100644 index 00000000000..7a228b1bf03 --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/after.kt.template @@ -0,0 +1,5 @@ +return when (n) { + 1 -> "one" + 2 -> "two" + else -> "many" +} diff --git a/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/before.kt.template b/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/before.kt.template new file mode 100644 index 00000000000..993f70971cb --- /dev/null +++ b/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/before.kt.template @@ -0,0 +1,5 @@ +when (n) { + 1 -> return "one" + 2 -> return "two" + else -> return "many" +} diff --git a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldWhenToReturnIntention/description.html b/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldWhenToReturnIntention/description.html rename to idea/resources/intentionDescriptions/FoldWhenToReturnIntention/description.html index 1101f0ea527..846a62ea0bc 100644 --- a/idea/resources/intentionDescriptions/FoldBranchedExpressionIntentionFoldWhenToReturnIntention/description.html +++ b/idea/resources/intentionDescriptions/FoldWhenToReturnIntention/description.html @@ -2,4 +2,4 @@ This intention converts 'when' expression where each branch is terminated with 'return' into a single 'return' with 'when' expression as a right-hand side - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/after.kt.template new file mode 100644 index 00000000000..556ea2de7b6 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/after.kt.template @@ -0,0 +1,5 @@ +if (ok) { + res = "ok" +} else { + res = "failed" +} diff --git a/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/before.kt.template new file mode 100644 index 00000000000..10d7a35ac23 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/before.kt.template @@ -0,0 +1,5 @@ +res = if (ok) { + "ok" +} else { + "failed" +} diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldAssignmentToIfIntention/description.html b/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/description.html similarity index 94% rename from idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldAssignmentToIfIntention/description.html rename to idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/description.html index 0491b178023..e7c3d41dad0 100644 --- a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldAssignmentToIfIntention/description.html +++ b/idea/resources/intentionDescriptions/UnfoldAssignmentToIfIntention/description.html @@ -2,4 +2,4 @@ This intention converts assignment with 'if' right-hand side to 'if' expression where each branch is terminated with assignment - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/after.kt.template new file mode 100644 index 00000000000..419247f332d --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/after.kt.template @@ -0,0 +1,5 @@ +when (n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = "many" +} diff --git a/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/before.kt.template new file mode 100644 index 00000000000..25effcc8557 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/before.kt.template @@ -0,0 +1,5 @@ +res = when (n) { + 1 -> "one" + 2 -> "two" + else -> "many" +} diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldAssignmentToWhenIntention/description.html b/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldAssignmentToWhenIntention/description.html rename to idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/description.html index 5c034ae4b11..4a5723c2234 100644 --- a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldAssignmentToWhenIntention/description.html +++ b/idea/resources/intentionDescriptions/UnfoldAssignmentToWhenIntention/description.html @@ -2,4 +2,4 @@ This intention converts assignment with 'when' right-hand side to 'when' expression where each branch is terminated with assignment - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/after.kt.template new file mode 100644 index 00000000000..bfe237c3fa7 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/after.kt.template @@ -0,0 +1,6 @@ +val res: String +if (ok) { + res = "ok" +} else { + res = "failed" +} diff --git a/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/before.kt.template new file mode 100644 index 00000000000..f79a3862532 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/before.kt.template @@ -0,0 +1,5 @@ +val res = if (ok) { + "ok" +} else { + "failed" +} diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/description.html b/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/description.html rename to idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/description.html index 275b2797db0..843740f571c 100644 --- a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/description.html +++ b/idea/resources/intentionDescriptions/UnfoldPropertyToIfIntention/description.html @@ -2,4 +2,4 @@ This intention converts property with 'if' initializer to uninitialized property followed by 'if' expression where each branch is terminated with assignment - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/after.kt.template new file mode 100644 index 00000000000..2233df601f8 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/after.kt.template @@ -0,0 +1,6 @@ +val res: String +when (n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = "many" +} diff --git a/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/before.kt.template new file mode 100644 index 00000000000..397e9587901 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/before.kt.template @@ -0,0 +1,5 @@ +val res = when (n) { + 1 -> "one" + 2 -> "two" + else -> "many" +} diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/description.html b/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/description.html rename to idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/description.html index 258d62e13d2..865ad4d930e 100644 --- a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/description.html +++ b/idea/resources/intentionDescriptions/UnfoldPropertyToWhenIntention/description.html @@ -2,4 +2,4 @@ This intention converts property with 'when' initializer to uninitialized property followed by 'when' expression where each branch is terminated with assignment - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/after.kt.template new file mode 100644 index 00000000000..ed1dec6fcc2 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/after.kt.template @@ -0,0 +1,5 @@ +if (ok) { + return "ok" +} else { + return "failed" +} diff --git a/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/before.kt.template new file mode 100644 index 00000000000..d930f801a5f --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/before.kt.template @@ -0,0 +1,5 @@ +return if (ok) { + "ok" +} else { + "failed" +} diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldReturnToIfIntention/description.html b/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldReturnToIfIntention/description.html rename to idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/description.html index b6ed03a21f3..432d89e350a 100644 --- a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldReturnToIfIntention/description.html +++ b/idea/resources/intentionDescriptions/UnfoldReturnToIfIntention/description.html @@ -2,4 +2,4 @@ This intention converts 'return' with 'if' expression as a result to 'if' expression where each branch is terminated with 'return' - \ No newline at end of file + diff --git a/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/after.kt.template new file mode 100644 index 00000000000..993f70971cb --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/after.kt.template @@ -0,0 +1,5 @@ +when (n) { + 1 -> return "one" + 2 -> return "two" + else -> return "many" +} diff --git a/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/before.kt.template new file mode 100644 index 00000000000..7a228b1bf03 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/before.kt.template @@ -0,0 +1,5 @@ +return when (n) { + 1 -> "one" + 2 -> "two" + else -> "many" +} diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldReturnToWhenIntention/description.html b/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/description.html similarity index 95% rename from idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldReturnToWhenIntention/description.html rename to idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/description.html index d28fc706aa2..101d8f4b6ba 100644 --- a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldReturnToWhenIntention/description.html +++ b/idea/resources/intentionDescriptions/UnfoldReturnToWhenIntention/description.html @@ -2,4 +2,4 @@ This intention converts 'return' with 'when' expression as a result to 'when' expression where each branch is terminated with 'return' - \ No newline at end of file + diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index aa8f8020d0e..7dcd637e835 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -365,57 +365,57 @@ - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldBranchedExpressionIntention$FoldIfToAssignmentIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldIfToAssignmentIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldBranchedExpressionIntention$FoldIfToReturnAsymmetricallyIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldIfToReturnAsymmetricallyIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldBranchedExpressionIntention$FoldIfToReturnIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldIfToReturnIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldBranchedExpressionIntention$FoldWhenToAssignmentIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldWhenToAssignmentIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldBranchedExpressionIntention$FoldWhenToReturnIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.FoldWhenToReturnIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldAssignmentToIfIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldAssignmentToIfIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldPropertyToIfIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldPropertyToIfIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldAssignmentToWhenIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldAssignmentToWhenIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldPropertyToWhenIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldPropertyToWhenIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldReturnToIfIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldReturnToIfIntention Kotlin - org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldReturnToWhenIntention + org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions.UnfoldReturnToWhenIntention Kotlin diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationIntention.java deleted file mode 100644 index e529ce7f4a1..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationIntention.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.intentions; - -import com.intellij.codeInsight.intention.impl.BaseIntentionAction; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.util.IncorrectOperationException; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetElement; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.psiUtil.PsiUtilPackage; -import org.jetbrains.jet.plugin.JetBundle; - -public abstract class AbstractCodeTransformationIntention extends BaseIntentionAction { - private final Transformer transformer; - private final Function1 isApplicable; - - protected AbstractCodeTransformationIntention(@NotNull Transformer transformer, @NotNull Function1 isApplicable) { - this.transformer = transformer; - this.isApplicable = isApplicable; - setText(JetBundle.message(transformer.getKey())); - } - - @Nullable - private PsiElement getTarget(@NotNull Editor editor, @NotNull PsiFile file) { - PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); - return PsiUtilPackage.getParentByTypeAndPredicate(element, JetElement.class, false, isApplicable); - } - - @NotNull - @Override - public String getFamilyName() { - return JetBundle.message(transformer.getKey() + ".family"); - } - - @Override - public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { - return getTarget(editor, file) != null; - } - - @Override - public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) throws IncorrectOperationException { - PsiElement target = getTarget(editor, file); - - assert target != null : "Intention is not applicable"; - - transformer.transform(target, editor, (JetFile) file); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/JetSelfTargetingIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/JetSelfTargetingIntention.kt new file mode 100644 index 00000000000..45593a2a78c --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/JetSelfTargetingIntention.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions + +import com.intellij.codeInsight.intention.impl.BaseIntentionAction +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.intellij.util.IncorrectOperationException +import jet.Function1 +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.lang.psi.JetElement +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.plugin.JetBundle +import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndPredicate + +public abstract class JetSelfTargetingIntention(val key: String, val elementType: Class) : BaseIntentionAction() { + { + setText(JetBundle.message(key)) + } + + protected abstract fun isApplicableTo(element: T): Boolean + protected abstract fun applyTo(element: T, editor: Editor) + + private fun getTarget(editor: Editor, file: PsiFile): T? { + val offset = editor.getCaretModel().getOffset() + return file.findElementAt(offset)?.getParentByTypeAndPredicate(elementType) { element -> isApplicableTo(element) } + } + + public override fun getFamilyName(): String { + return JetBundle.message(key + ".family") + } + + public override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean { + return getTarget(editor, file) != null + } + + public override fun invoke(project: Project, editor: Editor, file: PsiFile): Unit { + val target = getTarget(editor, file) + assert(target != null, "Intention is not applicable") + + applyTo(target!!, editor) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.java deleted file mode 100644 index ba09b31b5a9..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetWhenExpression; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.WhenUtils; -import org.jetbrains.jet.plugin.intentions.Transformer; - -public class EliminateWhenSubjectIntention extends AbstractCodeTransformationIntention { - private static final Transformer TRANSFORMER = new Transformer() { - @NotNull - @Override - public String getKey() { - return "eliminate.when.subject"; - } - - @Override - public void transform(@NotNull PsiElement element, @NotNull Editor editor, @NotNull JetFile file) { - WhenUtils.eliminateWhenSubject((JetWhenExpression) element); - } - }; - - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return input instanceof JetWhenExpression && WhenUtils.checkEliminateWhenSubject((JetWhenExpression) input); - } - }; - - public EliminateWhenSubjectIntention() { - super(TRANSFORMER, IS_APPLICABLE); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt new file mode 100644 index 00000000000..c13b375076a --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/EliminateWhenSubjectIntention.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.branchedTransformations.WhenUtils +import org.jetbrains.jet.lang.psi.JetWhenExpression +import com.intellij.openapi.editor.Editor + +public class EliminateWhenSubjectIntention : JetSelfTargetingIntention("eliminate.when.subject", javaClass()) { + override fun isApplicableTo(element: JetWhenExpression): Boolean = WhenUtils.checkEliminateWhenSubject(element) + + override fun applyTo(element: JetWhenExpression, editor: Editor) { + WhenUtils.eliminateWhenSubject(element) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FlattenWhenIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FlattenWhenIntention.java deleted file mode 100644 index 19f584b6076..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FlattenWhenIntention.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetWhenExpression; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.WhenUtils; -import org.jetbrains.jet.plugin.intentions.Transformer; - -public class FlattenWhenIntention extends AbstractCodeTransformationIntention { - private static final Transformer TRANSFORMER = new Transformer() { - @NotNull - @Override - public String getKey() { - return "flatten.when"; - } - - @Override - public void transform(@NotNull PsiElement element, @NotNull Editor editor, @NotNull JetFile file) { - WhenUtils.flattenWhen((JetWhenExpression) element); - } - }; - - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return input instanceof JetWhenExpression && WhenUtils.checkFlattenWhen((JetWhenExpression) input); - } - }; - - public FlattenWhenIntention() { - super(TRANSFORMER, IS_APPLICABLE); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt new file mode 100644 index 00000000000..19f0c34fcf2 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FlattenWhenIntention.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.branchedTransformations.WhenUtils +import org.jetbrains.jet.lang.psi.JetWhenExpression +import com.intellij.openapi.editor.Editor + +public class FlattenWhenIntention : JetSelfTargetingIntention("flatten.when", javaClass()) { + override fun isApplicableTo(element: JetWhenExpression): Boolean = WhenUtils.checkFlattenWhen(element) + + override fun applyTo(element: JetWhenExpression, editor: Editor) { + WhenUtils.flattenWhen(element) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.java deleted file mode 100644 index 4887031adc5..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.BranchedFoldingUtils; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.FoldableKind; - -public abstract class FoldBranchedExpressionIntention extends AbstractCodeTransformationIntention { - protected FoldBranchedExpressionIntention(@NotNull final FoldableKind foldableKind) { - super( - foldableKind, - new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return (input instanceof JetExpression) && BranchedFoldingUtils.getFoldableExpressionKind((JetExpression) input) == foldableKind; - } - } - ); - } - - public static class FoldIfToAssignmentIntention extends FoldBranchedExpressionIntention { - public FoldIfToAssignmentIntention() { - super(FoldableKind.IF_TO_ASSIGNMENT); - } - } - - public static class FoldIfToReturnAsymmetricallyIntention extends FoldBranchedExpressionIntention { - public FoldIfToReturnAsymmetricallyIntention() { - super(FoldableKind.IF_TO_RETURN_ASYMMETRICALLY); - } - } - - public static class FoldIfToReturnIntention extends FoldBranchedExpressionIntention { - public FoldIfToReturnIntention() { - super(FoldableKind.IF_TO_RETURN); - } - } - - public static class FoldWhenToAssignmentIntention extends FoldBranchedExpressionIntention { - public FoldWhenToAssignmentIntention() { - super(FoldableKind.WHEN_TO_ASSIGNMENT); - } - } - - public static class FoldWhenToReturnIntention extends FoldBranchedExpressionIntention { - public FoldWhenToReturnIntention() { - super(FoldableKind.WHEN_TO_RETURN); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt new file mode 100644 index 00000000000..504f6f908e4 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/FoldBranchedExpressionIntention.kt @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import com.intellij.psi.PsiElement +import jet.Function1 +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.lang.psi.JetExpression +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.branchedTransformations.BranchedFoldingUtils +import org.jetbrains.jet.plugin.intentions.branchedTransformations.FoldableKind +import org.jetbrains.jet.lang.psi.JetElement +import com.intellij.openapi.editor.Editor +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.psi.JetIfExpression +import org.jetbrains.jet.lang.psi.JetWhenExpression + +public open class FoldBranchedExpressionIntention( + val kind: FoldableKind, elementType: Class +) : JetSelfTargetingIntention(kind.getKey(), elementType) { + override fun isApplicableTo(element: T): Boolean = BranchedFoldingUtils.getFoldableExpressionKind(element) == kind + + override fun applyTo(element: T, editor: Editor) { + val file = element.getContainingFile() + if (file is JetFile) { + kind.transform(element, editor, file) + } + } +} + +public class FoldIfToAssignmentIntention : FoldBranchedExpressionIntention(FoldableKind.IF_TO_ASSIGNMENT, javaClass()) + +public class FoldIfToReturnAsymmetricallyIntention : FoldBranchedExpressionIntention( + FoldableKind.IF_TO_RETURN_ASYMMETRICALLY, javaClass() +) + +public class FoldIfToReturnIntention : FoldBranchedExpressionIntention(FoldableKind.IF_TO_RETURN, javaClass()) + +public class FoldWhenToAssignmentIntention : FoldBranchedExpressionIntention( + FoldableKind.WHEN_TO_ASSIGNMENT, javaClass() +) + +public class FoldWhenToReturnIntention : FoldBranchedExpressionIntention(FoldableKind.WHEN_TO_RETURN, javaClass()) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfToWhenIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfToWhenIntention.java deleted file mode 100644 index 841974e2a21..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfToWhenIntention.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetIfExpression; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.IfWhenUtils; -import org.jetbrains.jet.plugin.intentions.Transformer; - -public class IfToWhenIntention extends AbstractCodeTransformationIntention { - private static final Transformer TRANSFORMER = new Transformer() { - @NotNull - @Override - public String getKey() { - return "if.to.when"; - } - - @Override - public void transform(@NotNull PsiElement element, @NotNull Editor editor, @NotNull JetFile file) { - IfWhenUtils.transformIfToWhen((JetIfExpression) element); - } - }; - - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return (input instanceof JetIfExpression) && IfWhenUtils.checkIfToWhen((JetIfExpression) input); - } - }; - - public IfToWhenIntention() { - super(TRANSFORMER, IS_APPLICABLE); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfToWhenIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfToWhenIntention.kt new file mode 100644 index 00000000000..6989b683b79 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IfToWhenIntention.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.branchedTransformations.IfWhenUtils +import org.jetbrains.jet.lang.psi.JetWhenExpression +import org.jetbrains.jet.lang.psi.JetIfExpression +import com.intellij.openapi.editor.Editor + +public class IfToWhenIntention : JetSelfTargetingIntention("if.to.when", javaClass()) { + override fun isApplicableTo(element: JetIfExpression): Boolean = IfWhenUtils.checkIfToWhen(element) + + override fun applyTo(element: JetIfExpression, editor: Editor) { + IfWhenUtils.transformIfToWhen(element) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.java deleted file mode 100644 index 2b41543e477..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetWhenExpression; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.WhenUtils; -import org.jetbrains.jet.plugin.intentions.Transformer; - -public class IntroduceWhenSubjectIntention extends AbstractCodeTransformationIntention { - private static final Transformer TRANSFORMER = new Transformer() { - @NotNull - @Override - public String getKey() { - return "introduce.when.subject"; - } - - @Override - public void transform(@NotNull PsiElement element, @NotNull Editor editor, @NotNull JetFile file) { - WhenUtils.introduceWhenSubject((JetWhenExpression) element); - } - }; - - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return input instanceof JetWhenExpression && WhenUtils.checkIntroduceWhenSubject((JetWhenExpression) input); - } - }; - - public IntroduceWhenSubjectIntention() { - super(TRANSFORMER, IS_APPLICABLE); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt new file mode 100644 index 00000000000..77796818029 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/IntroduceWhenSubjectIntention.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.branchedTransformations.WhenUtils +import org.jetbrains.jet.lang.psi.JetWhenExpression +import com.intellij.openapi.editor.Editor + +public class IntroduceWhenSubjectIntention : JetSelfTargetingIntention("introduce.when.subject", javaClass()) { + override fun isApplicableTo(element: JetWhenExpression): Boolean = WhenUtils.checkIntroduceWhenSubject(element) + + override fun applyTo(element: JetWhenExpression, editor: Editor) { + WhenUtils.introduceWhenSubject(element) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java deleted file mode 100644 index d90682878f3..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetExpression; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.*; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; - -public abstract class UnfoldBranchedExpressionIntention extends AbstractCodeTransformationIntention { - protected UnfoldBranchedExpressionIntention(@NotNull final UnfoldableKind unfoldableKind) { - super( - unfoldableKind, - new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return (input instanceof JetExpression) && BranchedUnfoldingUtils.getUnfoldableExpressionKind((JetExpression) input) == unfoldableKind; - } - } - ); - } - - public static class UnfoldAssignmentToIfIntention extends UnfoldBranchedExpressionIntention { - public UnfoldAssignmentToIfIntention() { - super(UnfoldableKind.ASSIGNMENT_TO_IF); - } - } - - public static class UnfoldPropertyToIfIntention extends UnfoldBranchedExpressionIntention { - public UnfoldPropertyToIfIntention() { - super(UnfoldableKind.PROPERTY_TO_IF); - } - } - - public static class UnfoldAssignmentToWhenIntention extends UnfoldBranchedExpressionIntention { - public UnfoldAssignmentToWhenIntention() { - super(UnfoldableKind.ASSIGNMENT_TO_WHEN); - } - } - - public static class UnfoldPropertyToWhenIntention extends UnfoldBranchedExpressionIntention { - public UnfoldPropertyToWhenIntention() { - super(UnfoldableKind.PROPERTY_TO_WHEN); - } - } - - public static class UnfoldReturnToIfIntention extends UnfoldBranchedExpressionIntention { - public UnfoldReturnToIfIntention() { - super(UnfoldableKind.RETURN_TO_IF); - } - } - - public static class UnfoldReturnToWhenIntention extends UnfoldBranchedExpressionIntention { - public UnfoldReturnToWhenIntention() { - super(UnfoldableKind.RETURN_TO_WHEN); - } - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt new file mode 100644 index 00000000000..3e2c61f146d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import com.intellij.psi.PsiElement +import jet.Function1 +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.lang.psi.JetExpression +import org.jetbrains.jet.plugin.intentions.branchedTransformations.* +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import com.intellij.openapi.editor.Editor +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.psi.JetBinaryExpression +import org.jetbrains.jet.lang.psi.JetReturnExpression +import org.jetbrains.jet.lang.psi.JetProperty + +public open class UnfoldBranchedExpressionIntention( + val kind: UnfoldableKind, elementType: Class +) : JetSelfTargetingIntention(kind.getKey(), elementType) { + override fun isApplicableTo(element: T): Boolean = BranchedUnfoldingUtils.getUnfoldableExpressionKind(element) == kind + + override fun applyTo(element: T, editor: Editor) { + val file = element.getContainingFile() + if (file is JetFile) { + kind.transform(element, editor, file) + } + } +} + +public class UnfoldAssignmentToIfIntention : UnfoldBranchedExpressionIntention( + UnfoldableKind.ASSIGNMENT_TO_IF, javaClass() +) + +public class UnfoldPropertyToIfIntention : UnfoldBranchedExpressionIntention( + UnfoldableKind.PROPERTY_TO_IF, javaClass() +) + +public class UnfoldAssignmentToWhenIntention : UnfoldBranchedExpressionIntention( + UnfoldableKind.ASSIGNMENT_TO_WHEN, javaClass() +) + +public class UnfoldPropertyToWhenIntention : UnfoldBranchedExpressionIntention( + UnfoldableKind.PROPERTY_TO_WHEN, javaClass() +) + +public class UnfoldReturnToIfIntention : UnfoldBranchedExpressionIntention( + UnfoldableKind.RETURN_TO_IF, javaClass() +) + +public class UnfoldReturnToWhenIntention : UnfoldBranchedExpressionIntention( + UnfoldableKind.RETURN_TO_WHEN, javaClass() +) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/WhenToIfIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/WhenToIfIntention.java deleted file mode 100644 index 4fc251aa21a..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/WhenToIfIntention.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions; - -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetWhenExpression; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.branchedTransformations.IfWhenUtils; -import org.jetbrains.jet.plugin.intentions.Transformer; - -public class WhenToIfIntention extends AbstractCodeTransformationIntention { - private static final Transformer TRANSFORMER = new Transformer() { - @NotNull - @Override - public String getKey() { - return "when.to.if"; - } - - @Override - public void transform(@NotNull PsiElement element, @NotNull Editor editor, @NotNull JetFile file) { - IfWhenUtils.transformWhenToIf((JetWhenExpression) element); - } - }; - - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return (input instanceof JetWhenExpression) && IfWhenUtils.checkWhenToIf((JetWhenExpression) input); - } - }; - - public WhenToIfIntention() { - super(TRANSFORMER, IS_APPLICABLE); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/WhenToIfIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/WhenToIfIntention.kt new file mode 100644 index 00000000000..eb0242058a1 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/branchedTransformations/intentions/WhenToIfIntention.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.branchedTransformations.intentions + +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.branchedTransformations.IfWhenUtils +import org.jetbrains.jet.lang.psi.JetWhenExpression +import org.jetbrains.jet.lang.psi.JetIfExpression +import com.intellij.openapi.editor.Editor + +public class WhenToIfIntention : JetSelfTargetingIntention("if.to.when", javaClass()) { + override fun isApplicableTo(element: JetWhenExpression): Boolean = IfWhenUtils.checkWhenToIf(element) + + override fun applyTo(element: JetWhenExpression, editor: Editor) { + IfWhenUtils.transformWhenToIf(element) + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.java b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.java deleted file mode 100644 index a0b489c843c..00000000000 --- a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.plugin.intentions.declarations; - -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import jet.Function1; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.psi.JetFile; -import org.jetbrains.jet.lang.psi.JetProperty; -import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationIntention; -import org.jetbrains.jet.plugin.intentions.Transformer; - -public class SplitPropertyDeclarationIntention extends AbstractCodeTransformationIntention { - private static final Transformer TRANSFORMER = new Transformer() { - @NotNull - @Override - public String getKey() { - return "split.property.declaration"; - } - - @Override - public void transform(@NotNull PsiElement element, @NotNull Editor editor, @NotNull JetFile file) { - DeclarationUtils.splitPropertyDeclaration((JetProperty) element, file); - } - }; - - private static final Function1 IS_APPLICABLE = new Function1() { - @Override - public Boolean invoke(@Nullable PsiElement input) { - return (input instanceof JetProperty) && DeclarationUtils.checkSplitProperty((JetProperty) input); - } - }; - - public SplitPropertyDeclarationIntention() { - super(TRANSFORMER, IS_APPLICABLE); - } -} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt new file mode 100644 index 00000000000..86aba6b53a4 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/declarations/SplitPropertyDeclarationIntention.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.intentions.declarations + +import com.intellij.openapi.editor.Editor +import com.intellij.psi.PsiElement +import jet.Function1 +import org.jetbrains.annotations.Nullable +import org.jetbrains.jet.lang.psi.JetFile +import org.jetbrains.jet.lang.psi.JetProperty +import org.jetbrains.jet.plugin.intentions.JetSelfTargetingIntention +import org.jetbrains.jet.plugin.intentions.Transformer + +public class SplitPropertyDeclarationIntention : JetSelfTargetingIntention("split.property.declaration", javaClass()) { + override fun isApplicableTo(element: JetProperty): Boolean = DeclarationUtils.checkSplitProperty(element) + + override fun applyTo(element: JetProperty, editor: Editor) { + val file = element.getContainingFile() + if (file is JetFile) { + DeclarationUtils.splitPropertyDeclaration(element, file) + } + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java index e5aee15a1fe..71997f24fe3 100644 --- a/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/AbstractCodeTransformationTest.java @@ -31,47 +31,47 @@ import java.io.File; public abstract class AbstractCodeTransformationTest extends LightCodeInsightTestCase { public void doTestFoldIfToAssignment(@NotNull String path) throws Exception { - doTestIntention(path, new FoldBranchedExpressionIntention.FoldIfToAssignmentIntention()); + doTestIntention(path, new FoldIfToAssignmentIntention()); } public void doTestFoldIfToReturn(@NotNull String path) throws Exception { - doTestIntention(path, new FoldBranchedExpressionIntention.FoldIfToReturnIntention()); + doTestIntention(path, new FoldIfToReturnIntention()); } public void doTestFoldIfToReturnAsymmetrically(@NotNull String path) throws Exception { - doTestIntention(path, new FoldBranchedExpressionIntention.FoldIfToReturnAsymmetricallyIntention()); + doTestIntention(path, new FoldIfToReturnAsymmetricallyIntention()); } public void doTestFoldWhenToAssignment(@NotNull String path) throws Exception { - doTestIntention(path, new FoldBranchedExpressionIntention.FoldWhenToAssignmentIntention()); + doTestIntention(path, new FoldWhenToAssignmentIntention()); } public void doTestFoldWhenToReturn(@NotNull String path) throws Exception { - doTestIntention(path, new FoldBranchedExpressionIntention.FoldWhenToReturnIntention()); + doTestIntention(path, new FoldWhenToReturnIntention()); } public void doTestUnfoldAssignmentToIf(@NotNull String path) throws Exception { - doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToIfIntention()); + doTestIntention(path, new UnfoldAssignmentToIfIntention()); } public void doTestUnfoldAssignmentToWhen(@NotNull String path) throws Exception { - doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToWhenIntention()); + doTestIntention(path, new UnfoldAssignmentToWhenIntention()); } public void doTestUnfoldPropertyToIf(@NotNull String path) throws Exception { - doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToIfIntention()); + doTestIntention(path, new UnfoldPropertyToIfIntention()); } public void doTestUnfoldPropertyToWhen(@NotNull String path) throws Exception { - doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToWhenIntention()); + doTestIntention(path, new UnfoldPropertyToWhenIntention()); } public void doTestUnfoldReturnToIf(@NotNull String path) throws Exception { - doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToIfIntention()); + doTestIntention(path, new UnfoldReturnToIfIntention()); } public void doTestUnfoldReturnToWhen(@NotNull String path) throws Exception { - doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToWhenIntention()); + doTestIntention(path, new UnfoldReturnToWhenIntention()); } public void doTestIfToWhen(@NotNull String path) throws Exception {