diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/actions/GroovyStatementMover.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/actions/GroovyStatementMover.java index 68adcb776439..f0907e230b97 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/actions/GroovyStatementMover.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/editor/actions/GroovyStatementMover.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * 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. @@ -21,7 +21,6 @@ import com.intellij.codeInsight.editorActions.moveUpDown.StatementUpDownMover; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiComment; import com.intellij.psi.PsiElement; @@ -36,7 +35,9 @@ import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment; import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocCommentOwner; import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase; import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration; import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock; import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrCaseLabel; @@ -245,6 +246,18 @@ public class GroovyStatementMover extends StatementUpDownMover { return new LineRange(comment, pivot); } } + else if (pivot instanceof GrVariableDeclaration && pivot.getParent() instanceof GrTypeDefinitionBody) { + GrVariable[] variables = ((GrVariableDeclaration)pivot).getVariables(); + if (variables.length > 0) { + GrVariable variable = variables[0]; + if (variable instanceof GrField) { + GrDocComment comment = ((GrField)variable).getDocComment(); + if (comment != null) { + return new LineRange(comment, pivot); + } + } + } + } return new LineRange(pivot); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java index 3cd6a275ac77..84d03bd8f74d 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/updown/GroovyMoveStatementTest.java @@ -1,5 +1,6 @@ /* - * Copyright 2000-2008 JetBrains s.r.o. + * 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 @@ -65,6 +66,7 @@ public class GroovyMoveStatementTest extends GroovyEditorActionTestBase { public void testMoveGroovydocWithMethod() throws Throwable { bothTest(); } public void testLeaveGroovydocWithMethod() throws Throwable { bothTest(); } public void testMoveMethodWithGroovydoc() throws Throwable { bothTest(); } + public void testMoveGroovyDocWithField() throws Throwable { bothTest(); } public void testMoveSecondFieldUp() throws Throwable { bothTest(); } public void testMoveFirstFieldDown() throws Throwable { bothTest(); } diff --git a/plugins/groovy/testdata/groovy/actions/moveStatement/moveGroovyDocWithField.test b/plugins/groovy/testdata/groovy/actions/moveStatement/moveGroovyDocWithField.test new file mode 100644 index 000000000000..c7a975b796ee --- /dev/null +++ b/plugins/groovy/testdata/groovy/actions/moveStatement/moveGroovyDocWithField.test @@ -0,0 +1,35 @@ +class Person { + /** + * Full name of this person + */ + String name + + /** + * Age of this person in years + */ + int age +} +----- +class Person { + /** + * Age of this person in years + */ + int age + + /** + * Full name of this person + */ + String name +} +----- +class Person { + /** + * Full name of this person + */ + String name + + /** + * Age of this person in years + */ + int age +} \ No newline at end of file