@Nullable private SimpleNode visit(SimpleNode simpleNode, DomElement domElement) { boolean validCandidate = false; if (simpleNode instanceof AbstractDomElementNode) { final DomElement nodeElement = ((AbstractDomElementNode) simpleNode).getDomElement(); if (nodeElement != null) { validCandidate = !(simpleNode instanceof DomElementsGroupNode); if (validCandidate && nodeElement.equals(domElement)) { return simpleNode; } if (!(nodeElement instanceof MergedObject) && !isParent(nodeElement, domElement)) { return null; } } } final Object[] childElements = myBuilder.getTreeStructure().getChildElements(simpleNode); if (childElements.length == 0 && validCandidate) { // leaf return simpleNode; } for (Object child : childElements) { SimpleNode result = visit((SimpleNode) child, domElement); if (result != null) { return result; } } return validCandidate ? simpleNode : null; }
@Nullable private SimpleNode getNodeFor(final DomElement domElement) { return visit((SimpleNode) myBuilder.getTreeStructure().getRootElement(), domElement); }