Tree.java revision 3189:70ac078df098
166458Sdfr/*
296318Sobrien * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
366458Sdfr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
466458Sdfr *
566458Sdfr * This code is free software; you can redistribute it and/or modify it
666458Sdfr * under the terms of the GNU General Public License version 2 only, as
766458Sdfr * published by the Free Software Foundation.  Oracle designates this
866458Sdfr * particular file as subject to the "Classpath" exception as provided
966458Sdfr * by Oracle in the LICENSE file that accompanied this code.
1066458Sdfr *
1166458Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT
1266458Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1366458Sdfr * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1466458Sdfr * version 2 for more details (a copy is included in the LICENSE file that
1566458Sdfr * accompanied this code).
1666458Sdfr *
1766458Sdfr * You should have received a copy of the GNU General Public License version
1866458Sdfr * 2 along with this work; if not, write to the Free Software Foundation,
1966458Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2066458Sdfr *
2166458Sdfr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2266458Sdfr * or visit www.oracle.com if you need additional information or have any
2366458Sdfr * questions.
2466458Sdfr */
2566458Sdfr
2666458Sdfrpackage com.sun.source.tree;
2766458Sdfr
2866458Sdfr/**
2966458Sdfr * Common interface for all nodes in an abstract syntax tree.
3066458Sdfr *
3166458Sdfr * <p><b>WARNING:</b> This interface and its sub-interfaces are
3266458Sdfr * subject to change as the Java&trade; programming language evolves.
3366458Sdfr * These interfaces are implemented by the JDK Java compiler (javac)
3466458Sdfr * and should not be implemented either directly or indirectly by
3566458Sdfr * other applications.
3666458Sdfr *
3766458Sdfr * @author Peter von der Ah&eacute;
3866458Sdfr * @author Jonathan Gibbons
3966458Sdfr *
4096318Sobrien * @since 1.6
4166458Sdfr */
4266458Sdfr@jdk.Exported
4366458Sdfrpublic interface Tree {
4466458Sdfr
4566458Sdfr    /**
46120540Smarcel     * Enumerates all kinds of trees.
4766458Sdfr     */
4866458Sdfr    @jdk.Exported
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 PrimitiveTypeTree}.
226         */
227        PRIMITIVE_TYPE(PrimitiveTypeTree.class),
228
229        /**
230         * Used for instances of {@link ReturnTree}.
231         */
232        RETURN(ReturnTree.class),
233
234        /**
235         * Used for instances of {@link EmptyStatementTree}.
236         */
237        EMPTY_STATEMENT(EmptyStatementTree.class),
238
239        /**
240         * Used for instances of {@link SwitchTree}.
241         */
242        SWITCH(SwitchTree.class),
243
244        /**
245         * Used for instances of {@link SynchronizedTree}.
246         */
247        SYNCHRONIZED(SynchronizedTree.class),
248
249        /**
250         * Used for instances of {@link ThrowTree}.
251         */
252        THROW(ThrowTree.class),
253
254        /**
255         * Used for instances of {@link TryTree}.
256         */
257        TRY(TryTree.class),
258
259        /**
260         * Used for instances of {@link ParameterizedTypeTree}.
261         */
262        PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
263
264        /**
265         * Used for instances of {@link UnionTypeTree}.
266         */
267        UNION_TYPE(UnionTypeTree.class),
268
269        /**
270         * Used for instances of {@link IntersectionTypeTree}.
271         */
272        INTERSECTION_TYPE(IntersectionTypeTree.class),
273
274        /**
275         * Used for instances of {@link TypeCastTree}.
276         */
277        TYPE_CAST(TypeCastTree.class),
278
279        /**
280         * Used for instances of {@link TypeParameterTree}.
281         */
282        TYPE_PARAMETER(TypeParameterTree.class),
283
284        /**
285         * Used for instances of {@link VariableTree}.
286         */
287        VARIABLE(VariableTree.class),
288
289        /**
290         * Used for instances of {@link WhileLoopTree}.
291         */
292        WHILE_LOOP(WhileLoopTree.class),
293
294        /**
295         * Used for instances of {@link UnaryTree} representing postfix
296         * increment operator {@code ++}.
297         */
298        POSTFIX_INCREMENT(UnaryTree.class),
299
300        /**
301         * Used for instances of {@link UnaryTree} representing postfix
302         * decrement operator {@code --}.
303         */
304        POSTFIX_DECREMENT(UnaryTree.class),
305
306        /**
307         * Used for instances of {@link UnaryTree} representing prefix
308         * increment operator {@code ++}.
309         */
310        PREFIX_INCREMENT(UnaryTree.class),
311
312        /**
313         * Used for instances of {@link UnaryTree} representing prefix
314         * decrement operator {@code --}.
315         */
316        PREFIX_DECREMENT(UnaryTree.class),
317
318        /**
319         * Used for instances of {@link UnaryTree} representing unary plus
320         * operator {@code +}.
321         */
322        UNARY_PLUS(UnaryTree.class),
323
324        /**
325         * Used for instances of {@link UnaryTree} representing unary minus
326         * operator {@code -}.
327         */
328        UNARY_MINUS(UnaryTree.class),
329
330        /**
331         * Used for instances of {@link UnaryTree} representing bitwise
332         * complement operator {@code ~}.
333         */
334        BITWISE_COMPLEMENT(UnaryTree.class),
335
336        /**
337         * Used for instances of {@link UnaryTree} representing logical
338         * complement operator {@code !}.
339         */
340        LOGICAL_COMPLEMENT(UnaryTree.class),
341
342        /**
343         * Used for instances of {@link BinaryTree} representing
344         * multiplication {@code *}.
345         */
346        MULTIPLY(BinaryTree.class),
347
348        /**
349         * Used for instances of {@link BinaryTree} representing
350         * division {@code /}.
351         */
352        DIVIDE(BinaryTree.class),
353
354        /**
355         * Used for instances of {@link BinaryTree} representing
356         * remainder {@code %}.
357         */
358        REMAINDER(BinaryTree.class),
359
360        /**
361         * Used for instances of {@link BinaryTree} representing
362         * addition or string concatenation {@code +}.
363         */
364        PLUS(BinaryTree.class),
365
366        /**
367         * Used for instances of {@link BinaryTree} representing
368         * subtraction {@code -}.
369         */
370        MINUS(BinaryTree.class),
371
372        /**
373         * Used for instances of {@link BinaryTree} representing
374         * left shift {@code <<}.
375         */
376        LEFT_SHIFT(BinaryTree.class),
377
378        /**
379         * Used for instances of {@link BinaryTree} representing
380         * right shift {@code >>}.
381         */
382        RIGHT_SHIFT(BinaryTree.class),
383
384        /**
385         * Used for instances of {@link BinaryTree} representing
386         * unsigned right shift {@code >>>}.
387         */
388        UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
389
390        /**
391         * Used for instances of {@link BinaryTree} representing
392         * less-than {@code <}.
393         */
394        LESS_THAN(BinaryTree.class),
395
396        /**
397         * Used for instances of {@link BinaryTree} representing
398         * greater-than {@code >}.
399         */
400        GREATER_THAN(BinaryTree.class),
401
402        /**
403         * Used for instances of {@link BinaryTree} representing
404         * less-than-equal {@code <=}.
405         */
406        LESS_THAN_EQUAL(BinaryTree.class),
407
408        /**
409         * Used for instances of {@link BinaryTree} representing
410         * greater-than-equal {@code >=}.
411         */
412        GREATER_THAN_EQUAL(BinaryTree.class),
413
414        /**
415         * Used for instances of {@link BinaryTree} representing
416         * equal-to {@code ==}.
417         */
418        EQUAL_TO(BinaryTree.class),
419
420        /**
421         * Used for instances of {@link BinaryTree} representing
422         * not-equal-to {@code !=}.
423         */
424        NOT_EQUAL_TO(BinaryTree.class),
425
426        /**
427         * Used for instances of {@link BinaryTree} representing
428         * bitwise and logical "and" {@code &}.
429         */
430        AND(BinaryTree.class),
431
432        /**
433         * Used for instances of {@link BinaryTree} representing
434         * bitwise and logical "xor" {@code ^}.
435         */
436        XOR(BinaryTree.class),
437
438        /**
439         * Used for instances of {@link BinaryTree} representing
440         * bitwise and logical "or" {@code |}.
441         */
442        OR(BinaryTree.class),
443
444        /**
445         * Used for instances of {@link BinaryTree} representing
446         * conditional-and {@code &&}.
447         */
448        CONDITIONAL_AND(BinaryTree.class),
449
450        /**
451         * Used for instances of {@link BinaryTree} representing
452         * conditional-or {@code ||}.
453         */
454        CONDITIONAL_OR(BinaryTree.class),
455
456        /**
457         * Used for instances of {@link CompoundAssignmentTree} representing
458         * multiplication assignment {@code *=}.
459         */
460        MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
461
462        /**
463         * Used for instances of {@link CompoundAssignmentTree} representing
464         * division assignment {@code /=}.
465         */
466        DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
467
468        /**
469         * Used for instances of {@link CompoundAssignmentTree} representing
470         * remainder assignment {@code %=}.
471         */
472        REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
473
474        /**
475         * Used for instances of {@link CompoundAssignmentTree} representing
476         * addition or string concatenation assignment {@code +=}.
477         */
478        PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
479
480        /**
481         * Used for instances of {@link CompoundAssignmentTree} representing
482         * subtraction assignment {@code -=}.
483         */
484        MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
485
486        /**
487         * Used for instances of {@link CompoundAssignmentTree} representing
488         * left shift assignment {@code <<=}.
489         */
490        LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
491
492        /**
493         * Used for instances of {@link CompoundAssignmentTree} representing
494         * right shift assignment {@code >>=}.
495         */
496        RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
497
498        /**
499         * Used for instances of {@link CompoundAssignmentTree} representing
500         * unsigned right shift assignment {@code >>>=}.
501         */
502        UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
503
504        /**
505         * Used for instances of {@link CompoundAssignmentTree} representing
506         * bitwise and logical "and" assignment {@code &=}.
507         */
508        AND_ASSIGNMENT(CompoundAssignmentTree.class),
509
510        /**
511         * Used for instances of {@link CompoundAssignmentTree} representing
512         * bitwise and logical "xor" assignment {@code ^=}.
513         */
514        XOR_ASSIGNMENT(CompoundAssignmentTree.class),
515
516        /**
517         * Used for instances of {@link CompoundAssignmentTree} representing
518         * bitwise and logical "or" assignment {@code |=}.
519         */
520        OR_ASSIGNMENT(CompoundAssignmentTree.class),
521
522        /**
523         * Used for instances of {@link LiteralTree} representing
524         * an integral literal expression of type {@code int}.
525         */
526        INT_LITERAL(LiteralTree.class),
527
528        /**
529         * Used for instances of {@link LiteralTree} representing
530         * an integral literal expression of type {@code long}.
531         */
532        LONG_LITERAL(LiteralTree.class),
533
534        /**
535         * Used for instances of {@link LiteralTree} representing
536         * a floating-point literal expression of type {@code float}.
537         */
538        FLOAT_LITERAL(LiteralTree.class),
539
540        /**
541         * Used for instances of {@link LiteralTree} representing
542         * a floating-point literal expression of type {@code double}.
543         */
544        DOUBLE_LITERAL(LiteralTree.class),
545
546        /**
547         * Used for instances of {@link LiteralTree} representing
548         * a boolean literal expression of type {@code boolean}.
549         */
550        BOOLEAN_LITERAL(LiteralTree.class),
551
552        /**
553         * Used for instances of {@link LiteralTree} representing
554         * a character literal expression of type {@code char}.
555         */
556        CHAR_LITERAL(LiteralTree.class),
557
558        /**
559         * Used for instances of {@link LiteralTree} representing
560         * a string literal expression of type {@link String}.
561         */
562        STRING_LITERAL(LiteralTree.class),
563
564        /**
565         * Used for instances of {@link LiteralTree} representing
566         * the use of {@code null}.
567         */
568        NULL_LITERAL(LiteralTree.class),
569
570        /**
571         * Used for instances of {@link WildcardTree} representing
572         * an unbounded wildcard type argument.
573         */
574        UNBOUNDED_WILDCARD(WildcardTree.class),
575
576        /**
577         * Used for instances of {@link WildcardTree} representing
578         * an extends bounded wildcard type argument.
579         */
580        EXTENDS_WILDCARD(WildcardTree.class),
581
582        /**
583         * Used for instances of {@link WildcardTree} representing
584         * a super bounded wildcard type argument.
585         */
586        SUPER_WILDCARD(WildcardTree.class),
587
588        /**
589         * Used for instances of {@link ErroneousTree}.
590         */
591        ERRONEOUS(ErroneousTree.class),
592
593        /**
594         * Used for instances of {@link ClassTree} representing interfaces.
595         */
596        INTERFACE(ClassTree.class),
597
598        /**
599         * Used for instances of {@link ClassTree} representing enums.
600         */
601        ENUM(ClassTree.class),
602
603        /**
604         * Used for instances of {@link ClassTree} representing annotation types.
605         */
606        ANNOTATION_TYPE(ClassTree.class),
607
608        /**
609         * An implementation-reserved node. This is the not the node
610         * you are looking for.
611         */
612        OTHER(null);
613
614
615        Kind(Class<? extends Tree> intf) {
616            associatedInterface = intf;
617        }
618
619        /**
620         * Returns the associated interface type that uses this kind.
621         * @return the associated interface
622         */
623        public Class<? extends Tree> asInterface() {
624            return associatedInterface;
625        }
626
627        private final Class<? extends Tree> associatedInterface;
628    }
629
630    /**
631     * Returns the kind of this tree.
632     *
633     * @return the kind of this tree.
634     */
635    Kind getKind();
636
637    /**
638     * Accept method used to implement the visitor pattern.  The
639     * visitor pattern is used to implement operations on trees.
640     *
641     * @param <R> result type of this operation.
642     * @param <D> type of additional data.
643     * @param visitor the visitor to be called
644     * @param data a value to be passed to the visitor
645     * @return the result returned from calling the visitor
646     */
647    <R,D> R accept(TreeVisitor<R,D> visitor, D data);
648}
649