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 218b48bec3e..d56b23b3cff 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -830,4 +830,24 @@ public class JetPsiUtil { } return null; } + + @Nullable + public static PsiElement skipSiblingsBackwardByPredicate(@Nullable PsiElement element, Predicate elementsToSkip) { + if (element == null) return null; + for (PsiElement e = element.getPrevSibling(); e != null; e = e.getPrevSibling()) { + if (elementsToSkip.apply(e)) continue; + return e; + } + return null; + } + + @Nullable + public static PsiElement skipSiblingsForwardByPredicate(@Nullable PsiElement element, Predicate elementsToSkip) { + if (element == null) return null; + for (PsiElement e = element.getNextSibling(); e != null; e = e.getNextSibling()) { + if (elementsToSkip.apply(e)) continue; + return e; + } + return null; + } } diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index 9e5468b3c6a..2986708dde8 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -345,7 +345,9 @@ public class GenerateTests { testModel("idea/testData/codeInsight/codeTransformations/branched/ifWhen/whenToIf", "doTestWhenToIf"), testModel("idea/testData/codeInsight/codeTransformations/branched/when/flatten", "doTestFlattenWhen"), testModel("idea/testData/codeInsight/codeTransformations/branched/when/introduceSubject", "doTestIntroduceWhenSubject"), - testModel("idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject", "doTestEliminateWhenSubject") + testModel("idea/testData/codeInsight/codeTransformations/branched/when/eliminateSubject", "doTestEliminateWhenSubject"), + testModel("idea/testData/codeInsight/codeTransformations/declarations/split", "doTestSplitProperty"), + testModel("idea/testData/codeInsight/codeTransformations/declarations/join", "doTestJoinProperty") ); generateTest( diff --git a/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/after.kt.template b/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/after.kt.template new file mode 100644 index 00000000000..a3df810f61a --- /dev/null +++ b/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/after.kt.template @@ -0,0 +1,2 @@ +val n: Int +n = a + b \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/before.kt.template b/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/before.kt.template new file mode 100644 index 00000000000..c009c3df64f --- /dev/null +++ b/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/before.kt.template @@ -0,0 +1 @@ +val n = a + b \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/description.html b/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/description.html new file mode 100644 index 00000000000..90f46cf38d9 --- /dev/null +++ b/idea/resources/intentionDescriptions/SplitPropertyDeclarationIntention/description.html @@ -0,0 +1,5 @@ + + +This intention splits property declaration with initializer and turns initializer to assignment. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 02374c1d6e9..e9d773c8e00 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -291,6 +291,8 @@ implementation="org.jetbrains.jet.plugin.codeInsight.upDownMover.JetDeclarationMover" order="before jetExpression" /> + + org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction Kotlin @@ -386,6 +388,11 @@ Kotlin + + org.jetbrains.jet.plugin.codeInsight.codeTransformations.declarations.SplitPropertyDeclarationIntention + Kotlin + + diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index eb0de967683..d5268f23f8b 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -201,6 +201,8 @@ transform.if.statement.with.assignments.to.expression=Transform 'if' statement w transform.assignment.with.if.expression.to.statement=Transform assignment with 'if' expression to statement transform.if.statement.with.assignments.to.expression.family=Transform 'if' Statement with Assignments to Expression transform.assignment.with.if.expression.to.statement.family=Transform Assignment with 'if' Expression to Statement +split.property.declaration=Split property declaration +split.property.declaration.family=Split Property Declaration change.function.signature.action.single=Change function signature to ''{0}'' change.function.signature.action.multiple=Change function signature... change.function.signature.family=Change function signature diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/DeclarationUtils.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/DeclarationUtils.java new file mode 100644 index 00000000000..c802625201b --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/DeclarationUtils.java @@ -0,0 +1,171 @@ +/* + * 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.codeInsight.codeTransformations.declarations; + +import com.google.common.base.Predicate; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; +import com.intellij.psi.PsiComment; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiWhiteSpace; +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.ErrorUtils; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.lexer.JetTokens; +import org.jetbrains.jet.plugin.codeInsight.ReferenceToClassesShortening; +import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; +import org.jetbrains.jet.plugin.util.JetPsiMatcher; +import org.jetbrains.jet.renderer.DescriptorRenderer; + +import java.util.Collections; + +public class DeclarationUtils { + private DeclarationUtils() { + } + + private static void assertNotNull(Object value) { + assert value != null : "Expression must be checked before applying transformation"; + } + + public static boolean checkSplitProperty(@NotNull JetProperty property) { + return property.getInitializer() != null && property.isLocal(); + } + + public static final Predicate SKIP_DELIMITERS = new Predicate() { + @Override + public boolean apply(@Nullable PsiElement input) { + return input == null + || input instanceof PsiWhiteSpace || input instanceof PsiComment + || input.getNode().getElementType() == JetTokens.SEMICOLON; + } + }; + + @Nullable + public static Pair checkAndGetPropertyAndInitializer(@NotNull PsiElement element) { + JetProperty property = null; + JetExpression initializer = null; + + if (element instanceof JetProperty) { + PsiElement nextElement = JetPsiUtil.skipSiblingsForwardByPredicate(element, SKIP_DELIMITERS); + if (nextElement instanceof JetExpression) { + property = (JetProperty) element; + initializer = (JetExpression) nextElement; + } + } + + if (property == null) return null; + if (property.getInitializer() != null) return null; + if (!JetPsiUtil.isOrdinaryAssignment(initializer)) return null; + + JetBinaryExpression assignment = (JetBinaryExpression) initializer; + + if (!(assignment.getLeft() instanceof JetSimpleNameExpression)) return null; + if (assignment.getRight() == null) return null; + //noinspection ConstantConditions + if (!JetPsiMatcher.checkIdentifierMatch(property.getNameIdentifier().getText(), assignment.getLeft().getText())) return null; + + return new Pair(property, assignment); + } + + @Nullable + private static JetType getPropertyTypeIfNeeded(@NotNull JetProperty property, @NotNull JetFile file) { + if (property.getTypeRef() != null) return null; + + JetType type = AnalyzerFacadeWithCache.analyzeFileWithCache(file).getBindingContext().get( + BindingContext.EXPRESSION_TYPE, + property.getInitializer() + ); + + return type == null || ErrorUtils.isErrorType(type) ? null : type; + } + + // returns assignment which replaces initializer + @NotNull + public static JetBinaryExpression splitPropertyDeclaration(@NotNull JetProperty property, @NotNull JetFile file) { + Project project = property.getProject(); + + PsiElement parent = property.getParent(); + assertNotNull(parent); + + //noinspection unchecked + JetExpression initializer = property.getInitializer(); + assertNotNull(initializer); + + //noinspection ConstantConditions, unchecked + JetBinaryExpression newInitializer = JetPsiFactory.createBinaryExpression( + project, JetPsiFactory.createSimpleName(project, property.getName()), "=", initializer + ); + + newInitializer = (JetBinaryExpression) 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()); + + //noinspection ConstantConditions + property = (JetProperty) property.replace( + JetPsiFactory.createProperty(project, property.getNameIdentifier().getText(), typeStr, property.isVar()) + ); + + if (inferredType != null) { + ReferenceToClassesShortening.compactReferenceToClasses(Collections.singletonList(property.getTypeRef())); + } + + return newInitializer; + } + + // Returns joined property + @NotNull + public static JetProperty joinPropertyDeclarationWithInitializer( + @NotNull Pair propertyAndInitializer + ) { + JetProperty property = propertyAndInitializer.first; + assertNotNull(property); + + JetBinaryExpression assignment = propertyAndInitializer.second; + assertNotNull(assignment); + + //noinspection ConstantConditions + JetProperty newProperty = JetPsiFactory.createProperty( + property.getProject(), + property.getNameIdentifier().getText(), + JetPsiUtil.getNullableText(property.getTypeRef()), + property.isVar(), + JetPsiUtil.getNullableText(assignment.getRight()) + ); + + property.getParent().deleteChildRange(property.getNextSibling(), assignment); + return (JetProperty) property.replace(newProperty); + } + + // Returns joined property + @NotNull + public static JetProperty joinPropertyDeclarationWithInitializer(@NotNull PsiElement element) { + Pair propertyAndInitializer = checkAndGetPropertyAndInitializer(element); + assertNotNull(propertyAndInitializer); + + //noinspection ConstantConditions + return joinPropertyDeclarationWithInitializer(propertyAndInitializer); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/JetDeclarationJoinLinesHandler.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/JetDeclarationJoinLinesHandler.java new file mode 100644 index 00000000000..b5717a8d868 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/JetDeclarationJoinLinesHandler.java @@ -0,0 +1,34 @@ +package org.jetbrains.jet.plugin.codeInsight.codeTransformations.declarations; + +import com.google.common.base.Predicate; +import com.intellij.codeInsight.editorActions.JoinRawLinesHandlerDelegate; +import com.intellij.openapi.editor.Document; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.psi.JetElement; +import org.jetbrains.jet.lang.psi.JetPsiUtil; + +public class JetDeclarationJoinLinesHandler implements JoinRawLinesHandlerDelegate { + private static final Predicate IS_APPLICABLE = new Predicate() { + @Override + public boolean apply(@Nullable PsiElement input) { + return input != null && DeclarationUtils.checkAndGetPropertyAndInitializer(input) != null; + } + }; + + @Override + public int tryJoinRawLines(Document document, PsiFile file, int start, int end) { + PsiElement element = JetPsiUtil.skipSiblingsBackwardByPredicate(file.findElementAt(start), DeclarationUtils.SKIP_DELIMITERS); + + PsiElement target = JetPsiUtil.getParentByTypeAndPredicate(element, JetElement.class, IS_APPLICABLE, false); + if (target == null) return -1; + + return DeclarationUtils.joinPropertyDeclarationWithInitializer(target).getTextRange().getStartOffset(); + } + + @Override + public int tryJoinLines(Document document, PsiFile file, int start, int end) { + return -1; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/SplitPropertyDeclarationIntention.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/SplitPropertyDeclarationIntention.java new file mode 100644 index 00000000000..8d72546f57b --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/declarations/SplitPropertyDeclarationIntention.java @@ -0,0 +1,53 @@ +/* + * 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.codeInsight.codeTransformations.declarations; + +import com.google.common.base.Predicate; +import com.intellij.openapi.editor.Editor; +import com.intellij.psi.PsiElement; +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.codeInsight.codeTransformations.AbstractCodeTransformationIntention; +import org.jetbrains.jet.plugin.codeInsight.codeTransformations.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 Predicate IS_APPLICABLE = new Predicate() { + @Override + public boolean apply(@Nullable PsiElement input) { + return (input instanceof JetProperty) && DeclarationUtils.checkSplitProperty((JetProperty) input); + } + }; + + public SplitPropertyDeclarationIntention() { + super(TRANSFORMER, IS_APPLICABLE); + } +} diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt new file mode 100644 index 00000000000..e1e22d286ed --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt @@ -0,0 +1,7 @@ +fun foo(n: Int) { + val x: String + x = if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt.after new file mode 100644 index 00000000000..80667621272 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt.after @@ -0,0 +1,6 @@ +fun foo(n: Int) { + val x: String = if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt new file mode 100644 index 00000000000..7b6faaa3e20 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt @@ -0,0 +1,7 @@ +fun foo(n: Int) { + val x: String + x = if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt.after new file mode 100644 index 00000000000..80667621272 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt.after @@ -0,0 +1,6 @@ +fun foo(n: Int) { + val x: String = if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt new file mode 100644 index 00000000000..46137147953 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt.after new file mode 100644 index 00000000000..ef7e1ba3bdb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt new file mode 100644 index 00000000000..1f6db4d3138 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt.after new file mode 100644 index 00000000000..ef7e1ba3bdb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt new file mode 100644 index 00000000000..022012639ee --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: String + `x` = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt.after new file mode 100644 index 00000000000..ef7e1ba3bdb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt new file mode 100644 index 00000000000..a2f3816a230 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val `x`: String + `x` = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt.after new file mode 100644 index 00000000000..fbcef7338d0 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val `x`: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt new file mode 100644 index 00000000000..6a6659f3fcb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val `x`: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt.after new file mode 100644 index 00000000000..fbcef7338d0 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val `x`: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt new file mode 100644 index 00000000000..b49c9a9ebc0 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt @@ -0,0 +1,6 @@ +fun foo(n: Int) { + // foo3 + val /* foo */ x: String // foo2 + x = /* bar2 */ "" // bar3 + /* baz */ +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt.after new file mode 100644 index 00000000000..5548a74c627 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt.after @@ -0,0 +1,5 @@ +fun foo(n: Int) { + // foo3 + val x: String = "" // bar3 + /* baz */ +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt new file mode 100644 index 00000000000..ba90e151465 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt @@ -0,0 +1,6 @@ +fun foo(n: Int) { + // foo3 + val /* foo */ x: String // foo2 + x = /* bar2 */ "" // bar3 + /* baz */ +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt.after new file mode 100644 index 00000000000..5548a74c627 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt.after @@ -0,0 +1,5 @@ +fun foo(n: Int) { + // foo3 + val x: String = "" // bar3 + /* baz */ +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt new file mode 100644 index 00000000000..5246f1e36f2 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: String; ; + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt.after new file mode 100644 index 00000000000..ef7e1ba3bdb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt new file mode 100644 index 00000000000..99b66a867d8 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: String; ; + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt.after new file mode 100644 index 00000000000..ef7e1ba3bdb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt new file mode 100644 index 00000000000..45887333aaf --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt @@ -0,0 +1,5 @@ +fun foo(n: Int) { + val x: String; + ; + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt.after new file mode 100644 index 00000000000..ef7e1ba3bdb --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: String = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt new file mode 100644 index 00000000000..cff228fae7c --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: jet.String? + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt.after new file mode 100644 index 00000000000..bf7e5c44409 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: jet.String? = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt new file mode 100644 index 00000000000..350bb1b3954 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: jet.String? + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt.after new file mode 100644 index 00000000000..bf7e5c44409 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt.after @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: jet.String? = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt new file mode 100644 index 00000000000..fc700c8174b --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt @@ -0,0 +1,7 @@ +fun foo(n: Int) { + val x = + if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt.after new file mode 100644 index 00000000000..e1e22d286ed --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt.after @@ -0,0 +1,7 @@ +fun foo(n: Int) { + val x: String + x = if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt new file mode 100644 index 00000000000..263b64b5172 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt @@ -0,0 +1,7 @@ +fun foo(n: Int) { + var x = + if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt.after new file mode 100644 index 00000000000..635703d3a2e --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt.after @@ -0,0 +1,7 @@ +fun foo(n: Int) { + var x: String + x = if (n > 0) + "> 0" + else + "<= 0" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer.kt new file mode 100644 index 00000000000..fc532bafe49 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false +fun foo(n: Int) { + val x: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer2.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer2.kt new file mode 100644 index 00000000000..e76f2b43397 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer2.kt @@ -0,0 +1,5 @@ +// IS_APPLICABLE: false +fun foo(n: Int) { + var x: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/nonLocalProperty.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/nonLocalProperty.kt new file mode 100644 index 00000000000..b35d6d646b5 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/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/declarations/split/nonLocalProperty2.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/nonLocalProperty2.kt new file mode 100644 index 00000000000..b737d711db2 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/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/declarations/split/simpleInit.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit.kt new file mode 100644 index 00000000000..2febbf214c0 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit.kt @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit.kt.after new file mode 100644 index 00000000000..46137147953 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit.kt.after @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt new file mode 100644 index 00000000000..05d7e765d9b --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt @@ -0,0 +1,3 @@ +fun foo(n: Int) { + var x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt.after new file mode 100644 index 00000000000..1d649485621 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt.after @@ -0,0 +1,4 @@ +fun foo(n: Int) { + var x: String + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt new file mode 100644 index 00000000000..51bd3dcd82d --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt @@ -0,0 +1,3 @@ +fun foo(n: Int) { + var x = X<>() +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt.after new file mode 100644 index 00000000000..9dcfc7aecd4 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt.after @@ -0,0 +1,4 @@ +fun foo(n: Int) { + var x + x = X<>() +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt new file mode 100644 index 00000000000..bb139cd5e98 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x = X<>() +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt.after new file mode 100644 index 00000000000..d62ed3fdfe2 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt.after @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x + x = X<>() +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt new file mode 100644 index 00000000000..bf7e5c44409 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt @@ -0,0 +1,3 @@ +fun foo(n: Int) { + val x: jet.String? = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt.after new file mode 100644 index 00000000000..cff228fae7c --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt.after @@ -0,0 +1,4 @@ +fun foo(n: Int) { + val x: jet.String? + x = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt new file mode 100644 index 00000000000..a22d8ea95da --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt @@ -0,0 +1,3 @@ +fun foo(n: Int) { + var x: jet.String? = "" +} \ No newline at end of file diff --git a/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt.after b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt.after new file mode 100644 index 00000000000..9d063035f45 --- /dev/null +++ b/idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt.after @@ -0,0 +1,4 @@ +fun foo(n: Int) { + var x: jet.String? + x = "" +} \ 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 918cfc7349c..b5407f37d2b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java @@ -16,85 +16,96 @@ package org.jetbrains.jet.plugin.codeInsight.codeTransformations; +import com.intellij.codeInsight.editorActions.JoinLinesHandler; import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.util.io.FileUtil; import com.intellij.testFramework.LightCodeInsightTestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.InTextDirectivesUtils; import org.jetbrains.jet.plugin.codeInsight.codeTransformations.branchedTransformations.intentions.*; +import org.jetbrains.jet.plugin.codeInsight.codeTransformations.declarations.SplitPropertyDeclarationIntention; import java.io.File; public abstract class AbstractCodeTransformationTest extends LightCodeInsightTestCase { public void doTestFoldIfToAssignment(@NotNull String path) throws Exception { - doTest(path, new FoldBranchedExpressionIntention.FoldIfToAssignmentIntention()); + doTestIntention(path, new FoldBranchedExpressionIntention.FoldIfToAssignmentIntention()); } public void doTestFoldIfToReturn(@NotNull String path) throws Exception { - doTest(path, new FoldBranchedExpressionIntention.FoldIfToReturnIntention()); + doTestIntention(path, new FoldBranchedExpressionIntention.FoldIfToReturnIntention()); } public void doTestFoldIfToReturnAsymmetrically(@NotNull String path) throws Exception { - doTest(path, new FoldBranchedExpressionIntention.FoldIfToReturnAsymmetricallyIntention()); + doTestIntention(path, new FoldBranchedExpressionIntention.FoldIfToReturnAsymmetricallyIntention()); } public void doTestFoldWhenToAssignment(@NotNull String path) throws Exception { - doTest(path, new FoldBranchedExpressionIntention.FoldWhenToAssignmentIntention()); + doTestIntention(path, new FoldBranchedExpressionIntention.FoldWhenToAssignmentIntention()); } public void doTestFoldWhenToReturn(@NotNull String path) throws Exception { - doTest(path, new FoldBranchedExpressionIntention.FoldWhenToReturnIntention()); + doTestIntention(path, new FoldBranchedExpressionIntention.FoldWhenToReturnIntention()); } public void doTestUnfoldAssignmentToIf(@NotNull String path) throws Exception { - doTest(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToIfIntention()); + doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToIfIntention()); } public void doTestUnfoldAssignmentToWhen(@NotNull String path) throws Exception { - doTest(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToWhenIntention()); + doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldAssignmentToWhenIntention()); } public void doTestUnfoldPropertyToIf(@NotNull String path) throws Exception { - doTest(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToIfIntention()); + doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToIfIntention()); } public void doTestUnfoldPropertyToWhen(@NotNull String path) throws Exception { - doTest(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToWhenIntention()); + doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldPropertyToWhenIntention()); } public void doTestUnfoldReturnToIf(@NotNull String path) throws Exception { - doTest(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToIfIntention()); + doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToIfIntention()); } public void doTestUnfoldReturnToWhen(@NotNull String path) throws Exception { - doTest(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToWhenIntention()); + doTestIntention(path, new UnfoldBranchedExpressionIntention.UnfoldReturnToWhenIntention()); } public void doTestIfToWhen(@NotNull String path) throws Exception { - doTest(path, new IfToWhenIntention()); + doTestIntention(path, new IfToWhenIntention()); } public void doTestWhenToIf(@NotNull String path) throws Exception { - doTest(path, new WhenToIfIntention()); + doTestIntention(path, new WhenToIfIntention()); } public void doTestFlattenWhen(@NotNull String path) throws Exception { - doTest(path, new FlattenWhenIntention()); + doTestIntention(path, new FlattenWhenIntention()); } public void doTestIntroduceWhenSubject(@NotNull String path) throws Exception { - doTest(path, new IntroduceWhenSubjectIntention()); + doTestIntention(path, new IntroduceWhenSubjectIntention()); } public void doTestEliminateWhenSubject(@NotNull String path) throws Exception { - doTest(path, new EliminateWhenSubjectIntention()); + doTestIntention(path, new EliminateWhenSubjectIntention()); + } + + public void doTestSplitProperty(@NotNull String path) throws Exception { + doTestIntention(path, new SplitPropertyDeclarationIntention()); + } + + public void doTestJoinProperty(@NotNull String path) throws Exception { + doTestAction(path, new JoinLinesHandler(null)); } public void doTestRemoveUnnecessaryParentheses(@NotNull String path) throws Exception { - doTest(path, new RemoveUnnecessaryParenthesesIntention()); + doTestIntention(path, new RemoveUnnecessaryParenthesesIntention()); } - private void doTest(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception { + private void doTestIntention(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception { configureByFile(path); String fileText = FileUtil.loadFile(new File(path)); @@ -104,12 +115,14 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes assert isApplicableExpected == intentionAction.isAvailable(getProject(), getEditor(), getFile()) : "isAvailable() for " + intentionAction.getClass() + " should return " + isApplicableExpected; if (isApplicableExpected) { - invokeAndCheck(path, intentionAction); + intentionAction.invoke(getProject(), getEditor(), getFile()); + checkResultByFile(path + ".after"); } } - private void invokeAndCheck(@NotNull String path, @NotNull IntentionAction intentionAction) { - intentionAction.invoke(getProject(), getEditor(), getFile()); + private void doTestAction(@NotNull String path, @NotNull EditorActionHandler actionHandler) throws Exception { + configureByFile(path); + actionHandler.execute(getEditor(), getCurrentEditorDataContext()); checkResultByFile(path + ".after"); } 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 458a15e5641..d5ee04fb06f 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.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}) +@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, CodeTransformationsTestGenerated.Split.class, CodeTransformationsTestGenerated.Join.class}) public class CodeTransformationsTestGenerated extends AbstractCodeTransformationTest { @TestMetadata("idea/testData/codeInsight/codeTransformations/branched/folding/ifToAssignment") public static class IfToAssignment extends AbstractCodeTransformationTest { @@ -645,6 +645,152 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation } + @TestMetadata("idea/testData/codeInsight/codeTransformations/declarations/split") + public static class Split extends AbstractCodeTransformationTest { + public void testAllFilesPresentInSplit() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/declarations/split"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("longInit.kt") + public void testLongInit() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/longInit.kt"); + } + + @TestMetadata("longInit2.kt") + public void testLongInit2() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/longInit2.kt"); + } + + @TestMetadata("noInitializer.kt") + public void testNoInitializer() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer.kt"); + } + + @TestMetadata("noInitializer2.kt") + public void testNoInitializer2() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/noInitializer2.kt"); + } + + @TestMetadata("nonLocalProperty.kt") + public void testNonLocalProperty() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/nonLocalProperty.kt"); + } + + @TestMetadata("nonLocalProperty2.kt") + public void testNonLocalProperty2() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/nonLocalProperty2.kt"); + } + + @TestMetadata("simpleInit.kt") + public void testSimpleInit() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit.kt"); + } + + @TestMetadata("simpleInit2.kt") + public void testSimpleInit2() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/simpleInit2.kt"); + } + + @TestMetadata("simpleInitWithErrorType.kt") + public void testSimpleInitWithErrorType() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType.kt"); + } + + @TestMetadata("simpleInitWithErrorType2.kt") + public void testSimpleInitWithErrorType2() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithErrorType2.kt"); + } + + @TestMetadata("simpleInitWithType.kt") + public void testSimpleInitWithType() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType.kt"); + } + + @TestMetadata("simpleInitWithType2.kt") + public void testSimpleInitWithType2() throws Exception { + doTestSplitProperty("idea/testData/codeInsight/codeTransformations/declarations/split/simpleInitWithType2.kt"); + } + + } + + @TestMetadata("idea/testData/codeInsight/codeTransformations/declarations/join") + public static class Join extends AbstractCodeTransformationTest { + public void testAllFilesPresentInJoin() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/declarations/join"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("longInit.kt") + public void testLongInit() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/longInit.kt"); + } + + @TestMetadata("longInit2.kt") + public void testLongInit2() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/longInit2.kt"); + } + + @TestMetadata("simpleInit.kt") + public void testSimpleInit() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit.kt"); + } + + @TestMetadata("simpleInit2.kt") + public void testSimpleInit2() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInit2.kt"); + } + + @TestMetadata("simpleInitWithBackticks.kt") + public void testSimpleInitWithBackticks() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks.kt"); + } + + @TestMetadata("simpleInitWithBackticks2.kt") + public void testSimpleInitWithBackticks2() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks2.kt"); + } + + @TestMetadata("simpleInitWithBackticks3.kt") + public void testSimpleInitWithBackticks3() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithBackticks3.kt"); + } + + @TestMetadata("simpleInitWithComments.kt") + public void testSimpleInitWithComments() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments.kt"); + } + + @TestMetadata("simpleInitWithComments2.kt") + public void testSimpleInitWithComments2() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithComments2.kt"); + } + + @TestMetadata("simpleInitWithSemicolons.kt") + public void testSimpleInitWithSemicolons() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons.kt"); + } + + @TestMetadata("simpleInitWithSemicolons2.kt") + public void testSimpleInitWithSemicolons2() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons2.kt"); + } + + @TestMetadata("simpleInitWithSemicolons3.kt") + public void testSimpleInitWithSemicolons3() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithSemicolons3.kt"); + } + + @TestMetadata("simpleInitWithType.kt") + public void testSimpleInitWithType() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType.kt"); + } + + @TestMetadata("simpleInitWithType2.kt") + public void testSimpleInitWithType2() throws Exception { + doTestJoinProperty("idea/testData/codeInsight/codeTransformations/declarations/join/simpleInitWithType2.kt"); + } + + } + public static Test suite() { TestSuite suite = new TestSuite("CodeTransformationsTestGenerated"); suite.addTestSuite(IfToAssignment.class); @@ -663,6 +809,8 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation suite.addTestSuite(Flatten.class); suite.addTestSuite(IntroduceSubject.class); suite.addTestSuite(EliminateSubject.class); + suite.addTestSuite(Split.class); + suite.addTestSuite(Join.class); return suite; } }