1 /*
   2  * Copyright (c) 2005, 2019, 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 com.sun.source.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 <code>visit<i>Xyz</i></code> 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 Java&trade; programming
  44  * language.  Therefore, visitor classes directly implementing this
  45  * interface may be source incompatible with future versions of the
  46  * platform.
  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  * @author Peter von der Ah&eacute;
  55  * @author Jonathan Gibbons
  56  *
  57  * @since 1.6
  58  */
  59 public interface TreeVisitor<R,P> {
  60     /**
  61      * Visits an AnnotatedTypeTree node.
  62      * @param node the node being visited
  63      * @param p a parameter value
  64      * @return a result value
  65      */
  66     R visitAnnotatedType(AnnotatedTypeTree node, P p);
  67 
  68     /**
  69      * Visits an AnnotatedTree node.
  70      * @param node the node being visited
  71      * @param p a parameter value
  72      * @return a result value
  73      */
  74     R visitAnnotation(AnnotationTree node, P p);
  75 
  76     /**
  77      * Visits a MethodInvocationTree node.
  78      * @param node the node being visited
  79      * @param p a parameter value
  80      * @return a result value
  81      */
  82     R visitMethodInvocation(MethodInvocationTree node, P p);
  83 
  84     /**
  85      * Visits an AssertTree node.
  86      * @param node the node being visited
  87      * @param p a parameter value
  88      * @return a result value
  89      */
  90     R visitAssert(AssertTree node, P p);
  91 
  92     /**
  93      * Visits an AssignmentTree node.
  94      * @param node the node being visited
  95      * @param p a parameter value
  96      * @return a result value
  97      */
  98     R visitAssignment(AssignmentTree node, P p);
  99 
 100     /**
 101      * Visits a CompoundAssignmentTree node.
 102      * @param node the node being visited
 103      * @param p a parameter value
 104      * @return a result value
 105      */
 106     R visitCompoundAssignment(CompoundAssignmentTree node, P p);
 107 
 108     /**
 109      * Visits a BinaryTree node.
 110      * @param node the node being visited
 111      * @param p a parameter value
 112      * @return a result value
 113      */
 114     R visitBinary(BinaryTree node, P p);
 115 
 116     /**
 117      * Visits a BlockTree node.
 118      * @param node the node being visited
 119      * @param p a parameter value
 120      * @return a result value
 121      */
 122     R visitBlock(BlockTree node, P p);
 123 
 124     /**
 125      * Visits a BreakTree node.
 126      * @param node the node being visited
 127      * @param p a parameter value
 128      * @return a result value
 129      */
 130     R visitBreak(BreakTree node, P p);
 131 
 132     /**
 133      * Visits a CaseTree node.
 134      * @param node the node being visited
 135      * @param p a parameter value
 136      * @return a result value
 137      */
 138     R visitCase(CaseTree node, P p);
 139 
 140     /**
 141      * Visits a CatchTree node.
 142      * @param node the node being visited
 143      * @param p a parameter value
 144      * @return a result value
 145      */
 146     R visitCatch(CatchTree node, P p);
 147 
 148     /**
 149      * Visits a ClassTree node.
 150      * @param node the node being visited
 151      * @param p a parameter value
 152      * @return a result value
 153      */
 154     R visitClass(ClassTree node, P p);
 155 
 156     /**
 157      * Visits a ConditionalExpressionTree node.
 158      * @param node the node being visited
 159      * @param p a parameter value
 160      * @return a result value
 161      */
 162     R visitConditionalExpression(ConditionalExpressionTree node, P p);
 163 
 164     /**
 165      * Visits a ContinueTree node.
 166      * @param node the node being visited
 167      * @param p a parameter value
 168      * @return a result value
 169      */
 170     R visitContinue(ContinueTree node, P p);
 171 
 172     /**
 173      * Visits a DoWhileTree node.
 174      * @param node the node being visited
 175      * @param p a parameter value
 176      * @return a result value
 177      */
 178     R visitDoWhileLoop(DoWhileLoopTree node, P p);
 179 
 180     /**
 181      * Visits an ErroneousTree node.
 182      * @param node the node being visited
 183      * @param p a parameter value
 184      * @return a result value
 185      */
 186     R visitErroneous(ErroneousTree node, P p);
 187 
 188     /**
 189      * Visits an ExpressionStatementTree node.
 190      * @param node the node being visited
 191      * @param p a parameter value
 192      * @return a result value
 193      */
 194     R visitExpressionStatement(ExpressionStatementTree node, P p);
 195 
 196     /**
 197      * Visits an EnhancedForLoopTree node.
 198      * @param node the node being visited
 199      * @param p a parameter value
 200      * @return a result value
 201      */
 202     R visitEnhancedForLoop(EnhancedForLoopTree node, P p);
 203 
 204     /**
 205      * Visits a ForLoopTree node.
 206      * @param node the node being visited
 207      * @param p a parameter value
 208      * @return a result value
 209      */
 210     R visitForLoop(ForLoopTree node, P p);
 211 
 212     /**
 213      * Visits an IdentifierTree node.
 214      * @param node the node being visited
 215      * @param p a parameter value
 216      * @return a result value
 217      */
 218     R visitIdentifier(IdentifierTree node, P p);
 219 
 220     /**
 221      * Visits an IfTree node.
 222      * @param node the node being visited
 223      * @param p a parameter value
 224      * @return a result value
 225      */
 226     R visitIf(IfTree node, P p);
 227 
 228     /**
 229      * Visits an ImportTree node.
 230      * @param node the node being visited
 231      * @param p a parameter value
 232      * @return a result value
 233      */
 234     R visitImport(ImportTree node, P p);
 235 
 236     /**
 237      * Visits an ArrayAccessTree node.
 238      * @param node the node being visited
 239      * @param p a parameter value
 240      * @return a result value
 241      */
 242     R visitArrayAccess(ArrayAccessTree node, P p);
 243 
 244     /**
 245      * Visits a LabeledStatementTree node.
 246      * @param node the node being visited
 247      * @param p a parameter value
 248      * @return a result value
 249      */
 250     R visitLabeledStatement(LabeledStatementTree node, P p);
 251 
 252     /**
 253      * Visits a LiteralTree node.
 254      * @param node the node being visited
 255      * @param p a parameter value
 256      * @return a result value
 257      */
 258     R visitLiteral(LiteralTree node, P p);
 259 
 260     /**
 261      * Visits a MethodTree node.
 262      * @param node the node being visited
 263      * @param p a parameter value
 264      * @return a result value
 265      */
 266     R visitMethod(MethodTree node, P p);
 267 
 268     /**
 269      * Visits a ModifiersTree node.
 270      * @param node the node being visited
 271      * @param p a parameter value
 272      * @return a result value
 273      */
 274     R visitModifiers(ModifiersTree node, P p);
 275 
 276     /**
 277      * Visits a NewArrayTree node.
 278      * @param node the node being visited
 279      * @param p a parameter value
 280      * @return a result value
 281      */
 282     R visitNewArray(NewArrayTree node, P p);
 283 
 284     /**
 285      * Visits a NewClassTree node.
 286      * @param node the node being visited
 287      * @param p a parameter value
 288      * @return a result value
 289      */
 290     R visitNewClass(NewClassTree node, P p);
 291 
 292     /**
 293      * Visits a LambdaExpressionTree node.
 294      * @param node the node being visited
 295      * @param p a parameter value
 296      * @return a result value
 297      */
 298     R visitLambdaExpression(LambdaExpressionTree node, P p);
 299 
 300     /**
 301      * Visits a PackageTree node.
 302      * @param node the node being visited
 303      * @param p a parameter value
 304      * @return a result value
 305      */
 306     R visitPackage(PackageTree node, P p);
 307 
 308     /**
 309      * Visits a ParenthesizedTree node.
 310      * @param node the node being visited
 311      * @param p a parameter value
 312      * @return a result value
 313      */
 314     R visitParenthesized(ParenthesizedTree node, P p);
 315 
 316     /**
 317      * Visits a ReturnTree node.
 318      * @param node the node being visited
 319      * @param p a parameter value
 320      * @return a result value
 321      */
 322     R visitReturn(ReturnTree node, P p);
 323 
 324     /**
 325      * Visits a MemberSelectTree node.
 326      * @param node the node being visited
 327      * @param p a parameter value
 328      * @return a result value
 329      */
 330     R visitMemberSelect(MemberSelectTree node, P p);
 331 
 332     /**
 333      * Visits a MemberReferenceTree node.
 334      * @param node the node being visited
 335      * @param p a parameter value
 336      * @return a result value
 337      */
 338     R visitMemberReference(MemberReferenceTree node, P p);
 339 
 340     /**
 341      * Visits an EmptyStatementTree node.
 342      * @param node the node being visited
 343      * @param p a parameter value
 344      * @return a result value
 345      */
 346     R visitEmptyStatement(EmptyStatementTree node, P p);
 347 
 348     /**
 349      * Visits a SwitchTree node.
 350      * @param node the node being visited
 351      * @param p a parameter value
 352      * @return a result value
 353      */
 354     R visitSwitch(SwitchTree node, P p);
 355 
 356     /**
 357      * Visits a SwitchExpressionTree node.
 358      *
 359      * @param node the node being visited
 360      * @param p a parameter value
 361      * @return a result value
 362      * @since 12
 363      *
 364      * @deprecated
 365      * This method is modeling switch expressions,
 366      * which are part of a preview feature and may be removed
 367      * if the preview feature is removed.
 368      */
 369     @Deprecated(forRemoval=true, since="12")
 370     @SuppressWarnings("removal")
 371     R visitSwitchExpression(SwitchExpressionTree node, P p);
 372 
 373     /**
 374      * Visits a SynchronizedTree node.
 375      * @param node the node being visited
 376      * @param p a parameter value
 377      * @return a result value
 378      */
 379     R visitSynchronized(SynchronizedTree node, P p);
 380 
 381     /**
 382      * Visits a ThrowTree node.
 383      * @param node the node being visited
 384      * @param p a parameter value
 385      * @return a result value
 386      */
 387     R visitThrow(ThrowTree node, P p);
 388 
 389     /**
 390      * Visits a CompilationUnitTree node.
 391      * @param node the node being visited
 392      * @param p a parameter value
 393      * @return a result value
 394      */
 395     R visitCompilationUnit(CompilationUnitTree node, P p);
 396 
 397     /**
 398      * Visits a TryTree node.
 399      * @param node the node being visited
 400      * @param p a parameter value
 401      * @return a result value
 402      */
 403     R visitTry(TryTree node, P p);
 404 
 405     /**
 406      * Visits a ParameterizedTypeTree node.
 407      * @param node the node being visited
 408      * @param p a parameter value
 409      * @return a result value
 410      */
 411     R visitParameterizedType(ParameterizedTypeTree node, P p);
 412 
 413     /**
 414      * Visits a UnionTypeTree node.
 415      * @param node the node being visited
 416      * @param p a parameter value
 417      * @return a result value
 418      */
 419     R visitUnionType(UnionTypeTree node, P p);
 420 
 421     /**
 422      * Visits an IntersectionTypeTree node.
 423      * @param node the node being visited
 424      * @param p a parameter value
 425      * @return a result value
 426      */
 427     R visitIntersectionType(IntersectionTypeTree node, P p);
 428 
 429     /**
 430      * Visits an ArrayTypeTree node.
 431      * @param node the node being visited
 432      * @param p a parameter value
 433      * @return a result value
 434      */
 435     R visitArrayType(ArrayTypeTree node, P p);
 436 
 437     /**
 438      * Visits a TypeCastTree node.
 439      * @param node the node being visited
 440      * @param p a parameter value
 441      * @return a result value
 442      */
 443     R visitTypeCast(TypeCastTree node, P p);
 444 
 445     /**
 446      * Visits a PrimitiveTypeTree node.
 447      * @param node the node being visited
 448      * @param p a parameter value
 449      * @return a result value
 450      */
 451     R visitPrimitiveType(PrimitiveTypeTree node, P p);
 452 
 453     /**
 454      * Visits a TypeParameterTree node.
 455      * @param node the node being visited
 456      * @param p a parameter value
 457      * @return a result value
 458      */
 459     R visitTypeParameter(TypeParameterTree node, P p);
 460 
 461     /**
 462      * Visits an InstanceOfTree node.
 463      * @param node the node being visited
 464      * @param p a parameter value
 465      * @return a result value
 466      */
 467     R visitInstanceOf(InstanceOfTree node, P p);
 468 
 469     /**
 470      * Visits a UnaryTree node.
 471      * @param node the node being visited
 472      * @param p a parameter value
 473      * @return a result value
 474      */
 475     R visitUnary(UnaryTree node, P p);
 476 
 477     /**
 478      * Visits a VariableTree node.
 479      * @param node the node being visited
 480      * @param p a parameter value
 481      * @return a result value
 482      */
 483     R visitVariable(VariableTree node, P p);
 484 
 485     /**
 486      * Visits a WhileLoopTree node.
 487      * @param node the node being visited
 488      * @param p a parameter value
 489      * @return a result value
 490      */
 491     R visitWhileLoop(WhileLoopTree node, P p);
 492 
 493     /**
 494      * Visits a WithFieldTree node.
 495      * @param node the node being visited
 496      * @param p a parameter value
 497      * @return a result value
 498      */
 499     R visitWithField(WithFieldTree node, P p);
 500 
 501     /**
 502      * Visits a WildcardTypeTree node.
 503      * @param node the node being visited
 504      * @param p a parameter value
 505      * @return a result value
 506      */
 507     R visitWildcard(WildcardTree node, P p);
 508 
 509     /**
 510      * Visits a ModuleTree node.
 511      * @param node the node being visited
 512      * @param p a parameter value
 513      * @return a result value
 514      */
 515     R visitModule(ModuleTree node, P p);
 516 
 517     /**
 518      * Visits an ExportsTree node.
 519      * @param node the node being visited
 520      * @param p a parameter value
 521      * @return a result value
 522      */
 523     R visitExports(ExportsTree node, P p);
 524 
 525     /**
 526      * Visits an OpensTree node.
 527      * @param node the node being visited
 528      * @param p a parameter value
 529      * @return a result value
 530      */
 531     R visitOpens(OpensTree node, P p);
 532 
 533     /**
 534      * Visits a ProvidesTree node.
 535      * @param node the node being visited
 536      * @param p a parameter value
 537      * @return a result value
 538      */
 539     R visitProvides(ProvidesTree node, P p);
 540 
 541     /**
 542      * Visits a RequiresTree node.
 543      * @param node the node being visited
 544      * @param p a parameter value
 545      * @return a result value
 546      */
 547     R visitRequires(RequiresTree node, P p);
 548 
 549     /**
 550      * Visits a UsesTree node.
 551      * @param node the node being visited
 552      * @param p a parameter value
 553      * @return a result value
 554      */
 555     R visitUses(UsesTree node, P p);
 556 
 557     /**
 558      * Visits an unknown type of Tree node.
 559      * This can occur if the language evolves and new kinds
 560      * of nodes are added to the {@code Tree} hierarchy.
 561      * @param node the node being visited
 562      * @param p a parameter value
 563      * @return a result value
 564      */
 565     R visitOther(Tree node, P p);
 566 
 567     /**
 568      * Visits a YieldTree node.
 569      * @param node the node being visited
 570      * @param p a parameter value
 571      * @return a result value
 572      * @since 13
 573      *
 574      * @deprecated
 575      * This method is modeling yield statement,
 576      * which are part of a preview feature and may be removed
 577      * if the preview feature is removed.
 578      */
 579     @Deprecated(forRemoval=true, since="13")
 580     @SuppressWarnings("removal")
 581     R visitYield(YieldTree node, P p);
 582 }