Tree.java revision 2571:10fc81ac75b4
1263409Smarcel/* 2263409Smarcel * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. 3263409Smarcel * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4263409Smarcel * 5263409Smarcel * This code is free software; you can redistribute it and/or modify it 6263409Smarcel * under the terms of the GNU General Public License version 2 only, as 7263409Smarcel * published by the Free Software Foundation. Oracle designates this 8263409Smarcel * particular file as subject to the "Classpath" exception as provided 9263409Smarcel * by Oracle in the LICENSE file that accompanied this code. 10263409Smarcel * 11263409Smarcel * This code is distributed in the hope that it will be useful, but WITHOUT 12263409Smarcel * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13263409Smarcel * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14263409Smarcel * version 2 for more details (a copy is included in the LICENSE file that 15263409Smarcel * accompanied this code). 16263409Smarcel * 17263409Smarcel * You should have received a copy of the GNU General Public License version 18263409Smarcel * 2 along with this work; if not, write to the Free Software Foundation, 19263409Smarcel * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20263409Smarcel * 21263409Smarcel * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22263409Smarcel * or visit www.oracle.com if you need additional information or have any 23263409Smarcel * questions. 24263409Smarcel */ 25263409Smarcel 26263409Smarcelpackage com.sun.source.tree; 27263409Smarcel 28263409Smarcel/** 29263409Smarcel * Common interface for all nodes in an abstract syntax tree. 30263409Smarcel * 31263409Smarcel * <p><b>WARNING:</b> This interface and its sub-interfaces are 32263652Smarcel * subject to change as the Java™ programming language evolves. 33263442Smarcel * These interfaces are implemented by the JDK Java compiler (javac) 34263409Smarcel * and should not be implemented either directly or indirectly by 35263652Smarcel * other applications. 36263652Smarcel * 37263409Smarcel * @author Peter von der Ahé 38268161Smarcel * @author Jonathan Gibbons 39263409Smarcel * 40263409Smarcel * @since 1.6 41263409Smarcel */ 42268161Smarcel@jdk.Exported 43268161Smarcelpublic interface Tree { 44268161Smarcel 45268161Smarcel /** 46263409Smarcel * Enumerates all kinds of trees. 47263673Smarcel */ 48263673Smarcel @jdk.Exported 49263652Smarcel public enum Kind { 50263652Smarcel /** 51263409Smarcel * Used for instances of {@link AnnotatedTypeTree} 52263409Smarcel * representing annotated types. 53272030Smarcel */ 54272030Smarcel ANNOTATED_TYPE(AnnotatedTypeTree.class), 55263409Smarcel 56263409Smarcel /** 57272030Smarcel * Used for instances of {@link AnnotationTree} 58272030Smarcel * representing declaration annotations. 59263409Smarcel */ 60263409Smarcel ANNOTATION(AnnotationTree.class), 61263706Smarcel 62263706Smarcel /** 63263706Smarcel * Used for instances of {@link AnnotationTree} 64263706Smarcel * representing type annotations. 65263706Smarcel */ 66263706Smarcel TYPE_ANNOTATION(AnnotationTree.class), 67263706Smarcel 68263706Smarcel /** 69263706Smarcel * Used for instances of {@link ArrayAccessTree}. 70263442Smarcel */ 71268161Smarcel ARRAY_ACCESS(ArrayAccessTree.class), 72263442Smarcel 73263652Smarcel /** 74263652Smarcel * Used for instances of {@link ArrayTypeTree}. 75263652Smarcel */ 76263653Smarcel ARRAY_TYPE(ArrayTypeTree.class), 77263652Smarcel 78263652Smarcel /** 79263652Smarcel * Used for instances of {@link AssertTree}. 80263652Smarcel */ 81263652Smarcel ASSERT(AssertTree.class), 82263652Smarcel 83263652Smarcel /** 84263652Smarcel * Used for instances of {@link AssignmentTree}. 85263652Smarcel */ 86263654Smarcel ASSIGNMENT(AssignmentTree.class), 87263652Smarcel 88263652Smarcel /** 89263652Smarcel * Used for instances of {@link BlockTree}. 90263652Smarcel */ 91263706Smarcel BLOCK(BlockTree.class), 92263706Smarcel 93263652Smarcel /** 94263706Smarcel * Used for instances of {@link BreakTree}. 95263706Smarcel */ 96263841Smarcel BREAK(BreakTree.class), 97263841Smarcel 98263652Smarcel /** 99268161Smarcel * Used for instances of {@link CaseTree}. 100263652Smarcel */ 101263653Smarcel CASE(CaseTree.class), 102263442Smarcel 103263442Smarcel /** 104263409Smarcel * Used for instances of {@link CatchTree}. 105263409Smarcel */ 106263409Smarcel CATCH(CatchTree.class), 107263409Smarcel 108263440Smarcel /** 109263442Smarcel * Used for instances of {@link ClassTree} representing classes. 110263652Smarcel */ 111263700Smarcel CLASS(ClassTree.class), 112263700Smarcel 113263409Smarcel /** 114263409Smarcel * Used for instances of {@link CompilationUnitTree}. 115263409Smarcel */ 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 1.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