Search in sources :

Example 1 with ElementNode

use of com.puppycrawl.tools.checkstyle.xpath.ElementNode in project checkstyle by checkstyle.

the class XpathUtil method createChildren.

/**
 * Iterates siblings of the given node and creates new Xpath-nodes.
 *
 * @param root the root node
 * @param parent the parent node
 * @param firstChild the first DetailAST
 * @return children list
 */
public static List<AbstractNode> createChildren(AbstractNode root, AbstractNode parent, DetailAST firstChild) {
    DetailAST currentChild = firstChild;
    final int depth = parent.getDepth() + 1;
    final List<AbstractNode> result = new ArrayList<>();
    while (currentChild != null) {
        final int index = result.size();
        final ElementNode child = new ElementNode(root, parent, currentChild, depth, index);
        result.add(child);
        currentChild = currentChild.getNextSibling();
    }
    return result;
}
Also used : AbstractNode(com.puppycrawl.tools.checkstyle.xpath.AbstractNode) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) ArrayList(java.util.ArrayList) ElementNode(com.puppycrawl.tools.checkstyle.xpath.ElementNode)

Aggregations

DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)1 AbstractNode (com.puppycrawl.tools.checkstyle.xpath.AbstractNode)1 ElementNode (com.puppycrawl.tools.checkstyle.xpath.ElementNode)1 ArrayList (java.util.ArrayList)1