MCPcopy Index your code
hub / github.com/HtmlUnit/htmlunit / moveBefore

Method moveBefore

src/main/java/org/htmlunit/html/DomNode.java:1340–1378  ·  view source on GitHub ↗

Add a DOM node as a child to this node before the referenced node. If the referenced node is null, append to the end. @param movedDomNode the node to move @param referenceDomNode the node to move before @throws DOMException in case of problems

(final DomNode movedDomNode, final DomNode referenceDomNode)

Source from the content-addressed store, hash-verified

1338 * @throws DOMException in case of problems
1339 */
1340 public void moveBefore(final DomNode movedDomNode, final DomNode referenceDomNode) {
1341 if (movedDomNode == referenceDomNode) {
1342 return;
1343 }
1344
1345 if (movedDomNode instanceof DomDocumentFragment fragment) {
1346 for (final DomNode child : fragment.getChildren()) {
1347 moveBefore(child, referenceDomNode);
1348 }
1349 return;
1350 }
1351
1352 // If moving to the same position (node is already right before referenceNode), no operation needed
1353 if (referenceDomNode != null && movedDomNode.getNextSibling() == referenceDomNode) {
1354 return;
1355 }
1356
1357 if (movedDomNode.isAncestorOf(this)) {
1358 throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
1359 "The new child element contains the parent.");
1360 }
1361
1362 if (referenceDomNode != null && !this.isAncestorOf(referenceDomNode)) {
1363 throw new DOMException(DOMException.NOT_FOUND_ERR,
1364 "The node before which the new node is to be inserted is not a child of this node.");
1365 }
1366
1367 if (referenceDomNode != null && referenceDomNode.isAttachedToPage() && !movedDomNode.isAttachedToPage()) {
1368 throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
1369 "State-preserving atomic move cannot be performed on nodes participating in an invalid hierarchy.");
1370 }
1371
1372 if (referenceDomNode == null) {
1373 appendChild(movedDomNode);
1374 return;
1375 }
1376
1377 referenceDomNode.moveBefore(movedDomNode);
1378 }
1379
1380 /**
1381 * Inserts the specified node as a new child node before this node into the child relationship this node is a

Callers 15

restorePreservedElementsFunction · 0.45
handlePreservedElementsFunction · 0.45
TeFunction · 0.45
qeFunction · 0.45
restorePreservedElementsFunction · 0.45
handlePreservedElementsFunction · 0.45
TeFunction · 0.45
qeFunction · 0.45
restorePreservedElementsFunction · 0.45
handlePreservedElementsFunction · 0.45
TeFunction · 0.45
qeFunction · 0.45

Calls 8

isAncestorOfMethod · 0.95
appendChildMethod · 0.95
basicInsertBeforeMethod · 0.95
fireAdditionMethod · 0.95
getChildrenMethod · 0.45
getNextSiblingMethod · 0.45
isAttachedToPageMethod · 0.45
detachMethod · 0.45

Tested by

no test coverage detected