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  * Common interface for all nodes in an abstract syntax tree.
 32  *
 33  * <p><b>WARNING:</b> This interface and its sub-interfaces are
 34  * subject to change as the Java programming language evolves.
 35  * These interfaces are implemented by the JDK Java compiler (javac)
 36  * and should not be implemented either directly or indirectly by
 37  * other applications.
 38  *
 39  * @author Peter von der Ah&eacute;
 40  * @author Jonathan Gibbons
 41  *
 42  * @since 1.6
 43  */
 44 public interface Tree {
 45 
 46     /**
 47      * Enumerates all kinds of trees.
 48      */
 49     public enum Kind {
 50         /**
 51          * Used for instances of {@link AnnotatedTypeTree}
 52          * representing annotated types.
 53          */
 54         ANNOTATED_TYPE(AnnotatedTypeTree.class),
 55 
 56         /**
 57          * Used for instances of {@link AnnotationTree}
 58          * representing declaration annotations.
 59          */
 60         ANNOTATION(AnnotationTree.class),
 61 
 62         /**
 63          * Used for instances of {@link AnnotationTree}
 64          * representing type annotations.
 65          */
 66         TYPE_ANNOTATION(AnnotationTree.class),
 67 
 68         /**
 69          * Used for instances of {@link ArrayAccessTree}.
 70          */
 71         ARRAY_ACCESS(ArrayAccessTree.class),
 72 
 73         /**
 74          * Used for instances of {@link ArrayTypeTree}.
 75          */
 76         ARRAY_TYPE(ArrayTypeTree.class),
 77 
 78         /**
 79          * Used for instances of {@link AssertTree}.
 80          */
 81         ASSERT(AssertTree.class),
 82 
 83         /**
 84          * Used for instances of {@link AssignmentTree}.
 85          */
 86         ASSIGNMENT(AssignmentTree.class),
 87 
 88         /**
 89          * Used for instances of {@link BlockTree}.
 90          */
 91         BLOCK(BlockTree.class),
 92 
 93         /**
 94          * Used for instances of {@link BreakTree}.
 95          */
 96         BREAK(BreakTree.class),
 97 
 98         /**
 99          * Used for instances of {@link CaseTree}.
100          */
101         CASE(CaseTree.class),
102 
103         /**
104          * Used for instances of {@link CatchTree}.
105          */
106         CATCH(CatchTree.class),
107 
108         /**
109          * Used for instances of {@link ClassTree} representing classes.
110          */
111         CLASS(ClassTree.class),
112 
113         /**
114          * Used for instances of {@link CompilationUnitTree}.
115          */
116         COMPILATION_UNIT(CompilationUnitTree.class),
117 
118         /**
119          * Used for instances of {@link ConditionalExpressionTree}.
120          */
121         CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class),
122 
123         /**
124          * Used for instances of {@link ContinueTree}.
125          */
126         CONTINUE(ContinueTree.class),
127 
128         /**
129          * Used for instances of {@link DoWhileLoopTree}.
130          */
131         DO_WHILE_LOOP(DoWhileLoopTree.class),
132 
133         /**
134          * Used for instances of {@link EnhancedForLoopTree}.
135          */
136         ENHANCED_FOR_LOOP(EnhancedForLoopTree.class),
137 
138         /**
139          * Used for instances of {@link ExpressionStatementTree}.
140          */
141         EXPRESSION_STATEMENT(ExpressionStatementTree.class),
142 
143         /**
144          * Used for instances of {@link MemberSelectTree}.
145          */
146         MEMBER_SELECT(MemberSelectTree.class),
147 
148         /**
149          * Used for instances of {@link MemberReferenceTree}.
150          */
151         MEMBER_REFERENCE(MemberReferenceTree.class),
152 
153         /**
154          * Used for instances of {@link ForLoopTree}.
155          */
156         FOR_LOOP(ForLoopTree.class),
157 
158         /**
159          * Used for instances of {@link IdentifierTree}.
160          */
161         IDENTIFIER(IdentifierTree.class),
162 
163         /**
164          * Used for instances of {@link IfTree}.
165          */
166         IF(IfTree.class),
167 
168         /**
169          * Used for instances of {@link ImportTree}.
170          */
171         IMPORT(ImportTree.class),
172 
173         /**
174          * Used for instances of {@link InstanceOfTree}.
175          */
176         INSTANCE_OF(InstanceOfTree.class),
177 
178         /**
179          * Used for instances of {@link LabeledStatementTree}.
180          */
181         LABELED_STATEMENT(LabeledStatementTree.class),
182 
183         /**
184          * Used for instances of {@link MethodTree}.
185          */
186         METHOD(MethodTree.class),
187 
188         /**
189          * Used for instances of {@link MethodInvocationTree}.
190          */
191         METHOD_INVOCATION(MethodInvocationTree.class),
192 
193         /**
194          * Used for instances of {@link ModifiersTree}.
195          */
196         MODIFIERS(ModifiersTree.class),
197 
198         /**
199          * Used for instances of {@link NewArrayTree}.
200          */
201         NEW_ARRAY(NewArrayTree.class),
202 
203         /**
204          * Used for instances of {@link NewClassTree}.
205          */
206         NEW_CLASS(NewClassTree.class),
207 
208         /**
209          * Used for instances of {@link LambdaExpressionTree}.
210          */
211         LAMBDA_EXPRESSION(LambdaExpressionTree.class),
212 
213         /**
214          * Used for instances of {@link PackageTree}.
215          * @since 9
216          */
217         PACKAGE(PackageTree.class),
218 
219         /**
220          * Used for instances of {@link ParenthesizedTree}.
221          */
222         PARENTHESIZED(ParenthesizedTree.class),
223 
224         /**
225          * Used for instances of {@link BindingPatternTree}.
226          *
227          * @since 16
228          */
229         BINDING_PATTERN(BindingPatternTree.class),
230 
231         /**
232          * Used for instances of {@link GuardedPatternTree}.
233          *
234          * @since 17
235          */
236         @PreviewFeature(feature=PreviewFeature.Feature.SWITCH_PATTERN_MATCHING, reflective=true)
237         GUARDED_PATTERN(GuardedPatternTree.class),
238 
239         /**
240          * Used for instances of {@link ParenthesizedPatternTree}.
241          *
242          * @since 17
243          */
244         @PreviewFeature(feature=PreviewFeature.Feature.SWITCH_PATTERN_MATCHING, reflective=true)
245         PARENTHESIZED_PATTERN(ParenthesizedPatternTree.class),
246 
247         /**
248          * Used for instances of {@link DefaultCaseLabelTree}.
249          *
250          * @since 17
251          */
252         @PreviewFeature(feature=PreviewFeature.Feature.SWITCH_PATTERN_MATCHING, reflective=true)
253         DEFAULT_CASE_LABEL(DefaultCaseLabelTree.class),
254 
255         /**
256          * Used for instances of {@link PrimitiveTypeTree}.
257          */
258         PRIMITIVE_TYPE(PrimitiveTypeTree.class),
259 
260         /**
261          * Used for instances of {@link ReturnTree}.
262          */
263         RETURN(ReturnTree.class),
264 
265         /**
266          * Used for instances of {@link EmptyStatementTree}.
267          */
268         EMPTY_STATEMENT(EmptyStatementTree.class),
269 
270         /**
271          * Used for instances of {@link SwitchTree}.
272          */
273         SWITCH(SwitchTree.class),
274 
275         /**
276          * Used for instances of {@link SwitchExpressionTree}.
277          *
278          * @since 12
279          */
280         SWITCH_EXPRESSION(SwitchExpressionTree.class),
281 







282         /**
283          * Used for instances of {@link SynchronizedTree}.
284          */
285         SYNCHRONIZED(SynchronizedTree.class),
286 
287         /**
288          * Used for instances of {@link ThrowTree}.
289          */
290         THROW(ThrowTree.class),
291 
292         /**
293          * Used for instances of {@link TryTree}.
294          */
295         TRY(TryTree.class),
296 
297         /**
298          * Used for instances of {@link ParameterizedTypeTree}.
299          */
300         PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
301 
302         /**
303          * Used for instances of {@link UnionTypeTree}.
304          */
305         UNION_TYPE(UnionTypeTree.class),
306 
307         /**
308          * Used for instances of {@link IntersectionTypeTree}.
309          */
310         INTERSECTION_TYPE(IntersectionTypeTree.class),
311 
312         /**
313          * Used for instances of {@link TypeCastTree}.
314          */
315         TYPE_CAST(TypeCastTree.class),
316 
317         /**
318          * Used for instances of {@link TypeParameterTree}.
319          */
320         TYPE_PARAMETER(TypeParameterTree.class),
321 
322         /**
323          * Used for instances of {@link VariableTree}.
324          */
325         VARIABLE(VariableTree.class),
326 
327         /**
328          * Used for instances of {@link WhileLoopTree}.
329          */
330         WHILE_LOOP(WhileLoopTree.class),
331 





332         /**
333          * Used for instances of {@link UnaryTree} representing postfix
334          * increment operator {@code ++}.
335          */
336         POSTFIX_INCREMENT(UnaryTree.class),
337 
338         /**
339          * Used for instances of {@link UnaryTree} representing postfix
340          * decrement operator {@code --}.
341          */
342         POSTFIX_DECREMENT(UnaryTree.class),
343 
344         /**
345          * Used for instances of {@link UnaryTree} representing prefix
346          * increment operator {@code ++}.
347          */
348         PREFIX_INCREMENT(UnaryTree.class),
349 
350         /**
351          * Used for instances of {@link UnaryTree} representing prefix
352          * decrement operator {@code --}.
353          */
354         PREFIX_DECREMENT(UnaryTree.class),
355 
356         /**
357          * Used for instances of {@link UnaryTree} representing unary plus
358          * operator {@code +}.
359          */
360         UNARY_PLUS(UnaryTree.class),
361 
362         /**
363          * Used for instances of {@link UnaryTree} representing unary minus
364          * operator {@code -}.
365          */
366         UNARY_MINUS(UnaryTree.class),
367 
368         /**
369          * Used for instances of {@link UnaryTree} representing bitwise
370          * complement operator {@code ~}.
371          */
372         BITWISE_COMPLEMENT(UnaryTree.class),
373 
374         /**
375          * Used for instances of {@link UnaryTree} representing logical
376          * complement operator {@code !}.
377          */
378         LOGICAL_COMPLEMENT(UnaryTree.class),
379 
380         /**
381          * Used for instances of {@link BinaryTree} representing
382          * multiplication {@code *}.
383          */
384         MULTIPLY(BinaryTree.class),
385 
386         /**
387          * Used for instances of {@link BinaryTree} representing
388          * division {@code /}.
389          */
390         DIVIDE(BinaryTree.class),
391 
392         /**
393          * Used for instances of {@link BinaryTree} representing
394          * remainder {@code %}.
395          */
396         REMAINDER(BinaryTree.class),
397 
398         /**
399          * Used for instances of {@link BinaryTree} representing
400          * addition or string concatenation {@code +}.
401          */
402         PLUS(BinaryTree.class),
403 
404         /**
405          * Used for instances of {@link BinaryTree} representing
406          * subtraction {@code -}.
407          */
408         MINUS(BinaryTree.class),
409 
410         /**
411          * Used for instances of {@link BinaryTree} representing
412          * left shift {@code <<}.
413          */
414         LEFT_SHIFT(BinaryTree.class),
415 
416         /**
417          * Used for instances of {@link BinaryTree} representing
418          * right shift {@code >>}.
419          */
420         RIGHT_SHIFT(BinaryTree.class),
421 
422         /**
423          * Used for instances of {@link BinaryTree} representing
424          * unsigned right shift {@code >>>}.
425          */
426         UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
427 
428         /**
429          * Used for instances of {@link BinaryTree} representing
430          * less-than {@code <}.
431          */
432         LESS_THAN(BinaryTree.class),
433 
434         /**
435          * Used for instances of {@link BinaryTree} representing
436          * greater-than {@code >}.
437          */
438         GREATER_THAN(BinaryTree.class),
439 
440         /**
441          * Used for instances of {@link BinaryTree} representing
442          * less-than-equal {@code <=}.
443          */
444         LESS_THAN_EQUAL(BinaryTree.class),
445 
446         /**
447          * Used for instances of {@link BinaryTree} representing
448          * greater-than-equal {@code >=}.
449          */
450         GREATER_THAN_EQUAL(BinaryTree.class),
451 
452         /**
453          * Used for instances of {@link BinaryTree} representing
454          * equal-to {@code ==}.
455          */
456         EQUAL_TO(BinaryTree.class),
457 
458         /**
459          * Used for instances of {@link BinaryTree} representing
460          * not-equal-to {@code !=}.
461          */
462         NOT_EQUAL_TO(BinaryTree.class),
463 
464         /**
465          * Used for instances of {@link BinaryTree} representing
466          * bitwise and logical "and" {@code &}.
467          */
468         AND(BinaryTree.class),
469 
470         /**
471          * Used for instances of {@link BinaryTree} representing
472          * bitwise and logical "xor" {@code ^}.
473          */
474         XOR(BinaryTree.class),
475 
476         /**
477          * Used for instances of {@link BinaryTree} representing
478          * bitwise and logical "or" {@code |}.
479          */
480         OR(BinaryTree.class),
481 
482         /**
483          * Used for instances of {@link BinaryTree} representing
484          * conditional-and {@code &&}.
485          */
486         CONDITIONAL_AND(BinaryTree.class),
487 
488         /**
489          * Used for instances of {@link BinaryTree} representing
490          * conditional-or {@code ||}.
491          */
492         CONDITIONAL_OR(BinaryTree.class),
493 
494         /**
495          * Used for instances of {@link CompoundAssignmentTree} representing
496          * multiplication assignment {@code *=}.
497          */
498         MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
499 
500         /**
501          * Used for instances of {@link CompoundAssignmentTree} representing
502          * division assignment {@code /=}.
503          */
504         DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
505 
506         /**
507          * Used for instances of {@link CompoundAssignmentTree} representing
508          * remainder assignment {@code %=}.
509          */
510         REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
511 
512         /**
513          * Used for instances of {@link CompoundAssignmentTree} representing
514          * addition or string concatenation assignment {@code +=}.
515          */
516         PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
517 
518         /**
519          * Used for instances of {@link CompoundAssignmentTree} representing
520          * subtraction assignment {@code -=}.
521          */
522         MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
523 
524         /**
525          * Used for instances of {@link CompoundAssignmentTree} representing
526          * left shift assignment {@code <<=}.
527          */
528         LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
529 
530         /**
531          * Used for instances of {@link CompoundAssignmentTree} representing
532          * right shift assignment {@code >>=}.
533          */
534         RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
535 
536         /**
537          * Used for instances of {@link CompoundAssignmentTree} representing
538          * unsigned right shift assignment {@code >>>=}.
539          */
540         UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
541 
542         /**
543          * Used for instances of {@link CompoundAssignmentTree} representing
544          * bitwise and logical "and" assignment {@code &=}.
545          */
546         AND_ASSIGNMENT(CompoundAssignmentTree.class),
547 
548         /**
549          * Used for instances of {@link CompoundAssignmentTree} representing
550          * bitwise and logical "xor" assignment {@code ^=}.
551          */
552         XOR_ASSIGNMENT(CompoundAssignmentTree.class),
553 
554         /**
555          * Used for instances of {@link CompoundAssignmentTree} representing
556          * bitwise and logical "or" assignment {@code |=}.
557          */
558         OR_ASSIGNMENT(CompoundAssignmentTree.class),
559 
560         /**
561          * Used for instances of {@link LiteralTree} representing
562          * an integral literal expression of type {@code int}.
563          */
564         INT_LITERAL(LiteralTree.class),
565 
566         /**
567          * Used for instances of {@link LiteralTree} representing
568          * an integral literal expression of type {@code long}.
569          */
570         LONG_LITERAL(LiteralTree.class),
571 
572         /**
573          * Used for instances of {@link LiteralTree} representing
574          * a floating-point literal expression of type {@code float}.
575          */
576         FLOAT_LITERAL(LiteralTree.class),
577 
578         /**
579          * Used for instances of {@link LiteralTree} representing
580          * a floating-point literal expression of type {@code double}.
581          */
582         DOUBLE_LITERAL(LiteralTree.class),
583 
584         /**
585          * Used for instances of {@link LiteralTree} representing
586          * a boolean literal expression of type {@code boolean}.
587          */
588         BOOLEAN_LITERAL(LiteralTree.class),
589 
590         /**
591          * Used for instances of {@link LiteralTree} representing
592          * a character literal expression of type {@code char}.
593          */
594         CHAR_LITERAL(LiteralTree.class),
595 
596         /**
597          * Used for instances of {@link LiteralTree} representing
598          * a string literal expression of type {@link String}.
599          */
600         STRING_LITERAL(LiteralTree.class),
601 
602         /**
603          * Used for instances of {@link LiteralTree} representing
604          * the use of {@code null}.
605          */
606         NULL_LITERAL(LiteralTree.class),
607 
608         /**
609          * Used for instances of {@link WildcardTree} representing
610          * an unbounded wildcard type argument.
611          */
612         UNBOUNDED_WILDCARD(WildcardTree.class),
613 
614         /**
615          * Used for instances of {@link WildcardTree} representing
616          * an extends bounded wildcard type argument.
617          */
618         EXTENDS_WILDCARD(WildcardTree.class),
619 
620         /**
621          * Used for instances of {@link WildcardTree} representing
622          * a super bounded wildcard type argument.
623          */
624         SUPER_WILDCARD(WildcardTree.class),
625 
626         /**
627          * Used for instances of {@link ErroneousTree}.
628          */
629         ERRONEOUS(ErroneousTree.class),
630 
631         /**
632          * Used for instances of {@link ClassTree} representing interfaces.
633          */
634         INTERFACE(ClassTree.class),
635 
636         /**
637          * Used for instances of {@link ClassTree} representing enums.
638          */
639         ENUM(ClassTree.class),
640 
641         /**
642          * Used for instances of {@link ClassTree} representing annotation types.
643          */
644         ANNOTATION_TYPE(ClassTree.class),
645 
646         /**
647          * Used for instances of {@link ModuleTree} representing module declarations.
648          */
649         MODULE(ModuleTree.class),
650 
651         /**
652          * Used for instances of {@link ExportsTree} representing
653          * exports directives in a module declaration.
654          */
655         EXPORTS(ExportsTree.class),
656 
657         /**
658          * Used for instances of {@link ExportsTree} representing
659          * opens directives in a module declaration.
660          */
661         OPENS(OpensTree.class),
662 
663         /**
664          * Used for instances of {@link ProvidesTree} representing
665          * provides directives in a module declaration.
666          */
667         PROVIDES(ProvidesTree.class),
668 
669         /**
670          * Used for instances of {@link ClassTree} representing records.
671          * @since 16
672          */
673         RECORD(ClassTree.class),
674 
675         /**
676          * Used for instances of {@link RequiresTree} representing
677          * requires directives in a module declaration.
678          */
679         REQUIRES(RequiresTree.class),
680 
681         /**
682          * Used for instances of {@link UsesTree} representing
683          * uses directives in a module declaration.
684          */
685         USES(UsesTree.class),
686 
687         /**
688          * An implementation-reserved node. This is not the node
689          * you are looking for.
690          */
691         OTHER(null),
692 
693         /**
694          * Used for instances of {@link YieldTree}.
695          *
696          * @since 13
697          */
698         YIELD(YieldTree.class);
699 
700 
701         Kind(Class<? extends Tree> intf) {
702             associatedInterface = intf;
703         }
704 
705         /**
706          * Returns the associated interface type that uses this kind.
707          * @return the associated interface
708          */
709         public Class<? extends Tree> asInterface() {
710             return associatedInterface;
711         }
712 
713         private final Class<? extends Tree> associatedInterface;
714     }
715 
716     /**
717      * Returns the kind of this tree.
718      *
719      * @return the kind of this tree
720      */
721     Kind getKind();
722 
723     /**
724      * Accept method used to implement the visitor pattern.  The
725      * visitor pattern is used to implement operations on trees.
726      *
727      * @param <R> the result type of this operation
728      * @param <D> the type of additional data
729      * @param visitor the visitor to be called
730      * @param data a value to be passed to the visitor
731      * @return the result returned from calling the visitor
732      */
733     <R,D> R accept(TreeVisitor<R,D> visitor, D data);
734 }
--- EOF ---