public Node getChildOfType(Class... classes) { Node child = getFirstChild(); while (child != null) { for (Class nodeType : classes) { if (nodeType.isInstance(child)) return child; } child = child.getNext(); } return null; }
private void validateLinked(Node node) { if (node.getNext() == null && node.getParent() == null) { throw new IllegalStateException("Added block " + node + " is not linked into the AST"); } }
private void validateUnlinked(Node node) { if (!(node.getNext() == null && node.getParent() == null)) { throw new IllegalStateException("Removed block " + node + " is still linked in the AST"); } }
private void validateUnlinked(Node node) { if (!(node.getNext() == null && node.getParent() == null)) { throw new IllegalStateException("Removed block " + node + " is still linked in the AST"); } }
public boolean isItemParagraph(Paragraph node) { // see if this is the first paragraph child item Node child = getFirstChild(); while (child != null && !(child instanceof Paragraph)) child = child.getNext(); return child == node; }
private void validateLinked(Node node) { if (node.getNext() == null && node.getParent() == null) { throw new IllegalStateException("Added block " + node + " is not linked into the AST"); } }
public List<BasedSequence> getValuesSequences() { ArrayList<BasedSequence> list = new ArrayList<>(); Node child = getFirstChild(); while (child != null) { list.add(child.getChars()); child = child.getNext(); } return list; } }
public Map<String, String> getAttributes() { final Map<String, String> attributes = new LinkedHashMap<String, String>(); Node child = getFirstChild(); while (child != null) { if (child instanceof MacroAttribute) { MacroAttribute attribute = (MacroAttribute) child; attributes.put(attribute.getAttribute().toString(), attribute.getValue().toString()); } child = child.getNext(); } return attributes; }
public void visitChildren(Node parent) { Node node = parent.getFirstChild(); while (node != null) { // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no // node after visiting it. So get the next node before visiting. Node next = node.getNext(); visit(node); node = next; } } }
private void visitChildren(final Node parent) { Node node = parent.getFirstChild(); while (node != null) { // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no // node after visiting it. So get the next node before visiting. Node next = node.getNext(); visit(node); node = next; } } }
public void addChildrenOf(Node parent) { Node child = parent.getFirstChild(); while (child != null) { Node nextChild = child.getNext(); appendChild(child); child = nextChild; } }
void renderChildrenUnwrapped(final Node parent) { Node node = parent.getFirstChild(); while (node != null) { Node next = node.getNext(); render(node); node = next; } }
@SuppressWarnings("WeakerAccess") protected void renderChildrenNode(Node parent, NodeFormatterSubContext subContext) { Node node = parent.getFirstChild(); while (node != null) { Node next = node.getNext(); renderNode(node, subContext); node = next; } }
@SuppressWarnings("WeakerAccess") protected void renderChildrenNode(Node parent, NodeRendererSubContext subContext) { Node node = parent.getFirstChild(); while (node != null) { Node next = node.getNext(); renderNode(node, subContext); node = next; } }
private void visitChildren(final Node parent) { Node node = parent.getFirstChild(); while (node != null) { // A subclass of this visitor might modify the node, resulting in getNext returning a different node or no // node after visiting it. So get the next node before visiting. Node next = node.getNext(); process(node); visit(node); node = next; } } }
public void addChildrenOf(Node parent) { Node child = parent.getFirstChild(); while (child != null) { Node nextChild = child.getNext(); child.unlink(); add(child); child = nextChild; } }
static void textBaseWrap(final NodeTracker state, Node lastNonAttributesNode, final Node lastNode, final TextBase textBase) { while (lastNonAttributesNode != lastNode) { Node nextNode = lastNonAttributesNode.getNext(); lastNonAttributesNode.unlink(); state.nodeRemoved(lastNonAttributesNode); textBase.appendChild(lastNonAttributesNode); lastNonAttributesNode = nextNode; } textBase.setCharsFromContent(); lastNode.insertBefore(textBase); state.nodeAddedWithDescendants(textBase); }
protected static boolean containsLinkRefs(BasedSequence nodeChars, Node next, Boolean isDefined) { int startOffset = nodeChars.getStartOffset(); int endOffset = nodeChars.getEndOffset(); while (next != null) { if (next instanceof LinkRef && (isDefined == null || ((LinkRef) next).isDefined() == isDefined) && !(next.getChars().getStartOffset() >= endOffset || next.getChars().getEndOffset() <= startOffset)) { return true; } next = next.getNext(); } return false; }
public void moveNodesBetweenDelimitersTo(DelimitedNode delimitedNode, Delimiter closer) { Node tmp = getNode().getNext(); while (tmp != null && tmp != closer.getNode()) { Node next = tmp.getNext(); ((Node) delimitedNode).appendChild(tmp); tmp = next; } delimitedNode.setText(input.subSequence(getEndIndex(), closer.getStartIndex())); getNode().insertAfter((Node) delimitedNode); }