001////////////////////////////////////////////////////////////////////////////////
002// checkstyle: Checks Java source code for adherence to a set of rules.
003// Copyright (C) 2001-2020 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.api;
021
022/**
023 * A interface of Checkstyle's AST nodes for traversing trees generated from the
024 * Java code. The main purpose of this interface is to abstract away ANTLR
025 * specific classes from API package so other libraries won't require it.
026 *
027 * @see <a href="https://www.antlr.org/">ANTLR Website</a>
028 */
029public interface DetailAST {
030
031    /**
032     * Returns the number of child nodes one level below this node. That is is
033     * does not recurse down the tree.
034     * @return the number of child nodes
035     */
036    int getChildCount();
037
038    /**
039     * Returns the number of direct child tokens that have the specified type.
040     * @param type the token type to match
041     * @return the number of matching token
042     */
043    int getChildCount(int type);
044
045    /**
046     * Returns the parent token.
047     * @return the parent token
048     */
049    DetailAST getParent();
050
051    /**
052     * Gets the text of this AST.
053     * @return the text.
054     */
055    String getText();
056
057    /**
058     * Gets the type of this AST.
059     * @return the type.
060     */
061    int getType();
062
063    /**
064     * Gets line number.
065     * @return the line number
066     */
067    int getLineNo();
068
069    /**
070     * Gets column number.
071     * @return the column number
072     */
073    int getColumnNo();
074
075    /**
076     * Gets the last child node.
077     * @return the last child node
078     */
079    DetailAST getLastChild();
080
081    /**
082     * Checks if this branch of the parse tree contains a token
083     * of the provided type.
084     * @param type a TokenType
085     * @return true if and only if this branch (including this node)
086     *     contains a token of type {@code type}.
087     */
088    boolean branchContains(int type);
089
090    /**
091     * Returns the previous sibling or null if no such sibling exists.
092     * @return the previous sibling or null if no such sibling exists.
093     */
094    DetailAST getPreviousSibling();
095
096    /**
097     * Returns the first child token that makes a specified type.
098     * @param type the token type to match
099     * @return the matching token, or null if no match
100     */
101    DetailAST findFirstToken(int type);
102
103    /**
104     * Get the next sibling in line after this one.
105     * @return the next sibling or null if none.
106     */
107    DetailAST getNextSibling();
108
109    /**
110     * Get the first child of this AST.
111     * @return the first child or null if none.
112     */
113    DetailAST getFirstChild();
114
115    /**
116     * Get number of children of this AST.
117     * @return the number of children.
118     */
119    int getNumberOfChildren();
120
121    /**
122     * Returns whether this AST has any children.
123     *
124     * @return {@code true} if this AST has any children.
125     */
126    boolean hasChildren();
127}