protected void executeWriteAction()

in src/java/org/jetbrains/plugins/clojure/actions/editor/SpliceAction.java [42:72]


    protected void executeWriteAction(ClBraced sexp, Editor editor, Project project, DataContext dataContext) {
      PsiElement parent = sexp.getParent();
      if (parent == null) { return; }
      PsiElement[] children = sexp.getChildren();

      // if the s-exp is not the first in it's parent, e.g. (a (b c)) -> (a b c)
      PsiElement previous = PsiTreeUtil.getPrevSiblingOfType(sexp, ClojurePsiElement.class);
      if (previous != null) {
        for (PsiElement child : children) {
          previous = parent.addAfter(child, previous);
        }
        sexp.delete();
        return;
      }

      // if the s-exp is not the last in it's parent, e.g. ((a b) c) -> (a b c)
      PsiElement next = PsiTreeUtil.getNextSiblingOfType(sexp, ClojurePsiElement.class);
      if (next != null) {
        for (int i = children.length; i != 0;) {
          next = parent.addBefore(children[--i], next);
        }
        sexp.delete();
        return;
      }

      // the corner case of nested s-exps, e.g. ((a b c)) -> (a b c)
      for (PsiElement child : children) {
        parent.addBefore(child, parent.getLastChild());
      }
      sexp.delete();
    }