allow to move left/right more java constructs

This commit is contained in:
Bas Leijdekkers
2016-03-30 11:43:51 +02:00
parent de9ba9906c
commit 4d0e044c2f
2 changed files with 40 additions and 0 deletions
@@ -41,6 +41,20 @@ public class JavaMoveLeftRightHandler extends MoveElementLeftRightHandler {
return enumConstants;
}
}
else if (element instanceof PsiReferenceList) {
return ((PsiReferenceList)element).getReferenceElements();
}
else if (element instanceof PsiTypeElement) {
final PsiTypeElement[] result = PsiTreeUtil.getChildrenOfType(element, PsiTypeElement.class);
return result == null ? PsiElement.EMPTY_ARRAY : result;
}
else if (element instanceof PsiResourceList) {
final PsiElement[] result = PsiTreeUtil.getChildrenOfType(element, PsiResourceListElement.class);
return result == null ? PsiElement.EMPTY_ARRAY : result;
}
else if (element instanceof PsiPolyadicExpression) {
return ((PsiPolyadicExpression)element).getOperands();
}
return PsiElement.EMPTY_ARRAY;
}
}
@@ -80,6 +80,32 @@ public class MoveElementLeftRightTest extends AbstractMoveElementLeftRightTest {
"@SomeAnnotation(p2 = \"2\", p1=<caret>1) class C {}");
}
public void testMoveThrowsExceptions() throws Exception {
doTestFromLeftToRight("class C { void m() throws RuntimeExceptio<caret>n, Exception {} }",
"class C { void m() throws Exception, RuntimeExceptio<caret>n {} }");
}
public void testMoveImplementsClause() throws Exception {
doTestFromLeftToRight("class C implements Cl<caret>oneable, java.io.Serializable {}",
"class C implements java.io.Serializable, Cl<caret>oneable {}");
}
public void testMoveMulticatch() throws Exception {
doTestFromLeftToRight("class C { void m() { try {} catch (Runtime<caret>Exception | Exception e) {}",
"class C { void m() { try {} catch (Exception | Runtime<caret>Exception e) {}");
}
public void testMoveTryResource() throws Exception {
doTestFromLeftToRight("class C { void m(AutoCloseable a) { try (Auto<caret>Closeable b = a; AutoCloseable c = null) {} } }",
"class C { void m(AutoCloseable a) { try (AutoCloseable c = null; Auto<caret>Closeable b = a) {} } }");
}
public void testMovePolyadicExpressionOperand() throws Exception {
doTestFromLeftToRight("class C { int i = <caret>1 + 2 + 3; }",
"class C { int i = 2 + <caret>1 + 3; }",
"class C { int i = 2 + 3 + <caret>1; }");
}
@Override
protected void configureEditor(String contents) throws Exception {
init(contents, TestFileType.JAVA);