1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.nashorn.api.tree; 27 28 /** 29 * A visitor of trees, in the style of the visitor design pattern. 30 * Classes implementing this interface are used to operate 31 * on a tree when the kind of tree is unknown at compile time. 32 * When a visitor is passed to an tree's {@link Tree#accept 33 * accept} method, the <tt>visit<i>XYZ</i></tt> method most applicable 34 * to that tree is invoked. 35 * 36 * <p> Classes implementing this interface may or may not throw a 37 * {@code NullPointerException} if the additional parameter {@code p} 38 * is {@code null}; see documentation of the implementing class for 39 * details. 40 * 41 * <p> <b>WARNING:</b> It is possible that methods will be added to 42 this interface to accommodate new, currently unknown, language 43 structures added to future versions of the ECMAScript programming 44 language. When new visit methods are added for new Tree subtypes, 45 default method bodies will be introduced which will call visitUnknown 46 method as a fallback. 47 * 48 * @param <R> the return type of this visitor's methods. Use {@link 49 * Void} for visitors that do not need to return results. 50 * @param <P> the type of the additional parameter to this visitor's 51 * methods. Use {@code Void} for visitors that do not need an 52 * additional parameter. 53 * 54 * @since 1.9 55 */ 56 public interface TreeVisitor<R,P> { 57 /** 58 * Visit assignment tree. 59 * 60 * @param node node being visited 61 * @param p extra parameter passed to the visitor 62 * @return value from the visitor 63 */ 64 R visitAssignment(AssignmentTree node, P p); 65 66 /** 67 * Visit compound assignment tree. 68 * 69 * @param node node being visited 70 * @param p extra parameter passed to the visitor 71 * @return value from the visitor 72 */ 73 R visitCompoundAssignment(CompoundAssignmentTree node, P p); 74 75 /** 76 * Visit binary expression tree. 77 * 78 * @param node node being visited 79 * @param p extra parameter passed to the visitor 80 * @return value from the visitor 81 */ 82 R visitBinary(BinaryTree node, P p); 83 84 /** 85 * Visit block statement tree. 86 * 87 * @param node node being visited 88 * @param p extra parameter passed to the visitor 89 * @return value from the visitor 90 */ 91 R visitBlock(BlockTree node, P p); 92 93 /** 94 * Visit break statement tree. 95 * 96 * @param node node being visited 97 * @param p extra parameter passed to the visitor 98 * @return value from the visitor 99 */ 100 R visitBreak(BreakTree node, P p); 101 102 /** 103 * Visit case statement tree. 104 * 105 * @param node node being visited 106 * @param p extra parameter passed to the visitor 107 * @return value from the visitor 108 */ 109 R visitCase(CaseTree node, P p); 110 111 /** 112 * Visit catch block statement tree. 113 * 114 * @param node node being visited 115 * @param p extra parameter passed to the visitor 116 * @return value from the visitor 117 */ 118 R visitCatch(CatchTree node, P p); 119 120 /** 121 * Visit conditional expression tree. 122 * 123 * @param node node being visited 124 * @param p extra parameter passed to the visitor 125 * @return value from the visitor 126 */ 127 R visitConditionalExpression(ConditionalExpressionTree node, P p); 128 129 /** 130 * Visit continue statement tree. 131 * 132 * @param node node being visited 133 * @param p extra parameter passed to the visitor 134 * @return value from the visitor 135 */ 136 R visitContinue(ContinueTree node, P p); 137 138 /** 139 * Visit debugger statement tree. 140 * 141 * @param node node being visited 142 * @param p extra parameter passed to the visitor 143 * @return value from the visitor 144 */ 145 R visitDebugger(DebuggerTree node, P p); 146 147 /** 148 * Visit do-while statement tree. 149 * 150 * @param node node being visited 151 * @param p extra parameter passed to the visitor 152 * @return value from the visitor 153 */ 154 R visitDoWhileLoop(DoWhileLoopTree node, P p); 155 156 /** 157 * Visit error expression tree. 158 * 159 * @param node node being visited 160 * @param p extra parameter passed to the visitor 161 * @return value from the visitor 162 */ 163 R visitErroneous(ErroneousTree node, P p); 164 165 /** 166 * Visit expression statement tree. 167 * 168 * @param node node being visited 169 * @param p extra parameter passed to the visitor 170 * @return value from the visitor 171 */ 172 R visitExpressionStatement(ExpressionStatementTree node, P p); 173 174 /** 175 * Visit 'for' statement tree. 176 * 177 * @param node node being visited 178 * @param p extra parameter passed to the visitor 179 * @return value from the visitor 180 */ 181 R visitForLoop(ForLoopTree node, P p); 182 183 /** 184 * Visit for..in statement tree. 185 * 186 * @param node node being visited 187 * @param p extra parameter passed to the visitor 188 * @return value from the visitor 189 */ 190 R visitForInLoop(ForInLoopTree node, P p); 191 192 /** 193 * Visit function call expression tree. 194 * 195 * @param node node being visited 196 * @param p extra parameter passed to the visitor 197 * @return value from the visitor 198 */ 199 R visitFunctionCall(FunctionCallTree node, P p); 200 201 /** 202 * Visit function declaration tree. 203 * 204 * @param node node being visited 205 * @param p extra parameter passed to the visitor 206 * @return value from the visitor 207 */ 208 R visitFunctionDeclaration(FunctionDeclarationTree node, P p); 209 210 /** 211 * Visit function expression tree. 212 * 213 * @param node node being visited 214 * @param p extra parameter passed to the visitor 215 * @return value from the visitor 216 */ 217 R visitFunctionExpression(FunctionExpressionTree node, P p); 218 219 /** 220 * Visit identifier tree. 221 * 222 * @param node node being visited 223 * @param p extra parameter passed to the visitor 224 * @return value from the visitor 225 */ 226 R visitIdentifier(IdentifierTree node, P p); 227 228 /** 229 * Visit 'if' statement tree. 230 * 231 * @param node node being visited 232 * @param p extra parameter passed to the visitor 233 * @return value from the visitor 234 */ 235 R visitIf(IfTree node, P p); 236 237 /** 238 * Visit array access expression tree. 239 * 240 * @param node node being visited 241 * @param p extra parameter passed to the visitor 242 * @return value from the visitor 243 */ 244 R visitArrayAccess(ArrayAccessTree node, P p); 245 246 /** 247 * Visit array literal expression tree. 248 * 249 * @param node node being visited 250 * @param p extra parameter passed to the visitor 251 * @return value from the visitor 252 */ 253 R visitArrayLiteral(ArrayLiteralTree node, P p); 254 255 /** 256 * Visit labeled statement tree. 257 * 258 * @param node node being visited 259 * @param p extra parameter passed to the visitor 260 * @return value from the visitor 261 */ 262 R visitLabeledStatement(LabeledStatementTree node, P p); 263 264 /** 265 * Visit literal expression tree. 266 * 267 * @param node node being visited 268 * @param p extra parameter passed to the visitor 269 * @return value from the visitor 270 */ 271 R visitLiteral(LiteralTree node, P p); 272 273 /** 274 * Visit parenthesized expression tree. 275 * 276 * @param node node being visited 277 * @param p extra parameter passed to the visitor 278 * @return value from the visitor 279 */ 280 R visitParenthesized(ParenthesizedTree node, P p); 281 282 /** 283 * Visit return statement tree. 284 * 285 * @param node node being visited 286 * @param p extra parameter passed to the visitor 287 * @return value from the visitor 288 */ 289 R visitReturn(ReturnTree node, P p); 290 291 /** 292 * Visit member select expression tree. 293 * 294 * @param node node being visited 295 * @param p extra parameter passed to the visitor 296 * @return value from the visitor 297 */ 298 R visitMemberSelect(MemberSelectTree node, P p); 299 300 /** 301 * Visit 'new' expression tree. 302 * 303 * @param node node being visited 304 * @param p extra parameter passed to the visitor 305 * @return value from the visitor 306 */ 307 R visitNew(NewTree node, P p); 308 309 /** 310 * Visit object literal tree. 311 * 312 * @param node node being visited 313 * @param p extra parameter passed to the visitor 314 * @return value from the visitor 315 */ 316 R visitObjectLiteral(ObjectLiteralTree node, P p); 317 318 /** 319 * Visit a property of an object literal expression tree. 320 * 321 * @param node node being visited 322 * @param p extra parameter passed to the visitor 323 * @return value from the visitor 324 */ 325 R visitProperty(PropertyTree node, P p); 326 327 /** 328 * Visit regular expression literal tree. 329 * 330 * @param node node being visited 331 * @param p extra parameter passed to the visitor 332 * @return value from the visitor 333 */ 334 R visitRegExpLiteral(RegExpLiteralTree node, P p); 335 336 /** 337 * Visit an empty statement tree. 338 * 339 * @param node node being visited 340 * @param p extra parameter passed to the visitor 341 * @return value from the visitor 342 */ 343 R visitEmptyStatement(EmptyStatementTree node, P p); 344 345 /** 346 * Visit 'switch' statement tree. 347 * 348 * @param node node being visited 349 * @param p extra parameter passed to the visitor 350 * @return value from the visitor 351 */ 352 R visitSwitch(SwitchTree node, P p); 353 354 /** 355 * Visit 'throw' expression tree. 356 * 357 * @param node node being visited 358 * @param p extra parameter passed to the visitor 359 * @return value from the visitor 360 */ 361 R visitThrow(ThrowTree node, P p); 362 363 /** 364 * Visit compilation unit tree. 365 * 366 * @param node node being visited 367 * @param p extra parameter passed to the visitor 368 * @return value from the visitor 369 */ 370 R visitCompilationUnit(CompilationUnitTree node, P p); 371 372 /** 373 * Visit 'try' statement tree. 374 * 375 * @param node node being visited 376 * @param p extra parameter passed to the visitor 377 * @return value from the visitor 378 */ 379 R visitTry(TryTree node, P p); 380 381 /** 382 * Visit 'instanceof' expression tree. 383 * 384 * @param node node being visited 385 * @param p extra parameter passed to the visitor 386 * @return value from the visitor 387 */ 388 R visitInstanceOf(InstanceOfTree node, P p); 389 390 /** 391 * Visit unary expression tree. 392 * 393 * @param node node being visited 394 * @param p extra parameter passed to the visitor 395 * @return value from the visitor 396 */ 397 R visitUnary(UnaryTree node, P p); 398 399 /** 400 * Visit variable declaration tree. 401 * 402 * @param node node being visited 403 * @param p extra parameter passed to the visitor 404 * @return value from the visitor 405 */ 406 R visitVariable(VariableTree node, P p); 407 408 /** 409 * Visit 'while' statement tree. 410 * 411 * @param node node being visited 412 * @param p extra parameter passed to the visitor 413 * @return value from the visitor 414 */ 415 R visitWhileLoop(WhileLoopTree node, P p); 416 417 /** 418 * Visit 'with' statement tree. 419 * 420 * @param node node being visited 421 * @param p extra parameter passed to the visitor 422 * @return value from the visitor 423 */ 424 R visitWith(WithTree node, P p); 425 426 /** 427 * Visit unknown expression/statement tree. This fallback will be 428 * called if new Tree subtypes are introduced in future. A specific 429 * implementation may throw {{@linkplain UnknownTreeException unknown tree exception} 430 * if the visitor implementation was for an older language version. 431 * 432 * @param node node being visited 433 * @param p extra parameter passed to the visitor 434 * @return value from the visitor 435 */ 436 R visitUnknown(Tree node, P p); 437 }