protected <T extends Node> T cloneNodes(T _node, Object _arg) { if (_node == null) return null; Node r = _node.accept(this, _arg); if (r == null) return null; return (T) r; } }
private <T extends Node> boolean nodeEquals(final T n1, final T n2) { if (n1 == n2) { return true; } if (n1 == null) { if (n2 == null) { return true; } return false; } else if (n2 == null) { return false; } if (n1.getClass() != n2.getClass()) { return false; } return n1.accept(this, n2).booleanValue(); }
private void printOrphanCommentsEnding(final Node node){ List<Node> everything = new LinkedList<Node>(); everything.addAll(node.getChildrenNodes()); sortByBeginPosition(everything); if (everything.size()==0) return; int commentsAtEnd = 0; boolean findingComments = true; while (findingComments){ Node last = everything.get(everything.size()-1-commentsAtEnd); findingComments = (last instanceof Comment); if (findingComments) commentsAtEnd++; } for (int i=0;i<commentsAtEnd;i++){ everything.get(everything.size()-commentsAtEnd+i).accept(this,null); } }
private void printOrphanCommentsBeforeThisChildNode(final Node node){ if (node instanceof Comment) return; Node parent = node.getParentNode(); if (parent==null) return; List<Node> everything = new LinkedList<Node>(); everything.addAll(parent.getChildrenNodes()); sortByBeginPosition(everything); int positionOfTheChild = -1; for (int i=0;i<everything.size();i++){ if (everything.get(i)==node) positionOfTheChild=i; } if (positionOfTheChild==-1) throw new RuntimeException("My index not found!!! "+node); int positionOfPreviousChild = -1; for (int i=positionOfTheChild-1;i>=0 && positionOfPreviousChild==-1;i--){ if (!(everything.get(i) instanceof Comment)) positionOfPreviousChild = i; } for (int i=positionOfPreviousChild+1;i<positionOfTheChild;i++){ Node nodeToPrint = everything.get(i); if (!(nodeToPrint instanceof Comment)) throw new RuntimeException("Expected comment, instead "+nodeToPrint.getClass()+". Position of previous child: "+positionOfPreviousChild+", position of child "+positionOfTheChild); nodeToPrint.accept(this,null); } }
/** * Return the String representation of this node. * * @return the String representation of this node */ @Override public final String toString() { final DumpVisitor visitor = new DumpVisitor(); accept(visitor, null); return visitor.getSource(); }