View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2024 the original author or authors.
4   //
5   // This library is free software; you can redistribute it and/or
6   // modify it under the terms of the GNU Lesser General Public
7   // License as published by the Free Software Foundation; either
8   // version 2.1 of the License, or (at your option) any later version.
9   //
10  // This library is distributed in the hope that it will be useful,
11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  // Lesser General Public License for more details.
14  //
15  // You should have received a copy of the GNU Lesser General Public
16  // License along with this library; if not, write to the Free Software
17  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ///////////////////////////////////////////////////////////////////////////////////////////////
19  
20  package com.puppycrawl.tools.checkstyle.xpath;
21  
22  import java.util.List;
23  
24  import com.puppycrawl.tools.checkstyle.api.DetailAST;
25  import com.puppycrawl.tools.checkstyle.api.TokenTypes;
26  import com.puppycrawl.tools.checkstyle.utils.XpathUtil;
27  
28  /**
29   * Represents DetailAST's root node of Xpath-tree.
30   */
31  public class RootNode extends AbstractRootNode {
32  
33      /** The ast node. */
34      private final DetailAST detailAst;
35  
36      /**
37       * Creates a new {@code RootNode} instance.
38       *
39       * @param detailAst reference to {@code DetailAST}
40       */
41      public RootNode(DetailAST detailAst) {
42          this.detailAst = detailAst;
43      }
44  
45      /**
46       * Iterates siblings of the current node and
47       * recursively creates new Xpath-nodes.
48       *
49       * @return children list
50       */
51      @Override
52      protected List<AbstractNode> createChildren() {
53          return XpathUtil.createChildren(this, this, detailAst);
54      }
55  
56      /**
57       * Determine whether the node has any children.
58       *
59       * @return {@code true} is the node has any children.
60       */
61      @Override
62      public boolean hasChildNodes() {
63          return detailAst != null;
64      }
65  
66      /**
67       * Returns line number.
68       *
69       * @return line number
70       */
71      @Override
72      public int getLineNumber() {
73          return detailAst.getLineNo();
74      }
75  
76      /**
77       * Returns column number.
78       *
79       * @return column number
80       */
81      @Override
82      public int getColumnNumber() {
83          return detailAst.getColumnNo();
84      }
85  
86      /**
87       * Getter method for token type.
88       *
89       * @return token type
90       */
91      @Override
92      public int getTokenType() {
93          return TokenTypes.COMPILATION_UNIT;
94      }
95  
96      /**
97       * Returns underlying node.
98       *
99       * @return underlying node
100      */
101     @Override
102     public DetailAST getUnderlyingNode() {
103         return detailAst;
104     }
105 
106 }