Fixed moving of classes without body
This commit is contained in:
@@ -106,16 +106,36 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
|
|||||||
return element instanceof JetDeclaration;
|
return element instanceof JetDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static PsiElement skipInsignificantElements(@NotNull PsiElement element, boolean down) {
|
||||||
|
PsiElement result = element;
|
||||||
|
|
||||||
|
while (result instanceof PsiWhiteSpace || result.getTextLength() == 0) {
|
||||||
|
result = down ? result.getNextSibling() : result.getPrevSibling();
|
||||||
|
if (result == null) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LineRange getElementSourceLineRange(@NotNull PsiElement element, @NotNull Editor editor, @NotNull LineRange oldRange) {
|
protected LineRange getElementSourceLineRange(@NotNull PsiElement element, @NotNull Editor editor, @NotNull LineRange oldRange) {
|
||||||
JetDeclaration declaration = (JetDeclaration) element;
|
JetDeclaration declaration = (JetDeclaration) element;
|
||||||
|
|
||||||
Document doc = editor.getDocument();
|
PsiElement first = skipInsignificantElements(declaration.getFirstChild(), true);
|
||||||
TextRange textRange = declaration.getTextRange();
|
PsiElement last = skipInsignificantElements(declaration.getLastChild(), false);
|
||||||
if (doc.getTextLength() < textRange.getEndOffset()) return null;
|
|
||||||
|
|
||||||
int startLine = editor.offsetToLogicalPosition(textRange.getStartOffset()).line;
|
if (first == null || last == null) return null;
|
||||||
int endLine = editor.offsetToLogicalPosition(textRange.getEndOffset()).line + 1;
|
|
||||||
|
TextRange textRange1 = first.getTextRange();
|
||||||
|
TextRange textRange2 = last.getTextRange();
|
||||||
|
|
||||||
|
Document doc = editor.getDocument();
|
||||||
|
|
||||||
|
if (doc.getTextLength() < textRange2.getEndOffset()) return null;
|
||||||
|
|
||||||
|
int startLine = editor.offsetToLogicalPosition(textRange1.getStartOffset()).line;
|
||||||
|
int endLine = editor.offsetToLogicalPosition(textRange2.getEndOffset()).line + 1;
|
||||||
|
|
||||||
if (startLine == oldRange.startLine || startLine == oldRange.endLine
|
if (startLine == oldRange.startLine || startLine == oldRange.endLine
|
||||||
|| endLine == oldRange.startLine || endLine == oldRange.endLine) {
|
|| endLine == oldRange.startLine || endLine == oldRange.endLine) {
|
||||||
@@ -188,6 +208,13 @@ public class JetDeclarationMover extends AbstractJetUpDownMover {
|
|||||||
|
|
||||||
if (target instanceof JetPropertyAccessor && !(sibling instanceof JetPropertyAccessor)) return null;
|
if (target instanceof JetPropertyAccessor && !(sibling instanceof JetPropertyAccessor)) return null;
|
||||||
|
|
||||||
|
if (start != null && start.getFirstChild() != null) {
|
||||||
|
start = skipInsignificantElements(start.getFirstChild(), true);
|
||||||
|
}
|
||||||
|
if (end != null && end.getFirstChild() != null) {
|
||||||
|
end = skipInsignificantElements(end.getLastChild(), false);
|
||||||
|
}
|
||||||
|
|
||||||
return start != null && end != null ? new LineRange(start, end, editor.getDocument()) : null;
|
return start != null && end != null ? new LineRange(start, end, editor.getDocument()) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
<caret>class A
|
||||||
|
|
||||||
|
class D {
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: down
|
||||||
|
class D {
|
||||||
|
|
||||||
|
<caret>class A
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
class D {
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>class A
|
||||||
|
|
||||||
|
class C {
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// MOVE: up
|
||||||
|
class D {
|
||||||
|
<caret>class A
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// MOVE: down
|
||||||
|
<caret>class A
|
||||||
|
|
||||||
|
class D {
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// MOVE: down
|
||||||
|
class D {
|
||||||
|
|
||||||
|
<caret>class A
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// MOVE: up
|
||||||
|
class D {
|
||||||
|
}
|
||||||
|
|
||||||
|
<caret>class A
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// MOVE: up
|
||||||
|
class D {
|
||||||
|
<caret>class A
|
||||||
|
|
||||||
|
}
|
||||||
+20
@@ -153,6 +153,26 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest {
|
|||||||
doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtProperty2.kt");
|
doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classAtProperty2.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classWithoutBody1.kt")
|
||||||
|
public void testClassWithoutBody1() throws Exception {
|
||||||
|
doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classWithoutBody1.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classWithoutBody2.kt")
|
||||||
|
public void testClassWithoutBody2() throws Exception {
|
||||||
|
doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classWithoutBody2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classWithoutBody3.kt")
|
||||||
|
public void testClassWithoutBody3() throws Exception {
|
||||||
|
doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classWithoutBody3.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classWithoutBody4.kt")
|
||||||
|
public void testClassWithoutBody4() throws Exception {
|
||||||
|
doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/class/classWithoutBody4.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/classInitializer")
|
@TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/classInitializer")
|
||||||
|
|||||||
Reference in New Issue
Block a user