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 recursively creates new Xpath-nodes. 046 * 047 * @return children list 048 */ 049 @Override 050 protected List<AbstractNode> createChildren() { 051 return XpathUtil.createChildren(this, this, detailAst); 052 } 053 054 /** 055 * Determine whether the node has any children. 056 * 057 * @return {@code true} is the node has any children. 058 */ 059 @Override 060 public boolean hasChildNodes() { 061 return detailAst != null; 062 } 063 064 /** 065 * Returns line number. 066 * 067 * @return line number 068 */ 069 @Override 070 public int getLineNumber() { 071 return detailAst.getLineNo(); 072 } 073 074 /** 075 * Returns column number. 076 * 077 * @return column number 078 */ 079 @Override 080 public int getColumnNumber() { 081 return detailAst.getColumnNo(); 082 } 083 084 /** 085 * Getter method for token type. Returns the actual type of the underlying AST root, which is 086 * either {@code COMPILATION_UNIT} for an ordinary compilation unit or 087 * {@code COMPACT_COMPILATION_UNIT} for a JEP 512 compact source file. 088 * 089 * @return token type of the underlying AST root 090 */ 091 @Override 092 public int getTokenType() { 093 return detailAst.getType(); 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}