diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index 7f1f7e3093e..829fc43661d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -743,6 +743,11 @@ public class JetPsiUtil { return element != null ? element.getText() : ""; } + @Nullable + public static String getNullableText(@Nullable PsiElement element) { + return element != null ? element.getText() : null; + } + /** * CommentUtilCore.isComment fails if element inside comment. * diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index aa82e896ad7..15be16c3bc8 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -330,6 +330,8 @@ public class GenerateTests { testModel("idea/testData/codeInsight/codeTransformations/branched/folding/whenToReturn", "doTestFoldWhenToReturn"), testModel("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToIf", "doTestUnfoldAssignmentToIf"), testModel("idea/testData/codeInsight/codeTransformations/branched/unfolding/assignmentToWhen", "doTestUnfoldAssignmentToWhen"), + testModel("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf", "doTestUnfoldPropertyToIf"), + testModel("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen", "doTestUnfoldPropertyToWhen"), testModel("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToIf", "doTestUnfoldReturnToIf"), testModel("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToWhen", "doTestUnfoldReturnToWhen"), testModel("idea/testData/codeInsight/codeTransformations/branched/ifWhen/ifToWhen", "doTestIfToWhen"), diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/after.kt.template new file mode 100644 index 00000000000..34512084beb --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/after.kt.template @@ -0,0 +1,6 @@ +val res: String +if (ok) { + res = "ok" +} else { + res = "failed" +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/before.kt.template new file mode 100644 index 00000000000..f2a32466d14 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/before.kt.template @@ -0,0 +1,5 @@ +val res = if (ok) { + "ok" +} else { + "failed" +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/description.html b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/description.html new file mode 100644 index 00000000000..275b2797db0 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToIfIntention/description.html @@ -0,0 +1,5 @@ + + +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/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/after.kt.template b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/after.kt.template new file mode 100644 index 00000000000..996d8f0a33f --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/after.kt.template @@ -0,0 +1,6 @@ +val res: String +when (n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = "many" +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/before.kt.template b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/before.kt.template new file mode 100644 index 00000000000..59545857270 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/before.kt.template @@ -0,0 +1,5 @@ +val res = when (n) { + 1 -> "one" + 2 -> "two" + else -> "many" +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/description.html b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/description.html new file mode 100644 index 00000000000..258d62e13d2 --- /dev/null +++ b/idea/resources/intentionDescriptions/UnfoldBranchedExpressionIntentionUnfoldPropertyToWhenIntention/description.html @@ -0,0 +1,5 @@ + + +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/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 1148214b80e..02374c1d6e9 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -331,11 +331,21 @@ Kotlin + + org.jetbrains.jet.plugin.codeInsight.codeTransformations.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldPropertyToIfIntention + Kotlin + + org.jetbrains.jet.plugin.codeInsight.codeTransformations.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldAssignmentToWhenIntention Kotlin + + org.jetbrains.jet.plugin.codeInsight.codeTransformations.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldPropertyToWhenIntention + Kotlin + + org.jetbrains.jet.plugin.codeInsight.codeTransformations.branchedTransformations.intentions.UnfoldBranchedExpressionIntention$UnfoldReturnToIfIntention Kotlin diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index a68d3edbb91..53f164cac48 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -171,12 +171,16 @@ fold.when.to.call=Replace 'when' expression with method call fold.when.to.call.family=Replace 'when' Expression with Method Call unfold.assignment.to.if=Replace assignment with 'if' expression unfold.assignment.to.if.family=Replace Assignment with 'if' Expression +unfold.property.to.if=Replace property initializer with 'if' expression +unfold.property.to.if.family=Replace Property Initializer with 'if' Expression unfold.return.to.if=Replace return with 'if' expression unfold.return.to.if.family=Replace Return with 'if' Expression unfold.call.to.if=Replace method call with 'if' expression unfold.call.to.if.family=Replace Method Call with 'if' Expression unfold.assignment.to.when=Replace assignment with 'when' expression unfold.assignment.to.when.family=Replace Assignment with 'when' Expression +unfold.property.to.when=Replace property initializer with 'when' expression +unfold.property.to.when.family=Replace Property Initializer with 'when' Expression unfold.return.to.when=Replace return with 'when' expression unfold.return.to.when.family=Replace Return with 'when' Expression unfold.call.to.when=Replace method call with 'when' expression diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedUnfoldingUtils.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedUnfoldingUtils.java index 755ce457657..61ca1c961bf 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedUnfoldingUtils.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/BranchedUnfoldingUtils.java @@ -22,6 +22,13 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.plugin.codeInsight.ReferenceToClassesShortening; +import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; +import org.jetbrains.jet.renderer.DescriptorRenderer; + +import java.util.Collections; public class BranchedUnfoldingUtils { private BranchedUnfoldingUtils() { @@ -36,7 +43,7 @@ public class BranchedUnfoldingUtils { if (root == null) return null; if (JetPsiUtil.isAssignment(root)) { - JetBinaryExpression assignment = (JetBinaryExpression)root; + JetBinaryExpression assignment = (JetBinaryExpression) root; assertNotNull(assignment.getLeft()); @@ -45,29 +52,41 @@ public class BranchedUnfoldingUtils { if (rhs instanceof JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse((JetWhenExpression) rhs)) { return UnfoldableKind.ASSIGNMENT_TO_WHEN; } - } else if (root instanceof JetReturnExpression) { - JetExpression resultExpr = ((JetReturnExpression)root).getReturnedExpression(); + } + else if (root instanceof JetReturnExpression) { + JetExpression resultExpr = ((JetReturnExpression) root).getReturnedExpression(); if (resultExpr instanceof JetIfExpression) return UnfoldableKind.RETURN_TO_IF; if (resultExpr instanceof JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse((JetWhenExpression) resultExpr)) { return UnfoldableKind.RETURN_TO_WHEN; } } + else if (root instanceof JetProperty) { + JetProperty property = (JetProperty) root; + if (!property.isLocal()) return null; + + JetExpression initializer = property.getInitializer(); + + if (initializer instanceof JetIfExpression) return UnfoldableKind.PROPERTY_TO_IF; + if (initializer instanceof JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse((JetWhenExpression) initializer)) { + return UnfoldableKind.PROPERTY_TO_WHEN; + } + } return null; } public static final String UNFOLD_WITHOUT_CHECK = "Expression must be checked before unfolding"; - private static void assertNotNull(JetExpression expression) { - assert expression != null : UNFOLD_WITHOUT_CHECK; + private static void assertNotNull(Object value) { + assert value != null : UNFOLD_WITHOUT_CHECK; } public static void unfoldAssignmentToIf(@NotNull JetBinaryExpression assignment, @NotNull Editor editor) { Project project = assignment.getProject(); String op = assignment.getOperationReference().getText(); JetExpression lhs = assignment.getLeft(); - JetIfExpression ifExpression = (JetIfExpression)assignment.getRight(); + JetIfExpression ifExpression = (JetIfExpression) assignment.getRight(); assertNotNull(ifExpression); @@ -93,7 +112,7 @@ public class BranchedUnfoldingUtils { Project project = assignment.getProject(); String op = assignment.getOperationReference().getText(); JetExpression lhs = assignment.getLeft(); - JetWhenExpression whenExpression = (JetWhenExpression)assignment.getRight(); + JetWhenExpression whenExpression = (JetWhenExpression) assignment.getRight(); assertNotNull(whenExpression); @@ -114,9 +133,96 @@ public class BranchedUnfoldingUtils { editor.getCaretModel().moveToOffset(resultElement.getTextOffset()); } + private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property, @NotNull JetFile file) { + if (property.getTypeRef() != null) return null; + return AnalyzerFacadeWithCache.analyzeFileWithCache(file).getBindingContext().get(BindingContext.EXPRESSION_TYPE, property.getInitializer()); + } + + protected interface PropertyUnfolder { + void processInitializer(@NotNull T newInitializer, @NotNull JetExpression propertyRef, @NotNull Project project); + } + + protected static final PropertyUnfolder IF_EXPRESSION_PROPERTY_UNFOLDER = new PropertyUnfolder() { + @Override + public void processInitializer( + @NotNull JetIfExpression newInitializer, @NotNull JetExpression propertyRef, @NotNull Project project + ) { + JetExpression thenExpr = getOutermostLastBlockElement(newInitializer.getThen()); + JetExpression elseExpr = getOutermostLastBlockElement(newInitializer.getElse()); + + assertNotNull(thenExpr); + assertNotNull(elseExpr); + + thenExpr.replace(JetPsiFactory.createBinaryExpression(project, propertyRef, "=", thenExpr)); + elseExpr.replace(JetPsiFactory.createBinaryExpression(project, propertyRef, "=", elseExpr)); + } + }; + + protected static final PropertyUnfolder WHEN_EXPRESSION_PROPERTY_UNFOLDER = new PropertyUnfolder() { + @Override + public void processInitializer( + @NotNull JetWhenExpression newInitializer, @NotNull JetExpression propertyRef, @NotNull Project project + ) { + for (JetWhenEntry entry : newInitializer.getEntries()) { + JetExpression currExpr = getOutermostLastBlockElement(entry.getExpression()); + + assertNotNull(currExpr); + + //noinspection ConstantConditions + currExpr.replace(JetPsiFactory.createBinaryExpression(project, propertyRef, "=", currExpr)); + } + } + }; + + private static void unfoldProperty( + @NotNull JetProperty property, @NotNull JetFile file, PropertyUnfolder unfolder + ) { + Project project = property.getProject(); + + PsiElement parent = property.getParent(); + assertNotNull(parent); + + //noinspection unchecked + T initializer = (T) property.getInitializer(); + assertNotNull(initializer); + + JetSimpleNameExpression propertyName = JetPsiFactory.createSimpleName(project, property.getName()); + + //noinspection ConstantConditions, unchecked + T newInitializer = (T) initializer.copy(); + + unfolder.processInitializer(newInitializer, propertyName, project); + + parent.addAfter(newInitializer, property); + parent.addAfter(JetPsiFactory.createNewLine(project), property); + + //noinspection ConstantConditions + JetType inferredType = getPropertyTypeIfNeeded(property, file); + + String typeStr = inferredType != null + ? DescriptorRenderer.TEXT.renderType(inferredType) + : JetPsiUtil.getNullableText(property.getTypeRef()); + + property = (JetProperty) property.replace( + JetPsiFactory.createProperty(project, property.getName(), typeStr, property.isVar()) + ); + + if (inferredType != null) { + ReferenceToClassesShortening.compactReferenceToClasses(Collections.singletonList(property.getTypeRef())); + } + } + + public static void unfoldPropertyToIf(@NotNull JetProperty property, @NotNull JetFile file) { + unfoldProperty(property, file, IF_EXPRESSION_PROPERTY_UNFOLDER); + } + + public static void unfoldPropertyToWhen(@NotNull JetProperty property, @NotNull JetFile file) { + unfoldProperty(property, file, WHEN_EXPRESSION_PROPERTY_UNFOLDER); + } + public static void unfoldReturnToIf(@NotNull JetReturnExpression returnExpression) { Project project = returnExpression.getProject(); - JetIfExpression ifExpression = (JetIfExpression)returnExpression.getReturnedExpression(); + JetIfExpression ifExpression = (JetIfExpression) returnExpression.getReturnedExpression(); assertNotNull(ifExpression); @@ -137,7 +243,7 @@ public class BranchedUnfoldingUtils { public static void unfoldReturnToWhen(@NotNull JetReturnExpression returnExpression) { Project project = returnExpression.getProject(); - JetWhenExpression whenExpression = (JetWhenExpression)returnExpression.getReturnedExpression(); + JetWhenExpression whenExpression = (JetWhenExpression) returnExpression.getReturnedExpression(); assertNotNull(whenExpression); diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/UnfoldableKind.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/UnfoldableKind.java index 86ed5e5b5e6..5a78db9b0d0 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/UnfoldableKind.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/UnfoldableKind.java @@ -21,6 +21,7 @@ import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.lang.psi.JetBinaryExpression; import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.psi.JetProperty; import org.jetbrains.jet.lang.psi.JetReturnExpression; import org.jetbrains.jet.plugin.codeInsight.codeTransformations.branchedTransformations.core.Transformer; @@ -31,6 +32,12 @@ public enum UnfoldableKind implements Transformer { BranchedUnfoldingUtils.unfoldAssignmentToIf((JetBinaryExpression) element, editor); } }, + PROPERTY_TO_IF("unfold.property.to.if") { + @Override + public void transform(@NotNull PsiElement element, @NotNull Editor editor, JetFile file) { + BranchedUnfoldingUtils.unfoldPropertyToIf((JetProperty) element, file); + } + }, RETURN_TO_IF("unfold.return.to.if") { @Override public void transform(@NotNull PsiElement element, @NotNull Editor editor, JetFile file) { @@ -43,6 +50,12 @@ public enum UnfoldableKind implements Transformer { BranchedUnfoldingUtils.unfoldAssignmentToWhen((JetBinaryExpression) element, editor); } }, + PROPERTY_TO_WHEN("unfold.property.to.when") { + @Override + public void transform(@NotNull PsiElement element, @NotNull Editor editor, JetFile file) { + BranchedUnfoldingUtils.unfoldPropertyToWhen((JetProperty) element, file); + } + }, RETURN_TO_WHEN("unfold.return.to.when") { @Override public void transform(@NotNull PsiElement element, @NotNull Editor editor, JetFile file) { diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java index 40cf4066f8d..dae76bfdaf4 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.java @@ -42,12 +42,24 @@ public abstract class UnfoldBranchedExpressionIntention extends AbstractCodeTran } } + 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); diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt new file mode 100644 index 00000000000..d66fa1da47d --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt @@ -0,0 +1,19 @@ +fun test(n: Int): String? { + val res = if (n == 1) { + if (3 > 2) { + println("***") + "one" + } else { + println("***") + "???" + } + } else if (n == 2) { + println("***") + null + } else { + println("***") + "too many" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt.after new file mode 100644 index 00000000000..c0344100f46 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt.after @@ -0,0 +1,20 @@ +fun test(n: Int): String? { + val res: String? + if (n == 1) { + res = if (3 > 2) { + println("***") + "one" + } else { + println("***") + "???" + } + } else res = if (n == 2) { + println("***") + null + } else { + println("***") + "too many" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt new file mode 100644 index 00000000000..f395889d491 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt @@ -0,0 +1,19 @@ +fun test(n: Int): String? { + var res = if (n == 1) { + if (3 > 2) { + println("***") + "one" + } else { + println("***") + "???" + } + } else if (n == 2) { + println("***") + null + } else { + println("***") + "too many" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt.after new file mode 100644 index 00000000000..f560c0b982b --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt.after @@ -0,0 +1,20 @@ +fun test(n: Int): String? { + var res: String? + if (n == 1) { + res = if (3 > 2) { + println("***") + "one" + } else { + println("***") + "???" + } + } else res = if (n == 2) { + println("***") + null + } else { + println("***") + "too many" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty.kt new file mode 100644 index 00000000000..b35d6d646b5 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty.kt @@ -0,0 +1,2 @@ +// IS_APPLICABLE: false +val x = if (false) "0" else "1" \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty2.kt new file mode 100644 index 00000000000..b737d711db2 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty2.kt @@ -0,0 +1,2 @@ +// IS_APPLICABLE: false +var x = if (false) "0" else "1" \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt new file mode 100644 index 00000000000..06caf0f8f29 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt @@ -0,0 +1,5 @@ +fun test(n: Int): String { + val res = if (n == 1) "one" else "two" + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt.after new file mode 100644 index 00000000000..7025c616a42 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt.after @@ -0,0 +1,6 @@ +fun test(n: Int): String { + val res: String + if (n == 1) res = "one" else res = "two" + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt new file mode 100644 index 00000000000..a93f206354c --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt @@ -0,0 +1,5 @@ +fun test(n: Int): String { + var res = if (n == 1) "one" else "two" + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt.after new file mode 100644 index 00000000000..7e2a0315bd6 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt.after @@ -0,0 +1,6 @@ +fun test(n: Int): String { + var res: String + if (n == 1) res = "one" else res = "two" + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt new file mode 100644 index 00000000000..3bc95c25fd9 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt @@ -0,0 +1,11 @@ +fun test(n: Int): String { + val res = if (n == 1) { + println("***") + "one" + } else { + println("***") + "two" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt.after new file mode 100644 index 00000000000..d1471a6142e --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt.after @@ -0,0 +1,12 @@ +fun test(n: Int): String { + val res: String + if (n == 1) { + println("***") + res = "one" + } else { + println("***") + res = "two" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt new file mode 100644 index 00000000000..acfe1239167 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt @@ -0,0 +1,11 @@ +fun test(n: Int): String { + var res = if (n == 1) { + println("***") + "one" + } else { + println("***") + "two" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt.after new file mode 100644 index 00000000000..c16a32371c6 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt.after @@ -0,0 +1,12 @@ +fun test(n: Int): String { + var res: String + if (n == 1) { + println("***") + res = "one" + } else { + println("***") + res = "two" + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt new file mode 100644 index 00000000000..207ba54f08a --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt @@ -0,0 +1,5 @@ +fun test(n: Int): String { + val res: jet.String = if (n == 1) "one" else "two" + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt.after new file mode 100644 index 00000000000..3460d3bda79 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt.after @@ -0,0 +1,6 @@ +fun test(n: Int): String { + val res: jet.String + if (n == 1) res = "one" else res = "two" + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty.kt new file mode 100644 index 00000000000..a52943c29b9 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +val n = 10 + +val res = when(n) { + 1 -> "one" + 2 -> "two" + else -> null +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty2.kt new file mode 100644 index 00000000000..52eaadb5516 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty2.kt @@ -0,0 +1,8 @@ +// IS_APPLICABLE: false +val n = 10 + +var res = when(n) { + 1 -> "one" + 2 -> "two" + else -> null +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt new file mode 100644 index 00000000000..16796a9ac4a --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt @@ -0,0 +1,9 @@ +fun test(n: Int): String? { + val res = when(n) { + 1 -> "one" + 2 -> "two" + else -> null + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt.after new file mode 100644 index 00000000000..d0be88b8b7f --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt.after @@ -0,0 +1,10 @@ +fun test(n: Int): String? { + val res: String? + when(n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = null + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt new file mode 100644 index 00000000000..c4595f97b71 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt @@ -0,0 +1,9 @@ +fun test(n: Int): String? { + var res = when(n) { + 1 -> "one" + 2 -> "two" + else -> null + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt.after new file mode 100644 index 00000000000..a0dd0c4c2c8 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt.after @@ -0,0 +1,10 @@ +fun test(n: Int): String? { + var res: String? + when(n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = null + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt new file mode 100644 index 00000000000..f2f5f133833 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt @@ -0,0 +1,14 @@ +fun test(n: Int): String { + val res = when (n) { + 1 -> { + println("***") + "one" + } + else -> { + println("***") + "two" + } + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt.after new file mode 100644 index 00000000000..b900cde5fc2 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt.after @@ -0,0 +1,15 @@ +fun test(n: Int): String { + val res: String + when (n) { + 1 -> { + println("***") + res = "one" + } + else -> { + println("***") + res = "two" + } + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt new file mode 100644 index 00000000000..fad0c972531 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt @@ -0,0 +1,14 @@ +fun test(n: Int): String { + var res = when (n) { + 1 -> { + println("***") + "one" + } + else -> { + println("***") + "two" + } + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt.after new file mode 100644 index 00000000000..4487e97042d --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt.after @@ -0,0 +1,15 @@ +fun test(n: Int): String { + var res: String + when (n) { + 1 -> { + println("***") + res = "one" + } + else -> { + println("***") + res = "two" + } + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt new file mode 100644 index 00000000000..81fc08d943f --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt @@ -0,0 +1,9 @@ +fun test(n: Int): String? { + val res: jet.String? = when(n) { + 1 -> "one" + 2 -> "two" + else -> null + } + + return res +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt.after b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt.after new file mode 100644 index 00000000000..7bf0f8006d3 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt.after @@ -0,0 +1,10 @@ +fun test(n: Int): String? { + val res: jet.String? + when(n) { + 1 -> res = "one" + 2 -> res = "two" + else -> res = null + } + + return res +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java index c0db705a380..918cfc7349c 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java @@ -54,6 +54,14 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes doTest(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToWhenIntention()); } + public void doTestUnfoldPropertyToIf(@NotNull String path) throws Exception { + doTest(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToIfIntention()); + } + + public void doTestUnfoldPropertyToWhen(@NotNull String path) throws Exception { + doTest(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToWhenIntention()); + } + public void doTestUnfoldReturnToIf(@NotNull String path) throws Exception { doTest(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToIfIntention()); } diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java index ab6c63001dd..e13ed3d5a4c 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java @@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.codeInsight.codeTransformations.AbstractCodeTran /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@InnerTestClasses({CodeTransformationsTestGenerated.IfToAssignment.class, CodeTransformationsTestGenerated.IfToReturn.class, CodeTransformationsTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationsTestGenerated.WhenToAssignment.class, CodeTransformationsTestGenerated.WhenToReturn.class, CodeTransformationsTestGenerated.AssignmentToIf.class, CodeTransformationsTestGenerated.AssignmentToWhen.class, CodeTransformationsTestGenerated.ReturnToIf.class, CodeTransformationsTestGenerated.ReturnToWhen.class, CodeTransformationsTestGenerated.IfToWhen.class, CodeTransformationsTestGenerated.WhenToIf.class, CodeTransformationsTestGenerated.Flatten.class, CodeTransformationsTestGenerated.IntroduceSubject.class, CodeTransformationsTestGenerated.EliminateSubject.class}) +@InnerTestClasses({CodeTransformationsTestGenerated.IfToAssignment.class, CodeTransformationsTestGenerated.IfToReturn.class, CodeTransformationsTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationsTestGenerated.WhenToAssignment.class, CodeTransformationsTestGenerated.WhenToReturn.class, CodeTransformationsTestGenerated.AssignmentToIf.class, CodeTransformationsTestGenerated.AssignmentToWhen.class, CodeTransformationsTestGenerated.PropertyToIf.class, CodeTransformationsTestGenerated.PropertyToWhen.class, CodeTransformationsTestGenerated.ReturnToIf.class, CodeTransformationsTestGenerated.ReturnToWhen.class, CodeTransformationsTestGenerated.IfToWhen.class, CodeTransformationsTestGenerated.WhenToIf.class, CodeTransformationsTestGenerated.Flatten.class, CodeTransformationsTestGenerated.IntroduceSubject.class, CodeTransformationsTestGenerated.EliminateSubject.class}) public class CodeTransformationsTestGenerated extends AbstractCodeTransformationTest { @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/folding/ifToAssignment") public static class IfToAssignment extends AbstractCodeTransformationTest { @@ -263,6 +263,102 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation } + @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf") + public static class PropertyToIf extends AbstractCodeTransformationTest { + public void testAllFilesPresentInPropertyToIf() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("nestedIfs.kt") + public void testNestedIfs() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs.kt"); + } + + @TestMetadata("nestedIfs2.kt") + public void testNestedIfs2() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nestedIfs2.kt"); + } + + @TestMetadata("nonLocalProperty.kt") + public void testNonLocalProperty() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty.kt"); + } + + @TestMetadata("nonLocalProperty2.kt") + public void testNonLocalProperty2() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/nonLocalProperty2.kt"); + } + + @TestMetadata("simpleIf.kt") + public void testSimpleIf() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf.kt"); + } + + @TestMetadata("simpleIf2.kt") + public void testSimpleIf2() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIf2.kt"); + } + + @TestMetadata("simpleIfWithBlocks.kt") + public void testSimpleIfWithBlocks() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks.kt"); + } + + @TestMetadata("simpleIfWithBlocks2.kt") + public void testSimpleIfWithBlocks2() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithBlocks2.kt"); + } + + @TestMetadata("simpleIfWithType.kt") + public void testSimpleIfWithType() throws Exception { + doTestUnfoldPropertyToIf("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToIf/simpleIfWithType.kt"); + } + + } + + @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen") + public static class PropertyToWhen extends AbstractCodeTransformationTest { + public void testAllFilesPresentInPropertyToWhen() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("nonLocalProperty.kt") + public void testNonLocalProperty() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty.kt"); + } + + @TestMetadata("nonLocalProperty2.kt") + public void testNonLocalProperty2() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/nonLocalProperty2.kt"); + } + + @TestMetadata("simpleWhen.kt") + public void testSimpleWhen() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen.kt"); + } + + @TestMetadata("simpleWhen2.kt") + public void testSimpleWhen2() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhen2.kt"); + } + + @TestMetadata("simpleWhenWithBlocks.kt") + public void testSimpleWhenWithBlocks() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks.kt"); + } + + @TestMetadata("simpleWhenWithBlocks2.kt") + public void testSimpleWhenWithBlocks2() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithBlocks2.kt"); + } + + @TestMetadata("simpleWhenWithType.kt") + public void testSimpleWhenWithType() throws Exception { + doTestUnfoldPropertyToWhen("idea/testData/codeInsight/codeTransformations/branched/unfolding/propertyToWhen/simpleWhenWithType.kt"); + } + + } + @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/unfolding/returnToIf") public static class ReturnToIf extends AbstractCodeTransformationTest { public void testAllFilesPresentInReturnToIf() throws Exception { @@ -553,6 +649,8 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation suite.addTestSuite(WhenToReturn.class); suite.addTestSuite(AssignmentToIf.class); suite.addTestSuite(AssignmentToWhen.class); + suite.addTestSuite(PropertyToIf.class); + suite.addTestSuite(PropertyToWhen.class); suite.addTestSuite(ReturnToIf.class); suite.addTestSuite(ReturnToWhen.class); suite.addTestSuite(IfToWhen.class);