private void adoptUnadoptedHelper(final Node newChild) { assert newChild != null; if (newChild == this) { throw new IllegalStateException("The parent of a node can never be the node itself."); } newChild.parent = this; newChild.adoptUnadoptedHelper(); }
private void adoptUnadoptedHelper() { Iterable<Node> children = this.getChildren(); for (Node child : children) { if (child != null && child.getParent() == null) { this.adoptUnadoptedHelper(child); } } }
final void replaceHelper(Node newNode, CharSequence reason) { CompilerAsserts.neverPartOfCompilation("do not call Node.replaceHelper from compiled code"); assert inAtomicBlock(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode() // will always find the root node newNode.parent = this.parent; if (!NodeUtil.replaceChild(this.parent, this, newNode, true)) { this.parent.adoptUnadoptedHelper(newNode); } reportReplace(this, newNode, reason); onReplace(newNode, reason); }
final void replaceHelper(Node newNode, CharSequence reason) { CompilerAsserts.neverPartOfCompilation("do not call Node.replaceHelper from compiled code"); assert inAtomicBlock(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode() // will always find the root node newNode.parent = this.parent; if (!NodeUtil.replaceChild(this.parent, this, newNode, true)) { this.parent.adoptUnadoptedHelper(newNode); } reportReplace(this, newNode, reason); onReplace(newNode, reason); }
final void replaceHelper(Node newNode, CharSequence reason) { CompilerAsserts.neverPartOfCompilation(); assert inAtomicBlock(); if (this.getParent() == null) { throw new IllegalStateException("This node cannot be replaced, because it does not yet have a parent."); } if (sourceSection != null && newNode.getSourceSection() == null) { // Pass on the source section to the new node. newNode.assignSourceSection(sourceSection); } // (aw) need to set parent *before* replace, so that (unsynchronized) getRootNode() // will always find the root node newNode.parent = this.parent; if (NodeUtil.replaceChild(this.parent, this, newNode)) { this.parent.adoptHelper(newNode); } else { this.parent.adoptUnadoptedHelper(newNode); } reportReplace(this, newNode, reason); onReplace(newNode, reason); }