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