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