1 /* 2 * Copyright (c) 2005, 2019, 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 /** 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 { 43 44 /** 45 * Enumerates all kinds of trees. 46 */ 47 public enum Kind { 48 /** 49 * Used for instances of {@link AnnotatedTypeTree} 50 * representing annotated types. 51 */ 52 ANNOTATED_TYPE(AnnotatedTypeTree.class), 53 54 /** 55 * Used for instances of {@link AnnotationTree} 56 * representing declaration annotations. 57 */ 58 ANNOTATION(AnnotationTree.class), 59 60 /** 61 * Used for instances of {@link AnnotationTree} 62 * representing type annotations. 63 */ 64 TYPE_ANNOTATION(AnnotationTree.class), 65 66 /** 67 * Used for instances of {@link ArrayAccessTree}. 68 */ 69 ARRAY_ACCESS(ArrayAccessTree.class), 70 71 /** 72 * Used for instances of {@link ArrayTypeTree}. 73 */ 74 ARRAY_TYPE(ArrayTypeTree.class), 75 76 /** 77 * Used for instances of {@link AssertTree}. 78 */ 79 ASSERT(AssertTree.class), 80 81 /** 82 * Used for instances of {@link AssignmentTree}. 83 */ 84 ASSIGNMENT(AssignmentTree.class), 85 86 /** 87 * Used for instances of {@link BlockTree}. 88 */ 89 BLOCK(BlockTree.class), 90 91 /** 92 * Used for instances of {@link BreakTree}. 93 */ 94 BREAK(BreakTree.class), 95 96 /** 97 * Used for instances of {@link CaseTree}. 98 */ 99 CASE(CaseTree.class), 100 101 /** 102 * Used for instances of {@link CatchTree}. 103 */ 104 CATCH(CatchTree.class), 105 106 /** 107 * Used for instances of {@link ClassTree} representing classes. 108 */ 109 CLASS(ClassTree.class), 110 111 /** 112 * Used for instances of {@link CompilationUnitTree}. 113 */ 114 COMPILATION_UNIT(CompilationUnitTree.class), 115 116 /** 117 * Used for instances of {@link ConditionalExpressionTree}. 118 */ 119 CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class), 120 121 /** 122 * Used for instances of {@link ContinueTree}. 123 */ 124 CONTINUE(ContinueTree.class), 125 126 /** 127 * Used for instances of {@link DoWhileLoopTree}. 128 */ 129 DO_WHILE_LOOP(DoWhileLoopTree.class), 130 131 /** 132 * Used for instances of {@link EnhancedForLoopTree}. 133 */ 134 ENHANCED_FOR_LOOP(EnhancedForLoopTree.class), 135 136 /** 137 * Used for instances of {@link ExpressionStatementTree}. 138 */ 139 EXPRESSION_STATEMENT(ExpressionStatementTree.class), 140 141 /** 142 * Used for instances of {@link MemberSelectTree}. 143 */ 144 MEMBER_SELECT(MemberSelectTree.class), 145 146 /** 147 * Used for instances of {@link MemberReferenceTree}. 148 */ 149 MEMBER_REFERENCE(MemberReferenceTree.class), 150 151 /** 152 * Used for instances of {@link ForLoopTree}. 153 */ 154 FOR_LOOP(ForLoopTree.class), 155 156 /** 157 * Used for instances of {@link IdentifierTree}. 158 */ 159 IDENTIFIER(IdentifierTree.class), 160 161 /** 162 * Used for instances of {@link IfTree}. 163 */ 164 IF(IfTree.class), 165 166 /** 167 * Used for instances of {@link ImportTree}. 168 */ 169 IMPORT(ImportTree.class), 170 171 /** 172 * Used for instances of {@link InstanceOfTree}. 173 */ 174 INSTANCE_OF(InstanceOfTree.class), 175 176 /** 177 * Used for instances of {@link LabeledStatementTree}. 178 */ 179 LABELED_STATEMENT(LabeledStatementTree.class), 180 181 /** 182 * Used for instances of {@link MethodTree}. 183 */ 184 METHOD(MethodTree.class), 185 186 /** 187 * Used for instances of {@link MethodInvocationTree}. 188 */ 189 METHOD_INVOCATION(MethodInvocationTree.class), 190 191 /** 192 * Used for instances of {@link ModifiersTree}. 193 */ 194 MODIFIERS(ModifiersTree.class), 195 196 /** 197 * Used for instances of {@link NewArrayTree}. 198 */ 199 NEW_ARRAY(NewArrayTree.class), 200 201 /** 202 * Used for instances of {@link NewClassTree}. 203 */ 204 NEW_CLASS(NewClassTree.class), 205 206 /** 207 * Used for instances of {@link LambdaExpressionTree}. 208 */ 209 LAMBDA_EXPRESSION(LambdaExpressionTree.class), 210 211 /** 212 * Used for instances of {@link PackageTree}. 213 * @since 9 214 */ 215 PACKAGE(PackageTree.class), 216 217 /** 218 * Used for instances of {@link ParenthesizedTree}. 219 */ 220 PARENTHESIZED(ParenthesizedTree.class), 221 222 /** 223 * Used for instances of {@link PrimitiveTypeTree}. 224 */ 225 PRIMITIVE_TYPE(PrimitiveTypeTree.class), 226 227 /** 228 * Used for instances of {@link ReturnTree}. 229 */ 230 RETURN(ReturnTree.class), 231 232 /** 233 * Used for instances of {@link EmptyStatementTree}. 234 */ 235 EMPTY_STATEMENT(EmptyStatementTree.class), 236 237 /** 238 * Used for instances of {@link SwitchTree}. 239 */ 240 SWITCH(SwitchTree.class), 241 242 /** 243 * Used for instances of {@link SwitchExpressionTree}. 244 * 245 * @since 12 246 */ 247 SWITCH_EXPRESSION(SwitchExpressionTree.class), 248 249 /** 250 * Used for instances of {@link SynchronizedTree}. 251 */ 252 SYNCHRONIZED(SynchronizedTree.class), 253 254 /** 255 * Used for instances of {@link ThrowTree}. 256 */ 257 THROW(ThrowTree.class), 258 259 /** 260 * Used for instances of {@link TryTree}. 261 */ 262 TRY(TryTree.class), 263 264 /** 265 * Used for instances of {@link ParameterizedTypeTree}. 266 */ 267 PARAMETERIZED_TYPE(ParameterizedTypeTree.class), 268 269 /** 270 * Used for instances of {@link UnionTypeTree}. 271 */ 272 UNION_TYPE(UnionTypeTree.class), 273 274 /** 275 * Used for instances of {@link IntersectionTypeTree}. 276 */ 277 INTERSECTION_TYPE(IntersectionTypeTree.class), 278 279 /** 280 * Used for instances of {@link TypeCastTree}. 281 */ 282 TYPE_CAST(TypeCastTree.class), 283 284 /** 285 * Used for instances of {@link TypeParameterTree}. 286 */ 287 TYPE_PARAMETER(TypeParameterTree.class), 288 289 /** 290 * Used for instances of {@link VariableTree}. 291 */ 292 VARIABLE(VariableTree.class), 293 294 /** 295 * Used for instances of {@link WhileLoopTree}. 296 */ 297 WHILE_LOOP(WhileLoopTree.class), 298 299 /** 300 * Used for instances of {@link UnaryTree} representing postfix 301 * increment operator {@code ++}. 302 */ 303 POSTFIX_INCREMENT(UnaryTree.class), 304 305 /** 306 * Used for instances of {@link UnaryTree} representing postfix 307 * decrement operator {@code --}. 308 */ 309 POSTFIX_DECREMENT(UnaryTree.class), 310 311 /** 312 * Used for instances of {@link UnaryTree} representing prefix 313 * increment operator {@code ++}. 314 */ 315 PREFIX_INCREMENT(UnaryTree.class), 316 317 /** 318 * Used for instances of {@link UnaryTree} representing prefix 319 * decrement operator {@code --}. 320 */ 321 PREFIX_DECREMENT(UnaryTree.class), 322 323 /** 324 * Used for instances of {@link UnaryTree} representing unary plus 325 * operator {@code +}. 326 */ 327 UNARY_PLUS(UnaryTree.class), 328 329 /** 330 * Used for instances of {@link UnaryTree} representing unary minus 331 * operator {@code -}. 332 */ 333 UNARY_MINUS(UnaryTree.class), 334 335 /** 336 * Used for instances of {@link UnaryTree} representing bitwise 337 * complement operator {@code ~}. 338 */ 339 BITWISE_COMPLEMENT(UnaryTree.class), 340 341 /** 342 * Used for instances of {@link UnaryTree} representing logical 343 * complement operator {@code !}. 344 */ 345 LOGICAL_COMPLEMENT(UnaryTree.class), 346 347 /** 348 * Used for instances of {@link BinaryTree} representing 349 * multiplication {@code *}. 350 */ 351 MULTIPLY(BinaryTree.class), 352 353 /** 354 * Used for instances of {@link BinaryTree} representing 355 * division {@code /}. 356 */ 357 DIVIDE(BinaryTree.class), 358 359 /** 360 * Used for instances of {@link BinaryTree} representing 361 * remainder {@code %}. 362 */ 363 REMAINDER(BinaryTree.class), 364 365 /** 366 * Used for instances of {@link BinaryTree} representing 367 * addition or string concatenation {@code +}. 368 */ 369 PLUS(BinaryTree.class), 370 371 /** 372 * Used for instances of {@link BinaryTree} representing 373 * subtraction {@code -}. 374 */ 375 MINUS(BinaryTree.class), 376 377 /** 378 * Used for instances of {@link BinaryTree} representing 379 * left shift {@code <<}. 380 */ 381 LEFT_SHIFT(BinaryTree.class), 382 383 /** 384 * Used for instances of {@link BinaryTree} representing 385 * right shift {@code >>}. 386 */ 387 RIGHT_SHIFT(BinaryTree.class), 388 389 /** 390 * Used for instances of {@link BinaryTree} representing 391 * unsigned right shift {@code >>>}. 392 */ 393 UNSIGNED_RIGHT_SHIFT(BinaryTree.class), 394 395 /** 396 * Used for instances of {@link BinaryTree} representing 397 * less-than {@code <}. 398 */ 399 LESS_THAN(BinaryTree.class), 400 401 /** 402 * Used for instances of {@link BinaryTree} representing 403 * greater-than {@code >}. 404 */ 405 GREATER_THAN(BinaryTree.class), 406 407 /** 408 * Used for instances of {@link BinaryTree} representing 409 * less-than-equal {@code <=}. 410 */ 411 LESS_THAN_EQUAL(BinaryTree.class), 412 413 /** 414 * Used for instances of {@link BinaryTree} representing 415 * greater-than-equal {@code >=}. 416 */ 417 GREATER_THAN_EQUAL(BinaryTree.class), 418 419 /** 420 * Used for instances of {@link BinaryTree} representing 421 * equal-to {@code ==}. 422 */ 423 EQUAL_TO(BinaryTree.class), 424 425 /** 426 * Used for instances of {@link BinaryTree} representing 427 * not-equal-to {@code !=}. 428 */ 429 NOT_EQUAL_TO(BinaryTree.class), 430 431 /** 432 * Used for instances of {@link BinaryTree} representing 433 * bitwise and logical "and" {@code &}. 434 */ 435 AND(BinaryTree.class), 436 437 /** 438 * Used for instances of {@link BinaryTree} representing 439 * bitwise and logical "xor" {@code ^}. 440 */ 441 XOR(BinaryTree.class), 442 443 /** 444 * Used for instances of {@link BinaryTree} representing 445 * bitwise and logical "or" {@code |}. 446 */ 447 OR(BinaryTree.class), 448 449 /** 450 * Used for instances of {@link BinaryTree} representing 451 * conditional-and {@code &&}. 452 */ 453 CONDITIONAL_AND(BinaryTree.class), 454 455 /** 456 * Used for instances of {@link BinaryTree} representing 457 * conditional-or {@code ||}. 458 */ 459 CONDITIONAL_OR(BinaryTree.class), 460 461 /** 462 * Used for instances of {@link CompoundAssignmentTree} representing 463 * multiplication assignment {@code *=}. 464 */ 465 MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class), 466 467 /** 468 * Used for instances of {@link CompoundAssignmentTree} representing 469 * division assignment {@code /=}. 470 */ 471 DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class), 472 473 /** 474 * Used for instances of {@link CompoundAssignmentTree} representing 475 * remainder assignment {@code %=}. 476 */ 477 REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class), 478 479 /** 480 * Used for instances of {@link CompoundAssignmentTree} representing 481 * addition or string concatenation assignment {@code +=}. 482 */ 483 PLUS_ASSIGNMENT(CompoundAssignmentTree.class), 484 485 /** 486 * Used for instances of {@link CompoundAssignmentTree} representing 487 * subtraction assignment {@code -=}. 488 */ 489 MINUS_ASSIGNMENT(CompoundAssignmentTree.class), 490 491 /** 492 * Used for instances of {@link CompoundAssignmentTree} representing 493 * left shift assignment {@code <<=}. 494 */ 495 LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class), 496 497 /** 498 * Used for instances of {@link CompoundAssignmentTree} representing 499 * right shift assignment {@code >>=}. 500 */ 501 RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class), 502 503 /** 504 * Used for instances of {@link CompoundAssignmentTree} representing 505 * unsigned right shift assignment {@code >>>=}. 506 */ 507 UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class), 508 509 /** 510 * Used for instances of {@link CompoundAssignmentTree} representing 511 * bitwise and logical "and" assignment {@code &=}. 512 */ 513 AND_ASSIGNMENT(CompoundAssignmentTree.class), 514 515 /** 516 * Used for instances of {@link CompoundAssignmentTree} representing 517 * bitwise and logical "xor" assignment {@code ^=}. 518 */ 519 XOR_ASSIGNMENT(CompoundAssignmentTree.class), 520 521 /** 522 * Used for instances of {@link CompoundAssignmentTree} representing 523 * bitwise and logical "or" assignment {@code |=}. 524 */ 525 OR_ASSIGNMENT(CompoundAssignmentTree.class), 526 527 /** 528 * Used for instances of {@link LiteralTree} representing 529 * an integral literal expression of type {@code int}. 530 */ 531 INT_LITERAL(LiteralTree.class), 532 533 /** 534 * Used for instances of {@link LiteralTree} representing 535 * an integral literal expression of type {@code long}. 536 */ 537 LONG_LITERAL(LiteralTree.class), 538 539 /** 540 * Used for instances of {@link LiteralTree} representing 541 * a floating-point literal expression of type {@code float}. 542 */ 543 FLOAT_LITERAL(LiteralTree.class), 544 545 /** 546 * Used for instances of {@link LiteralTree} representing 547 * a floating-point literal expression of type {@code double}. 548 */ 549 DOUBLE_LITERAL(LiteralTree.class), 550 551 /** 552 * Used for instances of {@link LiteralTree} representing 553 * a boolean literal expression of type {@code boolean}. 554 */ 555 BOOLEAN_LITERAL(LiteralTree.class), 556 557 /** 558 * Used for instances of {@link LiteralTree} representing 559 * a character literal expression of type {@code char}. 560 */ 561 CHAR_LITERAL(LiteralTree.class), 562 563 /** 564 * Used for instances of {@link LiteralTree} representing 565 * a string literal expression of type {@link String}. 566 */ 567 STRING_LITERAL(LiteralTree.class), 568 569 /** 570 * Used for instances of {@link LiteralTree} representing 571 * the use of {@code null}. 572 */ 573 NULL_LITERAL(LiteralTree.class), 574 575 /** 576 * Used for instances of {@link WildcardTree} representing 577 * an unbounded wildcard type argument. 578 */ 579 UNBOUNDED_WILDCARD(WildcardTree.class), 580 581 /** 582 * Used for instances of {@link WildcardTree} representing 583 * an extends bounded wildcard type argument. 584 */ 585 EXTENDS_WILDCARD(WildcardTree.class), 586 587 /** 588 * Used for instances of {@link WildcardTree} representing 589 * a super bounded wildcard type argument. 590 */ 591 SUPER_WILDCARD(WildcardTree.class), 592 593 /** 594 * Used for instances of {@link ErroneousTree}. 595 */ 596 ERRONEOUS(ErroneousTree.class), 597 598 /** 599 * Used for instances of {@link ClassTree} representing interfaces. 600 */ 601 INTERFACE(ClassTree.class), 602 603 /** 604 * Used for instances of {@link ClassTree} representing enums. 605 */ 606 ENUM(ClassTree.class), 607 608 /** 609 * Used for instances of {@link ClassTree} representing annotation types. 610 */ 611 ANNOTATION_TYPE(ClassTree.class), 612 613 /** 614 * Used for instances of {@link ModuleTree} representing module declarations. 615 */ 616 MODULE(ModuleTree.class), 617 618 /** 619 * Used for instances of {@link ExportsTree} representing 620 * exports directives in a module declaration. 621 */ 622 EXPORTS(ExportsTree.class), 623 624 /** 625 * Used for instances of {@link ExportsTree} representing 626 * opens directives in a module declaration. 627 */ 628 OPENS(OpensTree.class), 629 630 /** 631 * Used for instances of {@link ProvidesTree} representing 632 * provides directives in a module declaration. 633 */ 634 PROVIDES(ProvidesTree.class), 635 636 /** 637 * Used for instances of {@link RequiresTree} representing 638 * requires directives in a module declaration. 639 */ 640 REQUIRES(RequiresTree.class), 641 642 /** 643 * Used for instances of {@link UsesTree} representing 644 * uses directives in a module declaration. 645 */ 646 USES(UsesTree.class), 647 648 /** 649 * An implementation-reserved node. This is the not the node 650 * you are looking for. 651 */ 652 OTHER(null), 653 654 /** 655 * Used for instances of {@link YieldTree}. 656 * 657 * @since 13 658 */ 659 YIELD(YieldTree.class); 660 661 662 Kind(Class<? extends Tree> intf) { 663 associatedInterface = intf; 664 } 665 666 /** 667 * Returns the associated interface type that uses this kind. 668 * @return the associated interface 669 */ 670 public Class<? extends Tree> asInterface() { 671 return associatedInterface; 672 } 673 674 private final Class<? extends Tree> associatedInterface; 675 } 676 677 /** 678 * Returns the kind of this tree. 679 * 680 * @return the kind of this tree. 681 */ 682 Kind getKind(); 683 684 /** 685 * Accept method used to implement the visitor pattern. The 686 * visitor pattern is used to implement operations on trees. 687 * 688 * @param <R> result type of this operation. 689 * @param <D> type of additional data. 690 * @param visitor the visitor to be called 691 * @param data a value to be passed to the visitor 692 * @return the result returned from calling the visitor 693 */ 694 <R,D> R accept(TreeVisitor<R,D> visitor, D data); 695 }