Allow moving out to arbitrary blocks and moving any declaration into class body
This commit is contained in:
@@ -809,6 +809,12 @@ public class JetPsiUtil {
|
||||
return first ? results.get(0) : results.get(results.size() - 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement findChildByType(@NotNull PsiElement element, @NotNull IElementType type) {
|
||||
ASTNode node = element.getNode().findChildByType(type);
|
||||
return node == null ? null : node.getPsi();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) {
|
||||
if (expression instanceof JetCallElement) {
|
||||
|
||||
@@ -190,9 +190,6 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
|
||||
|
||||
nextParent = jetClassOrObject.getParent();
|
||||
|
||||
// elements may be placed only to class body or file
|
||||
if (!(nextParent instanceof JetFile || nextParent instanceof JetClassBody)) return null;
|
||||
|
||||
if (!down) {
|
||||
start = jetClassOrObject;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
else {
|
||||
// moving into code block
|
||||
//noinspection unchecked
|
||||
JetElement blockLikeElement = JetPsiUtil.getOutermostJetElement(sibling, down, JetBlockExpression.class, JetWhenExpression.class);
|
||||
JetElement blockLikeElement = JetPsiUtil.getOutermostJetElement(sibling, down, JetBlockExpression.class, JetWhenExpression.class, JetClassBody.class);
|
||||
if (blockLikeElement != null &&
|
||||
!(PsiTreeUtil.instanceOf(blockLikeElement, FUNCTIONLIKE_ELEMENT_CLASSES))) {
|
||||
if (blockLikeElement instanceof JetWhenExpression) {
|
||||
@@ -212,13 +212,11 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
}
|
||||
|
||||
if (blockLikeElement != null) {
|
||||
JetBlockExpression block = (JetBlockExpression) blockLikeElement;
|
||||
|
||||
if (down) {
|
||||
end = block.getLBrace();
|
||||
end = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.LBRACE);
|
||||
}
|
||||
else {
|
||||
start = block.getRBrace();
|
||||
start = JetPsiUtil.findChildByType(blockLikeElement, JetTokens.RBRACE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// MOVE: down
|
||||
// IS_APPLICABLE: false
|
||||
fun foo() {
|
||||
class B {
|
||||
class A {
|
||||
<caret>class B {
|
||||
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
class A {
|
||||
}
|
||||
<caret>class B {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
// MOVE: up
|
||||
// IS_APPLICABLE: false
|
||||
fun foo() {
|
||||
class B {
|
||||
class A {
|
||||
<caret>class B {
|
||||
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
<caret>class B {
|
||||
|
||||
}
|
||||
class A {
|
||||
}
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// MOVE: down
|
||||
// IS_APPLICABLE: false
|
||||
fun foo() {
|
||||
class B {
|
||||
<caret>fun foo() {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
class B {
|
||||
}
|
||||
<caret>fun foo() {
|
||||
|
||||
}
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// MOVE: up
|
||||
// IS_APPLICABLE: false
|
||||
fun foo() {
|
||||
class B {
|
||||
<caret>fun foo() {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
<caret>fun foo() {
|
||||
|
||||
}
|
||||
class B {
|
||||
}
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// MOVE: down
|
||||
// IS_APPLICABLE: false
|
||||
fun foo() {
|
||||
class B {
|
||||
<caret>val y = ""
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// MOVE: down
|
||||
fun foo() {
|
||||
class B {
|
||||
}
|
||||
<caret>val y = ""
|
||||
}
|
||||
-1
@@ -1,5 +1,4 @@
|
||||
// MOVE: up
|
||||
// IS_APPLICABLE: false
|
||||
fun foo() {
|
||||
class B {
|
||||
<caret>val y = ""
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// MOVE: up
|
||||
fun foo() {
|
||||
<caret>val y = ""
|
||||
class B {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user