From 5345d0a0d51b7bfc536c31a27c162027f8031fdb Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 30 May 2013 17:30:51 +0400 Subject: [PATCH] Fix moving of value/type parameters --- .../upDownMover/AbstractJetUpDownMover.java | 6 ++ .../upDownMover/JetDeclarationMover.java | 6 +- .../upDownMover/JetExpressionMover.java | 37 +++++++- .../functionAnchors/keyword.kt | 9 ++ .../functionAnchors/keyword.kt.after | 9 ++ .../functionAnchors/name.kt | 9 ++ .../functionAnchors/name.kt.after | 9 ++ .../functionAnchors/returnType.kt | 9 ++ .../functionAnchors/returnType.kt.after | 9 ++ .../functionAnchors/typeParams1.kt | 15 +++ .../functionAnchors/typeParams1.kt.after | 15 +++ .../functionAnchors/typeParams2.kt | 15 +++ .../functionAnchors/typeParams2.kt.after | 15 +++ .../functionAnchors/typeParams3.kt | 15 +++ .../functionAnchors/typeParams3.kt.after | 15 +++ .../functionAnchors/valueParams1.kt | 16 ++++ .../functionAnchors/valueParams1.kt.after | 16 ++++ .../functionAnchors/valueParams2.kt | 16 ++++ .../functionAnchors/valueParams2.kt.after | 16 ++++ .../functionAnchors/valueParams3.kt | 16 ++++ .../functionAnchors/valueParams3.kt.after | 16 ++++ .../functionAnchors/valueParams4.kt | 16 ++++ .../functionAnchors/valueParams4.kt.after | 16 ++++ .../functionAnchors/valueParams5.kt | 17 ++++ .../functionAnchors/valueParams6.kt | 17 ++++ .../propertyAnchors/keyword.kt | 13 +++ .../propertyAnchors/keyword.kt.after | 13 +++ .../propertyAnchors/name.kt | 13 +++ .../propertyAnchors/name.kt.after | 13 +++ .../propertyAnchors/returnType.kt | 13 +++ .../propertyAnchors/returnType.kt.after | 13 +++ .../moveUpDown/AbstractCodeMoverTest.java | 9 +- .../moveUpDown/CodeMoverTestGenerated.java | 95 ++++++++++++++++++- 33 files changed, 526 insertions(+), 11 deletions(-) create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams5.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams6.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt.after create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt create mode 100644 idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt.after diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/AbstractJetUpDownMover.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/AbstractJetUpDownMover.java index 5c1b3851294..c752befc5e4 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/AbstractJetUpDownMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/AbstractJetUpDownMover.java @@ -8,6 +8,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.PsiWhiteSpace; +import com.intellij.psi.util.PsiTreeUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.psi.JetFile; @@ -51,6 +52,11 @@ public abstract class AbstractJetUpDownMover extends LineMover { return sibling; } + @Nullable + protected static PsiElement getSiblingOfType(@NotNull PsiElement element, boolean down, @NotNull Class type) { + return down ? PsiTreeUtil.getNextSiblingOfType(element, type) : PsiTreeUtil.getPrevSiblingOfType(element, type); + } + @Nullable protected static PsiElement firstNonWhiteSibling(@NotNull LineRange lineRange, boolean down) { return firstNonWhiteElement(down ? lineRange.lastElement.getNextSibling() : lineRange.firstElement.getPrevSibling(), down); diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java index d1ecaedb468..f31dbe9bbf8 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetDeclarationMover.java @@ -49,9 +49,6 @@ public class JetDeclarationMover extends AbstractJetUpDownMover { PsiElement equalsToken = function.getEqualsToken(); if (equalsToken != null) memberSuspects.add(equalsToken); - JetParameterList parameterList = function.getValueParameterList(); - if (parameterList != null) memberSuspects.add(parameterList); - JetTypeParameterList typeParameterList = function.getTypeParameterList(); if (typeParameterList != null) memberSuspects.add(typeParameterList); @@ -120,6 +117,9 @@ public class JetDeclarationMover extends AbstractJetUpDownMover { if (element == null) return null; JetDeclaration declaration = PsiTreeUtil.getParentOfType(element, JetDeclaration.class, false); + if (declaration instanceof JetTypeParameter) { + return getMovableDeclaration(declaration.getParent()); + } return PsiTreeUtil.instanceOf(PsiTreeUtil.getParentOfType(declaration, DECLARATION_CONTAINER_CLASSES), diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java index 828335213ad..bed8538821f 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/upDownMover/JetExpressionMover.java @@ -291,6 +291,23 @@ public class JetExpressionMover extends AbstractJetUpDownMover { return sourceRange; } + @Nullable + private static PsiElement getMovableElement(@NotNull PsiElement element) { + return PsiTreeUtil.getNonStrictParentOfType(element, MOVABLE_ELEMENT_CLASSES); + } + + // return true to forbid the move + // return false to permit the move + // return null to fall back to default line mover behavior + private static Boolean isForbiddenMove(@NotNull PsiElement element, boolean down) { + if (element instanceof JetParameter) { + PsiElement sibling = getSiblingOfType(element, down, element.getClass()); + return (sibling != null) ? null : true; + } + + return false; + } + @Override public boolean checkAvailable(@NotNull Editor editor, @NotNull PsiFile file, @NotNull MoveInfo info, boolean down) { if (!super.checkAvailable(editor, file, info, down)) return false; @@ -309,12 +326,22 @@ public class JetExpressionMover extends AbstractJetUpDownMover { if (psiRange == null) return false; //noinspection unchecked - PsiElement firstElement = PsiTreeUtil.getNonStrictParentOfType(psiRange.getFirst(), MOVABLE_ELEMENT_CLASSES); - if (firstElement == null) return false; + PsiElement firstElement = getMovableElement(psiRange.getFirst()); + PsiElement lastElement = getMovableElement(psiRange.getSecond()); - //noinspection unchecked - PsiElement lastElement = PsiTreeUtil.getNonStrictParentOfType(psiRange.getSecond(), MOVABLE_ELEMENT_CLASSES); - if (lastElement == null) return false; + if (firstElement == null || lastElement == null) return false; + + Boolean forbidFirst = isForbiddenMove(firstElement, down); + Boolean forbidLast = isForbiddenMove(lastElement, down); + + if (forbidFirst == null || forbidLast == null) { + return true; + } + + if (forbidFirst || forbidLast) { + info.toMove2 = null; + return true; + } LineRange sourceRange = getSourceRange(firstElement, lastElement, editor); if (sourceRange == null) return false; diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt new file mode 100644 index 00000000000..6150efb0be3 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt @@ -0,0 +1,9 @@ +// MOVE: down +class A { + fun foo() { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt.after new file mode 100644 index 00000000000..d616e7db69a --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt.after @@ -0,0 +1,9 @@ +// MOVE: down +class A { + class B { + fun foo() { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt new file mode 100644 index 00000000000..6150efb0be3 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt @@ -0,0 +1,9 @@ +// MOVE: down +class A { + fun foo() { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt.after new file mode 100644 index 00000000000..d616e7db69a --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt.after @@ -0,0 +1,9 @@ +// MOVE: down +class A { + class B { + fun foo() { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt new file mode 100644 index 00000000000..5f82e152611 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt @@ -0,0 +1,9 @@ +// MOVE: down +class A { + fun foo(): Unit { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt.after new file mode 100644 index 00000000000..47e320d8329 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt.after @@ -0,0 +1,9 @@ +// MOVE: down +class A { + class B { + fun foo(): Unit { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt new file mode 100644 index 00000000000..76b00ab230e --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt @@ -0,0 +1,15 @@ +// MOVE: down +class A { + fun foo<T, + U, + W>( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt.after new file mode 100644 index 00000000000..5599dc1ec8d --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt.after @@ -0,0 +1,15 @@ +// MOVE: down +class A { + class B { + fun foo<T, + U, + W>( + b: Int, + a: Int, + c: Int + ) { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt new file mode 100644 index 00000000000..06d46bf4afe --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt @@ -0,0 +1,15 @@ +// MOVE: down +class A { + fun foo, + W>( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt.after new file mode 100644 index 00000000000..717f68b8366 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt.after @@ -0,0 +1,15 @@ +// MOVE: down +class A { + class B { + fun foo, + W>( + b: Int, + a: Int, + c: Int + ) { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt new file mode 100644 index 00000000000..57ea5dd84da --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt @@ -0,0 +1,15 @@ +// MOVE: down +class A { + fun foo>( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt.after new file mode 100644 index 00000000000..8fe9444b7d8 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt.after @@ -0,0 +1,15 @@ +// MOVE: down +class A { + class B { + fun foo>( + b: Int, + a: Int, + c: Int + ) { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt new file mode 100644 index 00000000000..ac59006eaae --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt @@ -0,0 +1,16 @@ +// MOVE: down +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt.after new file mode 100644 index 00000000000..061c5220a57 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt.after @@ -0,0 +1,16 @@ +// MOVE: down +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + a: Int, + b: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt new file mode 100644 index 00000000000..4300aa586f3 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt @@ -0,0 +1,16 @@ +// MOVE: down +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt.after new file mode 100644 index 00000000000..ed71321452d --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt.after @@ -0,0 +1,16 @@ +// MOVE: down +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + b: Int, + c: Int + a: Int, + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt new file mode 100644 index 00000000000..eb98175f5ba --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt @@ -0,0 +1,16 @@ +// MOVE: up +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + a: Int, + b: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt.after new file mode 100644 index 00000000000..d8a000b41a3 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt.after @@ -0,0 +1,16 @@ +// MOVE: up +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt new file mode 100644 index 00000000000..e46e747c672 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt @@ -0,0 +1,16 @@ +// MOVE: up +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + b: Int, + c: Int + a: Int, + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt.after new file mode 100644 index 00000000000..73fef7e9453 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt.after @@ -0,0 +1,16 @@ +// MOVE: up +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +class A { + fun foo( + b: Int, + a: Int, + c: Int + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams5.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams5.kt new file mode 100644 index 00000000000..706e5b82cb1 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams5.kt @@ -0,0 +1,17 @@ +// MOVE: down +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +// IS_APPLICABLE: false +class A { + fun foo( + b: Int, + c: Int + a: Int, + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams6.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams6.kt new file mode 100644 index 00000000000..9fad3970685 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams6.kt @@ -0,0 +1,17 @@ +// MOVE: up +// MOVER_CLASS: org.jetbrains.jet.plugin.codeInsight.upDownMover.JetExpressionMover +// IS_APPLICABLE: false +class A { + fun foo( + b: Int, + c: Int + a: Int, + ) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt new file mode 100644 index 00000000000..c13119db2c6 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt @@ -0,0 +1,13 @@ +// MOVE: down +class A { + val x: String + get() { + return "" + } + set(v: String) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt.after new file mode 100644 index 00000000000..cc22dcc2c56 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt.after @@ -0,0 +1,13 @@ +// MOVE: down +class A { + class B { + val x: String + get() { + return "" + } + set(v: String) { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt new file mode 100644 index 00000000000..93950581d05 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt @@ -0,0 +1,13 @@ +// MOVE: down +class A { + val x: String + get() { + return "" + } + set(v: String) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt.after new file mode 100644 index 00000000000..cd15135fd3d --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt.after @@ -0,0 +1,13 @@ +// MOVE: down +class A { + class B { + val x: String + get() { + return "" + } + set(v: String) { + + } + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt new file mode 100644 index 00000000000..22720ebaa89 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt @@ -0,0 +1,13 @@ +// MOVE: down +class A { + val x: String + get() { + return "" + } + set(v: String) { + + } + class B { + + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt.after b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt.after new file mode 100644 index 00000000000..a735c09f511 --- /dev/null +++ b/idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt.after @@ -0,0 +1,13 @@ +// MOVE: down +class A { + class B { + val x: String + get() { + return "" + } + set(v: String) { + + } + + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/AbstractCodeMoverTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/AbstractCodeMoverTest.java index 329bf8489e8..53ade244493 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/AbstractCodeMoverTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/AbstractCodeMoverTest.java @@ -39,7 +39,7 @@ public abstract class AbstractCodeMoverTest extends LightCodeInsightTestCase { doTest(path, JetExpressionMover.class); } - private void doTest(@NotNull String path, @NotNull Class moverClass) throws Exception { + private void doTest(@NotNull String path, @NotNull Class defaultMoverClass) throws Exception { configureByFile(path); String fileText = FileUtil.loadFile(new File(path)); @@ -69,8 +69,13 @@ public abstract class AbstractCodeMoverTest extends LightCodeInsightTestCase { } } + String moverClassName = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MOVER_CLASS: "); + if (moverClassName == null) { + moverClassName = defaultMoverClass.getName(); + } + assertTrue("No mover found", actualMover != null); - assertEquals("Unmatched movers", moverClass, actualMover.getClass()); + assertEquals("Unmatched movers", moverClassName, actualMover.getClass().getName()); assertEquals("Invalid applicability", isApplicableExpected, info.toMove2 != null); if (isApplicableExpected) { diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java index 6b4ca6785ef..c7c96ca17f1 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/moveUpDown/CodeMoverTestGenerated.java @@ -33,7 +33,7 @@ import org.jetbrains.jet.plugin.codeInsight.moveUpDown.AbstractCodeMoverTest; @InnerTestClasses({CodeMoverTestGenerated.ClassBodyDeclarations.class, CodeMoverTestGenerated.ClosingBraces.class, CodeMoverTestGenerated.Expressions.class}) public class CodeMoverTestGenerated extends AbstractCodeMoverTest { @TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations") - @InnerTestClasses({ClassBodyDeclarations.Accessors.class, ClassBodyDeclarations.Class.class, ClassBodyDeclarations.ClassInitializer.class, ClassBodyDeclarations.Enums.class, ClassBodyDeclarations.Function.class, ClassBodyDeclarations.Property.class}) + @InnerTestClasses({ClassBodyDeclarations.Accessors.class, ClassBodyDeclarations.Class.class, ClassBodyDeclarations.ClassInitializer.class, ClassBodyDeclarations.Enums.class, ClassBodyDeclarations.Function.class, ClassBodyDeclarations.FunctionAnchors.class, ClassBodyDeclarations.Property.class, ClassBodyDeclarations.PropertyAnchors.class}) public static class ClassBodyDeclarations extends AbstractCodeMoverTest { public void testAllFilesPresentInClassBodyDeclarations() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/moveUpDown/classBodyDeclarations"), Pattern.compile("^(.+)\\.kt$"), true); @@ -349,6 +349,74 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { } + @TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors") + public static class FunctionAnchors extends AbstractCodeMoverTest { + public void testAllFilesPresentInFunctionAnchors() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("keyword.kt") + public void testKeyword() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/keyword.kt"); + } + + @TestMetadata("name.kt") + public void testName() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/name.kt"); + } + + @TestMetadata("returnType.kt") + public void testReturnType() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/returnType.kt"); + } + + @TestMetadata("typeParams1.kt") + public void testTypeParams1() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams1.kt"); + } + + @TestMetadata("typeParams2.kt") + public void testTypeParams2() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams2.kt"); + } + + @TestMetadata("typeParams3.kt") + public void testTypeParams3() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/typeParams3.kt"); + } + + @TestMetadata("valueParams1.kt") + public void testValueParams1() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams1.kt"); + } + + @TestMetadata("valueParams2.kt") + public void testValueParams2() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams2.kt"); + } + + @TestMetadata("valueParams3.kt") + public void testValueParams3() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams3.kt"); + } + + @TestMetadata("valueParams4.kt") + public void testValueParams4() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams4.kt"); + } + + @TestMetadata("valueParams5.kt") + public void testValueParams5() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams5.kt"); + } + + @TestMetadata("valueParams6.kt") + public void testValueParams6() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/functionAnchors/valueParams6.kt"); + } + + } + @TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/property") public static class Property extends AbstractCodeMoverTest { public void testAllFilesPresentInProperty() throws Exception { @@ -437,6 +505,29 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { } + @TestMetadata("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors") + public static class PropertyAnchors extends AbstractCodeMoverTest { + public void testAllFilesPresentInPropertyAnchors() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("keyword.kt") + public void testKeyword() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/keyword.kt"); + } + + @TestMetadata("name.kt") + public void testName() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/name.kt"); + } + + @TestMetadata("returnType.kt") + public void testReturnType() throws Exception { + doTestClassBodyDeclaration("idea/testData/codeInsight/moveUpDown/classBodyDeclarations/propertyAnchors/returnType.kt"); + } + + } + public static Test innerSuite() { TestSuite suite = new TestSuite("ClassBodyDeclarations"); suite.addTestSuite(ClassBodyDeclarations.class); @@ -445,7 +536,9 @@ public class CodeMoverTestGenerated extends AbstractCodeMoverTest { suite.addTestSuite(ClassInitializer.class); suite.addTestSuite(Enums.class); suite.addTestSuite(Function.class); + suite.addTestSuite(FunctionAnchors.class); suite.addTestSuite(Property.class); + suite.addTestSuite(PropertyAnchors.class); return suite; } }