private void doMoveClass(PsiSubstitutor substitutor, GrMemberInfo info) {
    GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(myProject);
    GrTypeDefinition aClass = (GrTypeDefinition) info.getMember();
    if (Boolean.FALSE.equals(info.getOverrides())) {
      final GrReferenceList sourceReferenceList = info.getSourceReferenceList();
      LOG.assertTrue(sourceReferenceList != null);
      GrCodeReferenceElement ref =
          mySourceClass.equals(sourceReferenceList.getParent())
              ? removeFromReferenceList(sourceReferenceList, aClass)
              : findReferenceToClass(sourceReferenceList, aClass);
      if (ref != null && !myTargetSuperClass.isInheritor(aClass, false)) {
        replaceMovedMemberTypeParameters(
            ref, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
        GrReferenceList referenceList;
        if (myTargetSuperClass.isInterface()) {
          referenceList = myTargetSuperClass.getExtendsClause();
          if (referenceList == null) {
            GrExtendsClause newClause =
                GroovyPsiElementFactory.getInstance(myProject).createExtendsClause();
            PsiElement anchor =
                myTargetSuperClass.getTypeParameterList() != null
                    ? myTargetSuperClass.getTypeParameterList()
                    : myTargetSuperClass.getNameIdentifierGroovy();
            referenceList = (GrReferenceList) myTargetSuperClass.addAfter(newClause, anchor);
            addSpacesAround(referenceList);
          }
        } else {
          referenceList = myTargetSuperClass.getImplementsClause();

          if (referenceList == null) {
            GrImplementsClause newClause =
                GroovyPsiElementFactory.getInstance(myProject).createImplementsClause();
            PsiElement anchor =
                myTargetSuperClass.getExtendsClause() != null
                    ? myTargetSuperClass.getExtendsClause()
                    : myTargetSuperClass.getTypeParameterList() != null
                        ? myTargetSuperClass.getTypeParameterList()
                        : myTargetSuperClass.getNameIdentifierGroovy();
            referenceList = (GrReferenceList) myTargetSuperClass.addAfter(newClause, anchor);
            addSpacesAround(referenceList);
          }
        }

        assert referenceList != null;
        referenceList.add(ref);
      }
    } else {
      replaceMovedMemberTypeParameters(
          aClass, PsiUtil.typeParametersIterable(mySourceClass), substitutor, elementFactory);
      // fixReferencesToStatic(aClass, movedMembers);
      PsiMember movedElement = (PsiMember) myTargetSuperClass.addAfter(aClass, null);
      // movedElement = (PsiMember)CodeStyleManager.getInstance(myProject).reformat(movedElement);
      myMembersAfterMove.add(movedElement);
      deleteMemberWithDocComment(aClass);
    }
  }
 public static GrCodeReferenceElement findReferenceToClass(
     GrReferenceList refList, PsiClass aClass) {
   GrCodeReferenceElement[] refs = refList.getReferenceElementsGroovy();
   for (GrCodeReferenceElement ref : refs) {
     if (ref.isReferenceTo(aClass)) {
       return ref;
     }
   }
   return null;
 }
 /**
  * removes a reference to the specified class from the reference list given
  *
  * @return if removed - a reference to the class or null if there were no references to this class
  *     in the reference list
  */
 public static GrCodeReferenceElement removeFromReferenceList(
     GrReferenceList refList, PsiClass aClass) throws IncorrectOperationException {
   GrCodeReferenceElement[] refs = refList.getReferenceElementsGroovy();
   for (GrCodeReferenceElement ref : refs) {
     if (ref.isReferenceTo(aClass)) {
       GrCodeReferenceElement refCopy = (GrCodeReferenceElement) ref.copy();
       ref.delete();
       return refCopy;
     }
   }
   return null;
 }
  private static void addSpacesAround(@NotNull GrReferenceList list) {
    PsiElement prev = list.getPrevSibling();
    if (!PsiImplUtil.isWhiteSpace(prev)) {
      list.getParent().getNode().addLeaf(TokenType.WHITE_SPACE, " ", list.getNode());
    }

    PsiElement next = list.getNextSibling();
    if (!PsiImplUtil.isWhiteSpace(next)) {
      list.getParent().getNode().addLeaf(TokenType.WHITE_SPACE, " ", list.getNode().getTreeNext());
    }
  }
 private static PsiClassType[] getReferenceListTypes(@Nullable GrReferenceList list) {
   if (list == null) return PsiClassType.EMPTY_ARRAY;
   return list.getReferencedTypes();
 }