1 /*
   2  * Copyright (c) 2005, 2016, 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&trade; 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&eacute;
  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          * @deprecated
 248          * This enum constant is modeling switch expressions,
 249          * which are part of a preview feature and may be removed
 250          * if the preview feature is removed.
 251          */
 252         @Deprecated(forRemoval=true, since="12")
 253         @SuppressWarnings("removal")
 254         SWITCH_EXPRESSION(SwitchExpressionTree.class),
 255 
 256         /**
 257          * Used for instances of {@link SynchronizedTree}.
 258          */
 259         SYNCHRONIZED(SynchronizedTree.class),
 260 
 261         /**
 262          * Used for instances of {@link ThrowTree}.
 263          */
 264         THROW(ThrowTree.class),
 265 
 266         /**
 267          * Used for instances of {@link TryTree}.
 268          */
 269         TRY(TryTree.class),
 270 
 271         /**
 272          * Used for instances of {@link ParameterizedTypeTree}.
 273          */
 274         PARAMETERIZED_TYPE(ParameterizedTypeTree.class),
 275 
 276         /**
 277          * Used for instances of {@link UnionTypeTree}.
 278          */
 279         UNION_TYPE(UnionTypeTree.class),
 280 
 281         /**
 282          * Used for instances of {@link IntersectionTypeTree}.
 283          */
 284         INTERSECTION_TYPE(IntersectionTypeTree.class),
 285 
 286         /**
 287          * Used for instances of {@link TypeCastTree}.
 288          */
 289         TYPE_CAST(TypeCastTree.class),
 290 
 291         /**
 292          * Used for instances of {@link TypeParameterTree}.
 293          */
 294         TYPE_PARAMETER(TypeParameterTree.class),
 295 
 296         /**
 297          * Used for instances of {@link VariableTree}.
 298          */
 299         VARIABLE(VariableTree.class),
 300 
 301         /**
 302          * Used for instances of {@link WhileLoopTree}.
 303          */
 304         WHILE_LOOP(WhileLoopTree.class),
 305 
 306         /**
 307          * Used for instances of {@link UnaryTree} representing postfix
 308          * increment operator {@code ++}.
 309          */
 310         POSTFIX_INCREMENT(UnaryTree.class),
 311 
 312         /**
 313          * Used for instances of {@link UnaryTree} representing postfix
 314          * decrement operator {@code --}.
 315          */
 316         POSTFIX_DECREMENT(UnaryTree.class),
 317 
 318         /**
 319          * Used for instances of {@link UnaryTree} representing prefix
 320          * increment operator {@code ++}.
 321          */
 322         PREFIX_INCREMENT(UnaryTree.class),
 323 
 324         /**
 325          * Used for instances of {@link UnaryTree} representing prefix
 326          * decrement operator {@code --}.
 327          */
 328         PREFIX_DECREMENT(UnaryTree.class),
 329 
 330         /**
 331          * Used for instances of {@link UnaryTree} representing unary plus
 332          * operator {@code +}.
 333          */
 334         UNARY_PLUS(UnaryTree.class),
 335 
 336         /**
 337          * Used for instances of {@link UnaryTree} representing unary minus
 338          * operator {@code -}.
 339          */
 340         UNARY_MINUS(UnaryTree.class),
 341 
 342         /**
 343          * Used for instances of {@link UnaryTree} representing bitwise
 344          * complement operator {@code ~}.
 345          */
 346         BITWISE_COMPLEMENT(UnaryTree.class),
 347 
 348         /**
 349          * Used for instances of {@link UnaryTree} representing logical
 350          * complement operator {@code !}.
 351          */
 352         LOGICAL_COMPLEMENT(UnaryTree.class),
 353 
 354         /**
 355          * Used for instances of {@link BinaryTree} representing
 356          * multiplication {@code *}.
 357          */
 358         MULTIPLY(BinaryTree.class),
 359 
 360         /**
 361          * Used for instances of {@link BinaryTree} representing
 362          * division {@code /}.
 363          */
 364         DIVIDE(BinaryTree.class),
 365 
 366         /**
 367          * Used for instances of {@link BinaryTree} representing
 368          * remainder {@code %}.
 369          */
 370         REMAINDER(BinaryTree.class),
 371 
 372         /**
 373          * Used for instances of {@link BinaryTree} representing
 374          * addition or string concatenation {@code +}.
 375          */
 376         PLUS(BinaryTree.class),
 377 
 378         /**
 379          * Used for instances of {@link BinaryTree} representing
 380          * subtraction {@code -}.
 381          */
 382         MINUS(BinaryTree.class),
 383 
 384         /**
 385          * Used for instances of {@link BinaryTree} representing
 386          * left shift {@code <<}.
 387          */
 388         LEFT_SHIFT(BinaryTree.class),
 389 
 390         /**
 391          * Used for instances of {@link BinaryTree} representing
 392          * right shift {@code >>}.
 393          */
 394         RIGHT_SHIFT(BinaryTree.class),
 395 
 396         /**
 397          * Used for instances of {@link BinaryTree} representing
 398          * unsigned right shift {@code >>>}.
 399          */
 400         UNSIGNED_RIGHT_SHIFT(BinaryTree.class),
 401 
 402         /**
 403          * Used for instances of {@link BinaryTree} representing
 404          * less-than {@code <}.
 405          */
 406         LESS_THAN(BinaryTree.class),
 407 
 408         /**
 409          * Used for instances of {@link BinaryTree} representing
 410          * greater-than {@code >}.
 411          */
 412         GREATER_THAN(BinaryTree.class),
 413 
 414         /**
 415          * Used for instances of {@link BinaryTree} representing
 416          * less-than-equal {@code <=}.
 417          */
 418         LESS_THAN_EQUAL(BinaryTree.class),
 419 
 420         /**
 421          * Used for instances of {@link BinaryTree} representing
 422          * greater-than-equal {@code >=}.
 423          */
 424         GREATER_THAN_EQUAL(BinaryTree.class),
 425 
 426         /**
 427          * Used for instances of {@link BinaryTree} representing
 428          * equal-to {@code ==}.
 429          */
 430         EQUAL_TO(BinaryTree.class),
 431 
 432         /**
 433          * Used for instances of {@link BinaryTree} representing
 434          * not-equal-to {@code !=}.
 435          */
 436         NOT_EQUAL_TO(BinaryTree.class),
 437 
 438         /**
 439          * Used for instances of {@link BinaryTree} representing
 440          * bitwise and logical "and" {@code &}.
 441          */
 442         AND(BinaryTree.class),
 443 
 444         /**
 445          * Used for instances of {@link BinaryTree} representing
 446          * bitwise and logical "xor" {@code ^}.
 447          */
 448         XOR(BinaryTree.class),
 449 
 450         /**
 451          * Used for instances of {@link BinaryTree} representing
 452          * bitwise and logical "or" {@code |}.
 453          */
 454         OR(BinaryTree.class),
 455 
 456         /**
 457          * Used for instances of {@link BinaryTree} representing
 458          * conditional-and {@code &&}.
 459          */
 460         CONDITIONAL_AND(BinaryTree.class),
 461 
 462         /**
 463          * Used for instances of {@link BinaryTree} representing
 464          * conditional-or {@code ||}.
 465          */
 466         CONDITIONAL_OR(BinaryTree.class),
 467 
 468         /**
 469          * Used for instances of {@link CompoundAssignmentTree} representing
 470          * multiplication assignment {@code *=}.
 471          */
 472         MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class),
 473 
 474         /**
 475          * Used for instances of {@link CompoundAssignmentTree} representing
 476          * division assignment {@code /=}.
 477          */
 478         DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class),
 479 
 480         /**
 481          * Used for instances of {@link CompoundAssignmentTree} representing
 482          * remainder assignment {@code %=}.
 483          */
 484         REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class),
 485 
 486         /**
 487          * Used for instances of {@link CompoundAssignmentTree} representing
 488          * addition or string concatenation assignment {@code +=}.
 489          */
 490         PLUS_ASSIGNMENT(CompoundAssignmentTree.class),
 491 
 492         /**
 493          * Used for instances of {@link CompoundAssignmentTree} representing
 494          * subtraction assignment {@code -=}.
 495          */
 496         MINUS_ASSIGNMENT(CompoundAssignmentTree.class),
 497 
 498         /**
 499          * Used for instances of {@link CompoundAssignmentTree} representing
 500          * left shift assignment {@code <<=}.
 501          */
 502         LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
 503 
 504         /**
 505          * Used for instances of {@link CompoundAssignmentTree} representing
 506          * right shift assignment {@code >>=}.
 507          */
 508         RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
 509 
 510         /**
 511          * Used for instances of {@link CompoundAssignmentTree} representing
 512          * unsigned right shift assignment {@code >>>=}.
 513          */
 514         UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class),
 515 
 516         /**
 517          * Used for instances of {@link CompoundAssignmentTree} representing
 518          * bitwise and logical "and" assignment {@code &=}.
 519          */
 520         AND_ASSIGNMENT(CompoundAssignmentTree.class),
 521 
 522         /**
 523          * Used for instances of {@link CompoundAssignmentTree} representing
 524          * bitwise and logical "xor" assignment {@code ^=}.
 525          */
 526         XOR_ASSIGNMENT(CompoundAssignmentTree.class),
 527 
 528         /**
 529          * Used for instances of {@link CompoundAssignmentTree} representing
 530          * bitwise and logical "or" assignment {@code |=}.
 531          */
 532         OR_ASSIGNMENT(CompoundAssignmentTree.class),
 533 
 534         /**
 535          * Used for instances of {@link LiteralTree} representing
 536          * an integral literal expression of type {@code int}.
 537          */
 538         INT_LITERAL(LiteralTree.class),
 539 
 540         /**
 541          * Used for instances of {@link LiteralTree} representing
 542          * an integral literal expression of type {@code long}.
 543          */
 544         LONG_LITERAL(LiteralTree.class),
 545 
 546         /**
 547          * Used for instances of {@link LiteralTree} representing
 548          * a floating-point literal expression of type {@code float}.
 549          */
 550         FLOAT_LITERAL(LiteralTree.class),
 551 
 552         /**
 553          * Used for instances of {@link LiteralTree} representing
 554          * a floating-point literal expression of type {@code double}.
 555          */
 556         DOUBLE_LITERAL(LiteralTree.class),
 557 
 558         /**
 559          * Used for instances of {@link LiteralTree} representing
 560          * a boolean literal expression of type {@code boolean}.
 561          */
 562         BOOLEAN_LITERAL(LiteralTree.class),
 563 
 564         /**
 565          * Used for instances of {@link LiteralTree} representing
 566          * a character literal expression of type {@code char}.
 567          */
 568         CHAR_LITERAL(LiteralTree.class),
 569 
 570         /**
 571          * Used for instances of {@link LiteralTree} representing
 572          * a string literal expression of type {@link String}.
 573          */
 574         STRING_LITERAL(LiteralTree.class),
 575 
 576         /**
 577          * Used for instances of {@link LiteralTree} representing
 578          * the use of {@code null}.
 579          */
 580         NULL_LITERAL(LiteralTree.class),
 581 
 582         /**
 583          * Used for instances of {@link WildcardTree} representing
 584          * an unbounded wildcard type argument.
 585          */
 586         UNBOUNDED_WILDCARD(WildcardTree.class),
 587 
 588         /**
 589          * Used for instances of {@link WildcardTree} representing
 590          * an extends bounded wildcard type argument.
 591          */
 592         EXTENDS_WILDCARD(WildcardTree.class),
 593 
 594         /**
 595          * Used for instances of {@link WildcardTree} representing
 596          * a super bounded wildcard type argument.
 597          */
 598         SUPER_WILDCARD(WildcardTree.class),
 599 
 600         /**
 601          * Used for instances of {@link ErroneousTree}.
 602          */
 603         ERRONEOUS(ErroneousTree.class),
 604 
 605         /**
 606          * Used for instances of {@link ClassTree} representing interfaces.
 607          */
 608         INTERFACE(ClassTree.class),
 609 
 610         /**
 611          * Used for instances of {@link ClassTree} representing enums.
 612          */
 613         ENUM(ClassTree.class),
 614 
 615         /**
 616          * Used for instances of {@link ClassTree} representing annotation types.
 617          */
 618         ANNOTATION_TYPE(ClassTree.class),
 619 
 620         /**
 621          * Used for instances of {@link ModuleTree} representing module declarations.
 622          */
 623         MODULE(ModuleTree.class),
 624 
 625         /**
 626          * Used for instances of {@link ExportsTree} representing
 627          * exports directives in a module declaration.
 628          */
 629         EXPORTS(ExportsTree.class),
 630 
 631         /**
 632          * Used for instances of {@link ExportsTree} representing
 633          * opens directives in a module declaration.
 634          */
 635         OPENS(OpensTree.class),
 636 
 637         /**
 638          * Used for instances of {@link ProvidesTree} representing
 639          * provides directives in a module declaration.
 640          */
 641         PROVIDES(ProvidesTree.class),
 642 
 643         /**
 644          * Used for instances of {@link RequiresTree} representing
 645          * requires directives in a module declaration.
 646          */
 647         REQUIRES(RequiresTree.class),
 648 
 649         /**
 650          * Used for instances of {@link UsesTree} representing
 651          * uses directives in a module declaration.
 652          */
 653         USES(UsesTree.class),
 654 
 655         /**
 656          * An implementation-reserved node. This is the not the node
 657          * you are looking for.
 658          */
 659         OTHER(null);
 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 }