001 /*
002 * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package com.sun.source.tree;
027
028 /**
029 * Common interface for all nodes in an abstract syntax tree.
030 *
031 * <p><b>WARNING:</b> This interface and its sub-interfaces are
032 * subject to change as the Java™ programming language evolves.
033 * These interfaces are implemented by Sun's Java compiler (javac)
034 * and should not be implemented either directly or indirectly by
035 * other applications.
036 *
037 * @author Peter von der Ahé
038 * @author Jonathan Gibbons
039 *
040 * @since 1.6
041 */
042 public interface Tree {
043
044 /**
045 * Enumerates all kinds of trees.
046 */
047 public enum Kind {
048 /**
049 * Used for instances of {@link AnnotationTree}.
050 */
051 ANNOTATION(AnnotationTree.class),
052
053 /**
054 * Used for instances of {@link ArrayAccessTree}.
055 */
056 ARRAY_ACCESS(ArrayAccessTree.class),
057
058 /**
059 * Used for instances of {@link ArrayTypeTree}.
060 */
061 ARRAY_TYPE(ArrayTypeTree.class),
062
063 /**
064 * Used for instances of {@link AssertTree}.
065 */
066 ASSERT(AssertTree.class),
067
068 /**
069 * Used for instances of {@link AssignmentTree}.
070 */
071 ASSIGNMENT(AssignmentTree.class),
072
073 /**
074 * Used for instances of {@link BlockTree}.
075 */
076 BLOCK(BlockTree.class),
077
078 /**
079 * Used for instances of {@link BreakTree}.
080 */
081 BREAK(BreakTree.class),
082
083 /**
084 * Used for instances of {@link CaseTree}.
085 */
086 CASE(CaseTree.class),
087
088 /**
089 * Used for instances of {@link CatchTree}.
090 */
091 CATCH(CatchTree.class),
092
093 /**
094 * Used for instances of {@link ClassTree}.
095 */
096 CLASS(ClassTree.class),
097
098 /**
099 * Used for instances of {@link CompilationUnitTree}.
100 */
101 COMPILATION_UNIT(CompilationUnitTree.class),
102
103 /**
104 * Used for instances of {@link ConditionalExpressionTree}.
105 */
106 CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class),
107
108 /**
109 * Used for instances of {@link ContinueTree}.
110 */
111 CONTINUE(ContinueTree.class),
112
113 /**
114 * Used for instances of {@link DoWhileLoopTree}.
115 */
116 DO_WHILE_LOOP(DoWhileLoopTree.class),
117
118 /**
119 * Used for instances of {@link EnhancedForLoopTree}.
120 */
121 ENHANCED_FOR_LOOP(EnhancedForLoopTree.class),
122
123 /**
124 * Used for instances of {@link ExpressionStatementTree}.
125 */
126 EXPRESSION_STATEMENT(ExpressionStatementTree.class),
127
128 /**
129 * Used for instances of {@link MemberSelectTree}.
130 */
131 MEMBER_SELECT(MemberSelectTree.class),
132
133 /**
134 * Used for instances of {@link ForLoopTree}.
135 */
136 FOR_LOOP(ForLoopTree.class),
137
138 /**
139 * Used for instances of {@link IdentifierTree}.
140 */
141 IDENTIFIER(IdentifierTree.class),
142
143 /**
144 * Used for instances of {@link IfTree}.
145 */
146 IF(IfTree.class),
147
148 /**
149 * Used for instances of {@link ImportTree}.
150 */
151 IMPORT(ImportTree.class),
152
153 /**
154 * Used for instances of {@link InstanceOfTree}.
155 */
156 INSTANCE_OF(InstanceOfTree.class),
157
158 /**
159 * Used for instances of {@link LabeledStatementTree}.
160 */
161 LABELED_STATEMENT(LabeledStatementTree.class),
162
163 /**
164 * Used for instances of {@link MethodTree}.
165 */
166 METHOD(MethodTree.class),
167
168 /**
169 * Used for instances of {@link MethodInvocationTree}.
170 */
171 METHOD_INVOCATION(MethodInvocationTree.class),
172
173 /**
174 * Used for instances of {@link ModifiersTree}.
175 */
176 MODIFIERS(ModifiersTree.class),
177
178 /**
179 * Used for instances of {@link NewArrayTree}.
180 */
181 NEW_ARRAY(NewArrayTree.class),
182
183 /**
184 * Used for instances of {@link NewClassTree}.
185 */
186 NEW_CLASS(NewClassTree.class),
187
188 /**
189 * Used for instances of {@link ParenthesizedTree}.
190 */
191 PARENTHESIZED(ParenthesizedTree.class),
192
193 /**
194 * Used for instances of {@link PrimitiveTypeTree}.
195 */
196 PRIMITIVE_TYPE(PrimitiveTypeTree.class),
197
198 /**
199 * Used for instances of {@link ReturnTree}.
200 */
201 RETURN(ReturnTree.class),
202
203 /**
204 * Used for instances of {@link EmptyStatementTree}.
205 */
206 EMPTY_STATEMENT(EmptyStatementTree.class),
207
208 /**
209 * Used for instances of {@link SwitchTree}.
210 */
211 SWITCH(SwitchTree.class),
212
213 /**
214 * Used for instances of {@link SynchronizedTree}.
215 */
216 SYNCHRONIZED(SynchronizedTree.class),
217
218 /**
219 * Used for instances of {@link ThrowTree}.
220 */
221 THROW(ThrowTree.class),
222
223 /**
224 * Used for instances of {@link TryTree}.
225 */
226 TRY(TryTree.class),
227
228 /**
229 * Used for instances of {@link ParameterizedTypeTree}.
230 */
231 PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
232
233 /**
234 * Used for instances of {@link TypeCastTree}.
235 */
236 TYPE_CAST(TypeCastTree.class),
237
238 /**
239 * Used for instances of {@link TypeParameterTree}.
240 */
241 TYPE_PARAMETER(TypeParameterTree.class),
242
243 /**
244 * Used for instances of {@link VariableTree}.
245 */
246 VARIABLE(VariableTree.class),
247
248 /**
249 * Used for instances of {@link WhileLoopTree}.
250 */
251 WHILE_LOOP(WhileLoopTree.class),
252
253 /**
254 * Used for instances of {@link UnaryTree} representing postfix
255 * increment operator {@code ++}.
256 */
257 POSTFIX_INCREMENT(UnaryTree.class),
258
259 /**
260 * Used for instances of {@link UnaryTree} representing postfix
261 * decrement operator {@code --}.
262 */
263 POSTFIX_DECREMENT(UnaryTree.class),
264
265 /**
266 * Used for instances of {@link UnaryTree} representing prefix
267 * increment operator {@code ++}.
268 */
269 PREFIX_INCREMENT(UnaryTree.class),
270
271 /**
272 * Used for instances of {@link UnaryTree} representing prefix
273 * decrement operator {@code --}.
274 */
275 PREFIX_DECREMENT(UnaryTree.class),
276
277 /**
278 * Used for instances of {@link UnaryTree} representing unary plus
279 * operator {@code +}.
280 */
281 UNARY_PLUS(UnaryTree.class),
282
283 /**
284 * Used for instances of {@link UnaryTree} representing unary minus
285 * operator {@code -}.
286 */
287 UNARY_MINUS(UnaryTree.class),
288
289 /**
290 * Used for instances of {@link UnaryTree} representing bitwise
291 * complement operator {@code ~}.
292 */
293 BITWISE_COMPLEMENT(UnaryTree.class),
294
295 /**
296 * Used for instances of {@link UnaryTree} representing logical
297 * complement operator {@code !}.
298 */
299 LOGICAL_COMPLEMENT(UnaryTree.class),
300
301 /**
302 * Used for instances of {@link BinaryTree} representing
303 * multiplication {@code *}.
304 */
305 MULTIPLY(BinaryTree.class),
306
307 /**
308 * Used for instances of {@link BinaryTree} representing
309 * division {@code /}.
310 */
311 DIVIDE(BinaryTree.class),
312
313 /**
314 * Used for instances of {@link BinaryTree} representing
315 * remainder {@code %}.
316 */
317 REMAINDER(BinaryTree.class),
318
319 /**
320 * Used for instances of {@link BinaryTree} representing
321 * addition or string concatenation {@code +}.
322 */
323 PLUS(BinaryTree.class),
324
325 /**
326 * Used for instances of {@link BinaryTree} representing
327 * subtraction {@code -}.
328 */
329 MINUS(BinaryTree.class),
330
331 /**
332 * Used for instances of {@link BinaryTree} representing
333 * left shift {@code <<}.
334 */
335 LEFT_SHIFT(BinaryTree.class),
336
337 /**
338 * Used for instances of {@link BinaryTree} representing
339 * right shift {@code >>}.
340 */
341 RIGHT_SHIFT(BinaryTree.class),
342
343 /**
344 * Used for instances of {@link BinaryTree} representing
345 * unsigned right shift {@code >>>}.
346 */
347 UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
348
349 /**
350 * Used for instances of {@link BinaryTree} representing
351 * less-than {@code <}.
352 */
353 LESS_THAN(BinaryTree.class),
354
355 /**
356 * Used for instances of {@link BinaryTree} representing
357 * greater-than {@code >}.
358 */
359 GREATER_THAN(BinaryTree.class),
360
361 /**
362 * Used for instances of {@link BinaryTree} representing
363 * less-than-equal {@code <=}.
364 */
365 LESS_THAN_EQUAL(BinaryTree.class),
366
367 /**
368 * Used for instances of {@link BinaryTree} representing
369 * greater-than-equal {@code >=}.
370 */
371 GREATER_THAN_EQUAL(BinaryTree.class),
372
373 /**
374 * Used for instances of {@link BinaryTree} representing
375 * equal-to {@code ==}.
376 */
377 EQUAL_TO(BinaryTree.class),
378
379 /**
380 * Used for instances of {@link BinaryTree} representing
381 * not-equal-to {@code !=}.
382 */
383 NOT_EQUAL_TO(BinaryTree.class),
384
385 /**
386 * Used for instances of {@link BinaryTree} representing
387 * bitwise and logical "and" {@code &}.
388 */
389 AND(BinaryTree.class),
390
391 /**
392 * Used for instances of {@link BinaryTree} representing
393 * bitwise and logical "xor" {@code ^}.
394 */
395 XOR(BinaryTree.class),
396
397 /**
398 * Used for instances of {@link BinaryTree} representing
399 * bitwise and logical "or" {@code |}.
400 */
401 OR(BinaryTree.class),
402
403 /**
404 * Used for instances of {@link BinaryTree} representing
405 * conditional-and {@code &&}.
406 */
407 CONDITIONAL_AND(BinaryTree.class),
408
409 /**
410 * Used for instances of {@link BinaryTree} representing
411 * conditional-or {@code ||}.
412 */
413 CONDITIONAL_OR(BinaryTree.class),
414
415 /**
416 * Used for instances of {@link CompoundAssignmentTree} representing
417 * multiplication assignment {@code *=}.
418 */
419 MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
420
421 /**
422 * Used for instances of {@link CompoundAssignmentTree} representing
423 * division assignment {@code /=}.
424 */
425 DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
426
427 /**
428 * Used for instances of {@link CompoundAssignmentTree} representing
429 * remainder assignment {@code %=}.
430 */
431 REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
432
433 /**
434 * Used for instances of {@link CompoundAssignmentTree} representing
435 * addition or string concatenation assignment {@code +=}.
436 */
437 PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
438
439 /**
440 * Used for instances of {@link CompoundAssignmentTree} representing
441 * subtraction assignment {@code -=}.
442 */
443 MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
444
445 /**
446 * Used for instances of {@link CompoundAssignmentTree} representing
447 * left shift assignment {@code <<=}.
448 */
449 LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
450
451 /**
452 * Used for instances of {@link CompoundAssignmentTree} representing
453 * right shift assignment {@code >>=}.
454 */
455 RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
456
457 /**
458 * Used for instances of {@link CompoundAssignmentTree} representing
459 * unsigned right shift assignment {@code >>>=}.
460 */
461 UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
462
463 /**
464 * Used for instances of {@link CompoundAssignmentTree} representing
465 * bitwise and logical "and" assignment {@code &=}.
466 */
467 AND_ASSIGNMENT(CompoundAssignmentTree.class),
468
469 /**
470 * Used for instances of {@link CompoundAssignmentTree} representing
471 * bitwise and logical "xor" assignment {@code ^=}.
472 */
473 XOR_ASSIGNMENT(CompoundAssignmentTree.class),
474
475 /**
476 * Used for instances of {@link CompoundAssignmentTree} representing
477 * bitwise and logical "or" assignment {@code |=}.
478 */
479 OR_ASSIGNMENT(CompoundAssignmentTree.class),
480
481 /**
482 * Used for instances of {@link LiteralTree} representing
483 * an integral literal expression of type {@code int}.
484 */
485 INT_LITERAL(LiteralTree.class),
486
487 /**
488 * Used for instances of {@link LiteralTree} representing
489 * an integral literal expression of type {@code long}.
490 */
491 LONG_LITERAL(LiteralTree.class),
492
493 /**
494 * Used for instances of {@link LiteralTree} representing
495 * a floating-point literal expression of type {@code float}.
496 */
497 FLOAT_LITERAL(LiteralTree.class),
498
499 /**
500 * Used for instances of {@link LiteralTree} representing
501 * a floating-point literal expression of type {@code double}.
502 */
503 DOUBLE_LITERAL(LiteralTree.class),
504
505 /**
506 * Used for instances of {@link LiteralTree} representing
507 * a boolean literal expression of type {@code boolean}.
508 */
509 BOOLEAN_LITERAL(LiteralTree.class),
510
511 /**
512 * Used for instances of {@link LiteralTree} representing
513 * a character literal expression of type {@code char}.
514 */
515 CHAR_LITERAL(LiteralTree.class),
516
517 /**
518 * Used for instances of {@link LiteralTree} representing
519 * a string literal expression of type {@link String}.
520 */
521 STRING_LITERAL(LiteralTree.class),
522
523 /**
524 * Used for instances of {@link LiteralTree} representing
525 * the use of {@code null}.
526 */
527 NULL_LITERAL(LiteralTree.class),
528
529 /**
530 * Used for instances of {@link WildcardTree} representing
531 * an unbounded wildcard type argument.
532 */
533 UNBOUNDED_WILDCARD(WildcardTree.class),
534
535 /**
536 * Used for instances of {@link WildcardTree} representing
537 * an extends bounded wildcard type argument.
538 */
539 EXTENDS_WILDCARD(WildcardTree.class),
540
541 /**
542 * Used for instances of {@link WildcardTree} representing
543 * a super bounded wildcard type argument.
544 */
545 SUPER_WILDCARD(WildcardTree.class),
546
547 /**
548 * Used for instances of {@link ErroneousTree}.
549 */
550 ERRONEOUS(ErroneousTree.class),
551
552 /**
553 * An implementation-reserved node. This is the not the node
554 * you are looking for.
555 */
556 OTHER(null);
557
558
559 Kind(Class<? extends Tree> intf) {
560 associatedInterface = intf;
561 }
562
563 public Class<? extends Tree> asInterface() {
564 return associatedInterface;
565 }
566
567 private final Class<? extends Tree> associatedInterface;
568 }
569
570 /**
571 * Gets the kind of this tree.
572 *
573 * @return the kind of this tree.
574 */
575 Kind getKind();
576
577 /**
578 * Accept method used to implement the visitor pattern. The
579 * visitor pattern is used to implement operations on trees.
580 *
581 * @param <R> result type of this operation.
582 * @param <D> type of additonal data.
583 */
584 <R,D> R accept(TreeVisitor<R,D> visitor, D data);
585 }