TreeVisitor.java revision 1904:a3022cc65b17
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
26package 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 * @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 9
55 */
56public 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 class statement 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 visitClassDeclaration(ClassDeclarationTree node, P p);
128
129    /**
130     * Visit class expression 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 visitClassExpression(ClassExpressionTree node, P p);
137
138    /**
139     * Visit conditional expression 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 visitConditionalExpression(ConditionalExpressionTree node, P p);
146
147    /**
148     * Visit continue 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 visitContinue(ContinueTree node, P p);
155
156    /**
157     * Visit debugger statement 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 visitDebugger(DebuggerTree node, P p);
164
165    /**
166     * Visit do-while 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 visitDoWhileLoop(DoWhileLoopTree node, P p);
173
174    /**
175     * Visit error expression 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 visitErroneous(ErroneousTree node, P p);
182
183    /**
184     * Visit expression 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 visitExpressionStatement(ExpressionStatementTree node, P p);
191
192    /**
193     * Visit 'for' statement 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 visitForLoop(ForLoopTree node, P p);
200
201    /**
202     * Visit for..in statement 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 visitForInLoop(ForInLoopTree node, P p);
209
210    /**
211     * Visit for..of statement 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 visitForOfLoop(ForOfLoopTree node, P p);
218
219    /**
220     * Visit function call expression 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 visitFunctionCall(FunctionCallTree node, P p);
227
228    /**
229     * Visit function declaration 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 visitFunctionDeclaration(FunctionDeclarationTree node, P p);
236
237    /**
238     * Visit function 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 visitFunctionExpression(FunctionExpressionTree node, P p);
245
246    /**
247     * Visit identifier 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 visitIdentifier(IdentifierTree node, P p);
254
255    /**
256     * Visit 'if' 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 visitIf(IfTree node, P p);
263
264    /**
265     * Visit array access 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 visitArrayAccess(ArrayAccessTree node, P p);
272
273    /**
274     * Visit array literal 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 visitArrayLiteral(ArrayLiteralTree node, P p);
281
282    /**
283     * Visit labeled 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 visitLabeledStatement(LabeledStatementTree node, P p);
290
291    /**
292     * Visit literal 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 visitLiteral(LiteralTree node, P p);
299
300    /**
301     * Visit parenthesized 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 visitParenthesized(ParenthesizedTree node, P p);
308
309    /**
310     * Visit return statement 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 visitReturn(ReturnTree node, P p);
317
318    /**
319     * Visit member select 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 visitMemberSelect(MemberSelectTree node, P p);
326
327    /**
328     * Visit 'new' expression 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 visitNew(NewTree node, P p);
335
336    /**
337     * Visit object literal 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 visitObjectLiteral(ObjectLiteralTree node, P p);
344
345    /**
346     * Visit a property of an object literal expression 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 visitProperty(PropertyTree node, P p);
353
354    /**
355     * Visit regular expression literal 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 visitRegExpLiteral(RegExpLiteralTree node, P p);
362
363    /**
364     * Visit template literal 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 visitTemplateLiteral(TemplateLiteralTree node, P p);
371
372    /**
373     * Visit an empty 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 visitEmptyStatement(EmptyStatementTree node, P p);
380
381    /**
382     * Visit 'spread' 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 visitSpread(SpreadTree node, P p);
389
390    /**
391     * Visit 'switch' statement 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 visitSwitch(SwitchTree node, P p);
398
399    /**
400     * Visit 'throw' expression 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 visitThrow(ThrowTree node, P p);
407
408    /**
409     * Visit compilation unit 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 visitCompilationUnit(CompilationUnitTree node, P p);
416
417    /**
418     * Visit Module 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 visitModule(ModuleTree node, P p);
425
426    /**
427     * Visit Module ExportEntry tree.
428     *
429     * @param node node being visited
430     * @param p extra parameter passed to the visitor
431     * @return value from the visitor
432     */
433    R visitExportEntry(ExportEntryTree node, P p);
434
435    /**
436     * Visit Module ImportEntry tree.
437     *
438     * @param node node being visited
439     * @param p extra parameter passed to the visitor
440     * @return value from the visitor
441     */
442    R visitImportEntry(ImportEntryTree node, P p);
443
444    /**
445     * Visit 'try' statement tree.
446     *
447     * @param node node being visited
448     * @param p extra parameter passed to the visitor
449     * @return value from the visitor
450     */
451    R visitTry(TryTree node, P p);
452
453    /**
454     * Visit 'instanceof' expression tree.
455     *
456     * @param node node being visited
457     * @param p extra parameter passed to the visitor
458     * @return value from the visitor
459     */
460    R visitInstanceOf(InstanceOfTree node, P p);
461
462    /**
463     * Visit unary expression tree.
464     *
465     * @param node node being visited
466     * @param p extra parameter passed to the visitor
467     * @return value from the visitor
468     */
469    R visitUnary(UnaryTree node, P p);
470
471    /**
472     * Visit variable declaration tree.
473     *
474     * @param node node being visited
475     * @param p extra parameter passed to the visitor
476     * @return value from the visitor
477     */
478    R visitVariable(VariableTree node, P p);
479
480    /**
481     * Visit 'while' statement tree.
482     *
483     * @param node node being visited
484     * @param p extra parameter passed to the visitor
485     * @return value from the visitor
486     */
487    R visitWhileLoop(WhileLoopTree node, P p);
488
489    /**
490     * Visit 'with' statement tree.
491     *
492     * @param node node being visited
493     * @param p extra parameter passed to the visitor
494     * @return value from the visitor
495     */
496    R visitWith(WithTree node, P p);
497
498    /**
499     * Visit 'yield' expression tree.
500     *
501     * @param node node being visited
502     * @param p extra parameter passed to the visitor
503     * @return value from the visitor
504     */
505    R visitYield(YieldTree node, P p);
506
507    /**
508     * Visit unknown expression/statement tree. This fallback will be
509     * called if new Tree subtypes are introduced in future. A specific
510     * implementation may throw {{@linkplain UnknownTreeException unknown tree exception}
511     * if the visitor implementation was for an older language version.
512     *
513     * @param node node being visited
514     * @param p extra parameter passed to the visitor
515     * @return value from the visitor
516     */
517    R visitUnknown(Tree node, P p);
518}
519