1 //////////////////////////////////////////////////////////////////////////////// 2 // checkstyle: Checks Java source code for adherence to a set of rules. 3 // Copyright (C) 2001-2020 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.api; 21 22 /** 23 * A interface of Checkstyle's AST nodes for traversing trees generated from the 24 * Java code. The main purpose of this interface is to abstract away ANTLR 25 * specific classes from API package so other libraries won't require it. 26 * 27 * @see <a href="https://www.antlr.org/">ANTLR Website</a> 28 */ 29 public interface DetailAST { 30 31 /** 32 * Returns the number of child nodes one level below this node. That is is 33 * does not recurse down the tree. 34 * 35 * @return the number of child nodes 36 */ 37 int getChildCount(); 38 39 /** 40 * Returns the number of direct child tokens that have the specified type. 41 * 42 * @param type the token type to match 43 * @return the number of matching token 44 */ 45 int getChildCount(int type); 46 47 /** 48 * Returns the parent token. 49 * 50 * @return the parent token 51 */ 52 DetailAST getParent(); 53 54 /** 55 * Gets the text of this AST. 56 * 57 * @return the text. 58 */ 59 String getText(); 60 61 /** 62 * Gets the type of this AST. 63 * 64 * @return the type. 65 */ 66 int getType(); 67 68 /** 69 * Gets line number. 70 * 71 * @return the line number 72 */ 73 int getLineNo(); 74 75 /** 76 * Gets column number. 77 * 78 * @return the column number 79 */ 80 int getColumnNo(); 81 82 /** 83 * Gets the last child node. 84 * 85 * @return the last child node 86 */ 87 DetailAST getLastChild(); 88 89 /** 90 * Checks if this branch of the parse tree contains a token 91 * of the provided type. 92 * 93 * @param type a TokenType 94 * @return true if and only if this branch (including this node) 95 * contains a token of type {@code type}. 96 */ 97 boolean branchContains(int type); 98 99 /** 100 * Returns the previous sibling or null if no such sibling exists. 101 * 102 * @return the previous sibling or null if no such sibling exists. 103 */ 104 DetailAST getPreviousSibling(); 105 106 /** 107 * Returns the first child token that makes a specified type. 108 * 109 * @param type the token type to match 110 * @return the matching token, or null if no match 111 */ 112 DetailAST findFirstToken(int type); 113 114 /** 115 * Get the next sibling in line after this one. 116 * 117 * @return the next sibling or null if none. 118 */ 119 DetailAST getNextSibling(); 120 121 /** 122 * Get the first child of this AST. 123 * 124 * @return the first child or null if none. 125 */ 126 DetailAST getFirstChild(); 127 128 /** 129 * Get number of children of this AST. 130 * 131 * @return the number of children. 132 * @deprecated This method will be removed in a future release. 133 * Use {@link #getChildCount()} instead. 134 */ 135 @Deprecated 136 int getNumberOfChildren(); 137 138 /** 139 * Returns whether this AST has any children. 140 * 141 * @return {@code true} if this AST has any children. 142 */ 143 boolean hasChildren(); 144 }