001///////////////////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code and other text files for adherence to a set of rules.
003// Copyright (C) 2001-2024 the original author or authors.
004//
005// This library is free software; you can redistribute it and/or
006// modify it under the terms of the GNU Lesser General Public
007// License as published by the Free Software Foundation; either
008// version 2.1 of the License, or (at your option) any later version.
009//
010// This library is distributed in the hope that it will be useful,
011// but WITHOUT ANY WARRANTY; without even the implied warranty of
012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013// Lesser General Public License for more details.
014//
015// You should have received a copy of the GNU Lesser General Public
016// License along with this library; if not, write to the Free Software
017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018///////////////////////////////////////////////////////////////////////////////////////////////
019
020package com.puppycrawl.tools.checkstyle.xpath;
021
022import java.util.List;
023
024import com.puppycrawl.tools.checkstyle.api.DetailAST;
025import com.puppycrawl.tools.checkstyle.api.TokenTypes;
026import com.puppycrawl.tools.checkstyle.utils.XpathUtil;
027
028/**
029 * Represents DetailAST's root node of Xpath-tree.
030 */
031public class RootNode extends AbstractRootNode {
032
033    /** The ast node. */
034    private final DetailAST detailAst;
035
036    /**
037     * Creates a new {@code RootNode} instance.
038     *
039     * @param detailAst reference to {@code DetailAST}
040     */
041    public RootNode(DetailAST detailAst) {
042        this.detailAst = detailAst;
043    }
044
045    /**
046     * Iterates siblings of the current node and
047     * recursively creates new Xpath-nodes.
048     *
049     * @return children list
050     */
051    @Override
052    protected List<AbstractNode> createChildren() {
053        return XpathUtil.createChildren(this, this, detailAst);
054    }
055
056    /**
057     * Determine whether the node has any children.
058     *
059     * @return {@code true} is the node has any children.
060     */
061    @Override
062    public boolean hasChildNodes() {
063        return detailAst != null;
064    }
065
066    /**
067     * Returns line number.
068     *
069     * @return line number
070     */
071    @Override
072    public int getLineNumber() {
073        return detailAst.getLineNo();
074    }
075
076    /**
077     * Returns column number.
078     *
079     * @return column number
080     */
081    @Override
082    public int getColumnNumber() {
083        return detailAst.getColumnNo();
084    }
085
086    /**
087     * Getter method for token type.
088     *
089     * @return token type
090     */
091    @Override
092    public int getTokenType() {
093        return TokenTypes.COMPILATION_UNIT;
094    }
095
096    /**
097     * Returns underlying node.
098     *
099     * @return underlying node
100     */
101    @Override
102    public DetailAST getUnderlyingNode() {
103        return detailAst;
104    }
105
106}