001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2026 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.utils.XpathUtil; 026 027/** 028 * Represents DetailAST's root node of Xpath-tree. 029 */ 030public class RootNode extends AbstractRootNode { 031 032 /** The ast node. */ 033 private final DetailAST detailAst; 034 035 /** 036 * Creates a new {@code RootNode} instance. 037 * 038 * @param detailAst reference to {@code DetailAST} 039 */ 040 public RootNode(DetailAST detailAst) { 041 this.detailAst = detailAst; 042 } 043 044 /** 045 * Iterates siblings of the current node and 046 * recursively creates new Xpath-nodes. 047 * 048 * @return children list 049 */ 050 @Override 051 protected List<AbstractNode> createChildren() { 052 return XpathUtil.createChildren(this, this, detailAst); 053 } 054 055 /** 056 * Determine whether the node has any children. 057 * 058 * @return {@code true} is the node has any children. 059 */ 060 @Override 061 public boolean hasChildNodes() { 062 return detailAst != null; 063 } 064 065 /** 066 * Returns line number. 067 * 068 * @return line number 069 */ 070 @Override 071 public int getLineNumber() { 072 return detailAst.getLineNo(); 073 } 074 075 /** 076 * Returns column number. 077 * 078 * @return column number 079 */ 080 @Override 081 public int getColumnNumber() { 082 return detailAst.getColumnNo(); 083 } 084 085 /** 086 * Getter method for token type. Returns the actual type of the underlying 087 * AST root, which is either {@code COMPILATION_UNIT} for an ordinary 088 * compilation unit or {@code COMPACT_COMPILATION_UNIT} for a JEP 512 089 * compact source file. 090 * 091 * @return token type of the underlying AST root 092 */ 093 @Override 094 public int getTokenType() { 095 return detailAst.getType(); 096 } 097 098 /** 099 * Returns underlying node. 100 * 101 * @return underlying node 102 */ 103 @Override 104 public DetailAST getUnderlyingNode() { 105 return detailAst; 106 } 107 108}