View Javadoc
1   ///////////////////////////////////////////////////////////////////////////////////////////////
2   // checkstyle: Checks Java source code and other text files for adherence to a set of rules.
3   // Copyright (C) 2001-2026 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.utils.XpathUtil;
26  
27  /**
28   * Represents DetailAST's root node of Xpath-tree.
29   */
30  public class RootNode extends AbstractRootNode {
31  
32      /** The ast node. */
33      private final DetailAST detailAst;
34  
35      /**
36       * Creates a new {@code RootNode} instance.
37       *
38       * @param detailAst reference to {@code DetailAST}
39       */
40      public RootNode(DetailAST detailAst) {
41          this.detailAst = detailAst;
42      }
43  
44      /**
45       * Iterates siblings of the current node and
46       * recursively creates new Xpath-nodes.
47       *
48       * @return children list
49       */
50      @Override
51      protected List<AbstractNode> createChildren() {
52          return XpathUtil.createChildren(this, this, detailAst);
53      }
54  
55      /**
56       * Determine whether the node has any children.
57       *
58       * @return {@code true} is the node has any children.
59       */
60      @Override
61      public boolean hasChildNodes() {
62          return detailAst != null;
63      }
64  
65      /**
66       * Returns line number.
67       *
68       * @return line number
69       */
70      @Override
71      public int getLineNumber() {
72          return detailAst.getLineNo();
73      }
74  
75      /**
76       * Returns column number.
77       *
78       * @return column number
79       */
80      @Override
81      public int getColumnNumber() {
82          return detailAst.getColumnNo();
83      }
84  
85      /**
86       * Getter method for token type. Returns the actual type of the underlying
87       * AST root, which is either {@code COMPILATION_UNIT} for an ordinary
88       * compilation unit or {@code COMPACT_COMPILATION_UNIT} for a JEP 512
89       * compact source file.
90       *
91       * @return token type of the underlying AST root
92       */
93      @Override
94      public int getTokenType() {
95          return detailAst.getType();
96      }
97  
98      /**
99       * Returns underlying node.
100      *
101      * @return underlying node
102      */
103     @Override
104     public DetailAST getUnderlyingNode() {
105         return detailAst;
106     }
107 
108 }