diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToIfIntention.kt new file mode 100644 index 00000000000..63c1a934474 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToIfIntention.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.psi.JetBinaryExpression +import org.jetbrains.kotlin.psi.JetIfExpression + +public class UnfoldAssignmentToIfIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace assignment with 'if' expression") { + override fun isApplicableTo(element: JetBinaryExpression): Boolean { + if (element.getOperationToken() !in JetTokens.ALL_ASSIGNMENTS) return false + if (element.getLeft() == null) return false + return element.getRight() is JetIfExpression + } + + override fun applyTo(element: JetBinaryExpression, editor: Editor) { + BranchedUnfoldingUtils.unfoldAssignmentToIf(element, editor) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt new file mode 100644 index 00000000000..1372bacfc6b --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldAssignmentToWhenIntention.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.psi.JetBinaryExpression +import org.jetbrains.kotlin.psi.JetPsiUtil +import org.jetbrains.kotlin.psi.JetWhenExpression + +public class UnfoldAssignmentToWhenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace assignment with 'when' expression" ) { + override fun isApplicableTo(element: JetBinaryExpression): Boolean { + if (element.getOperationToken() !in JetTokens.ALL_ASSIGNMENTS) return false + if (element.getLeft() == null) return false + val right = element.getRight() + return right is JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse(right) + } + + override fun applyTo(element: JetBinaryExpression, editor: Editor) { + BranchedUnfoldingUtils.unfoldAssignmentToWhen(element, editor) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt deleted file mode 100644 index 69801ee1f57..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldBranchedExpressionIntention.kt +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions - -import com.intellij.openapi.editor.Editor -import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention -import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils -import org.jetbrains.kotlin.lexer.JetTokens -import org.jetbrains.kotlin.psi.* - -public class UnfoldAssignmentToIfIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace assignment with 'if' expression") { - override fun isApplicableTo(element: JetBinaryExpression): Boolean { - if (element.getOperationToken() !in JetTokens.ALL_ASSIGNMENTS) return false - if (element.getLeft() == null) return false - return element.getRight() is JetIfExpression - } - - override fun applyTo(element: JetBinaryExpression, editor: Editor) { - BranchedUnfoldingUtils.unfoldAssignmentToIf(element, editor) - } -} - -public class UnfoldPropertyToIfIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace property initializer with 'if' expression") { - override fun isApplicableTo(element: JetProperty): Boolean { - if (!element.isLocal()) return false - return element.getInitializer() is JetIfExpression - } - - override fun applyTo(element: JetProperty, editor: Editor) { - BranchedUnfoldingUtils.unfoldPropertyToIf(element, editor) - } -} - -public class UnfoldAssignmentToWhenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace assignment with 'when' expression" ) { - override fun isApplicableTo(element: JetBinaryExpression): Boolean { - if (element.getOperationToken() !in JetTokens.ALL_ASSIGNMENTS) return false - if (element.getLeft() == null) return false - val right = element.getRight() - return right is JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse(right) - } - - override fun applyTo(element: JetBinaryExpression, editor: Editor) { - BranchedUnfoldingUtils.unfoldAssignmentToWhen(element, editor) - } -} - -public class UnfoldPropertyToWhenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace property initializer with 'when' expression") { - override fun isApplicableTo(element: JetProperty): Boolean { - if (!element.isLocal()) return false - val initializer = element.getInitializer() - return initializer is JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse(initializer) - } - - override fun applyTo(element: JetProperty, editor: Editor) { - BranchedUnfoldingUtils.unfoldPropertyToWhen(element, editor) - } -} - -public class UnfoldReturnToIfIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace return with 'if' expression") { - override fun isApplicableTo(element: JetReturnExpression): Boolean { - return element.getReturnedExpression() is JetIfExpression - } - - override fun applyTo(element: JetReturnExpression, editor: Editor) { - BranchedUnfoldingUtils.unfoldReturnToIf(element) - } -} - -public class UnfoldReturnToWhenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace return with 'when' expression") { - override fun isApplicableTo(element: JetReturnExpression): Boolean { - val expr = element.getReturnedExpression() - return expr is JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse(expr) - } - - override fun applyTo(element: JetReturnExpression, editor: Editor) { - BranchedUnfoldingUtils.unfoldReturnToWhen(element) - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToIfIntention.kt new file mode 100644 index 00000000000..465e72d3064 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToIfIntention.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.psi.JetIfExpression +import org.jetbrains.kotlin.psi.JetProperty + +public class UnfoldPropertyToIfIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace property initializer with 'if' expression") { + override fun isApplicableTo(element: JetProperty): Boolean { + if (!element.isLocal()) return false + return element.getInitializer() is JetIfExpression + } + + override fun applyTo(element: JetProperty, editor: Editor) { + BranchedUnfoldingUtils.unfoldPropertyToIf(element, editor) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt new file mode 100644 index 00000000000..1f829fff507 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldPropertyToWhenIntention.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.psi.JetProperty +import org.jetbrains.kotlin.psi.JetPsiUtil +import org.jetbrains.kotlin.psi.JetWhenExpression + +public class UnfoldPropertyToWhenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace property initializer with 'when' expression") { + override fun isApplicableTo(element: JetProperty): Boolean { + if (!element.isLocal()) return false + val initializer = element.getInitializer() + return initializer is JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse(initializer) + } + + override fun applyTo(element: JetProperty, editor: Editor) { + BranchedUnfoldingUtils.unfoldPropertyToWhen(element, editor) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt new file mode 100644 index 00000000000..5c39a8f3508 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToIfIntention.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.psi.JetIfExpression +import org.jetbrains.kotlin.psi.JetReturnExpression + +public class UnfoldReturnToIfIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace return with 'if' expression") { + override fun isApplicableTo(element: JetReturnExpression): Boolean { + return element.getReturnedExpression() is JetIfExpression + } + + override fun applyTo(element: JetReturnExpression, editor: Editor) { + BranchedUnfoldingUtils.unfoldReturnToIf(element) + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt new file mode 100644 index 00000000000..8f0a2e5574a --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/intentions/UnfoldReturnToWhenIntention.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions + +import com.intellij.openapi.editor.Editor +import org.jetbrains.kotlin.idea.intentions.JetSelfTargetingOffsetIndependentIntention +import org.jetbrains.kotlin.idea.intentions.branchedTransformations.BranchedUnfoldingUtils +import org.jetbrains.kotlin.psi.JetPsiUtil +import org.jetbrains.kotlin.psi.JetReturnExpression +import org.jetbrains.kotlin.psi.JetWhenExpression + +public class UnfoldReturnToWhenIntention : JetSelfTargetingOffsetIndependentIntention(javaClass(), "Replace return with 'when' expression") { + override fun isApplicableTo(element: JetReturnExpression): Boolean { + val expr = element.getReturnedExpression() + return expr is JetWhenExpression && JetPsiUtil.checkWhenExpressionHasSingleElse(expr) + } + + override fun applyTo(element: JetReturnExpression, editor: Editor) { + BranchedUnfoldingUtils.unfoldReturnToWhen(element) + } +}