Thu, 24 Nov 2011 13:36:20 +0000
7115046: Add AST node for lambda expressions
Summary: Add tree nodes for representing lambda expressions and update relevant visitors interfaces
Reviewed-by: jjg
1 /*
2 * Copyright (c) 2005, 2011, 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 */
26 package com.sun.source.tree;
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™ 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é
38 * @author Jonathan Gibbons
39 *
40 * @since 1.6
41 */
42 public interface Tree {
44 /**
45 * Enumerates all kinds of trees.
46 */
47 public enum Kind {
49 /**
50 * Used for instances of {@link AnnotationTree}.
51 */
52 ANNOTATION(AnnotationTree.class),
54 /**
55 * Used for instances of {@link ArrayAccessTree}.
56 */
57 ARRAY_ACCESS(ArrayAccessTree.class),
59 /**
60 * Used for instances of {@link ArrayTypeTree}.
61 */
62 ARRAY_TYPE(ArrayTypeTree.class),
64 /**
65 * Used for instances of {@link AssertTree}.
66 */
67 ASSERT(AssertTree.class),
69 /**
70 * Used for instances of {@link AssignmentTree}.
71 */
72 ASSIGNMENT(AssignmentTree.class),
74 /**
75 * Used for instances of {@link BlockTree}.
76 */
77 BLOCK(BlockTree.class),
79 /**
80 * Used for instances of {@link BreakTree}.
81 */
82 BREAK(BreakTree.class),
84 /**
85 * Used for instances of {@link CaseTree}.
86 */
87 CASE(CaseTree.class),
89 /**
90 * Used for instances of {@link CatchTree}.
91 */
92 CATCH(CatchTree.class),
94 /**
95 * Used for instances of {@link ClassTree} representing classes.
96 */
97 CLASS(ClassTree.class),
99 /**
100 * Used for instances of {@link CompilationUnitTree}.
101 */
102 COMPILATION_UNIT(CompilationUnitTree.class),
104 /**
105 * Used for instances of {@link ConditionalExpressionTree}.
106 */
107 CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class),
109 /**
110 * Used for instances of {@link ContinueTree}.
111 */
112 CONTINUE(ContinueTree.class),
114 /**
115 * Used for instances of {@link DoWhileLoopTree}.
116 */
117 DO_WHILE_LOOP(DoWhileLoopTree.class),
119 /**
120 * Used for instances of {@link EnhancedForLoopTree}.
121 */
122 ENHANCED_FOR_LOOP(EnhancedForLoopTree.class),
124 /**
125 * Used for instances of {@link ExpressionStatementTree}.
126 */
127 EXPRESSION_STATEMENT(ExpressionStatementTree.class),
129 /**
130 * Used for instances of {@link MemberSelectTree}.
131 */
132 MEMBER_SELECT(MemberSelectTree.class),
134 /**
135 * Used for instances of {@link ForLoopTree}.
136 */
137 FOR_LOOP(ForLoopTree.class),
139 /**
140 * Used for instances of {@link IdentifierTree}.
141 */
142 IDENTIFIER(IdentifierTree.class),
144 /**
145 * Used for instances of {@link IfTree}.
146 */
147 IF(IfTree.class),
149 /**
150 * Used for instances of {@link ImportTree}.
151 */
152 IMPORT(ImportTree.class),
154 /**
155 * Used for instances of {@link InstanceOfTree}.
156 */
157 INSTANCE_OF(InstanceOfTree.class),
159 /**
160 * Used for instances of {@link LabeledStatementTree}.
161 */
162 LABELED_STATEMENT(LabeledStatementTree.class),
164 /**
165 * Used for instances of {@link MethodTree}.
166 */
167 METHOD(MethodTree.class),
169 /**
170 * Used for instances of {@link MethodInvocationTree}.
171 */
172 METHOD_INVOCATION(MethodInvocationTree.class),
174 /**
175 * Used for instances of {@link ModifiersTree}.
176 */
177 MODIFIERS(ModifiersTree.class),
179 /**
180 * Used for instances of {@link NewArrayTree}.
181 */
182 NEW_ARRAY(NewArrayTree.class),
184 /**
185 * Used for instances of {@link NewClassTree}.
186 */
187 NEW_CLASS(NewClassTree.class),
189 /**
190 * Used for instances of {@link LambdaExpressionTree}.
191 */
192 LAMBDA_EXPRESSION(LambdaExpressionTree.class),
194 /**
195 * Used for instances of {@link ParenthesizedTree}.
196 */
197 PARENTHESIZED(ParenthesizedTree.class),
199 /**
200 * Used for instances of {@link PrimitiveTypeTree}.
201 */
202 PRIMITIVE_TYPE(PrimitiveTypeTree.class),
204 /**
205 * Used for instances of {@link ReturnTree}.
206 */
207 RETURN(ReturnTree.class),
209 /**
210 * Used for instances of {@link EmptyStatementTree}.
211 */
212 EMPTY_STATEMENT(EmptyStatementTree.class),
214 /**
215 * Used for instances of {@link SwitchTree}.
216 */
217 SWITCH(SwitchTree.class),
219 /**
220 * Used for instances of {@link SynchronizedTree}.
221 */
222 SYNCHRONIZED(SynchronizedTree.class),
224 /**
225 * Used for instances of {@link ThrowTree}.
226 */
227 THROW(ThrowTree.class),
229 /**
230 * Used for instances of {@link TryTree}.
231 */
232 TRY(TryTree.class),
234 /**
235 * Used for instances of {@link ParameterizedTypeTree}.
236 */
237 PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
239 /**
240 * Used for instances of {@link UnionTypeTree}.
241 */
242 UNION_TYPE(UnionTypeTree.class),
244 /**
245 * Used for instances of {@link TypeCastTree}.
246 */
247 TYPE_CAST(TypeCastTree.class),
249 /**
250 * Used for instances of {@link TypeParameterTree}.
251 */
252 TYPE_PARAMETER(TypeParameterTree.class),
254 /**
255 * Used for instances of {@link VariableTree}.
256 */
257 VARIABLE(VariableTree.class),
259 /**
260 * Used for instances of {@link WhileLoopTree}.
261 */
262 WHILE_LOOP(WhileLoopTree.class),
264 /**
265 * Used for instances of {@link UnaryTree} representing postfix
266 * increment operator {@code ++}.
267 */
268 POSTFIX_INCREMENT(UnaryTree.class),
270 /**
271 * Used for instances of {@link UnaryTree} representing postfix
272 * decrement operator {@code --}.
273 */
274 POSTFIX_DECREMENT(UnaryTree.class),
276 /**
277 * Used for instances of {@link UnaryTree} representing prefix
278 * increment operator {@code ++}.
279 */
280 PREFIX_INCREMENT(UnaryTree.class),
282 /**
283 * Used for instances of {@link UnaryTree} representing prefix
284 * decrement operator {@code --}.
285 */
286 PREFIX_DECREMENT(UnaryTree.class),
288 /**
289 * Used for instances of {@link UnaryTree} representing unary plus
290 * operator {@code +}.
291 */
292 UNARY_PLUS(UnaryTree.class),
294 /**
295 * Used for instances of {@link UnaryTree} representing unary minus
296 * operator {@code -}.
297 */
298 UNARY_MINUS(UnaryTree.class),
300 /**
301 * Used for instances of {@link UnaryTree} representing bitwise
302 * complement operator {@code ~}.
303 */
304 BITWISE_COMPLEMENT(UnaryTree.class),
306 /**
307 * Used for instances of {@link UnaryTree} representing logical
308 * complement operator {@code !}.
309 */
310 LOGICAL_COMPLEMENT(UnaryTree.class),
312 /**
313 * Used for instances of {@link BinaryTree} representing
314 * multiplication {@code *}.
315 */
316 MULTIPLY(BinaryTree.class),
318 /**
319 * Used for instances of {@link BinaryTree} representing
320 * division {@code /}.
321 */
322 DIVIDE(BinaryTree.class),
324 /**
325 * Used for instances of {@link BinaryTree} representing
326 * remainder {@code %}.
327 */
328 REMAINDER(BinaryTree.class),
330 /**
331 * Used for instances of {@link BinaryTree} representing
332 * addition or string concatenation {@code +}.
333 */
334 PLUS(BinaryTree.class),
336 /**
337 * Used for instances of {@link BinaryTree} representing
338 * subtraction {@code -}.
339 */
340 MINUS(BinaryTree.class),
342 /**
343 * Used for instances of {@link BinaryTree} representing
344 * left shift {@code <<}.
345 */
346 LEFT_SHIFT(BinaryTree.class),
348 /**
349 * Used for instances of {@link BinaryTree} representing
350 * right shift {@code >>}.
351 */
352 RIGHT_SHIFT(BinaryTree.class),
354 /**
355 * Used for instances of {@link BinaryTree} representing
356 * unsigned right shift {@code >>>}.
357 */
358 UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
360 /**
361 * Used for instances of {@link BinaryTree} representing
362 * less-than {@code <}.
363 */
364 LESS_THAN(BinaryTree.class),
366 /**
367 * Used for instances of {@link BinaryTree} representing
368 * greater-than {@code >}.
369 */
370 GREATER_THAN(BinaryTree.class),
372 /**
373 * Used for instances of {@link BinaryTree} representing
374 * less-than-equal {@code <=}.
375 */
376 LESS_THAN_EQUAL(BinaryTree.class),
378 /**
379 * Used for instances of {@link BinaryTree} representing
380 * greater-than-equal {@code >=}.
381 */
382 GREATER_THAN_EQUAL(BinaryTree.class),
384 /**
385 * Used for instances of {@link BinaryTree} representing
386 * equal-to {@code ==}.
387 */
388 EQUAL_TO(BinaryTree.class),
390 /**
391 * Used for instances of {@link BinaryTree} representing
392 * not-equal-to {@code !=}.
393 */
394 NOT_EQUAL_TO(BinaryTree.class),
396 /**
397 * Used for instances of {@link BinaryTree} representing
398 * bitwise and logical "and" {@code &}.
399 */
400 AND(BinaryTree.class),
402 /**
403 * Used for instances of {@link BinaryTree} representing
404 * bitwise and logical "xor" {@code ^}.
405 */
406 XOR(BinaryTree.class),
408 /**
409 * Used for instances of {@link BinaryTree} representing
410 * bitwise and logical "or" {@code |}.
411 */
412 OR(BinaryTree.class),
414 /**
415 * Used for instances of {@link BinaryTree} representing
416 * conditional-and {@code &&}.
417 */
418 CONDITIONAL_AND(BinaryTree.class),
420 /**
421 * Used for instances of {@link BinaryTree} representing
422 * conditional-or {@code ||}.
423 */
424 CONDITIONAL_OR(BinaryTree.class),
426 /**
427 * Used for instances of {@link CompoundAssignmentTree} representing
428 * multiplication assignment {@code *=}.
429 */
430 MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
432 /**
433 * Used for instances of {@link CompoundAssignmentTree} representing
434 * division assignment {@code /=}.
435 */
436 DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
438 /**
439 * Used for instances of {@link CompoundAssignmentTree} representing
440 * remainder assignment {@code %=}.
441 */
442 REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
444 /**
445 * Used for instances of {@link CompoundAssignmentTree} representing
446 * addition or string concatenation assignment {@code +=}.
447 */
448 PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
450 /**
451 * Used for instances of {@link CompoundAssignmentTree} representing
452 * subtraction assignment {@code -=}.
453 */
454 MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
456 /**
457 * Used for instances of {@link CompoundAssignmentTree} representing
458 * left shift assignment {@code <<=}.
459 */
460 LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
462 /**
463 * Used for instances of {@link CompoundAssignmentTree} representing
464 * right shift assignment {@code >>=}.
465 */
466 RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
468 /**
469 * Used for instances of {@link CompoundAssignmentTree} representing
470 * unsigned right shift assignment {@code >>>=}.
471 */
472 UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
474 /**
475 * Used for instances of {@link CompoundAssignmentTree} representing
476 * bitwise and logical "and" assignment {@code &=}.
477 */
478 AND_ASSIGNMENT(CompoundAssignmentTree.class),
480 /**
481 * Used for instances of {@link CompoundAssignmentTree} representing
482 * bitwise and logical "xor" assignment {@code ^=}.
483 */
484 XOR_ASSIGNMENT(CompoundAssignmentTree.class),
486 /**
487 * Used for instances of {@link CompoundAssignmentTree} representing
488 * bitwise and logical "or" assignment {@code |=}.
489 */
490 OR_ASSIGNMENT(CompoundAssignmentTree.class),
492 /**
493 * Used for instances of {@link LiteralTree} representing
494 * an integral literal expression of type {@code int}.
495 */
496 INT_LITERAL(LiteralTree.class),
498 /**
499 * Used for instances of {@link LiteralTree} representing
500 * an integral literal expression of type {@code long}.
501 */
502 LONG_LITERAL(LiteralTree.class),
504 /**
505 * Used for instances of {@link LiteralTree} representing
506 * a floating-point literal expression of type {@code float}.
507 */
508 FLOAT_LITERAL(LiteralTree.class),
510 /**
511 * Used for instances of {@link LiteralTree} representing
512 * a floating-point literal expression of type {@code double}.
513 */
514 DOUBLE_LITERAL(LiteralTree.class),
516 /**
517 * Used for instances of {@link LiteralTree} representing
518 * a boolean literal expression of type {@code boolean}.
519 */
520 BOOLEAN_LITERAL(LiteralTree.class),
522 /**
523 * Used for instances of {@link LiteralTree} representing
524 * a character literal expression of type {@code char}.
525 */
526 CHAR_LITERAL(LiteralTree.class),
528 /**
529 * Used for instances of {@link LiteralTree} representing
530 * a string literal expression of type {@link String}.
531 */
532 STRING_LITERAL(LiteralTree.class),
534 /**
535 * Used for instances of {@link LiteralTree} representing
536 * the use of {@code null}.
537 */
538 NULL_LITERAL(LiteralTree.class),
540 /**
541 * Used for instances of {@link WildcardTree} representing
542 * an unbounded wildcard type argument.
543 */
544 UNBOUNDED_WILDCARD(WildcardTree.class),
546 /**
547 * Used for instances of {@link WildcardTree} representing
548 * an extends bounded wildcard type argument.
549 */
550 EXTENDS_WILDCARD(WildcardTree.class),
552 /**
553 * Used for instances of {@link WildcardTree} representing
554 * a super bounded wildcard type argument.
555 */
556 SUPER_WILDCARD(WildcardTree.class),
558 /**
559 * Used for instances of {@link ErroneousTree}.
560 */
561 ERRONEOUS(ErroneousTree.class),
563 /**
564 * Used for instances of {@link ClassTree} representing interfaces.
565 */
566 INTERFACE(ClassTree.class),
568 /**
569 * Used for instances of {@link ClassTree} representing enums.
570 */
571 ENUM(ClassTree.class),
573 /**
574 * Used for instances of {@link ClassTree} representing annotation types.
575 */
576 ANNOTATION_TYPE(ClassTree.class),
578 /**
579 * An implementation-reserved node. This is the not the node
580 * you are looking for.
581 */
582 OTHER(null);
585 Kind(Class<? extends Tree> intf) {
586 associatedInterface = intf;
587 }
589 public Class<? extends Tree> asInterface() {
590 return associatedInterface;
591 }
593 private final Class<? extends Tree> associatedInterface;
594 }
596 /**
597 * Gets the kind of this tree.
598 *
599 * @return the kind of this tree.
600 */
601 Kind getKind();
603 /**
604 * Accept method used to implement the visitor pattern. The
605 * visitor pattern is used to implement operations on trees.
606 *
607 * @param <R> result type of this operation.
608 * @param <D> type of additonal data.
609 */
610 <R,D> R accept(TreeVisitor<R,D> visitor, D data);
611 }