1 /*
2  * Copyright (c) 2005, 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 com.sun.source.tree;
27 
28 /**
29  * Common interface for all nodes in an abstract syntax tree.
30  *
31  * <p><b>WARNING:</b> This interface and its sub-interfaces are
32  * subject to change as the Java&trade; programming language evolves.
33  * These interfaces are implemented by the JDK Java compiler (javac)
34  * and should not be implemented either directly or indirectly by
35  * other applications.
36  *
37  * @author Peter von der Ah&eacute;
38  * @author Jonathan Gibbons
39  *
40  * @since 1.6
41  */
42 public interface Tree {
43 
44     /**
45      * Enumerates all kinds of trees.
46      */
47     public enum Kind {
48         /**
49          * Used for instances of {@link AnnotatedTypeTree}
50          * representing annotated types.
51          */
52         ANNOTATED_TYPE(AnnotatedTypeTree.class),
53 
54         /**
55          * Used for instances of {@link AnnotationTree}
56          * representing declaration annotations.
57          */
58         ANNOTATION(AnnotationTree.class),
59 
60         /**
61          * Used for instances of {@link AnnotationTree}
62          * representing type annotations.
63          */
64         TYPE_ANNOTATION(AnnotationTree.class),
65 
66         /**
67          * Used for instances of {@link ArrayAccessTree}.
68          */
69         ARRAY_ACCESS(ArrayAccessTree.class),
70 
71         /**
72          * Used for instances of {@link ArrayTypeTree}.
73          */
74         ARRAY_TYPE(ArrayTypeTree.class),
75 
76         /**
77          * Used for instances of {@link AssertTree}.
78          */
79         ASSERT(AssertTree.class),
80 
81         /**
82          * Used for instances of {@link AssignmentTree}.
83          */
84         ASSIGNMENT(AssignmentTree.class),
85 
86         /**
87          * Used for instances of {@link BlockTree}.
88          */
89         BLOCK(BlockTree.class),
90 
91         /**
92          * Used for instances of {@link BreakTree}.
93          */
94         BREAK(BreakTree.class),
95 
96         /**
97          * Used for instances of {@link CaseTree}.
98          */
99         CASE(CaseTree.class),
100 
101         /**
102          * Used for instances of {@link CatchTree}.
103          */
104         CATCH(CatchTree.class),
105 
106         /**
107          * Used for instances of {@link ClassTree} representing classes.
108          */
109         CLASS(ClassTree.class),
110 
111         /**
112          * Used for instances of {@link CompilationUnitTree}.
113          */
114         COMPILATION_UNIT(CompilationUnitTree.class),
115 
116         /**
117          * Used for instances of {@link ConditionalExpressionTree}.
118          */
119         CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class),
120 
121         /**
122          * Used for instances of {@link ContinueTree}.
123          */
124         CONTINUE(ContinueTree.class),
125 
126         /**
127          * Used for instances of {@link DoWhileLoopTree}.
128          */
129         DO_WHILE_LOOP(DoWhileLoopTree.class),
130 
131         /**
132          * Used for instances of {@link EnhancedForLoopTree}.
133          */
134         ENHANCED_FOR_LOOP(EnhancedForLoopTree.class),
135 
136         /**
137          * Used for instances of {@link ExpressionStatementTree}.
138          */
139         EXPRESSION_STATEMENT(ExpressionStatementTree.class),
140 
141         /**
142          * Used for instances of {@link MemberSelectTree}.
143          */
144         MEMBER_SELECT(MemberSelectTree.class),
145 
146         /**
147          * Used for instances of {@link MemberReferenceTree}.
148          */
149         MEMBER_REFERENCE(MemberReferenceTree.class),
150 
151         /**
152          * Used for instances of {@link ForLoopTree}.
153          */
154         FOR_LOOP(ForLoopTree.class),
155 
156         /**
157          * Used for instances of {@link IdentifierTree}.
158          */
159         IDENTIFIER(IdentifierTree.class),
160 
161         /**
162          * Used for instances of {@link IfTree}.
163          */
164         IF(IfTree.class),
165 
166         /**
167          * Used for instances of {@link ImportTree}.
168          */
169         IMPORT(ImportTree.class),
170 
171         /**
172          * Used for instances of {@link InstanceOfTree}.
173          */
174         INSTANCE_OF(InstanceOfTree.class),
175 
176         /**
177          * Used for instances of {@link LabeledStatementTree}.
178          */
179         LABELED_STATEMENT(LabeledStatementTree.class),
180 
181         /**
182          * Used for instances of {@link MethodTree}.
183          */
184         METHOD(MethodTree.class),
185 
186         /**
187          * Used for instances of {@link MethodInvocationTree}.
188          */
189         METHOD_INVOCATION(MethodInvocationTree.class),
190 
191         /**
192          * Used for instances of {@link ModifiersTree}.
193          */
194         MODIFIERS(ModifiersTree.class),
195 
196         /**
197          * Used for instances of {@link NewArrayTree}.
198          */
199         NEW_ARRAY(NewArrayTree.class),
200 
201         /**
202          * Used for instances of {@link NewClassTree}.
203          */
204         NEW_CLASS(NewClassTree.class),
205 
206         /**
207          * Used for instances of {@link LambdaExpressionTree}.
208          */
209         LAMBDA_EXPRESSION(LambdaExpressionTree.class),
210 
211         /**
212          * Used for instances of {@link PackageTree}.
213          * @since 9
214          */
215         PACKAGE(PackageTree.class),
216 
217         /**
218          * Used for instances of {@link ParenthesizedTree}.
219          */
220         PARENTHESIZED(ParenthesizedTree.class),
221 
222         /**
223          * Used for instances of {@link PrimitiveTypeTree}.
224          */
225         PRIMITIVE_TYPE(PrimitiveTypeTree.class),
226 
227         /**
228          * Used for instances of {@link ReturnTree}.
229          */
230         RETURN(ReturnTree.class),
231 
232         /**
233          * Used for instances of {@link EmptyStatementTree}.
234          */
235         EMPTY_STATEMENT(EmptyStatementTree.class),
236 
237         /**
238          * Used for instances of {@link SwitchTree}.
239          */
240         SWITCH(SwitchTree.class),
241 
242         /**
243          * Used for instances of {@link SynchronizedTree}.
244          */
245         SYNCHRONIZED(SynchronizedTree.class),
246 
247         /**
248          * Used for instances of {@link ThrowTree}.
249          */
250         THROW(ThrowTree.class),
251 
252         /**
253          * Used for instances of {@link TryTree}.
254          */
255         TRY(TryTree.class),
256 
257         /**
258          * Used for instances of {@link ParameterizedTypeTree}.
259          */
260         PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
261 
262         /**
263          * Used for instances of {@link UnionTypeTree}.
264          */
265         UNION_TYPE(UnionTypeTree.class),
266 
267         /**
268          * Used for instances of {@link IntersectionTypeTree}.
269          */
270         INTERSECTION_TYPE(IntersectionTypeTree.class),
271 
272         /**
273          * Used for instances of {@link TypeCastTree}.
274          */
275         TYPE_CAST(TypeCastTree.class),
276 
277         /**
278          * Used for instances of {@link TypeParameterTree}.
279          */
280         TYPE_PARAMETER(TypeParameterTree.class),
281 
282         /**
283          * Used for instances of {@link VariableTree}.
284          */
285         VARIABLE(VariableTree.class),
286 
287         /**
288          * Used for instances of {@link WhileLoopTree}.
289          */
290         WHILE_LOOP(WhileLoopTree.class),
291 
292         /**
293          * Used for instances of {@link UnaryTree} representing postfix
294          * increment operator {@code ++}.
295          */
296         POSTFIX_INCREMENT(UnaryTree.class),
297 
298         /**
299          * Used for instances of {@link UnaryTree} representing postfix
300          * decrement operator {@code --}.
301          */
302         POSTFIX_DECREMENT(UnaryTree.class),
303 
304         /**
305          * Used for instances of {@link UnaryTree} representing prefix
306          * increment operator {@code ++}.
307          */
308         PREFIX_INCREMENT(UnaryTree.class),
309 
310         /**
311          * Used for instances of {@link UnaryTree} representing prefix
312          * decrement operator {@code --}.
313          */
314         PREFIX_DECREMENT(UnaryTree.class),
315 
316         /**
317          * Used for instances of {@link UnaryTree} representing unary plus
318          * operator {@code +}.
319          */
320         UNARY_PLUS(UnaryTree.class),
321 
322         /**
323          * Used for instances of {@link UnaryTree} representing unary minus
324          * operator {@code -}.
325          */
326         UNARY_MINUS(UnaryTree.class),
327 
328         /**
329          * Used for instances of {@link UnaryTree} representing bitwise
330          * complement operator {@code ~}.
331          */
332         BITWISE_COMPLEMENT(UnaryTree.class),
333 
334         /**
335          * Used for instances of {@link UnaryTree} representing logical
336          * complement operator {@code !}.
337          */
338         LOGICAL_COMPLEMENT(UnaryTree.class),
339 
340         /**
341          * Used for instances of {@link BinaryTree} representing
342          * multiplication {@code *}.
343          */
344         MULTIPLY(BinaryTree.class),
345 
346         /**
347          * Used for instances of {@link BinaryTree} representing
348          * division {@code /}.
349          */
350         DIVIDE(BinaryTree.class),
351 
352         /**
353          * Used for instances of {@link BinaryTree} representing
354          * remainder {@code %}.
355          */
356         REMAINDER(BinaryTree.class),
357 
358         /**
359          * Used for instances of {@link BinaryTree} representing
360          * addition or string concatenation {@code +}.
361          */
362         PLUS(BinaryTree.class),
363 
364         /**
365          * Used for instances of {@link BinaryTree} representing
366          * subtraction {@code -}.
367          */
368         MINUS(BinaryTree.class),
369 
370         /**
371          * Used for instances of {@link BinaryTree} representing
372          * left shift {@code <<}.
373          */
374         LEFT_SHIFT(BinaryTree.class),
375 
376         /**
377          * Used for instances of {@link BinaryTree} representing
378          * right shift {@code >>}.
379          */
380         RIGHT_SHIFT(BinaryTree.class),
381 
382         /**
383          * Used for instances of {@link BinaryTree} representing
384          * unsigned right shift {@code >>>}.
385          */
386         UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
387 
388         /**
389          * Used for instances of {@link BinaryTree} representing
390          * less-than {@code <}.
391          */
392         LESS_THAN(BinaryTree.class),
393 
394         /**
395          * Used for instances of {@link BinaryTree} representing
396          * greater-than {@code >}.
397          */
398         GREATER_THAN(BinaryTree.class),
399 
400         /**
401          * Used for instances of {@link BinaryTree} representing
402          * less-than-equal {@code <=}.
403          */
404         LESS_THAN_EQUAL(BinaryTree.class),
405 
406         /**
407          * Used for instances of {@link BinaryTree} representing
408          * greater-than-equal {@code >=}.
409          */
410         GREATER_THAN_EQUAL(BinaryTree.class),
411 
412         /**
413          * Used for instances of {@link BinaryTree} representing
414          * equal-to {@code ==}.
415          */
416         EQUAL_TO(BinaryTree.class),
417 
418         /**
419          * Used for instances of {@link BinaryTree} representing
420          * not-equal-to {@code !=}.
421          */
422         NOT_EQUAL_TO(BinaryTree.class),
423 
424         /**
425          * Used for instances of {@link BinaryTree} representing
426          * bitwise and logical "and" {@code &}.
427          */
428         AND(BinaryTree.class),
429 
430         /**
431          * Used for instances of {@link BinaryTree} representing
432          * bitwise and logical "xor" {@code ^}.
433          */
434         XOR(BinaryTree.class),
435 
436         /**
437          * Used for instances of {@link BinaryTree} representing
438          * bitwise and logical "or" {@code |}.
439          */
440         OR(BinaryTree.class),
441 
442         /**
443          * Used for instances of {@link BinaryTree} representing
444          * conditional-and {@code &&}.
445          */
446         CONDITIONAL_AND(BinaryTree.class),
447 
448         /**
449          * Used for instances of {@link BinaryTree} representing
450          * conditional-or {@code ||}.
451          */
452         CONDITIONAL_OR(BinaryTree.class),
453 
454         /**
455          * Used for instances of {@link CompoundAssignmentTree} representing
456          * multiplication assignment {@code *=}.
457          */
458         MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
459 
460         /**
461          * Used for instances of {@link CompoundAssignmentTree} representing
462          * division assignment {@code /=}.
463          */
464         DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
465 
466         /**
467          * Used for instances of {@link CompoundAssignmentTree} representing
468          * remainder assignment {@code %=}.
469          */
470         REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
471 
472         /**
473          * Used for instances of {@link CompoundAssignmentTree} representing
474          * addition or string concatenation assignment {@code +=}.
475          */
476         PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
477 
478         /**
479          * Used for instances of {@link CompoundAssignmentTree} representing
480          * subtraction assignment {@code -=}.
481          */
482         MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
483 
484         /**
485          * Used for instances of {@link CompoundAssignmentTree} representing
486          * left shift assignment {@code <<=}.
487          */
488         LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
489 
490         /**
491          * Used for instances of {@link CompoundAssignmentTree} representing
492          * right shift assignment {@code >>=}.
493          */
494         RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
495 
496         /**
497          * Used for instances of {@link CompoundAssignmentTree} representing
498          * unsigned right shift assignment {@code >>>=}.
499          */
500         UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
501 
502         /**
503          * Used for instances of {@link CompoundAssignmentTree} representing
504          * bitwise and logical "and" assignment {@code &=}.
505          */
506         AND_ASSIGNMENT(CompoundAssignmentTree.class),
507 
508         /**
509          * Used for instances of {@link CompoundAssignmentTree} representing
510          * bitwise and logical "xor" assignment {@code ^=}.
511          */
512         XOR_ASSIGNMENT(CompoundAssignmentTree.class),
513 
514         /**
515          * Used for instances of {@link CompoundAssignmentTree} representing
516          * bitwise and logical "or" assignment {@code |=}.
517          */
518         OR_ASSIGNMENT(CompoundAssignmentTree.class),
519 
520         /**
521          * Used for instances of {@link LiteralTree} representing
522          * an integral literal expression of type {@code int}.
523          */
524         INT_LITERAL(LiteralTree.class),
525 
526         /**
527          * Used for instances of {@link LiteralTree} representing
528          * an integral literal expression of type {@code long}.
529          */
530         LONG_LITERAL(LiteralTree.class),
531 
532         /**
533          * Used for instances of {@link LiteralTree} representing
534          * a floating-point literal expression of type {@code float}.
535          */
536         FLOAT_LITERAL(LiteralTree.class),
537 
538         /**
539          * Used for instances of {@link LiteralTree} representing
540          * a floating-point literal expression of type {@code double}.
541          */
542         DOUBLE_LITERAL(LiteralTree.class),
543 
544         /**
545          * Used for instances of {@link LiteralTree} representing
546          * a boolean literal expression of type {@code boolean}.
547          */
548         BOOLEAN_LITERAL(LiteralTree.class),
549 
550         /**
551          * Used for instances of {@link LiteralTree} representing
552          * a character literal expression of type {@code char}.
553          */
554         CHAR_LITERAL(LiteralTree.class),
555 
556         /**
557          * Used for instances of {@link LiteralTree} representing
558          * a string literal expression of type {@link String}.
559          */
560         STRING_LITERAL(LiteralTree.class),
561 
562         /**
563          * Used for instances of {@link LiteralTree} representing
564          * the use of {@code null}.
565          */
566         NULL_LITERAL(LiteralTree.class),
567 
568         /**
569          * Used for instances of {@link WildcardTree} representing
570          * an unbounded wildcard type argument.
571          */
572         UNBOUNDED_WILDCARD(WildcardTree.class),
573 
574         /**
575          * Used for instances of {@link WildcardTree} representing
576          * an extends bounded wildcard type argument.
577          */
578         EXTENDS_WILDCARD(WildcardTree.class),
579 
580         /**
581          * Used for instances of {@link WildcardTree} representing
582          * a super bounded wildcard type argument.
583          */
584         SUPER_WILDCARD(WildcardTree.class),
585 
586         /**
587          * Used for instances of {@link ErroneousTree}.
588          */
589         ERRONEOUS(ErroneousTree.class),
590 
591         /**
592          * Used for instances of {@link ClassTree} representing interfaces.
593          */
594         INTERFACE(ClassTree.class),
595 
596         /**
597          * Used for instances of {@link ClassTree} representing enums.
598          */
599         ENUM(ClassTree.class),
600 
601         /**
602          * Used for instances of {@link ClassTree} representing annotation types.
603          */
604         ANNOTATION_TYPE(ClassTree.class),
605 
606         /**
607          * Used for instances of {@link ModuleTree} representing module declarations.
608          */
609         MODULE(ModuleTree.class),
610 
611         /**
612          * Used for instances of {@link ExportsTree} representing
613          * exports directives in a module declaration.
614          */
615         EXPORTS(ExportsTree.class),
616 
617         /**
618          * Used for instances of {@link ExportsTree} representing
619          * opens directives in a module declaration.
620          */
621         OPENS(OpensTree.class),
622 
623         /**
624          * Used for instances of {@link ProvidesTree} representing
625          * provides directives in a module declaration.
626          */
627         PROVIDES(ProvidesTree.class),
628 
629         /**
630          * Used for instances of {@link RequiresTree} representing
631          * requires directives in a module declaration.
632          */
633         REQUIRES(RequiresTree.class),
634 
635         /**
636          * Used for instances of {@link UsesTree} representing
637          * uses directives in a module declaration.
638          */
639         USES(UsesTree.class),
640 
641         /**
642          * An implementation-reserved node. This is the not the node
643          * you are looking for.
644          */
645         OTHER(null);
646 
647 
Kind(Class<? extends Tree> intf)648         Kind(Class<? extends Tree> intf) {
649             associatedInterface = intf;
650         }
651 
652         /**
653          * Returns the associated interface type that uses this kind.
654          * @return the associated interface
655          */
asInterface()656         public Class<? extends Tree> asInterface() {
657             return associatedInterface;
658         }
659 
660         private final Class<? extends Tree> associatedInterface;
661     }
662 
663     /**
664      * Returns the kind of this tree.
665      *
666      * @return the kind of this tree.
667      */
getKind()668     Kind getKind();
669 
670     /**
671      * Accept method used to implement the visitor pattern.  The
672      * visitor pattern is used to implement operations on trees.
673      *
674      * @param <R> result type of this operation.
675      * @param <D> type of additional data.
676      * @param visitor the visitor to be called
677      * @param data a value to be passed to the visitor
678      * @return the result returned from calling the visitor
679      */
accept(TreeVisitor<R,D> visitor, D data)680     <R,D> R accept(TreeVisitor<R,D> visitor, D data);
681 }
682