/* * Copyright 2000-2016 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 com.intellij.codeInsight.editorActions; import com.intellij.testFramework.TestFileType; public class MoveElementLeftRightTest extends AbstractMoveElementLeftRightTest { public void testMoveLiteralMethodParameter() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(\"a\", \"b\"); } }", "class C { void m() { System.setProperty(\"b\", \"a\"); } }"); } public void testMoveAtLiteralMethodParameterEnd() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(\"a\", \"b\"); } }", "class C { void m() { System.setProperty(\"b\", \"a\"); } }"); } public void testMoveComplexMethodParameter() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(System.getEnv(null), \"b\"); } }", "class C { void m() { System.setProperty(\"b\", System.getEnv(null)); } }"); } public void testMoveOuterLevelOutsideParenthesis() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(System.setProperty(\"c\", \"d\"), \"b\"); } }", "class C { void m() { System.setProperty(\"b\", System.setProperty(\"c\", \"d\")); } }"); } public void testMoveInnerLevelInsideParenthesis() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(System.setProperty(\"c\", \"d\"), \"b\"); } }", "class C { void m() { System.setProperty(System.setProperty(\"d\", \"c\"), \"b\"); } }"); } public void testMoveOuterLevelInsideParenthesisWithSingleParameter() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(System.getEnv(null), \"b\"); } }", "class C { void m() { System.setProperty(\"b\", System.getEnv(null)); } }"); } public void testMoveSingleParameterWithSelection() throws Exception { doTestFromLeftToRight("class C { void m() { System.setProperty(\"a\", \"b\"); } }", "class C { void m() { System.setProperty(\"b\", \"a\"); } }"); } public void testMoveTwoParametersWithSelection() throws Exception { doTestFromLeftToRight("class C { void m() { java.util.Arrays.asList(\"a\", \"b\", \"c\"); } }", "class C { void m() { java.util.Arrays.asList(\"c\", \"a\", \"b\"); } }"); } public void testMovingMethodDeclaredParameters() throws Exception { doTestFromLeftToRight("class C { void m(int a, String b, @NotNull List c) {} }", "class C { void m(String b, int a, @NotNull List c) {} }", "class C { void m(String b, @NotNull List c, int a) {} }"); } public void testMovingArrayInitializerComponents() throws Exception { doTestFromLeftToRight("class C { int[] a = {1, 2, 3}; }", "class C { int[] a = {2, 1, 3}; }", "class C { int[] a = {2, 3, 1}; }"); } public void testMoveEnumConstants() throws Exception { doTestFromLeftToRight("enum E { AA, BB, }", "enum E { BB, AA, }"); } public void testMoveAnnotationParameters() throws Exception { doTestFromLeftToRight("@SomeAnnotation(p1=1, p2 = \"2\") class C {}", "@SomeAnnotation(p2 = \"2\", p1=1) class C {}"); } public void testMoveThrowsExceptions() throws Exception { doTestFromLeftToRight("class C { void m() throws RuntimeException, Exception {} }", "class C { void m() throws Exception, RuntimeException {} }"); } public void testMoveThrowsExceptionsWithCaretAtEnd() throws Exception { doTestFromRightToLeft("class C { void m() throws RuntimeException, Exception {} }", "class C { void m() throws Exception, RuntimeException {} }"); } public void testMoveImplementsClause() throws Exception { doTestFromLeftToRight("class C implements Cloneable, java.io.Serializable {}", "class C implements java.io.Serializable, Cloneable {}"); } public void testMoveMulticatch() throws Exception { doTestFromLeftToRight("class C { void m() { try {} catch (RuntimeException | Exception e) {}", "class C { void m() { try {} catch (Exception | RuntimeException e) {}"); } public void testMoveTryResource() throws Exception { doTestFromLeftToRight("class C { void m(AutoCloseable a) { try (AutoCloseable b = a; AutoCloseable c = null) {} } }", "class C { void m(AutoCloseable a) { try (AutoCloseable c = null; AutoCloseable b = a) {} } }"); } public void testMovePolyadicExpressionOperand() throws Exception { doTestFromLeftToRight("class C { int i = 1 + 2 + 3; }", "class C { int i = 2 + 1 + 3; }", "class C { int i = 2 + 3 + 1; }"); } public void testMoveTypeParameter() throws Exception { doTestFromLeftToRight("class C {{ java.util.Map, String> map; }}", "class C {{ java.util.Map> map; }}"); } public void testMoveClassTypeParameter() throws Exception { doTestFromLeftToRight("class C<A, B> {}", "class CA> {}"); } public void testMoveModifier() throws Exception { doTestFromLeftToRight("@SuppressWarnings(\"ALL\") final class C {}", "final @SuppressWarnings(\"ALL\") class C {}"); } public void testMoveAnnotationMemberValue() throws Exception { doTestFromLeftToRight("@SuppressWarnings({\"a\", \"b\"}) final class C {}", "@SuppressWarnings({\"b\", \"a\"}) final class C {}"); } @Override protected void configureEditor(String contents) throws Exception { init(contents, TestFileType.JAVA); } }