       1 /*
       2  * Copyright (c) 2016, 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 <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 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  * @deprecated Nashorn JavaScript script engine and APIs, and the jjs tool
      49  * are deprecated with the intent to remove them in a future release.
      50  *
      51  * @param <R> the return type of this visitor's methods.  Use {@link
      52  *            Void} for visitors that do not need to return results.
      53  * @param <P> the type of the additional parameter to this visitor's
      54  *            methods.  Use {@code Void} for visitors that do not need an
      55  *            additional parameter.
      56  *
      57  * @since 9
      58  */
      59 @Deprecated(since="11", forRemoval=true)
      60 public interface TreeVisitor<R,P> {
      61     /**
      62      * Visit assignment tree.
      63      *
      64      * @param node node being visited
      65      * @param p extra parameter passed to the visitor
      66      * @return value from the visitor
      67      */
      68     R visitAssignment(AssignmentTree node, P p);
      69
      70     /**
      71      * Visit compound assignment tree.
      72      *
      73      * @param node node being visited
      74      * @param p extra parameter passed to the visitor
      75      * @return value from the visitor
      76      */
      77     R visitCompoundAssignment(CompoundAssignmentTree node, P p);
      78
      79     /**
      80      * Visit binary expression tree.
      81      *
      82      * @param node node being visited
      83      * @param p extra parameter passed to the visitor
      84      * @return value from the visitor
      85      */
      86     R visitBinary(BinaryTree node, P p);
      87
      88     /**
      89      * Visit block statement tree.
      90      *
      91      * @param node node being visited
      92      * @param p extra parameter passed to the visitor
      93      * @return value from the visitor
      94      */
      95     R visitBlock(BlockTree node, P p);
      96
      97     /**
      98      * Visit break statement tree.
      99      *
     100      * @param node node being visited
     101      * @param p extra parameter passed to the visitor
     102      * @return value from the visitor
     103      */
     104     R visitBreak(BreakTree node, P p);
     105
     106     /**
     107      * Visit case statement tree.
     108      *
     109      * @param node node being visited
     110      * @param p extra parameter passed to the visitor
     111      * @return value from the visitor
     112      */
     113     R visitCase(CaseTree node, P p);
     114
     115     /**
     116      * Visit catch block statement tree.
     117      *
     118      * @param node node being visited
     119      * @param p extra parameter passed to the visitor
     120      * @return value from the visitor
     121      */
     122     R visitCatch(CatchTree node, P p);
     123
     124     /**
     125      * Visit class statement tree.
     126      *
     127      * @param node node being visited
     128      * @param p extra parameter passed to the visitor
     129      * @return value from the visitor
     130      */
     131     R visitClassDeclaration(ClassDeclarationTree node, P p);
     132
     133     /**
     134      * Visit class expression tree.
     135      *
     136      * @param node node being visited
     137      * @param p extra parameter passed to the visitor
     138      * @return value from the visitor
     139      */
     140     R visitClassExpression(ClassExpressionTree node, P p);
     141
     142     /**
     143      * Visit conditional expression tree.
     144      *
     145      * @param node node being visited
     146      * @param p extra parameter passed to the visitor
     147      * @return value from the visitor
     148      */
     149     R visitConditionalExpression(ConditionalExpressionTree node, P p);
     150
     151     /**
     152      * Visit continue statement tree.
     153      *
     154      * @param node node being visited
     155      * @param p extra parameter passed to the visitor
     156      * @return value from the visitor
     157      */
     158     R visitContinue(ContinueTree node, P p);
     159
     160     /**
     161      * Visit debugger statement tree.
     162      *
     163      * @param node node being visited
     164      * @param p extra parameter passed to the visitor
     165      * @return value from the visitor
     166      */
     167     R visitDebugger(DebuggerTree node, P p);
     168
     169     /**
     170      * Visit do-while statement tree.
     171      *
     172      * @param node node being visited
     173      * @param p extra parameter passed to the visitor
     174      * @return value from the visitor
     175      */
     176     R visitDoWhileLoop(DoWhileLoopTree node, P p);
     177
     178     /**
     179      * Visit error expression tree.
     180      *
     181      * @param node node being visited
     182      * @param p extra parameter passed to the visitor
     183      * @return value from the visitor
     184      */
     185     R visitErroneous(ErroneousTree node, P p);
     186
     187     /**
     188      * Visit expression statement tree.
     189      *
     190      * @param node node being visited
     191      * @param p extra parameter passed to the visitor
     192      * @return value from the visitor
     193      */
     194     R visitExpressionStatement(ExpressionStatementTree node, P p);
     195
     196     /**
     197      * Visit 'for' statement tree.
     198      *
     199      * @param node node being visited
     200      * @param p extra parameter passed to the visitor
     201      * @return value from the visitor
     202      */
     203     R visitForLoop(ForLoopTree node, P p);
     204
     205     /**
     206      * Visit for..in statement tree.
     207      *
     208      * @param node node being visited
     209      * @param p extra parameter passed to the visitor
     210      * @return value from the visitor
     211      */
     212     R visitForInLoop(ForInLoopTree node, P p);
     213
     214     /**
     215      * Visit for..of statement tree.
     216      *
     217      * @param node node being visited
     218      * @param p extra parameter passed to the visitor
     219      * @return value from the visitor
     220      */
     221     R visitForOfLoop(ForOfLoopTree node, P p);
     222
     223     /**
     224      * Visit function call expression tree.
     225      *
     226      * @param node node being visited
     227      * @param p extra parameter passed to the visitor
     228      * @return value from the visitor
     229      */
     230     R visitFunctionCall(FunctionCallTree node, P p);
     231
     232     /**
     233      * Visit function declaration tree.
     234      *
     235      * @param node node being visited
     236      * @param p extra parameter passed to the visitor
     237      * @return value from the visitor
     238      */
     239     R visitFunctionDeclaration(FunctionDeclarationTree node, P p);
     240
     241     /**
     242      * Visit function expression tree.
     243      *
     244      * @param node node being visited
     245      * @param p extra parameter passed to the visitor
     246      * @return value from the visitor
     247      */
     248     R visitFunctionExpression(FunctionExpressionTree node, P p);
     249
     250     /**
     251      * Visit identifier tree.
     252      *
     253      * @param node node being visited
     254      * @param p extra parameter passed to the visitor
     255      * @return value from the visitor
     256      */
     257     R visitIdentifier(IdentifierTree node, P p);
     258
     259     /**
     260      * Visit 'if' statement tree.
     261      *
     262      * @param node node being visited
     263      * @param p extra parameter passed to the visitor
     264      * @return value from the visitor
     265      */
     266     R visitIf(IfTree node, P p);
     267
     268     /**
     269      * Visit array access expression tree.
     270      *
     271      * @param node node being visited
     272      * @param p extra parameter passed to the visitor
     273      * @return value from the visitor
     274      */
     275     R visitArrayAccess(ArrayAccessTree node, P p);
     276
     277     /**
     278      * Visit array literal expression tree.
     279      *
     280      * @param node node being visited
     281      * @param p extra parameter passed to the visitor
     282      * @return value from the visitor
     283      */
     284     R visitArrayLiteral(ArrayLiteralTree node, P p);
     285
     286     /**
     287      * Visit labeled statement tree.
     288      *
     289      * @param node node being visited
     290      * @param p extra parameter passed to the visitor
     291      * @return value from the visitor
     292      */
     293     R visitLabeledStatement(LabeledStatementTree node, P p);
     294
     295     /**
     296      * Visit literal expression tree.
     297      *
     298      * @param node node being visited
     299      * @param p extra parameter passed to the visitor
     300      * @return value from the visitor
     301      */
     302     R visitLiteral(LiteralTree node, P p);
     303
     304     /**
     305      * Visit parenthesized expression tree.
     306      *
     307      * @param node node being visited
     308      * @param p extra parameter passed to the visitor
     309      * @return value from the visitor
     310      */
     311     R visitParenthesized(ParenthesizedTree node, P p);
     312
     313     /**
     314      * Visit return statement tree.
     315      *
     316      * @param node node being visited
     317      * @param p extra parameter passed to the visitor
     318      * @return value from the visitor
     319      */
     320     R visitReturn(ReturnTree node, P p);
     321
     322     /**
     323      * Visit member select expression tree.
     324      *
     325      * @param node node being visited
     326      * @param p extra parameter passed to the visitor
     327      * @return value from the visitor
     328      */
     329     R visitMemberSelect(MemberSelectTree node, P p);
     330
     331     /**
     332      * Visit 'new' expression tree.
     333      *
     334      * @param node node being visited
     335      * @param p extra parameter passed to the visitor
     336      * @return value from the visitor
     337      */
     338     R visitNew(NewTree node, P p);
     339
     340     /**
     341      * Visit object literal tree.
     342      *
     343      * @param node node being visited
     344      * @param p extra parameter passed to the visitor
     345      * @return value from the visitor
     346      */
     347     R visitObjectLiteral(ObjectLiteralTree node, P p);
     348
     349     /**
     350      * Visit a property of an object literal expression tree.
     351      *
     352      * @param node node being visited
     353      * @param p extra parameter passed to the visitor
     354      * @return value from the visitor
     355      */
     356     R visitProperty(PropertyTree node, P p);
     357
     358     /**
     359      * Visit regular expression literal tree.
     360      *
     361      * @param node node being visited
     362      * @param p extra parameter passed to the visitor
     363      * @return value from the visitor
     364      */
     365     R visitRegExpLiteral(RegExpLiteralTree node, P p);
     366
     367     /**
     368      * Visit template literal tree.
     369      *
     370      * @param node node being visited
     371      * @param p extra parameter passed to the visitor
     372      * @return value from the visitor
     373      */
     374     R visitTemplateLiteral(TemplateLiteralTree node, P p);
     375
     376     /**
     377      * Visit an empty statement tree.
     378      *
     379      * @param node node being visited
     380      * @param p extra parameter passed to the visitor
     381      * @return value from the visitor
     382      */
     383     R visitEmptyStatement(EmptyStatementTree node, P p);
     384
     385     /**
     386      * Visit 'spread' expression tree.
     387      *
     388      * @param node node being visited
     389      * @param p extra parameter passed to the visitor
     390      * @return value from the visitor
     391      */
     392     R visitSpread(SpreadTree node, P p);
     393
     394     /**
     395      * Visit 'switch' statement tree.
     396      *
     397      * @param node node being visited
     398      * @param p extra parameter passed to the visitor
     399      * @return value from the visitor
     400      */
     401     R visitSwitch(SwitchTree node, P p);
     402
     403     /**
     404      * Visit 'throw' expression tree.
     405      *
     406      * @param node node being visited
     407      * @param p extra parameter passed to the visitor
     408      * @return value from the visitor
     409      */
     410     R visitThrow(ThrowTree node, P p);
     411
     412     /**
     413      * Visit compilation unit tree.
     414      *
     415      * @param node node being visited
     416      * @param p extra parameter passed to the visitor
     417      * @return value from the visitor
     418      */
     419     R visitCompilationUnit(CompilationUnitTree node, P p);
     420
     421     /**
     422      * Visit Module tree.
     423      *
     424      * @param node node being visited
     425      * @param p extra parameter passed to the visitor
     426      * @return value from the visitor
     427      */
     428     R visitModule(ModuleTree node, P p);
     429
     430     /**
     431      * Visit Module ExportEntry tree.
     432      *
     433      * @param node node being visited
     434      * @param p extra parameter passed to the visitor
     435      * @return value from the visitor
     436      */
     437     R visitExportEntry(ExportEntryTree node, P p);
     438
     439     /**
     440      * Visit Module ImportEntry tree.
     441      *
     442      * @param node node being visited
     443      * @param p extra parameter passed to the visitor
     444      * @return value from the visitor
     445      */
     446     R visitImportEntry(ImportEntryTree node, P p);
     447
     448     /**
     449      * Visit 'try' statement tree.
     450      *
     451      * @param node node being visited
     452      * @param p extra parameter passed to the visitor
     453      * @return value from the visitor
     454      */
     455     R visitTry(TryTree node, P p);
     456
     457     /**
     458      * Visit 'instanceof' expression tree.
     459      *
     460      * @param node node being visited
     461      * @param p extra parameter passed to the visitor
     462      * @return value from the visitor
     463      */
     464     R visitInstanceOf(InstanceOfTree node, P p);
     465
     466     /**
     467      * Visit unary expression tree.
     468      *
     469      * @param node node being visited
     470      * @param p extra parameter passed to the visitor
     471      * @return value from the visitor
     472      */
     473     R visitUnary(UnaryTree node, P p);
     474
     475     /**
     476      * Visit variable declaration tree.
     477      *
     478      * @param node node being visited
     479      * @param p extra parameter passed to the visitor
     480      * @return value from the visitor
     481      */
     482     R visitVariable(VariableTree node, P p);
     483
     484     /**
     485      * Visit 'while' statement tree.
     486      *
     487      * @param node node being visited
     488      * @param p extra parameter passed to the visitor
     489      * @return value from the visitor
     490      */
     491     R visitWhileLoop(WhileLoopTree node, P p);
     492
     493     /**
     494      * Visit 'with' statement tree.
     495      *
     496      * @param node node being visited
     497      * @param p extra parameter passed to the visitor
     498      * @return value from the visitor
     499      */
     500     R visitWith(WithTree node, P p);
     501
     502     /**
     503      * Visit 'yield' expression tree.
     504      *
     505      * @param node node being visited
     506      * @param p extra parameter passed to the visitor
     507      * @return value from the visitor
     508      */
     509     R visitYield(YieldTree node, P p);
     510
     511     /**
     512      * Visit unknown expression/statement tree. This fallback will be
     513      * called if new Tree subtypes are introduced in future. A specific
     514      * implementation may throw {{@linkplain UnknownTreeException unknown tree exception}
     515      * if the visitor implementation was for an older language version.
     516      *
     517      * @param node node being visited
     518      * @param p extra parameter passed to the visitor
     519      * @return value from the visitor
     520      */
     521     R visitUnknown(Tree node, P p);
     522 }