PsiMember (@NotNull MoveMembersOptions options, @NotNull PsiMember member, PsiElement anchor, @NotNull PsiClass targetClass) { GroovyChangeContextUtil.encodeContextInfo(member); final PsiDocComment docComment; if (member instanceof PsiDocCommentOwner) { docComment = ((PsiDocCommentOwner)member).getDocComment(); } else { docComment = null; } PsiMember moved; if (options.makeEnumConstant() && member instanceof GrVariable && EnumConstantsUtil.isSuitableForEnumConstant(((PsiVariable)member).getType(), targetClass)) { final GrEnumConstant prototype = createEnumConstant(member.getName(), ((GrVariable)member).getInitializerGroovy(), member.getProject()); moved = (PsiMember)addEnumConstant(targetClass, prototype, anchor); member.delete(); } else if (member instanceof GrEnumConstant) { moved = (PsiMember)addEnumConstant(targetClass, (GrEnumConstant)member, null); } else if (member instanceof GrField) { if (anchor != null) anchor = anchor.getParent(); final GrVariableDeclaration parent = (GrVariableDeclaration)member.getParent(); GrVariableDeclaration movedDeclaration = (GrVariableDeclaration)targetClass.addAfter(parent, anchor); int number = ArrayUtil.find(parent.getMembers(), member); final GrMember[] members = movedDeclaration.getMembers(); for (int i = 0; i < number; i++) { members[i].delete(); } for (int i = number + 1; i < members.length; i++) { members[i].delete(); } if (member.getContainingClass().isInterface() && !targetClass.isInterface()) { //might need to make modifiers explicit, see IDEADEV-11416 final PsiModifierList list = movedDeclaration.getModifierList(); VisibilityUtil.setVisibility(list, VisibilityUtil.getVisibilityModifier(member.getModifierList())); list.setModifierProperty(PsiModifier.STATIC, member.hasModifierProperty(PsiModifier.STATIC)); list.setModifierProperty(PsiModifier.FINAL, member.hasModifierProperty(PsiModifier.FINAL)); } moved = movedDeclaration.getMembers()[0]; } else if (member instanceof GrMethod) { moved = (PsiMember)targetClass.addAfter(member, anchor); if (member.getContainingClass().isInterface() && !targetClass.isInterface()) { //might need to make modifiers explicit, see IDEADEV-11416 final PsiModifierList list = moved.getModifierList(); assert list != null; list.setModifierProperty(PsiModifier.STATIC, member.hasModifierProperty(PsiModifier.STATIC)); list.setModifierProperty(PsiModifier.FINAL, member.hasModifierProperty(PsiModifier.FINAL)); VisibilityUtil.setVisibility(list, VisibilityUtil.getVisibilityModifier(member.getModifierList())); } } else { moved = (PsiMember)targetClass.addAfter(member, anchor); } if (docComment != null) { PsiElement insertedDocComment = targetClass.addBefore(docComment, moved); PsiElement prevSibling = insertedDocComment.getPrevSibling(); addLineFeedIfNeeded(prevSibling); docComment.delete(); } member.delete(); return moved; }