Implement split/join property declaration
This commit is contained in:
+34
-21
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
+149
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user