1 /*
   2  * Copyright (c) 1999, 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.tools.javac.tree;
  27 
  28 import java.io.IOException;
  29 import java.io.StringWriter;
  30 import java.util.*;
  31 
  32 import javax.lang.model.element.Modifier;
  33 import javax.lang.model.type.TypeKind;
  34 import javax.tools.JavaFileObject;
  35 
  36 import com.sun.source.tree.*;
  37 import com.sun.tools.javac.code.*;
  38 import com.sun.tools.javac.code.Directive.RequiresDirective;
  39 import com.sun.tools.javac.code.Scope.*;
  40 import com.sun.tools.javac.code.Symbol.*;
  41 import com.sun.tools.javac.util.*;
  42 import com.sun.tools.javac.util.DefinedBy.Api;
  43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  44 import com.sun.tools.javac.util.List;
  45 
  46 import static com.sun.tools.javac.tree.JCTree.Tag.*;
  47 
  48 import javax.tools.JavaFileManager.Location;
  49 
  50 import com.sun.source.tree.CaseTree.CaseKind;
  51 import com.sun.source.tree.ModuleTree.ModuleKind;
  52 import com.sun.tools.javac.code.Directive.ExportsDirective;
  53 import com.sun.tools.javac.code.Directive.OpensDirective;
  54 import com.sun.tools.javac.code.Type.ModuleType;
  55 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.PolyKind;
  56 
  57 /**
  58  * Root class for abstract syntax tree nodes. It provides definitions
  59  * for specific tree nodes as subclasses nested inside.
  60  *
  61  * <p>Each subclass is highly standardized.  It generally contains
  62  * only tree fields for the syntactic subcomponents of the node.  Some
  63  * classes that represent identifier uses or definitions also define a
  64  * Symbol field that denotes the represented identifier.  Classes for
  65  * non-local jumps also carry the jump target as a field.  The root
  66  * class Tree itself defines fields for the tree's type and position.
  67  * No other fields are kept in a tree node; instead parameters are
  68  * passed to methods accessing the node.
  69  *
  70  * <p>Except for the methods defined by com.sun.source, the only
  71  * method defined in subclasses is `visit' which applies a given
  72  * visitor to the tree. The actual tree processing is done by visitor
  73  * classes in other packages. The abstract class Visitor, as well as
  74  * an Factory interface for trees, are defined as inner classes in
  75  * Tree.
  76  *
  77  * <p>To avoid ambiguities with the Tree API in com.sun.source all sub
  78  * classes should, by convention, start with JC (javac).
  79  *
  80  * <p><b>This is NOT part of any supported API.
  81  * If you write code that depends on this, you do so at your own risk.
  82  * This code and its internal interfaces are subject to change or
  83  * deletion without notice.</b>
  84  *
  85  * @see TreeMaker
  86  * @see TreeInfo
  87  * @see TreeTranslator
  88  * @see Pretty
  89  */
  90 public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
  91 
  92     /* Tree tag values, identifying kinds of trees */
  93     public enum Tag {
  94         /** For methods that return an invalid tag if a given condition is not met
  95          */
  96         NO_TAG,
  97 
  98         /** Toplevel nodes, of type TopLevel, representing entire source files.
  99         */
 100         TOPLEVEL,
 101 
 102         /** Package level definitions.
 103          */
 104         PACKAGEDEF,
 105 
 106         /** Import clauses, of type Import.
 107          */
 108         IMPORT,
 109 
 110         /** Class definitions, of type ClassDef.
 111          */
 112         CLASSDEF,
 113 
 114         /** Method definitions, of type MethodDef.
 115          */
 116         METHODDEF,
 117 
 118         /** Variable definitions, of type VarDef.
 119          */
 120         VARDEF,
 121 
 122         /** The no-op statement ";", of type Skip
 123          */
 124         SKIP,
 125 
 126         /** Blocks, of type Block.
 127          */
 128         BLOCK,
 129 
 130         /** Do-while loops, of type DoLoop.
 131          */
 132         DOLOOP,
 133 
 134         /** While-loops, of type WhileLoop.
 135          */
 136         WHILELOOP,
 137 
 138         /** Withfields, of type WithField.
 139          */
 140         WITHFIELD,
 141 
 142         /** For-loops, of type ForLoop.
 143          */
 144         FORLOOP,
 145 
 146         /** Foreach-loops, of type ForeachLoop.
 147          */
 148         FOREACHLOOP,
 149 
 150         /** Labelled statements, of type Labelled.
 151          */
 152         LABELLED,
 153 
 154         /** Switch statements, of type Switch.
 155          */
 156         SWITCH,
 157 
 158         /** Case parts in switch statements/expressions, of type Case.
 159          */
 160         CASE,
 161 
 162         /** Switch expression statements, of type Switch.
 163          */
 164         SWITCH_EXPRESSION,
 165 
 166         /** Synchronized statements, of type Synchonized.
 167          */
 168         SYNCHRONIZED,
 169 
 170         /** Try statements, of type Try.
 171          */
 172         TRY,
 173 
 174         /** Catch clauses in try statements, of type Catch.
 175          */
 176         CATCH,
 177 
 178         /** Conditional expressions, of type Conditional.
 179          */
 180         CONDEXPR,
 181 
 182         /** Conditional statements, of type If.
 183          */
 184         IF,
 185 
 186         /** Expression statements, of type Exec.
 187          */
 188         EXEC,
 189 
 190         /** Break statements, of type Break.
 191          */
 192         BREAK,
 193 
 194         /** Yield statements, of type Yield.
 195          */
 196         YIELD,
 197 
 198         /** Continue statements, of type Continue.
 199          */
 200         CONTINUE,
 201 
 202         /** Return statements, of type Return.
 203          */
 204         RETURN,
 205 
 206         /** Throw statements, of type Throw.
 207          */
 208         THROW,
 209 
 210         /** Assert statements, of type Assert.
 211          */
 212         ASSERT,
 213 
 214         /** Method invocation expressions, of type Apply.
 215          */
 216         APPLY,
 217 
 218         /** Class instance creation expressions, of type NewClass.
 219          */
 220         NEWCLASS,
 221 
 222         /** Array creation expressions, of type NewArray.
 223          */
 224         NEWARRAY,
 225 
 226         /** Lambda expression, of type Lambda.
 227          */
 228         LAMBDA,
 229 
 230         /** Parenthesized subexpressions, of type Parens.
 231          */
 232         PARENS,
 233 
 234         /** Assignment expressions, of type Assign.
 235          */
 236         ASSIGN,
 237 
 238         /** Type cast expressions, of type TypeCast.
 239          */
 240         TYPECAST,
 241 
 242         /** Type test expressions, of type TypeTest.
 243          */
 244         TYPETEST,
 245 
 246         /** Indexed array expressions, of type Indexed.
 247          */
 248         INDEXED,
 249 
 250         /** Selections, of type Select.
 251          */
 252         SELECT,
 253 
 254         /** Member references, of type Reference.
 255          */
 256         REFERENCE,
 257 
 258         /** Simple identifiers, of type Ident.
 259          */
 260         IDENT,
 261 
 262         /** Literals, of type Literal.
 263          */
 264         LITERAL,
 265 
 266         /** Basic type identifiers, of type TypeIdent.
 267          */
 268         TYPEIDENT,
 269 
 270         /** Array types, of type TypeArray.
 271          */
 272         TYPEARRAY,
 273 
 274         /** Parameterized types, of type TypeApply.
 275          */
 276         TYPEAPPLY,
 277 
 278         /** Union types, of type TypeUnion.
 279          */
 280         TYPEUNION,
 281 
 282         /** Intersection types, of type TypeIntersection.
 283          */
 284         TYPEINTERSECTION,
 285 
 286         /** Formal type parameters, of type TypeParameter.
 287          */
 288         TYPEPARAMETER,
 289 
 290         /** Type argument.
 291          */
 292         WILDCARD,
 293 
 294         /** Bound kind: extends, super, exact, or unbound
 295          */
 296         TYPEBOUNDKIND,
 297 
 298         /** metadata: Annotation.
 299          */
 300         ANNOTATION,
 301 
 302         /** metadata: Type annotation.
 303          */
 304         TYPE_ANNOTATION,
 305 
 306         /** metadata: Modifiers
 307          */
 308         MODIFIERS,
 309 
 310         /** An annotated type tree.
 311          */
 312         ANNOTATED_TYPE,
 313 
 314         /** Error trees, of type Erroneous.
 315          */
 316         ERRONEOUS,
 317 
 318         /** Unary operators, of type Unary.
 319          */
 320         POS,                             // +
 321         NEG,                             // -
 322         NOT,                             // !
 323         COMPL,                           // ~
 324         PREINC,                          // ++ _
 325         PREDEC,                          // -- _
 326         POSTINC,                         // _ ++
 327         POSTDEC,                         // _ --
 328 
 329         /** unary operator for null reference checks, only used internally.
 330          */
 331         NULLCHK,
 332 
 333         /** Binary operators, of type Binary.
 334          */
 335         OR,                              // ||
 336         AND,                             // &&
 337         BITOR,                           // |
 338         BITXOR,                          // ^
 339         BITAND,                          // &
 340         EQ,                              // ==
 341         NE,                              // !=
 342         LT,                              // <
 343         GT,                              // >
 344         LE,                              // <=
 345         GE,                              // >=
 346         SL,                              // <<
 347         SR,                              // >>
 348         USR,                             // >>>
 349         PLUS,                            // +
 350         MINUS,                           // -
 351         MUL,                             // *
 352         DIV,                             // /
 353         MOD,                             // %
 354 
 355         /** Assignment operators, of type Assignop.
 356          */
 357         BITOR_ASG(BITOR),                // |=
 358         BITXOR_ASG(BITXOR),              // ^=
 359         BITAND_ASG(BITAND),              // &=
 360 
 361         SL_ASG(SL),                      // <<=
 362         SR_ASG(SR),                      // >>=
 363         USR_ASG(USR),                    // >>>=
 364         PLUS_ASG(PLUS),                  // +=
 365         MINUS_ASG(MINUS),                // -=
 366         MUL_ASG(MUL),                    // *=
 367         DIV_ASG(DIV),                    // /=
 368         MOD_ASG(MOD),                    // %=
 369 
 370         MODULEDEF,
 371         EXPORTS,
 372         OPENS,
 373         PROVIDES,
 374         REQUIRES,
 375         USES,
 376 
 377         /** A synthetic let expression, of type LetExpr.
 378          */
 379         LETEXPR;                         // ala scheme
 380 
 381         private final Tag noAssignTag;
 382 
 383         private static final int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
 384 
 385         private Tag(Tag noAssignTag) {
 386             this.noAssignTag = noAssignTag;
 387         }
 388 
 389         private Tag() {
 390             this(null);
 391         }
 392 
 393         public static int getNumberOfOperators() {
 394             return numberOfOperators;
 395         }
 396 
 397         public Tag noAssignOp() {
 398             if (noAssignTag != null)
 399                 return noAssignTag;
 400             throw new AssertionError("noAssignOp() method is not available for non assignment tags");
 401         }
 402 
 403         public boolean isPostUnaryOp() {
 404             return (this == POSTINC || this == POSTDEC);
 405         }
 406 
 407         public boolean isIncOrDecUnaryOp() {
 408             return (this == PREINC || this == PREDEC || this == POSTINC || this == POSTDEC);
 409         }
 410 
 411         public boolean isAssignop() {
 412             return noAssignTag != null;
 413         }
 414 
 415         public int operatorIndex() {
 416             return (this.ordinal() - POS.ordinal());
 417         }
 418     }
 419 
 420     /* The (encoded) position in the source file. @see util.Position.
 421      */
 422     public int pos;
 423 
 424     /* The type of this node.
 425      */
 426     public Type type;
 427 
 428     /* The tag of this node -- one of the constants declared above.
 429      */
 430     public abstract Tag getTag();
 431 
 432     /* Returns true if the tag of this node is equals to tag.
 433      */
 434     public boolean hasTag(Tag tag) {
 435         return tag == getTag();
 436     }
 437 
 438     /** Convert a tree to a pretty-printed string. */
 439     @Override
 440     public String toString() {
 441         StringWriter s = new StringWriter();
 442         try {
 443             new Pretty(s, false).printExpr(this);
 444         }
 445         catch (IOException e) {
 446             // should never happen, because StringWriter is defined
 447             // never to throw any IOExceptions
 448             throw new AssertionError(e);
 449         }
 450         return s.toString();
 451     }
 452 
 453     /** Set position field and return this tree.
 454      */
 455     public JCTree setPos(int pos) {
 456         this.pos = pos;
 457         return this;
 458     }
 459 
 460     /** Set type field and return this tree.
 461      */
 462     public JCTree setType(Type type) {
 463         this.type = type;
 464         return this;
 465     }
 466 
 467     /** Visit this tree with a given visitor.
 468      */
 469     public abstract void accept(Visitor v);
 470 
 471     @DefinedBy(Api.COMPILER_TREE)
 472     public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);
 473 
 474     /** Return a shallow copy of this tree.
 475      */
 476     @Override
 477     public Object clone() {
 478         try {
 479             return super.clone();
 480         } catch(CloneNotSupportedException e) {
 481             throw new RuntimeException(e);
 482         }
 483     }
 484 
 485     /** Get a default position for this tree node.
 486      */
 487     public DiagnosticPosition pos() {
 488         return this;
 489     }
 490 
 491     // for default DiagnosticPosition
 492     public JCTree getTree() {
 493         return this;
 494     }
 495 
 496     // for default DiagnosticPosition
 497     public int getStartPosition() {
 498         return TreeInfo.getStartPos(this);
 499     }
 500 
 501     // for default DiagnosticPosition
 502     public int getPreferredPosition() {
 503         return pos;
 504     }
 505 
 506     // for default DiagnosticPosition
 507     public int getEndPosition(EndPosTable endPosTable) {
 508         return TreeInfo.getEndPos(this, endPosTable);
 509     }
 510 
 511     /**
 512      * Everything in one source file is kept in a {@linkplain JCCompilationUnit} structure.
 513      */
 514     public static class JCCompilationUnit extends JCTree implements CompilationUnitTree {
 515         /** All definitions in this file (ClassDef, Import, and Skip) */
 516         public List<JCTree> defs;
 517         /** The source file name. */
 518         public JavaFileObject sourcefile;
 519         /** The module to which this compilation unit belongs. */
 520         public ModuleSymbol modle;
 521         /** The location in which this compilation unit was found. */
 522         public Location locn;
 523         /** The package to which this compilation unit belongs. */
 524         public PackageSymbol packge;
 525         /** A scope containing top level classes. */
 526         public WriteableScope toplevelScope;
 527         /** A scope for all named imports. */
 528         public NamedImportScope namedImportScope;
 529         /** A scope for all import-on-demands. */
 530         public StarImportScope starImportScope;
 531         /** Line starting positions, defined only if option -g is set. */
 532         public Position.LineMap lineMap = null;
 533         /** A table that stores all documentation comments indexed by the tree
 534          * nodes they refer to. defined only if option -s is set. */
 535         public DocCommentTable docComments = null;
 536         /* An object encapsulating ending positions of source ranges indexed by
 537          * the tree nodes they belong to. Defined only if option -Xjcov is set. */
 538         public EndPosTable endPositions = null;
 539         protected JCCompilationUnit(List<JCTree> defs) {
 540             this.defs = defs;
 541         }
 542         @Override
 543         public void accept(Visitor v) { v.visitTopLevel(this); }
 544 
 545         @DefinedBy(Api.COMPILER_TREE)
 546         public Kind getKind() { return Kind.COMPILATION_UNIT; }
 547 
 548         public JCModuleDecl getModuleDecl() {
 549             for (JCTree tree : defs) {
 550                 if (tree.hasTag(MODULEDEF)) {
 551                     return (JCModuleDecl) tree;
 552                 }
 553             }
 554 
 555             return null;
 556         }
 557 
 558         @DefinedBy(Api.COMPILER_TREE)
 559         public JCPackageDecl getPackage() {
 560             // PackageDecl must be the first entry if it exists
 561             if (!defs.isEmpty() && defs.head.hasTag(PACKAGEDEF))
 562                 return (JCPackageDecl)defs.head;
 563             return null;
 564         }
 565         @DefinedBy(Api.COMPILER_TREE)
 566         public List<JCAnnotation> getPackageAnnotations() {
 567             JCPackageDecl pd = getPackage();
 568             return pd != null ? pd.getAnnotations() : List.nil();
 569         }
 570         @DefinedBy(Api.COMPILER_TREE)
 571         public ExpressionTree getPackageName() {
 572             JCPackageDecl pd = getPackage();
 573             return pd != null ? pd.getPackageName() : null;
 574         }
 575 
 576         @DefinedBy(Api.COMPILER_TREE)
 577         public List<JCImport> getImports() {
 578             ListBuffer<JCImport> imports = new ListBuffer<>();
 579             for (JCTree tree : defs) {
 580                 if (tree.hasTag(IMPORT))
 581                     imports.append((JCImport)tree);
 582                 else if (!tree.hasTag(PACKAGEDEF) && !tree.hasTag(SKIP))
 583                     break;
 584             }
 585             return imports.toList();
 586         }
 587         @DefinedBy(Api.COMPILER_TREE)
 588         public JavaFileObject getSourceFile() {
 589             return sourcefile;
 590         }
 591         @DefinedBy(Api.COMPILER_TREE)
 592         public Position.LineMap getLineMap() {
 593             return lineMap;
 594         }
 595         @DefinedBy(Api.COMPILER_TREE)
 596         public List<JCTree> getTypeDecls() {
 597             List<JCTree> typeDefs;
 598             for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)
 599                 if (!typeDefs.head.hasTag(PACKAGEDEF) && !typeDefs.head.hasTag(IMPORT))
 600                     break;
 601             return typeDefs;
 602         }
 603         @Override @DefinedBy(Api.COMPILER_TREE)
 604         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 605             return v.visitCompilationUnit(this, d);
 606         }
 607 
 608         @Override
 609         public Tag getTag() {
 610             return TOPLEVEL;
 611         }
 612     }
 613 
 614     /**
 615      * Package definition.
 616      */
 617     public static class JCPackageDecl extends JCTree implements PackageTree {
 618         public List<JCAnnotation> annotations;
 619         /** The tree representing the package clause. */
 620         public JCExpression pid;
 621         public PackageSymbol packge;
 622         public JCPackageDecl(List<JCAnnotation> annotations, JCExpression pid) {
 623             this.annotations = annotations;
 624             this.pid = pid;
 625         }
 626         @Override
 627         public void accept(Visitor v) { v.visitPackageDef(this); }
 628         @DefinedBy(Api.COMPILER_TREE)
 629         public Kind getKind() {
 630             return Kind.PACKAGE;
 631         }
 632         @DefinedBy(Api.COMPILER_TREE)
 633         public List<JCAnnotation> getAnnotations() {
 634             return annotations;
 635         }
 636         @DefinedBy(Api.COMPILER_TREE)
 637         public JCExpression getPackageName() {
 638             return pid;
 639         }
 640         @Override @DefinedBy(Api.COMPILER_TREE)
 641         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 642             return v.visitPackage(this, d);
 643         }
 644         @Override
 645         public Tag getTag() {
 646             return PACKAGEDEF;
 647         }
 648     }
 649 
 650     /**
 651      * An import clause.
 652      */
 653     public static class JCImport extends JCTree implements ImportTree {
 654         public boolean staticImport;
 655         /** The imported class(es). */
 656         public JCTree qualid;
 657         public com.sun.tools.javac.code.Scope importScope;
 658         protected JCImport(JCTree qualid, boolean importStatic) {
 659             this.qualid = qualid;
 660             this.staticImport = importStatic;
 661         }
 662         @Override
 663         public void accept(Visitor v) { v.visitImport(this); }
 664 
 665         @DefinedBy(Api.COMPILER_TREE)
 666         public boolean isStatic() { return staticImport; }
 667         @DefinedBy(Api.COMPILER_TREE)
 668         public JCTree getQualifiedIdentifier() { return qualid; }
 669 
 670         @DefinedBy(Api.COMPILER_TREE)
 671         public Kind getKind() { return Kind.IMPORT; }
 672         @Override @DefinedBy(Api.COMPILER_TREE)
 673         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 674             return v.visitImport(this, d);
 675         }
 676 
 677         @Override
 678         public Tag getTag() {
 679             return IMPORT;
 680         }
 681     }
 682 
 683     public static abstract class JCStatement extends JCTree implements StatementTree {
 684         @Override
 685         public JCStatement setType(Type type) {
 686             super.setType(type);
 687             return this;
 688         }
 689         @Override
 690         public JCStatement setPos(int pos) {
 691             super.setPos(pos);
 692             return this;
 693         }
 694     }
 695 
 696     public static abstract class JCExpression extends JCTree implements ExpressionTree {
 697         boolean questioned = false;
 698         @Override
 699         public JCExpression setType(Type type) {
 700             super.setType(type);
 701             return this;
 702         }
 703         @Override
 704         public JCExpression setPos(int pos) {
 705             super.setPos(pos);
 706             return this;
 707         }
 708 
 709         public void setQuestioned() {
 710             this.questioned = true;
 711         }
 712         public boolean isQuestioned() {
 713             return this.questioned;
 714         }
 715 
 716         public boolean isPoly() { return false; }
 717         public boolean isStandalone() { return true; }
 718     }
 719 
 720     /**
 721      * Common supertype for all poly expression trees (lambda, method references,
 722      * conditionals, method and constructor calls)
 723      */
 724     public static abstract class JCPolyExpression extends JCExpression {
 725 
 726         /**
 727          * A poly expression can only be truly 'poly' in certain contexts
 728          */
 729         public enum PolyKind {
 730             /** poly expression to be treated as a standalone expression */
 731             STANDALONE,
 732             /** true poly expression */
 733             POLY
 734         }
 735 
 736         /** is this poly expression a 'true' poly expression? */
 737         public PolyKind polyKind;
 738 
 739         @Override public boolean isPoly() { return polyKind == PolyKind.POLY; }
 740         @Override public boolean isStandalone() { return polyKind == PolyKind.STANDALONE; }
 741     }
 742 
 743     /**
 744      * Common supertype for all functional expression trees (lambda and method references)
 745      */
 746     public static abstract class JCFunctionalExpression extends JCPolyExpression {
 747 
 748         public JCFunctionalExpression() {
 749             //a functional expression is always a 'true' poly
 750             polyKind = PolyKind.POLY;
 751         }
 752 
 753         /** list of target types inferred for this functional expression. */
 754         public Type target;
 755 
 756         public Type getDescriptorType(Types types) {
 757             return target != null ? types.findDescriptorType(target) : types.createErrorType(null);
 758         }
 759     }
 760 
 761     /**
 762      * A class definition.
 763      */
 764     public static class JCClassDecl extends JCStatement implements ClassTree {
 765         /** the modifiers */
 766         public JCModifiers mods;
 767         /** the name of the class */
 768         public Name name;
 769         /** formal class parameters */
 770         public List<JCTypeParameter> typarams;
 771         /** the classes this class extends */
 772         public JCExpression extending;
 773         /** the interfaces implemented by this class */
 774         public List<JCExpression> implementing;
 775         /** all variables and methods defined in this class */
 776         public List<JCTree> defs;
 777         /** the symbol */
 778         public ClassSymbol sym;
 779         protected JCClassDecl(JCModifiers mods,
 780                            Name name,
 781                            List<JCTypeParameter> typarams,
 782                            JCExpression extending,
 783                            List<JCExpression> implementing,
 784                            List<JCTree> defs,
 785                            ClassSymbol sym)
 786         {
 787             this.mods = mods;
 788             this.name = name;
 789             this.typarams = typarams;
 790             this.extending = extending;
 791             this.implementing = implementing;
 792             this.defs = defs;
 793             this.sym = sym;
 794         }
 795         @Override
 796         public void accept(Visitor v) { v.visitClassDef(this); }
 797 
 798         @DefinedBy(Api.COMPILER_TREE)
 799         public Kind getKind() {
 800             if ((mods.flags & Flags.ANNOTATION) != 0)
 801                 return Kind.ANNOTATION_TYPE;
 802             else if ((mods.flags & Flags.INTERFACE) != 0)
 803                 return Kind.INTERFACE;
 804             else if ((mods.flags & Flags.ENUM) != 0)
 805                 return Kind.ENUM;
 806             else
 807                 return Kind.CLASS;
 808         }
 809 
 810         @DefinedBy(Api.COMPILER_TREE)
 811         public JCModifiers getModifiers() { return mods; }
 812         @DefinedBy(Api.COMPILER_TREE)
 813         public Name getSimpleName() { return name; }
 814         @DefinedBy(Api.COMPILER_TREE)
 815         public List<JCTypeParameter> getTypeParameters() {
 816             return typarams;
 817         }
 818         @DefinedBy(Api.COMPILER_TREE)
 819         public JCExpression getExtendsClause() { return extending; }
 820         @DefinedBy(Api.COMPILER_TREE)
 821         public List<JCExpression> getImplementsClause() {
 822             return implementing;
 823         }
 824         @DefinedBy(Api.COMPILER_TREE)
 825         public List<JCTree> getMembers() {
 826             return defs;
 827         }
 828         @Override @DefinedBy(Api.COMPILER_TREE)
 829         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 830             return v.visitClass(this, d);
 831         }
 832 
 833         @Override
 834         public Tag getTag() {
 835             return CLASSDEF;
 836         }
 837     }
 838 
 839     /**
 840      * A method definition.
 841      */
 842     public static class JCMethodDecl extends JCTree implements MethodTree {
 843         /** method modifiers */
 844         public JCModifiers mods;
 845         /** method name */
 846         public Name name;
 847         /** type of method return value */
 848         public JCExpression restype;
 849         /** type parameters */
 850         public List<JCTypeParameter> typarams;
 851         /** receiver parameter */
 852         public JCVariableDecl recvparam;
 853         /** value parameters */
 854         public List<JCVariableDecl> params;
 855         /** exceptions thrown by this method */
 856         public List<JCExpression> thrown;
 857         /** statements in the method */
 858         public JCBlock body;
 859         /** default value, for annotation types */
 860         public JCExpression defaultValue;
 861         /** method symbol */
 862         public MethodSymbol sym;
 863         /** nascent value that evolves into the return value for a value factory */
 864         public VarSymbol factoryProduct;
 865 
 866         protected JCMethodDecl(JCModifiers mods,
 867                             Name name,
 868                             JCExpression restype,
 869                             List<JCTypeParameter> typarams,
 870                             JCVariableDecl recvparam,
 871                             List<JCVariableDecl> params,
 872                             List<JCExpression> thrown,
 873                             JCBlock body,
 874                             JCExpression defaultValue,
 875                             MethodSymbol sym)
 876         {
 877             this.mods = mods;
 878             this.name = name;
 879             this.restype = restype;
 880             this.typarams = typarams;
 881             this.params = params;
 882             this.recvparam = recvparam;
 883             // TODO: do something special if the given type is null?
 884             // receiver != null ? receiver : List.<JCTypeAnnotation>nil());
 885             this.thrown = thrown;
 886             this.body = body;
 887             this.defaultValue = defaultValue;
 888             this.sym = sym;
 889         }
 890         @Override
 891         public void accept(Visitor v) { v.visitMethodDef(this); }
 892 
 893         @DefinedBy(Api.COMPILER_TREE)
 894         public Kind getKind() { return Kind.METHOD; }
 895         @DefinedBy(Api.COMPILER_TREE)
 896         public JCModifiers getModifiers() { return mods; }
 897         @DefinedBy(Api.COMPILER_TREE)
 898         public Name getName() { return name; }
 899         @DefinedBy(Api.COMPILER_TREE)
 900         public JCTree getReturnType() { return restype; }
 901         @DefinedBy(Api.COMPILER_TREE)
 902         public List<JCTypeParameter> getTypeParameters() {
 903             return typarams;
 904         }
 905         @DefinedBy(Api.COMPILER_TREE)
 906         public List<JCVariableDecl> getParameters() {
 907             return params;
 908         }
 909         @DefinedBy(Api.COMPILER_TREE)
 910         public JCVariableDecl getReceiverParameter() { return recvparam; }
 911         @DefinedBy(Api.COMPILER_TREE)
 912         public List<JCExpression> getThrows() {
 913             return thrown;
 914         }
 915         @DefinedBy(Api.COMPILER_TREE)
 916         public JCBlock getBody() { return body; }
 917         @DefinedBy(Api.COMPILER_TREE)
 918         public JCTree getDefaultValue() { // for annotation types
 919             return defaultValue;
 920         }
 921         @Override @DefinedBy(Api.COMPILER_TREE)
 922         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 923             return v.visitMethod(this, d);
 924         }
 925 
 926         @Override
 927         public Tag getTag() {
 928             return METHODDEF;
 929         }
 930   }
 931 
 932     /**
 933      * A variable definition.
 934      */
 935     public static class JCVariableDecl extends JCStatement implements VariableTree {
 936         /** variable modifiers */
 937         public JCModifiers mods;
 938         /** variable name */
 939         public Name name;
 940         /** variable name expression */
 941         public JCExpression nameexpr;
 942         /** type of the variable */
 943         public JCExpression vartype;
 944         /** variable's initial value */
 945         public JCExpression init;
 946         /** symbol */
 947         public VarSymbol sym;
 948         /** explicit start pos */
 949         public int startPos = Position.NOPOS;
 950 
 951         protected JCVariableDecl(JCModifiers mods,
 952                          Name name,
 953                          JCExpression vartype,
 954                          JCExpression init,
 955                          VarSymbol sym) {
 956             this.mods = mods;
 957             this.name = name;
 958             this.vartype = vartype;
 959             this.init = init;
 960             this.sym = sym;
 961         }
 962 
 963         protected JCVariableDecl(JCModifiers mods,
 964                          JCExpression nameexpr,
 965                          JCExpression vartype) {
 966             this(mods, null, vartype, null, null);
 967             this.nameexpr = nameexpr;
 968             if (nameexpr.hasTag(Tag.IDENT)) {
 969                 this.name = ((JCIdent)nameexpr).name;
 970             } else {
 971                 // Only other option is qualified name x.y.this;
 972                 this.name = ((JCFieldAccess)nameexpr).name;
 973             }
 974         }
 975 
 976         public boolean isImplicitlyTyped() {
 977             return vartype == null;
 978         }
 979 
 980         @Override
 981         public void accept(Visitor v) { v.visitVarDef(this); }
 982 
 983         @DefinedBy(Api.COMPILER_TREE)
 984         public Kind getKind() { return Kind.VARIABLE; }
 985         @DefinedBy(Api.COMPILER_TREE)
 986         public JCModifiers getModifiers() { return mods; }
 987         @DefinedBy(Api.COMPILER_TREE)
 988         public Name getName() { return name; }
 989         @DefinedBy(Api.COMPILER_TREE)
 990         public JCExpression getNameExpression() { return nameexpr; }
 991         @DefinedBy(Api.COMPILER_TREE)
 992         public JCTree getType() { return vartype; }
 993         @DefinedBy(Api.COMPILER_TREE)
 994         public JCExpression getInitializer() {
 995             return init;
 996         }
 997         @Override @DefinedBy(Api.COMPILER_TREE)
 998         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 999             return v.visitVariable(this, d);
1000         }
1001 
1002         @Override
1003         public Tag getTag() {
1004             return VARDEF;
1005         }
1006     }
1007 
1008     /**
1009      * A no-op statement ";".
1010      */
1011     public static class JCSkip extends JCStatement implements EmptyStatementTree {
1012         protected JCSkip() {
1013         }
1014         @Override
1015         public void accept(Visitor v) { v.visitSkip(this); }
1016 
1017         @DefinedBy(Api.COMPILER_TREE)
1018         public Kind getKind() { return Kind.EMPTY_STATEMENT; }
1019         @Override @DefinedBy(Api.COMPILER_TREE)
1020         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1021             return v.visitEmptyStatement(this, d);
1022         }
1023 
1024         @Override
1025         public Tag getTag() {
1026             return SKIP;
1027         }
1028     }
1029 
1030     /**
1031      * A statement block.
1032      */
1033     public static class JCBlock extends JCStatement implements BlockTree {
1034         /** flags */
1035         public long flags;
1036         /** statements */
1037         public List<JCStatement> stats;
1038         /** Position of closing brace, optional. */
1039         public int endpos = Position.NOPOS;
1040         protected JCBlock(long flags, List<JCStatement> stats) {
1041             this.stats = stats;
1042             this.flags = flags;
1043         }
1044         @Override
1045         public void accept(Visitor v) { v.visitBlock(this); }
1046 
1047         @DefinedBy(Api.COMPILER_TREE)
1048         public Kind getKind() { return Kind.BLOCK; }
1049         @DefinedBy(Api.COMPILER_TREE)
1050         public List<JCStatement> getStatements() {
1051             return stats;
1052         }
1053         @DefinedBy(Api.COMPILER_TREE)
1054         public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
1055         @Override @DefinedBy(Api.COMPILER_TREE)
1056         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1057             return v.visitBlock(this, d);
1058         }
1059 
1060         @Override
1061         public Tag getTag() {
1062             return BLOCK;
1063         }
1064     }
1065 
1066     /**
1067      * A do loop
1068      */
1069     public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
1070         public JCStatement body;
1071         public JCExpression cond;
1072         protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
1073             this.body = body;
1074             this.cond = cond;
1075         }
1076         @Override
1077         public void accept(Visitor v) { v.visitDoLoop(this); }
1078 
1079         @DefinedBy(Api.COMPILER_TREE)
1080         public Kind getKind() { return Kind.DO_WHILE_LOOP; }
1081         @DefinedBy(Api.COMPILER_TREE)
1082         public JCExpression getCondition() { return cond; }
1083         @DefinedBy(Api.COMPILER_TREE)
1084         public JCStatement getStatement() { return body; }
1085         @Override @DefinedBy(Api.COMPILER_TREE)
1086         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1087             return v.visitDoWhileLoop(this, d);
1088         }
1089 
1090         @Override
1091         public Tag getTag() {
1092             return DOLOOP;
1093         }
1094     }
1095 
1096     /**
1097      * A while loop
1098      */
1099     public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
1100         public JCExpression cond;
1101         public JCStatement body;
1102         protected JCWhileLoop(JCExpression cond, JCStatement body) {
1103             this.cond = cond;
1104             this.body = body;
1105         }
1106         @Override
1107         public void accept(Visitor v) { v.visitWhileLoop(this); }
1108 
1109         @DefinedBy(Api.COMPILER_TREE)
1110         public Kind getKind() { return Kind.WHILE_LOOP; }
1111         @DefinedBy(Api.COMPILER_TREE)
1112         public JCExpression getCondition() { return cond; }
1113         @DefinedBy(Api.COMPILER_TREE)
1114         public JCStatement getStatement() { return body; }
1115         @Override @DefinedBy(Api.COMPILER_TREE)
1116         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1117             return v.visitWhileLoop(this, d);
1118         }
1119 
1120         @Override
1121         public Tag getTag() {
1122             return WHILELOOP;
1123         }
1124     }
1125 
1126     /**
1127      * A withfield expression
1128      */
1129     public static class JCWithField extends JCExpression implements WithFieldTree {
1130         public JCExpression field;
1131         public JCExpression value;
1132         protected JCWithField(JCExpression field, JCExpression value) {
1133             this.field = field;
1134             this.value = value;
1135         }
1136         @Override
1137         public void accept(Visitor v) { v.visitWithField(this); }
1138 
1139         @DefinedBy(Api.COMPILER_TREE)
1140         public Kind getKind() { return Kind.WITH_FIELD; }
1141         @DefinedBy(Api.COMPILER_TREE)
1142         public JCExpression getField() { return field; }
1143         @DefinedBy(Api.COMPILER_TREE)
1144         public JCExpression getValue() { return value; }
1145         @Override @DefinedBy(Api.COMPILER_TREE)
1146         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1147             return v.visitWithField(this, d);
1148         }
1149 
1150         @Override
1151         public Tag getTag() {
1152             return WITHFIELD;
1153         }
1154     }
1155 
1156     /**
1157      * A for loop.
1158      */
1159     public static class JCForLoop extends JCStatement implements ForLoopTree {
1160         public List<JCStatement> init;
1161         public JCExpression cond;
1162         public List<JCExpressionStatement> step;
1163         public JCStatement body;
1164         protected JCForLoop(List<JCStatement> init,
1165                           JCExpression cond,
1166                           List<JCExpressionStatement> update,
1167                           JCStatement body)
1168         {
1169             this.init = init;
1170             this.cond = cond;
1171             this.step = update;
1172             this.body = body;
1173         }
1174         @Override
1175         public void accept(Visitor v) { v.visitForLoop(this); }
1176 
1177         @DefinedBy(Api.COMPILER_TREE)
1178         public Kind getKind() { return Kind.FOR_LOOP; }
1179         @DefinedBy(Api.COMPILER_TREE)
1180         public JCExpression getCondition() { return cond; }
1181         @DefinedBy(Api.COMPILER_TREE)
1182         public JCStatement getStatement() { return body; }
1183         @DefinedBy(Api.COMPILER_TREE)
1184         public List<JCStatement> getInitializer() {
1185             return init;
1186         }
1187         @DefinedBy(Api.COMPILER_TREE)
1188         public List<JCExpressionStatement> getUpdate() {
1189             return step;
1190         }
1191         @Override @DefinedBy(Api.COMPILER_TREE)
1192         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1193             return v.visitForLoop(this, d);
1194         }
1195 
1196         @Override
1197         public Tag getTag() {
1198             return FORLOOP;
1199         }
1200     }
1201 
1202     /**
1203      * The enhanced for loop.
1204      */
1205     public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
1206         public JCVariableDecl var;
1207         public JCExpression expr;
1208         public JCStatement body;
1209         protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
1210             this.var = var;
1211             this.expr = expr;
1212             this.body = body;
1213         }
1214         @Override
1215         public void accept(Visitor v) { v.visitForeachLoop(this); }
1216 
1217         @DefinedBy(Api.COMPILER_TREE)
1218         public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
1219         @DefinedBy(Api.COMPILER_TREE)
1220         public JCVariableDecl getVariable() { return var; }
1221         @DefinedBy(Api.COMPILER_TREE)
1222         public JCExpression getExpression() { return expr; }
1223         @DefinedBy(Api.COMPILER_TREE)
1224         public JCStatement getStatement() { return body; }
1225         @Override @DefinedBy(Api.COMPILER_TREE)
1226         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1227             return v.visitEnhancedForLoop(this, d);
1228         }
1229         @Override
1230         public Tag getTag() {
1231             return FOREACHLOOP;
1232         }
1233     }
1234 
1235     /**
1236      * A labelled expression or statement.
1237      */
1238     public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
1239         public Name label;
1240         public JCStatement body;
1241         protected JCLabeledStatement(Name label, JCStatement body) {
1242             this.label = label;
1243             this.body = body;
1244         }
1245         @Override
1246         public void accept(Visitor v) { v.visitLabelled(this); }
1247         @DefinedBy(Api.COMPILER_TREE)
1248         public Kind getKind() { return Kind.LABELED_STATEMENT; }
1249         @DefinedBy(Api.COMPILER_TREE)
1250         public Name getLabel() { return label; }
1251         @DefinedBy(Api.COMPILER_TREE)
1252         public JCStatement getStatement() { return body; }
1253         @Override @DefinedBy(Api.COMPILER_TREE)
1254         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1255             return v.visitLabeledStatement(this, d);
1256         }
1257         @Override
1258         public Tag getTag() {
1259             return LABELLED;
1260         }
1261     }
1262 
1263     /**
1264      * A "switch ( ) { }" construction.
1265      */
1266     public static class JCSwitch extends JCStatement implements SwitchTree {
1267         public JCExpression selector;
1268         public List<JCCase> cases;
1269         protected JCSwitch(JCExpression selector, List<JCCase> cases) {
1270             this.selector = selector;
1271             this.cases = cases;
1272         }
1273         @Override
1274         public void accept(Visitor v) { v.visitSwitch(this); }
1275 
1276         @DefinedBy(Api.COMPILER_TREE)
1277         public Kind getKind() { return Kind.SWITCH; }
1278         @DefinedBy(Api.COMPILER_TREE)
1279         public JCExpression getExpression() { return selector; }
1280         @DefinedBy(Api.COMPILER_TREE)
1281         public List<JCCase> getCases() { return cases; }
1282         @Override @DefinedBy(Api.COMPILER_TREE)
1283         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1284             return v.visitSwitch(this, d);
1285         }
1286         @Override
1287         public Tag getTag() {
1288             return SWITCH;
1289         }
1290     }
1291 
1292     /**
1293      * A "case  :" of a switch.
1294      */
1295     public static class JCCase extends JCStatement implements CaseTree {
1296         //as CaseKind is deprecated for removal (as it is part of a preview feature),
1297         //using indirection through these fields to avoid unnecessary @SuppressWarnings:
1298         @SuppressWarnings("removal")
1299         public static final CaseKind STATEMENT = CaseKind.STATEMENT;
1300         @SuppressWarnings("removal")
1301         public static final CaseKind RULE = CaseKind.RULE;
1302         @SuppressWarnings("removal")
1303         public final CaseKind caseKind;
1304         public List<JCExpression> pats;
1305         public List<JCStatement> stats;
1306         public JCTree body;
1307         public boolean completesNormally;
1308         protected JCCase(@SuppressWarnings("removal") CaseKind caseKind, List<JCExpression> pats,
1309                          List<JCStatement> stats, JCTree body) {
1310             Assert.checkNonNull(pats);
1311             Assert.check(pats.isEmpty() || pats.head != null);
1312             this.caseKind = caseKind;
1313             this.pats = pats;
1314             this.stats = stats;
1315             this.body = body;
1316         }
1317         @Override
1318         public void accept(Visitor v) { v.visitCase(this); }
1319 
1320         @Override @DefinedBy(Api.COMPILER_TREE)
1321         public Kind getKind() { return Kind.CASE; }
1322         @Override @DefinedBy(Api.COMPILER_TREE)
1323         public JCExpression getExpression() { return pats.head; }
1324         @Override @DefinedBy(Api.COMPILER_TREE)
1325         @SuppressWarnings("removal")
1326         public List<JCExpression> getExpressions() { return pats; }
1327         @Override @DefinedBy(Api.COMPILER_TREE)
1328         @SuppressWarnings("removal")
1329         public List<JCStatement> getStatements() {
1330             return caseKind == CaseKind.STATEMENT ? stats : null;
1331         }
1332         @Override @DefinedBy(Api.COMPILER_TREE)
1333         @SuppressWarnings("removal")
1334         public JCTree getBody() { return body; }
1335         @Override @DefinedBy(Api.COMPILER_TREE)
1336         @SuppressWarnings("removal")
1337         public CaseKind getCaseKind() {
1338             return caseKind;
1339         }
1340         @Override @DefinedBy(Api.COMPILER_TREE)
1341         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1342             return v.visitCase(this, d);
1343         }
1344         @Override
1345         public Tag getTag() {
1346             return CASE;
1347         }
1348     }
1349 
1350     /**
1351      * A "switch ( ) { }" construction.
1352      */
1353     @SuppressWarnings("removal")
1354     public static class JCSwitchExpression extends JCPolyExpression implements SwitchExpressionTree {
1355         public JCExpression selector;
1356         public List<JCCase> cases;
1357         /** Position of closing brace, optional. */
1358         public int endpos = Position.NOPOS;
1359         protected JCSwitchExpression(JCExpression selector, List<JCCase> cases) {
1360             this.selector = selector;
1361             this.cases = cases;
1362         }
1363         @Override
1364         public void accept(Visitor v) { v.visitSwitchExpression(this); }
1365 
1366         @DefinedBy(Api.COMPILER_TREE)
1367         public Kind getKind() { return Kind.SWITCH_EXPRESSION; }
1368         @DefinedBy(Api.COMPILER_TREE)
1369         public JCExpression getExpression() { return selector; }
1370         @DefinedBy(Api.COMPILER_TREE)
1371         public List<JCCase> getCases() { return cases; }
1372         @Override @DefinedBy(Api.COMPILER_TREE)
1373         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1374             return v.visitSwitchExpression(this, d);
1375         }
1376         @Override
1377         public Tag getTag() {
1378             return SWITCH_EXPRESSION;
1379         }
1380     }
1381 
1382     /**
1383      * A synchronized block.
1384      */
1385     public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1386         public JCExpression lock;
1387         public JCBlock body;
1388         protected JCSynchronized(JCExpression lock, JCBlock body) {
1389             this.lock = lock;
1390             this.body = body;
1391         }
1392         @Override
1393         public void accept(Visitor v) { v.visitSynchronized(this); }
1394 
1395         @DefinedBy(Api.COMPILER_TREE)
1396         public Kind getKind() { return Kind.SYNCHRONIZED; }
1397         @DefinedBy(Api.COMPILER_TREE)
1398         public JCExpression getExpression() { return lock; }
1399         @DefinedBy(Api.COMPILER_TREE)
1400         public JCBlock getBlock() { return body; }
1401         @Override @DefinedBy(Api.COMPILER_TREE)
1402         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1403             return v.visitSynchronized(this, d);
1404         }
1405         @Override
1406         public Tag getTag() {
1407             return SYNCHRONIZED;
1408         }
1409     }
1410 
1411     /**
1412      * A "try { } catch ( ) { } finally { }" block.
1413      */
1414     public static class JCTry extends JCStatement implements TryTree {
1415         public JCBlock body;
1416         public List<JCCatch> catchers;
1417         public JCBlock finalizer;
1418         public List<JCTree> resources;
1419         public boolean finallyCanCompleteNormally;
1420         protected JCTry(List<JCTree> resources,
1421                         JCBlock body,
1422                         List<JCCatch> catchers,
1423                         JCBlock finalizer) {
1424             this.body = body;
1425             this.catchers = catchers;
1426             this.finalizer = finalizer;
1427             this.resources = resources;
1428         }
1429         @Override
1430         public void accept(Visitor v) { v.visitTry(this); }
1431 
1432         @DefinedBy(Api.COMPILER_TREE)
1433         public Kind getKind() { return Kind.TRY; }
1434         @DefinedBy(Api.COMPILER_TREE)
1435         public JCBlock getBlock() { return body; }
1436         @DefinedBy(Api.COMPILER_TREE)
1437         public List<JCCatch> getCatches() {
1438             return catchers;
1439         }
1440         @DefinedBy(Api.COMPILER_TREE)
1441         public JCBlock getFinallyBlock() { return finalizer; }
1442         @Override @DefinedBy(Api.COMPILER_TREE)
1443         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1444             return v.visitTry(this, d);
1445         }
1446         @Override @DefinedBy(Api.COMPILER_TREE)
1447         public List<JCTree> getResources() {
1448             return resources;
1449         }
1450         @Override
1451         public Tag getTag() {
1452             return TRY;
1453         }
1454     }
1455 
1456     /**
1457      * A catch block.
1458      */
1459     public static class JCCatch extends JCTree implements CatchTree {
1460         public JCVariableDecl param;
1461         public JCBlock body;
1462         protected JCCatch(JCVariableDecl param, JCBlock body) {
1463             this.param = param;
1464             this.body = body;
1465         }
1466         @Override
1467         public void accept(Visitor v) { v.visitCatch(this); }
1468 
1469         @DefinedBy(Api.COMPILER_TREE)
1470         public Kind getKind() { return Kind.CATCH; }
1471         @DefinedBy(Api.COMPILER_TREE)
1472         public JCVariableDecl getParameter() { return param; }
1473         @DefinedBy(Api.COMPILER_TREE)
1474         public JCBlock getBlock() { return body; }
1475         @Override @DefinedBy(Api.COMPILER_TREE)
1476         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1477             return v.visitCatch(this, d);
1478         }
1479         @Override
1480         public Tag getTag() {
1481             return CATCH;
1482         }
1483     }
1484 
1485     /**
1486      * A ( ) ? ( ) : ( ) conditional expression
1487      */
1488     public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree {
1489         public JCExpression cond;
1490         public JCExpression truepart;
1491         public JCExpression falsepart;
1492         protected JCConditional(JCExpression cond,
1493                               JCExpression truepart,
1494                               JCExpression falsepart)
1495         {
1496             this.cond = cond;
1497             this.truepart = truepart;
1498             this.falsepart = falsepart;
1499         }
1500         @Override
1501         public void accept(Visitor v) { v.visitConditional(this); }
1502 
1503         @DefinedBy(Api.COMPILER_TREE)
1504         public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
1505         @DefinedBy(Api.COMPILER_TREE)
1506         public JCExpression getCondition() { return cond; }
1507         @DefinedBy(Api.COMPILER_TREE)
1508         public JCExpression getTrueExpression() { return truepart; }
1509         @DefinedBy(Api.COMPILER_TREE)
1510         public JCExpression getFalseExpression() { return falsepart; }
1511         @Override @DefinedBy(Api.COMPILER_TREE)
1512         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1513             return v.visitConditionalExpression(this, d);
1514         }
1515         @Override
1516         public Tag getTag() {
1517             return CONDEXPR;
1518         }
1519     }
1520 
1521     /**
1522      * An "if ( ) { } else { }" block
1523      */
1524     public static class JCIf extends JCStatement implements IfTree {
1525         public JCExpression cond;
1526         public JCStatement thenpart;
1527         public JCStatement elsepart;
1528         protected JCIf(JCExpression cond,
1529                      JCStatement thenpart,
1530                      JCStatement elsepart)
1531         {
1532             this.cond = cond;
1533             this.thenpart = thenpart;
1534             this.elsepart = elsepart;
1535         }
1536         @Override
1537         public void accept(Visitor v) { v.visitIf(this); }
1538 
1539         @DefinedBy(Api.COMPILER_TREE)
1540         public Kind getKind() { return Kind.IF; }
1541         @DefinedBy(Api.COMPILER_TREE)
1542         public JCExpression getCondition() { return cond; }
1543         @DefinedBy(Api.COMPILER_TREE)
1544         public JCStatement getThenStatement() { return thenpart; }
1545         @DefinedBy(Api.COMPILER_TREE)
1546         public JCStatement getElseStatement() { return elsepart; }
1547         @Override @DefinedBy(Api.COMPILER_TREE)
1548         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1549             return v.visitIf(this, d);
1550         }
1551         @Override
1552         public Tag getTag() {
1553             return IF;
1554         }
1555     }
1556 
1557     /**
1558      * an expression statement
1559      */
1560     public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
1561         /** expression structure */
1562         public JCExpression expr;
1563         protected JCExpressionStatement(JCExpression expr)
1564         {
1565             this.expr = expr;
1566         }
1567         @Override
1568         public void accept(Visitor v) { v.visitExec(this); }
1569 
1570         @DefinedBy(Api.COMPILER_TREE)
1571         public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
1572         @DefinedBy(Api.COMPILER_TREE)
1573         public JCExpression getExpression() { return expr; }
1574         @Override @DefinedBy(Api.COMPILER_TREE)
1575         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1576             return v.visitExpressionStatement(this, d);
1577         }
1578         @Override
1579         public Tag getTag() {
1580             return EXEC;
1581         }
1582 
1583         /** Convert a expression-statement tree to a pretty-printed string. */
1584         @Override
1585         public String toString() {
1586             StringWriter s = new StringWriter();
1587             try {
1588                 new Pretty(s, false).printStat(this);
1589             }
1590             catch (IOException e) {
1591                 // should never happen, because StringWriter is defined
1592                 // never to throw any IOExceptions
1593                 throw new AssertionError(e);
1594             }
1595             return s.toString();
1596         }
1597     }
1598 
1599     /**
1600      * A break from a loop or switch.
1601      */
1602     public static class JCBreak extends JCStatement implements BreakTree {
1603         public Name label;
1604         public JCTree target;
1605         protected JCBreak(Name label, JCTree target) {
1606             this.label = label;
1607             this.target = target;
1608         }
1609         @Override
1610         public void accept(Visitor v) { v.visitBreak(this); }
1611         public boolean isValueBreak() {
1612             return target != null && target.hasTag(SWITCH_EXPRESSION);
1613         }
1614 
1615         @DefinedBy(Api.COMPILER_TREE)
1616         public Kind getKind() { return Kind.BREAK; }
1617         @DefinedBy(Api.COMPILER_TREE)
1618         public Name getLabel() {
1619             return label;
1620         }
1621         @Override @DefinedBy(Api.COMPILER_TREE)
1622         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1623             return v.visitBreak(this, d);
1624         }
1625         @Override
1626         public Tag getTag() {
1627             return BREAK;
1628         }
1629     }
1630 
1631     /**
1632      * A break-with from a switch expression.
1633      */
1634     @SuppressWarnings("removal")
1635     public static class JCYield extends JCStatement implements YieldTree {
1636         public JCExpression value;
1637         public JCTree target;
1638         protected JCYield(JCExpression value, JCTree target) {
1639             this.value = value;
1640             this.target = target;
1641         }
1642         @Override
1643         public void accept(Visitor v) { v.visitYield(this); }
1644         @DefinedBy(Api.COMPILER_TREE)
1645         public Kind getKind() { return Kind.YIELD; }
1646         @DefinedBy(Api.COMPILER_TREE)
1647         public JCExpression getValue() { return value; }
1648         @Override @DefinedBy(Api.COMPILER_TREE)
1649         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1650             return v.visitYield(this, d);
1651         }
1652         @Override
1653         public Tag getTag() {
1654             return YIELD;
1655         }
1656     }
1657 
1658     /**
1659      * A continue of a loop.
1660      */
1661     public static class JCContinue extends JCStatement implements ContinueTree {
1662         public Name label;
1663         public JCTree target;
1664         protected JCContinue(Name label, JCTree target) {
1665             this.label = label;
1666             this.target = target;
1667         }
1668         @Override
1669         public void accept(Visitor v) { v.visitContinue(this); }
1670 
1671         @DefinedBy(Api.COMPILER_TREE)
1672         public Kind getKind() { return Kind.CONTINUE; }
1673         @DefinedBy(Api.COMPILER_TREE)
1674         public Name getLabel() { return label; }
1675         @Override @DefinedBy(Api.COMPILER_TREE)
1676         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1677             return v.visitContinue(this, d);
1678         }
1679         @Override
1680         public Tag getTag() {
1681             return CONTINUE;
1682         }
1683     }
1684 
1685     /**
1686      * A return statement.
1687      */
1688     public static class JCReturn extends JCStatement implements ReturnTree {
1689         public JCExpression expr;
1690         protected JCReturn(JCExpression expr) {
1691             this.expr = expr;
1692         }
1693         @Override
1694         public void accept(Visitor v) { v.visitReturn(this); }
1695 
1696         @DefinedBy(Api.COMPILER_TREE)
1697         public Kind getKind() { return Kind.RETURN; }
1698         @DefinedBy(Api.COMPILER_TREE)
1699         public JCExpression getExpression() { return expr; }
1700         @Override @DefinedBy(Api.COMPILER_TREE)
1701         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1702             return v.visitReturn(this, d);
1703         }
1704         @Override
1705         public Tag getTag() {
1706             return RETURN;
1707         }
1708     }
1709 
1710     /**
1711      * A throw statement.
1712      */
1713     public static class JCThrow extends JCStatement implements ThrowTree {
1714         public JCExpression expr;
1715         protected JCThrow(JCExpression expr) {
1716             this.expr = expr;
1717         }
1718         @Override
1719         public void accept(Visitor v) { v.visitThrow(this); }
1720 
1721         @DefinedBy(Api.COMPILER_TREE)
1722         public Kind getKind() { return Kind.THROW; }
1723         @DefinedBy(Api.COMPILER_TREE)
1724         public JCExpression getExpression() { return expr; }
1725         @Override @DefinedBy(Api.COMPILER_TREE)
1726         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1727             return v.visitThrow(this, d);
1728         }
1729         @Override
1730         public Tag getTag() {
1731             return THROW;
1732         }
1733     }
1734 
1735     /**
1736      * An assert statement.
1737      */
1738     public static class JCAssert extends JCStatement implements AssertTree {
1739         public JCExpression cond;
1740         public JCExpression detail;
1741         protected JCAssert(JCExpression cond, JCExpression detail) {
1742             this.cond = cond;
1743             this.detail = detail;
1744         }
1745         @Override
1746         public void accept(Visitor v) { v.visitAssert(this); }
1747 
1748         @DefinedBy(Api.COMPILER_TREE)
1749         public Kind getKind() { return Kind.ASSERT; }
1750         @DefinedBy(Api.COMPILER_TREE)
1751         public JCExpression getCondition() { return cond; }
1752         @DefinedBy(Api.COMPILER_TREE)
1753         public JCExpression getDetail() { return detail; }
1754         @Override @DefinedBy(Api.COMPILER_TREE)
1755         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1756             return v.visitAssert(this, d);
1757         }
1758         @Override
1759         public Tag getTag() {
1760             return ASSERT;
1761         }
1762     }
1763 
1764     /**
1765      * A method invocation
1766      */
1767     public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree {
1768         public List<JCExpression> typeargs;
1769         public JCExpression meth;
1770         public List<JCExpression> args;
1771         public Type varargsElement;
1772         protected JCMethodInvocation(List<JCExpression> typeargs,
1773                         JCExpression meth,
1774                         List<JCExpression> args)
1775         {
1776             this.typeargs = (typeargs == null) ? List.nil()
1777                                                : typeargs;
1778             this.meth = meth;
1779             this.args = args;
1780         }
1781         @Override
1782         public void accept(Visitor v) { v.visitApply(this); }
1783 
1784         @DefinedBy(Api.COMPILER_TREE)
1785         public Kind getKind() { return Kind.METHOD_INVOCATION; }
1786         @DefinedBy(Api.COMPILER_TREE)
1787         public List<JCExpression> getTypeArguments() {
1788             return typeargs;
1789         }
1790         @DefinedBy(Api.COMPILER_TREE)
1791         public JCExpression getMethodSelect() { return meth; }
1792         @DefinedBy(Api.COMPILER_TREE)
1793         public List<JCExpression> getArguments() {
1794             return args;
1795         }
1796         @Override @DefinedBy(Api.COMPILER_TREE)
1797         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1798             return v.visitMethodInvocation(this, d);
1799         }
1800         @Override
1801         public JCMethodInvocation setType(Type type) {
1802             super.setType(type);
1803             return this;
1804         }
1805         @Override
1806         public Tag getTag() {
1807             return(APPLY);
1808         }
1809     }
1810 
1811     /**
1812      * A new(...) operation.
1813      */
1814     public static class JCNewClass extends JCPolyExpression implements NewClassTree {
1815         public JCExpression encl;
1816         public List<JCExpression> typeargs;
1817         public JCExpression clazz;
1818         public List<JCExpression> args;
1819         public JCClassDecl def;
1820         public Symbol constructor;
1821         public Type varargsElement;
1822         public Type constructorType;
1823         protected JCNewClass(JCExpression encl,
1824                            List<JCExpression> typeargs,
1825                            JCExpression clazz,
1826                            List<JCExpression> args,
1827                            JCClassDecl def)
1828         {
1829             this.encl = encl;
1830             this.typeargs = (typeargs == null) ? List.nil()
1831                                                : typeargs;
1832             this.clazz = clazz;
1833             this.args = args;
1834             this.def = def;
1835         }
1836         @Override
1837         public void accept(Visitor v) { v.visitNewClass(this); }
1838 
1839         @DefinedBy(Api.COMPILER_TREE)
1840         public Kind getKind() { return Kind.NEW_CLASS; }
1841         @DefinedBy(Api.COMPILER_TREE)
1842         public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
1843             return encl;
1844         }
1845         @DefinedBy(Api.COMPILER_TREE)
1846         public List<JCExpression> getTypeArguments() {
1847             return typeargs;
1848         }
1849         @DefinedBy(Api.COMPILER_TREE)
1850         public JCExpression getIdentifier() { return clazz; }
1851         @DefinedBy(Api.COMPILER_TREE)
1852         public List<JCExpression> getArguments() {
1853             return args;
1854         }
1855         @DefinedBy(Api.COMPILER_TREE)
1856         public JCClassDecl getClassBody() { return def; }
1857         @Override @DefinedBy(Api.COMPILER_TREE)
1858         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1859             return v.visitNewClass(this, d);
1860         }
1861         @Override
1862         public Tag getTag() {
1863             return NEWCLASS;
1864         }
1865 
1866         public boolean classDeclRemoved() {
1867             return false;
1868         }
1869     }
1870 
1871     /**
1872      * A new[...] operation.
1873      */
1874     public static class JCNewArray extends JCExpression implements NewArrayTree {
1875         public JCExpression elemtype;
1876         public List<JCExpression> dims;
1877         // type annotations on inner-most component
1878         public List<JCAnnotation> annotations;
1879         // type annotations on dimensions
1880         public List<List<JCAnnotation>> dimAnnotations;
1881         public List<JCExpression> elems;
1882         protected JCNewArray(JCExpression elemtype,
1883                            List<JCExpression> dims,
1884                            List<JCExpression> elems)
1885         {
1886             this.elemtype = elemtype;
1887             this.dims = dims;
1888             this.annotations = List.nil();
1889             this.dimAnnotations = List.nil();
1890             this.elems = elems;
1891         }
1892         @Override
1893         public void accept(Visitor v) { v.visitNewArray(this); }
1894 
1895         @DefinedBy(Api.COMPILER_TREE)
1896         public Kind getKind() { return Kind.NEW_ARRAY; }
1897         @DefinedBy(Api.COMPILER_TREE)
1898         public JCExpression getType() { return elemtype; }
1899         @DefinedBy(Api.COMPILER_TREE)
1900         public List<JCExpression> getDimensions() {
1901             return dims;
1902         }
1903         @DefinedBy(Api.COMPILER_TREE)
1904         public List<JCExpression> getInitializers() {
1905             return elems;
1906         }
1907         @Override @DefinedBy(Api.COMPILER_TREE)
1908         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1909             return v.visitNewArray(this, d);
1910         }
1911         @Override
1912         public Tag getTag() {
1913             return NEWARRAY;
1914         }
1915 
1916         @Override @DefinedBy(Api.COMPILER_TREE)
1917         public List<JCAnnotation> getAnnotations() {
1918             return annotations;
1919         }
1920 
1921         @Override @DefinedBy(Api.COMPILER_TREE)
1922         public List<List<JCAnnotation>> getDimAnnotations() {
1923             return dimAnnotations;
1924         }
1925     }
1926 
1927     /**
1928      * A lambda expression.
1929      */
1930     public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
1931 
1932         public enum ParameterKind {
1933             IMPLICIT,
1934             EXPLICIT
1935         }
1936 
1937         public List<JCVariableDecl> params;
1938         public JCTree body;
1939         public boolean canCompleteNormally = true;
1940         public ParameterKind paramKind;
1941 
1942         public JCLambda(List<JCVariableDecl> params,
1943                         JCTree body) {
1944             this.params = params;
1945             this.body = body;
1946             if (params.isEmpty() ||
1947                 params.head.vartype != null) {
1948                 paramKind = ParameterKind.EXPLICIT;
1949             } else {
1950                 paramKind = ParameterKind.IMPLICIT;
1951             }
1952         }
1953         @Override
1954         public Tag getTag() {
1955             return LAMBDA;
1956         }
1957         @Override
1958         public void accept(Visitor v) {
1959             v.visitLambda(this);
1960         }
1961         @Override @DefinedBy(Api.COMPILER_TREE)
1962         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
1963             return v.visitLambdaExpression(this, d);
1964         }
1965         @DefinedBy(Api.COMPILER_TREE)
1966         public Kind getKind() {
1967             return Kind.LAMBDA_EXPRESSION;
1968         }
1969         @DefinedBy(Api.COMPILER_TREE)
1970         public JCTree getBody() {
1971             return body;
1972         }
1973         @DefinedBy(Api.COMPILER_TREE)
1974         public java.util.List<? extends VariableTree> getParameters() {
1975             return params;
1976         }
1977         @Override
1978         public JCLambda setType(Type type) {
1979             super.setType(type);
1980             return this;
1981         }
1982         @Override @DefinedBy(Api.COMPILER_TREE)
1983         public BodyKind getBodyKind() {
1984             return body.hasTag(BLOCK) ?
1985                     BodyKind.STATEMENT :
1986                     BodyKind.EXPRESSION;
1987         }
1988     }
1989 
1990     /**
1991      * A parenthesized subexpression ( ... )
1992      */
1993     public static class JCParens extends JCExpression implements ParenthesizedTree {
1994         public JCExpression expr;
1995         protected JCParens(JCExpression expr) {
1996             this.expr = expr;
1997         }
1998         @Override
1999         public void accept(Visitor v) { v.visitParens(this); }
2000 
2001         @DefinedBy(Api.COMPILER_TREE)
2002         public Kind getKind() { return Kind.PARENTHESIZED; }
2003         @DefinedBy(Api.COMPILER_TREE)
2004         public JCExpression getExpression() { return expr; }
2005         @Override @DefinedBy(Api.COMPILER_TREE)
2006         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2007             return v.visitParenthesized(this, d);
2008         }
2009         @Override
2010         public Tag getTag() {
2011             return PARENS;
2012         }
2013     }
2014 
2015     /**
2016      * A assignment with "=".
2017      */
2018     public static class JCAssign extends JCExpression implements AssignmentTree {
2019         public JCExpression lhs;
2020         public JCExpression rhs;
2021         protected JCAssign(JCExpression lhs, JCExpression rhs) {
2022             this.lhs = lhs;
2023             this.rhs = rhs;
2024         }
2025         @Override
2026         public void accept(Visitor v) { v.visitAssign(this); }
2027 
2028         @DefinedBy(Api.COMPILER_TREE)
2029         public Kind getKind() { return Kind.ASSIGNMENT; }
2030         @DefinedBy(Api.COMPILER_TREE)
2031         public JCExpression getVariable() { return lhs; }
2032         @DefinedBy(Api.COMPILER_TREE)
2033         public JCExpression getExpression() { return rhs; }
2034         @Override @DefinedBy(Api.COMPILER_TREE)
2035         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2036             return v.visitAssignment(this, d);
2037         }
2038         @Override
2039         public Tag getTag() {
2040             return ASSIGN;
2041         }
2042     }
2043 
2044     public static abstract class JCOperatorExpression extends JCExpression {
2045         public enum OperandPos {
2046             LEFT,
2047             RIGHT
2048         }
2049 
2050         protected Tag opcode;
2051         public OperatorSymbol operator;
2052 
2053         public OperatorSymbol getOperator() {
2054             return operator;
2055         }
2056 
2057         @Override
2058         public Tag getTag() {
2059             return opcode;
2060         }
2061 
2062         public abstract JCExpression getOperand(OperandPos pos);
2063     }
2064 
2065     /**
2066      * An assignment with "+=", "|=" ...
2067      */
2068     public static class JCAssignOp extends JCOperatorExpression implements CompoundAssignmentTree {
2069         public JCExpression lhs;
2070         public JCExpression rhs;
2071         protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, OperatorSymbol operator) {
2072             this.opcode = opcode;
2073             this.lhs = (JCExpression)lhs;
2074             this.rhs = (JCExpression)rhs;
2075             this.operator = operator;
2076         }
2077         @Override
2078         public void accept(Visitor v) { v.visitAssignop(this); }
2079 
2080         @DefinedBy(Api.COMPILER_TREE)
2081         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2082         @DefinedBy(Api.COMPILER_TREE)
2083         public JCExpression getVariable() { return lhs; }
2084         @DefinedBy(Api.COMPILER_TREE)
2085         public JCExpression getExpression() { return rhs; }
2086         @Override @DefinedBy(Api.COMPILER_TREE)
2087         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2088             return v.visitCompoundAssignment(this, d);
2089         }
2090         @Override
2091         public JCExpression getOperand(OperandPos pos) {
2092             return pos == OperandPos.LEFT ? lhs : rhs;
2093         }
2094     }
2095 
2096     /**
2097      * A unary operation.
2098      */
2099     public static class JCUnary extends JCOperatorExpression implements UnaryTree {
2100         public JCExpression arg;
2101         protected JCUnary(Tag opcode, JCExpression arg) {
2102             this.opcode = opcode;
2103             this.arg = arg;
2104         }
2105         @Override
2106         public void accept(Visitor v) { v.visitUnary(this); }
2107 
2108         @DefinedBy(Api.COMPILER_TREE)
2109         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2110         @DefinedBy(Api.COMPILER_TREE)
2111         public JCExpression getExpression() { return arg; }
2112         @Override @DefinedBy(Api.COMPILER_TREE)
2113         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2114             return v.visitUnary(this, d);
2115         }
2116         public void setTag(Tag tag) {
2117             opcode = tag;
2118         }
2119         @Override
2120         public JCExpression getOperand(OperandPos pos) {
2121             return arg;
2122         }
2123     }
2124 
2125     /**
2126      * A binary operation.
2127      */
2128     public static class JCBinary extends JCOperatorExpression implements BinaryTree {
2129         public JCExpression lhs;
2130         public JCExpression rhs;
2131         protected JCBinary(Tag opcode,
2132                          JCExpression lhs,
2133                          JCExpression rhs,
2134                          OperatorSymbol operator) {
2135             this.opcode = opcode;
2136             this.lhs = lhs;
2137             this.rhs = rhs;
2138             this.operator = operator;
2139         }
2140         @Override
2141         public void accept(Visitor v) { v.visitBinary(this); }
2142 
2143         @DefinedBy(Api.COMPILER_TREE)
2144         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2145         @DefinedBy(Api.COMPILER_TREE)
2146         public JCExpression getLeftOperand() { return lhs; }
2147         @DefinedBy(Api.COMPILER_TREE)
2148         public JCExpression getRightOperand() { return rhs; }
2149         @Override @DefinedBy(Api.COMPILER_TREE)
2150         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2151             return v.visitBinary(this, d);
2152         }
2153         @Override
2154         public JCExpression getOperand(OperandPos pos) {
2155             return pos == OperandPos.LEFT ? lhs : rhs;
2156         }
2157     }
2158 
2159     /**
2160      * A type cast.
2161      */
2162     public static class JCTypeCast extends JCExpression implements TypeCastTree {
2163         public JCTree clazz;
2164         public JCExpression expr;
2165         protected JCTypeCast(JCTree clazz, JCExpression expr) {
2166             this.clazz = clazz;
2167             this.expr = expr;
2168         }
2169         @Override
2170         public void accept(Visitor v) { v.visitTypeCast(this); }
2171 
2172         @DefinedBy(Api.COMPILER_TREE)
2173         public Kind getKind() { return Kind.TYPE_CAST; }
2174         @DefinedBy(Api.COMPILER_TREE)
2175         public JCTree getType() { return clazz; }
2176         @DefinedBy(Api.COMPILER_TREE)
2177         public JCExpression getExpression() { return expr; }
2178         @Override @DefinedBy(Api.COMPILER_TREE)
2179         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2180             return v.visitTypeCast(this, d);
2181         }
2182         @Override
2183         public Tag getTag() {
2184             return TYPECAST;
2185         }
2186     }
2187 
2188     /**
2189      * A type test.
2190      */
2191     public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
2192         public JCExpression expr;
2193         public JCTree clazz;
2194         protected JCInstanceOf(JCExpression expr, JCTree clazz) {
2195             this.expr = expr;
2196             this.clazz = clazz;
2197         }
2198         @Override
2199         public void accept(Visitor v) { v.visitTypeTest(this); }
2200 
2201         @DefinedBy(Api.COMPILER_TREE)
2202         public Kind getKind() { return Kind.INSTANCE_OF; }
2203         @DefinedBy(Api.COMPILER_TREE)
2204         public JCTree getType() { return clazz; }
2205         @DefinedBy(Api.COMPILER_TREE)
2206         public JCExpression getExpression() { return expr; }
2207         @Override @DefinedBy(Api.COMPILER_TREE)
2208         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2209             return v.visitInstanceOf(this, d);
2210         }
2211         @Override
2212         public Tag getTag() {
2213             return TYPETEST;
2214         }
2215     }
2216 
2217     /**
2218      * An array selection
2219      */
2220     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
2221         public JCExpression indexed;
2222         public JCExpression index;
2223         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
2224             this.indexed = indexed;
2225             this.index = index;
2226         }
2227         @Override
2228         public void accept(Visitor v) { v.visitIndexed(this); }
2229 
2230         @DefinedBy(Api.COMPILER_TREE)
2231         public Kind getKind() { return Kind.ARRAY_ACCESS; }
2232         @DefinedBy(Api.COMPILER_TREE)
2233         public JCExpression getExpression() { return indexed; }
2234         @DefinedBy(Api.COMPILER_TREE)
2235         public JCExpression getIndex() { return index; }
2236         @Override @DefinedBy(Api.COMPILER_TREE)
2237         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2238             return v.visitArrayAccess(this, d);
2239         }
2240         @Override
2241         public Tag getTag() {
2242             return INDEXED;
2243         }
2244     }
2245 
2246     /**
2247      * Selects through packages and classes
2248      */
2249     public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
2250         /** selected Tree hierarchy */
2251         public JCExpression selected;
2252         /** name of field to select thru */
2253         public Name name;
2254         /** symbol of the selected class */
2255         public Symbol sym;
2256         protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
2257             this.selected = selected;
2258             this.name = name;
2259             this.sym = sym;
2260         }
2261         @Override
2262         public void accept(Visitor v) { v.visitSelect(this); }
2263 
2264         @DefinedBy(Api.COMPILER_TREE)
2265         public Kind getKind() { return Kind.MEMBER_SELECT; }
2266         @DefinedBy(Api.COMPILER_TREE)
2267         public JCExpression getExpression() { return selected; }
2268         @Override @DefinedBy(Api.COMPILER_TREE)
2269         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2270             return v.visitMemberSelect(this, d);
2271         }
2272         @DefinedBy(Api.COMPILER_TREE)
2273         public Name getIdentifier() { return name; }
2274         @Override
2275         public Tag getTag() {
2276             return SELECT;
2277         }
2278     }
2279 
2280     /**
2281      * Selects a member expression.
2282      */
2283     public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
2284 
2285         public ReferenceMode mode;
2286         public ReferenceKind kind;
2287         public Name name;
2288         public JCExpression expr;
2289         public List<JCExpression> typeargs;
2290         public Symbol sym;
2291         public Type varargsElement;
2292         public PolyKind refPolyKind;
2293         public boolean ownerAccessible;
2294         private OverloadKind overloadKind;
2295         public Type referentType;
2296 
2297         public enum OverloadKind {
2298             OVERLOADED,
2299             UNOVERLOADED,
2300             ERROR
2301         }
2302 
2303         /**
2304          * Javac-dependent classification for member references, based
2305          * on relevant properties w.r.t. code-generation
2306          */
2307         public enum ReferenceKind {
2308             /** super # instMethod */
2309             SUPER(ReferenceMode.INVOKE, false),
2310             /** Type # instMethod */
2311             UNBOUND(ReferenceMode.INVOKE, true),
2312             /** Type # staticMethod */
2313             STATIC(ReferenceMode.INVOKE, false),
2314             /** Expr # instMethod */
2315             BOUND(ReferenceMode.INVOKE, false),
2316             /** Inner # new */
2317             IMPLICIT_INNER(ReferenceMode.NEW, false),
2318             /** Toplevel # new */
2319             TOPLEVEL(ReferenceMode.NEW, false),
2320             /** ArrayType # new */
2321             ARRAY_CTOR(ReferenceMode.NEW, false);
2322 
2323             final ReferenceMode mode;
2324             final boolean unbound;
2325 
2326             private ReferenceKind(ReferenceMode mode, boolean unbound) {
2327                 this.mode = mode;
2328                 this.unbound = unbound;
2329             }
2330 
2331             public boolean isUnbound() {
2332                 return unbound;
2333             }
2334         }
2335 
2336         public JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
2337             this.mode = mode;
2338             this.name = name;
2339             this.expr = expr;
2340             this.typeargs = typeargs;
2341         }
2342         @Override
2343         public void accept(Visitor v) { v.visitReference(this); }
2344 
2345         @DefinedBy(Api.COMPILER_TREE)
2346         public Kind getKind() { return Kind.MEMBER_REFERENCE; }
2347         @Override @DefinedBy(Api.COMPILER_TREE)
2348         public ReferenceMode getMode() { return mode; }
2349         @Override @DefinedBy(Api.COMPILER_TREE)
2350         public JCExpression getQualifierExpression() { return expr; }
2351         @Override @DefinedBy(Api.COMPILER_TREE)
2352         public Name getName() { return name; }
2353         @Override @DefinedBy(Api.COMPILER_TREE)
2354         public List<JCExpression> getTypeArguments() { return typeargs; }
2355 
2356         @Override @DefinedBy(Api.COMPILER_TREE)
2357         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2358             return v.visitMemberReference(this, d);
2359         }
2360         @Override
2361         public Tag getTag() {
2362             return REFERENCE;
2363         }
2364         public boolean hasKind(ReferenceKind kind) {
2365             return this.kind == kind;
2366         }
2367 
2368         /**
2369          * @return the overloadKind
2370          */
2371         public OverloadKind getOverloadKind() {
2372             return overloadKind;
2373         }
2374 
2375         /**
2376          * @param overloadKind the overloadKind to set
2377          */
2378         public void setOverloadKind(OverloadKind overloadKind) {
2379             this.overloadKind = overloadKind;
2380         }
2381     }
2382 
2383     /**
2384      * An identifier
2385      */
2386     public static class JCIdent extends JCExpression implements IdentifierTree {
2387         /** the name */
2388         public Name name;
2389         /** the symbol */
2390         public Symbol sym;
2391         protected JCIdent(Name name, Symbol sym) {
2392             this.name = name;
2393             this.sym = sym;
2394         }
2395         @Override
2396         public void accept(Visitor v) { v.visitIdent(this); }
2397 
2398         @DefinedBy(Api.COMPILER_TREE)
2399         public Kind getKind() { return Kind.IDENTIFIER; }
2400         @DefinedBy(Api.COMPILER_TREE)
2401         public Name getName() { return name; }
2402         @Override @DefinedBy(Api.COMPILER_TREE)
2403         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2404             return v.visitIdentifier(this, d);
2405         }
2406         @Override
2407         public Tag getTag() {
2408             return IDENT;
2409         }
2410     }
2411 
2412     /**
2413      * A constant value given literally.
2414      */
2415     public static class JCLiteral extends JCExpression implements LiteralTree {
2416         public TypeTag typetag;
2417         /** value representation */
2418         public Object value;
2419         protected JCLiteral(TypeTag typetag, Object value) {
2420             this.typetag = typetag;
2421             this.value = value;
2422         }
2423         @Override
2424         public void accept(Visitor v) { v.visitLiteral(this); }
2425 
2426         @DefinedBy(Api.COMPILER_TREE)
2427         public Kind getKind() {
2428             return typetag.getKindLiteral();
2429         }
2430 
2431         @DefinedBy(Api.COMPILER_TREE)
2432         public Object getValue() {
2433             switch (typetag) {
2434                 case BOOLEAN:
2435                     int bi = (Integer) value;
2436                     return (bi != 0);
2437                 case CHAR:
2438                     int ci = (Integer) value;
2439                     char c = (char) ci;
2440                     if (c != ci)
2441                         throw new AssertionError("bad value for char literal");
2442                     return c;
2443                 default:
2444                     return value;
2445             }
2446         }
2447         @Override @DefinedBy(Api.COMPILER_TREE)
2448         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2449             return v.visitLiteral(this, d);
2450         }
2451         @Override
2452         public JCLiteral setType(Type type) {
2453             super.setType(type);
2454             return this;
2455         }
2456         @Override
2457         public Tag getTag() {
2458             return LITERAL;
2459         }
2460     }
2461 
2462     /**
2463      * Identifies a basic type.
2464      * @see TypeTag
2465      */
2466     public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
2467         /** the basic type id */
2468         public TypeTag typetag;
2469         protected JCPrimitiveTypeTree(TypeTag typetag) {
2470             this.typetag = typetag;
2471         }
2472         @Override
2473         public void accept(Visitor v) { v.visitTypeIdent(this); }
2474 
2475         @DefinedBy(Api.COMPILER_TREE)
2476         public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
2477         @DefinedBy(Api.COMPILER_TREE)
2478         public TypeKind getPrimitiveTypeKind() {
2479             return typetag.getPrimitiveTypeKind();
2480         }
2481 
2482         @Override @DefinedBy(Api.COMPILER_TREE)
2483         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2484             return v.visitPrimitiveType(this, d);
2485         }
2486         @Override
2487         public Tag getTag() {
2488             return TYPEIDENT;
2489         }
2490     }
2491 
2492     /**
2493      * An array type, A[]
2494      */
2495     public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
2496         public JCExpression elemtype;
2497         protected JCArrayTypeTree(JCExpression elemtype) {
2498             this.elemtype = elemtype;
2499         }
2500         @Override
2501         public void accept(Visitor v) { v.visitTypeArray(this); }
2502 
2503         @DefinedBy(Api.COMPILER_TREE)
2504         public Kind getKind() { return Kind.ARRAY_TYPE; }
2505         @DefinedBy(Api.COMPILER_TREE)
2506         public JCTree getType() { return elemtype; }
2507         @Override @DefinedBy(Api.COMPILER_TREE)
2508         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2509             return v.visitArrayType(this, d);
2510         }
2511         @Override
2512         public Tag getTag() {
2513             return TYPEARRAY;
2514         }
2515     }
2516 
2517     /**
2518      * A parameterized type, {@literal T<...>}
2519      */
2520     public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
2521         public JCExpression clazz;
2522         public List<JCExpression> arguments;
2523         protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
2524             this.clazz = clazz;
2525             this.arguments = arguments;
2526         }
2527         @Override
2528         public void accept(Visitor v) { v.visitTypeApply(this); }
2529 
2530         @DefinedBy(Api.COMPILER_TREE)
2531         public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
2532         @DefinedBy(Api.COMPILER_TREE)
2533         public JCTree getType() { return clazz; }
2534         @DefinedBy(Api.COMPILER_TREE)
2535         public List<JCExpression> getTypeArguments() {
2536             return arguments;
2537         }
2538         @Override @DefinedBy(Api.COMPILER_TREE)
2539         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2540             return v.visitParameterizedType(this, d);
2541         }
2542         @Override
2543         public Tag getTag() {
2544             return TYPEAPPLY;
2545         }
2546     }
2547 
2548     /**
2549      * A union type, T1 | T2 | ... Tn (used in multicatch statements)
2550      */
2551     public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
2552 
2553         public List<JCExpression> alternatives;
2554 
2555         protected JCTypeUnion(List<JCExpression> components) {
2556             this.alternatives = components;
2557         }
2558         @Override
2559         public void accept(Visitor v) { v.visitTypeUnion(this); }
2560 
2561         @DefinedBy(Api.COMPILER_TREE)
2562         public Kind getKind() { return Kind.UNION_TYPE; }
2563 
2564         @DefinedBy(Api.COMPILER_TREE)
2565         public List<JCExpression> getTypeAlternatives() {
2566             return alternatives;
2567         }
2568         @Override @DefinedBy(Api.COMPILER_TREE)
2569         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2570             return v.visitUnionType(this, d);
2571         }
2572         @Override
2573         public Tag getTag() {
2574             return TYPEUNION;
2575         }
2576     }
2577 
2578     /**
2579      * An intersection type, {@code T1 & T2 & ... Tn} (used in cast expressions)
2580      */
2581     public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree {
2582 
2583         public List<JCExpression> bounds;
2584 
2585         protected JCTypeIntersection(List<JCExpression> bounds) {
2586             this.bounds = bounds;
2587         }
2588         @Override
2589         public void accept(Visitor v) { v.visitTypeIntersection(this); }
2590 
2591         @DefinedBy(Api.COMPILER_TREE)
2592         public Kind getKind() { return Kind.INTERSECTION_TYPE; }
2593 
2594         @DefinedBy(Api.COMPILER_TREE)
2595         public List<JCExpression> getBounds() {
2596             return bounds;
2597         }
2598         @Override @DefinedBy(Api.COMPILER_TREE)
2599         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2600             return v.visitIntersectionType(this, d);
2601         }
2602         @Override
2603         public Tag getTag() {
2604             return TYPEINTERSECTION;
2605         }
2606     }
2607 
2608     /**
2609      * A formal class parameter.
2610      */
2611     public static class JCTypeParameter extends JCTree implements TypeParameterTree {
2612         /** name */
2613         public Name name;
2614         /** bounds */
2615         public List<JCExpression> bounds;
2616         /** type annotations on type parameter */
2617         public List<JCAnnotation> annotations;
2618         protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) {
2619             this.name = name;
2620             this.bounds = bounds;
2621             this.annotations = annotations;
2622         }
2623         @Override
2624         public void accept(Visitor v) { v.visitTypeParameter(this); }
2625 
2626         @DefinedBy(Api.COMPILER_TREE)
2627         public Kind getKind() { return Kind.TYPE_PARAMETER; }
2628         @DefinedBy(Api.COMPILER_TREE)
2629         public Name getName() { return name; }
2630         @DefinedBy(Api.COMPILER_TREE)
2631         public List<JCExpression> getBounds() {
2632             return bounds;
2633         }
2634         @DefinedBy(Api.COMPILER_TREE)
2635         public List<JCAnnotation> getAnnotations() {
2636             return annotations;
2637         }
2638         @Override @DefinedBy(Api.COMPILER_TREE)
2639         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2640             return v.visitTypeParameter(this, d);
2641         }
2642         @Override
2643         public Tag getTag() {
2644             return TYPEPARAMETER;
2645         }
2646     }
2647 
2648     public static class JCWildcard extends JCExpression implements WildcardTree {
2649         public TypeBoundKind kind;
2650         public JCTree inner;
2651         protected JCWildcard(TypeBoundKind kind, JCTree inner) {
2652             this.kind = Assert.checkNonNull(kind);
2653             this.inner = inner;
2654         }
2655         @Override
2656         public void accept(Visitor v) { v.visitWildcard(this); }
2657 
2658         @DefinedBy(Api.COMPILER_TREE)
2659         public Kind getKind() {
2660             switch (kind.kind) {
2661             case UNBOUND:
2662                 return Kind.UNBOUNDED_WILDCARD;
2663             case EXTENDS:
2664                 return Kind.EXTENDS_WILDCARD;
2665             case SUPER:
2666                 return Kind.SUPER_WILDCARD;
2667             default:
2668                 throw new AssertionError("Unknown wildcard bound " + kind);
2669             }
2670         }
2671         @DefinedBy(Api.COMPILER_TREE)
2672         public JCTree getBound() { return inner; }
2673         @Override @DefinedBy(Api.COMPILER_TREE)
2674         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2675             return v.visitWildcard(this, d);
2676         }
2677         @Override
2678         public Tag getTag() {
2679             return Tag.WILDCARD;
2680         }
2681     }
2682 
2683     public static class TypeBoundKind extends JCTree {
2684         public BoundKind kind;
2685         protected TypeBoundKind(BoundKind kind) {
2686             this.kind = kind;
2687         }
2688         @Override
2689         public void accept(Visitor v) { v.visitTypeBoundKind(this); }
2690 
2691         @DefinedBy(Api.COMPILER_TREE)
2692         public Kind getKind() {
2693             throw new AssertionError("TypeBoundKind is not part of a public API");
2694         }
2695         @Override @DefinedBy(Api.COMPILER_TREE)
2696         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2697             throw new AssertionError("TypeBoundKind is not part of a public API");
2698         }
2699         @Override
2700         public Tag getTag() {
2701             return TYPEBOUNDKIND;
2702         }
2703     }
2704 
2705     public static class JCAnnotation extends JCExpression implements AnnotationTree {
2706         // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION
2707         private Tag tag;
2708 
2709         public JCTree annotationType;
2710         public List<JCExpression> args;
2711         public Attribute.Compound attribute;
2712 
2713         protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) {
2714             this.tag = tag;
2715             this.annotationType = annotationType;
2716             this.args = args;
2717         }
2718 
2719         @Override
2720         public void accept(Visitor v) { v.visitAnnotation(this); }
2721 
2722         @DefinedBy(Api.COMPILER_TREE)
2723         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2724 
2725         @DefinedBy(Api.COMPILER_TREE)
2726         public JCTree getAnnotationType() { return annotationType; }
2727         @DefinedBy(Api.COMPILER_TREE)
2728         public List<JCExpression> getArguments() {
2729             return args;
2730         }
2731         @Override @DefinedBy(Api.COMPILER_TREE)
2732         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2733             return v.visitAnnotation(this, d);
2734         }
2735         @Override
2736         public Tag getTag() {
2737             return tag;
2738         }
2739     }
2740 
2741     public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
2742         public long flags;
2743         public List<JCAnnotation> annotations;
2744         protected JCModifiers(long flags, List<JCAnnotation> annotations) {
2745             this.flags = flags;
2746             this.annotations = annotations;
2747         }
2748         @Override
2749         public void accept(Visitor v) { v.visitModifiers(this); }
2750 
2751         @DefinedBy(Api.COMPILER_TREE)
2752         public Kind getKind() { return Kind.MODIFIERS; }
2753         @DefinedBy(Api.COMPILER_TREE)
2754         public Set<Modifier> getFlags() {
2755             return Flags.asModifierSet(flags);
2756         }
2757         @DefinedBy(Api.COMPILER_TREE)
2758         public List<JCAnnotation> getAnnotations() {
2759             return annotations;
2760         }
2761         @Override @DefinedBy(Api.COMPILER_TREE)
2762         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2763             return v.visitModifiers(this, d);
2764         }
2765         @Override
2766         public Tag getTag() {
2767             return MODIFIERS;
2768         }
2769     }
2770 
2771     public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
2772         // type annotations
2773         public List<JCAnnotation> annotations;
2774         public JCExpression underlyingType;
2775 
2776         protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
2777             Assert.check(annotations != null && annotations.nonEmpty());
2778             this.annotations = annotations;
2779             this.underlyingType = underlyingType;
2780         }
2781         @Override
2782         public void accept(Visitor v) { v.visitAnnotatedType(this); }
2783 
2784         @DefinedBy(Api.COMPILER_TREE)
2785         public Kind getKind() { return Kind.ANNOTATED_TYPE; }
2786         @DefinedBy(Api.COMPILER_TREE)
2787         public List<JCAnnotation> getAnnotations() {
2788             return annotations;
2789         }
2790         @DefinedBy(Api.COMPILER_TREE)
2791         public JCExpression getUnderlyingType() {
2792             return underlyingType;
2793         }
2794         @Override @DefinedBy(Api.COMPILER_TREE)
2795         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2796             return v.visitAnnotatedType(this, d);
2797         }
2798         @Override
2799         public Tag getTag() {
2800             return ANNOTATED_TYPE;
2801         }
2802     }
2803 
2804     public static abstract class JCDirective extends JCTree
2805         implements DirectiveTree {
2806     }
2807 
2808     public static class JCModuleDecl extends JCTree implements ModuleTree {
2809         public JCModifiers mods;
2810         public ModuleType type;
2811         private final ModuleKind kind;
2812         public JCExpression qualId;
2813         public List<JCDirective> directives;
2814         public ModuleSymbol sym;
2815 
2816         protected JCModuleDecl(JCModifiers mods, ModuleKind kind,
2817                 JCExpression qualId, List<JCDirective> directives) {
2818             this.mods = mods;
2819             this.kind = kind;
2820             this.qualId = qualId;
2821             this.directives = directives;
2822         }
2823 
2824         @Override
2825         public void accept(Visitor v) { v.visitModuleDef(this); }
2826 
2827         @Override @DefinedBy(Api.COMPILER_TREE)
2828         public Kind getKind() {
2829             return Kind.MODULE;
2830         }
2831 
2832         @Override @DefinedBy(Api.COMPILER_TREE)
2833         public List<? extends AnnotationTree> getAnnotations() {
2834             return mods.annotations;
2835         }
2836 
2837         @Override @DefinedBy(Api.COMPILER_TREE)
2838         public ModuleKind getModuleType() {
2839             return kind;
2840         }
2841 
2842         @Override @DefinedBy(Api.COMPILER_TREE)
2843         public JCExpression getName() {
2844             return qualId;
2845         }
2846 
2847         @Override @DefinedBy(Api.COMPILER_TREE)
2848         public List<JCDirective> getDirectives() {
2849             return directives;
2850         }
2851 
2852         @Override @DefinedBy(Api.COMPILER_TREE)
2853         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2854             return v.visitModule(this, d);
2855         }
2856 
2857         @Override
2858         public Tag getTag() {
2859             return MODULEDEF;
2860         }
2861     }
2862 
2863     public static class JCExports extends JCDirective
2864             implements ExportsTree {
2865         public JCExpression qualid;
2866         public List<JCExpression> moduleNames;
2867         public ExportsDirective directive;
2868 
2869         protected JCExports(JCExpression qualId, List<JCExpression> moduleNames) {
2870             this.qualid = qualId;
2871             this.moduleNames = moduleNames;
2872         }
2873 
2874         @Override
2875         public void accept(Visitor v) { v.visitExports(this); }
2876 
2877         @Override @DefinedBy(Api.COMPILER_TREE)
2878         public Kind getKind() {
2879             return Kind.EXPORTS;
2880         }
2881 
2882         @Override @DefinedBy(Api.COMPILER_TREE)
2883         public JCExpression getPackageName() {
2884             return qualid;
2885         }
2886 
2887         @Override @DefinedBy(Api.COMPILER_TREE)
2888         public List<JCExpression> getModuleNames() {
2889             return moduleNames;
2890         }
2891 
2892         @Override @DefinedBy(Api.COMPILER_TREE)
2893         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2894             return v.visitExports(this, d);
2895         }
2896 
2897         @Override
2898         public Tag getTag() {
2899             return Tag.EXPORTS;
2900         }
2901     }
2902 
2903     public static class JCOpens extends JCDirective
2904             implements OpensTree {
2905         public JCExpression qualid;
2906         public List<JCExpression> moduleNames;
2907         public OpensDirective directive;
2908 
2909         protected JCOpens(JCExpression qualId, List<JCExpression> moduleNames) {
2910             this.qualid = qualId;
2911             this.moduleNames = moduleNames;
2912         }
2913 
2914         @Override
2915         public void accept(Visitor v) { v.visitOpens(this); }
2916 
2917         @Override @DefinedBy(Api.COMPILER_TREE)
2918         public Kind getKind() {
2919             return Kind.OPENS;
2920         }
2921 
2922         @Override @DefinedBy(Api.COMPILER_TREE)
2923         public JCExpression getPackageName() {
2924             return qualid;
2925         }
2926 
2927         @Override @DefinedBy(Api.COMPILER_TREE)
2928         public List<JCExpression> getModuleNames() {
2929             return moduleNames;
2930         }
2931 
2932         @Override @DefinedBy(Api.COMPILER_TREE)
2933         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2934             return v.visitOpens(this, d);
2935         }
2936 
2937         @Override
2938         public Tag getTag() {
2939             return Tag.OPENS;
2940         }
2941     }
2942 
2943     public static class JCProvides extends JCDirective
2944             implements ProvidesTree {
2945         public JCExpression serviceName;
2946         public List<JCExpression> implNames;
2947 
2948         protected JCProvides(JCExpression serviceName, List<JCExpression> implNames) {
2949             this.serviceName = serviceName;
2950             this.implNames = implNames;
2951         }
2952 
2953         @Override
2954         public void accept(Visitor v) { v.visitProvides(this); }
2955 
2956         @Override @DefinedBy(Api.COMPILER_TREE)
2957         public Kind getKind() {
2958             return Kind.PROVIDES;
2959         }
2960 
2961         @Override @DefinedBy(Api.COMPILER_TREE)
2962         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2963             return v.visitProvides(this, d);
2964         }
2965 
2966         @Override @DefinedBy(Api.COMPILER_TREE)
2967         public JCExpression getServiceName() {
2968             return serviceName;
2969         }
2970 
2971         @Override @DefinedBy(Api.COMPILER_TREE)
2972         public List<JCExpression> getImplementationNames() {
2973             return implNames;
2974         }
2975 
2976         @Override
2977         public Tag getTag() {
2978             return PROVIDES;
2979         }
2980     }
2981 
2982     public static class JCRequires extends JCDirective
2983             implements RequiresTree {
2984         public boolean isTransitive;
2985         public boolean isStaticPhase;
2986         public JCExpression moduleName;
2987         public RequiresDirective directive;
2988 
2989         protected JCRequires(boolean isTransitive, boolean isStaticPhase, JCExpression moduleName) {
2990             this.isTransitive = isTransitive;
2991             this.isStaticPhase = isStaticPhase;
2992             this.moduleName = moduleName;
2993         }
2994 
2995         @Override
2996         public void accept(Visitor v) { v.visitRequires(this); }
2997 
2998         @Override @DefinedBy(Api.COMPILER_TREE)
2999         public Kind getKind() {
3000             return Kind.REQUIRES;
3001         }
3002 
3003         @Override @DefinedBy(Api.COMPILER_TREE)
3004         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3005             return v.visitRequires(this, d);
3006         }
3007 
3008         @Override @DefinedBy(Api.COMPILER_TREE)
3009         public boolean isTransitive() {
3010             return isTransitive;
3011         }
3012 
3013         @Override @DefinedBy(Api.COMPILER_TREE)
3014         public boolean isStatic() {
3015             return isStaticPhase;
3016         }
3017 
3018         @Override @DefinedBy(Api.COMPILER_TREE)
3019         public JCExpression getModuleName() {
3020             return moduleName;
3021         }
3022 
3023         @Override
3024         public Tag getTag() {
3025             return REQUIRES;
3026         }
3027     }
3028 
3029     public static class JCUses extends JCDirective
3030             implements UsesTree {
3031         public JCExpression qualid;
3032 
3033         protected JCUses(JCExpression qualId) {
3034             this.qualid = qualId;
3035         }
3036 
3037         @Override
3038         public void accept(Visitor v) { v.visitUses(this); }
3039 
3040         @Override @DefinedBy(Api.COMPILER_TREE)
3041         public Kind getKind() {
3042             return Kind.USES;
3043         }
3044 
3045         @Override @DefinedBy(Api.COMPILER_TREE)
3046         public JCExpression getServiceName() {
3047             return qualid;
3048         }
3049 
3050         @Override @DefinedBy(Api.COMPILER_TREE)
3051         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3052             return v.visitUses(this, d);
3053         }
3054 
3055         @Override
3056         public Tag getTag() {
3057             return USES;
3058         }
3059     }
3060 
3061     public static class JCErroneous extends JCExpression
3062             implements ErroneousTree {
3063         public List<? extends JCTree> errs;
3064         protected JCErroneous(List<? extends JCTree> errs) {
3065             this.errs = errs;
3066         }
3067         @Override
3068         public void accept(Visitor v) { v.visitErroneous(this); }
3069 
3070         @DefinedBy(Api.COMPILER_TREE)
3071         public Kind getKind() { return Kind.ERRONEOUS; }
3072 
3073         @DefinedBy(Api.COMPILER_TREE)
3074         public List<? extends JCTree> getErrorTrees() {
3075             return errs;
3076         }
3077 
3078         @Override @DefinedBy(Api.COMPILER_TREE)
3079         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3080             return v.visitErroneous(this, d);
3081         }
3082         @Override
3083         public Tag getTag() {
3084             return ERRONEOUS;
3085         }
3086     }
3087 
3088     /** (let int x = 3; in x+2) */
3089     public static class LetExpr extends JCExpression {
3090         public List<JCStatement> defs;
3091         public JCExpression expr;
3092         /**true if a expr should be run through Gen.genCond:*/
3093         public boolean needsCond;
3094         protected LetExpr(List<JCStatement> defs, JCExpression expr) {
3095             this.defs = defs;
3096             this.expr = expr;
3097         }
3098         @Override
3099         public void accept(Visitor v) { v.visitLetExpr(this); }
3100 
3101         @DefinedBy(Api.COMPILER_TREE)
3102         public Kind getKind() {
3103             throw new AssertionError("LetExpr is not part of a public API");
3104         }
3105         @Override @DefinedBy(Api.COMPILER_TREE)
3106         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3107             throw new AssertionError("LetExpr is not part of a public API");
3108         }
3109         @Override
3110         public Tag getTag() {
3111             return LETEXPR;
3112         }
3113     }
3114 
3115     /** An interface for tree factories
3116      */
3117     public interface Factory {
3118         JCCompilationUnit TopLevel(List<JCTree> defs);
3119         JCPackageDecl PackageDecl(List<JCAnnotation> annotations,
3120                                   JCExpression pid);
3121         JCImport Import(JCTree qualid, boolean staticImport);
3122         JCClassDecl ClassDef(JCModifiers mods,
3123                           Name name,
3124                           List<JCTypeParameter> typarams,
3125                           JCExpression extending,
3126                           List<JCExpression> implementing,
3127                           List<JCTree> defs);
3128         JCMethodDecl MethodDef(JCModifiers mods,
3129                             Name name,
3130                             JCExpression restype,
3131                             List<JCTypeParameter> typarams,
3132                             JCVariableDecl recvparam,
3133                             List<JCVariableDecl> params,
3134                             List<JCExpression> thrown,
3135                             JCBlock body,
3136                             JCExpression defaultValue);
3137         JCVariableDecl VarDef(JCModifiers mods,
3138                       Name name,
3139                       JCExpression vartype,
3140                       JCExpression init);
3141         JCSkip Skip();
3142         JCBlock Block(long flags, List<JCStatement> stats);
3143         JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
3144         JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
3145         JCForLoop ForLoop(List<JCStatement> init,
3146                         JCExpression cond,
3147                         List<JCExpressionStatement> step,
3148                         JCStatement body);
3149         JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
3150         JCLabeledStatement Labelled(Name label, JCStatement body);
3151         JCSwitch Switch(JCExpression selector, List<JCCase> cases);
3152         JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases);
3153         JCCase Case(@SuppressWarnings("removal") CaseKind caseKind, List<JCExpression> pat,
3154                     List<JCStatement> stats, JCTree body);
3155         JCSynchronized Synchronized(JCExpression lock, JCBlock body);
3156         JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
3157         JCTry Try(List<JCTree> resources,
3158                   JCBlock body,
3159                   List<JCCatch> catchers,
3160                   JCBlock finalizer);
3161         JCCatch Catch(JCVariableDecl param, JCBlock body);
3162         JCConditional Conditional(JCExpression cond,
3163                                 JCExpression thenpart,
3164                                 JCExpression elsepart);
3165         JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
3166         JCExpressionStatement Exec(JCExpression expr);
3167         JCBreak Break(Name label);
3168         JCYield Yield(JCExpression value);
3169         JCContinue Continue(Name label);
3170         JCReturn Return(JCExpression expr);
3171         JCThrow Throw(JCExpression expr);
3172         JCAssert Assert(JCExpression cond, JCExpression detail);
3173         JCMethodInvocation Apply(List<JCExpression> typeargs,
3174                     JCExpression fn,
3175                     List<JCExpression> args);
3176         JCNewClass NewClass(JCExpression encl,
3177                           List<JCExpression> typeargs,
3178                           JCExpression clazz,
3179                           List<JCExpression> args,
3180                           JCClassDecl def);
3181         JCNewArray NewArray(JCExpression elemtype,
3182                           List<JCExpression> dims,
3183                           List<JCExpression> elems);
3184         JCParens Parens(JCExpression expr);
3185         JCAssign Assign(JCExpression lhs, JCExpression rhs);
3186         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3187         JCUnary Unary(Tag opcode, JCExpression arg);
3188         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3189         JCTypeCast TypeCast(JCTree expr, JCExpression type);
3190         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3191         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3192         JCFieldAccess Select(JCExpression selected, Name selector);
3193         JCIdent Ident(Name idname);
3194         JCLiteral Literal(TypeTag tag, Object value);
3195         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3196         JCArrayTypeTree TypeArray(JCExpression elemtype);
3197         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3198         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3199         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3200         TypeBoundKind TypeBoundKind(BoundKind kind);
3201         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3202         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3203         JCErroneous Erroneous(List<? extends JCTree> errs);
3204         JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3205         JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3206         JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3207         JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3208         JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3209         JCUses Uses(JCExpression qualId);
3210         LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);
3211     }
3212 
3213     /** A generic visitor class for trees.
3214      */
3215     public static abstract class Visitor {
3216         public void visitTopLevel(JCCompilationUnit that)    { visitTree(that); }
3217         public void visitPackageDef(JCPackageDecl that)      { visitTree(that); }
3218         public void visitImport(JCImport that)               { visitTree(that); }
3219         public void visitClassDef(JCClassDecl that)          { visitTree(that); }
3220         public void visitMethodDef(JCMethodDecl that)        { visitTree(that); }
3221         public void visitVarDef(JCVariableDecl that)         { visitTree(that); }
3222         public void visitSkip(JCSkip that)                   { visitTree(that); }
3223         public void visitBlock(JCBlock that)                 { visitTree(that); }
3224         public void visitDoLoop(JCDoWhileLoop that)          { visitTree(that); }
3225         public void visitWhileLoop(JCWhileLoop that)         { visitTree(that); }
3226         public void visitWithField(JCWithField that)         { visitTree(that); }
3227         public void visitForLoop(JCForLoop that)             { visitTree(that); }
3228         public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3229         public void visitLabelled(JCLabeledStatement that)   { visitTree(that); }
3230         public void visitSwitch(JCSwitch that)               { visitTree(that); }
3231         public void visitCase(JCCase that)                   { visitTree(that); }
3232         public void visitSwitchExpression(JCSwitchExpression that)               { visitTree(that); }
3233         public void visitSynchronized(JCSynchronized that)   { visitTree(that); }
3234         public void visitTry(JCTry that)                     { visitTree(that); }
3235         public void visitCatch(JCCatch that)                 { visitTree(that); }
3236         public void visitConditional(JCConditional that)     { visitTree(that); }
3237         public void visitIf(JCIf that)                       { visitTree(that); }
3238         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
3239         public void visitBreak(JCBreak that)                 { visitTree(that); }
3240         public void visitYield(JCYield that)                 { visitTree(that); }
3241         public void visitContinue(JCContinue that)           { visitTree(that); }
3242         public void visitReturn(JCReturn that)               { visitTree(that); }
3243         public void visitThrow(JCThrow that)                 { visitTree(that); }
3244         public void visitAssert(JCAssert that)               { visitTree(that); }
3245         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
3246         public void visitNewClass(JCNewClass that)           { visitTree(that); }
3247         public void visitNewArray(JCNewArray that)           { visitTree(that); }
3248         public void visitLambda(JCLambda that)               { visitTree(that); }
3249         public void visitParens(JCParens that)               { visitTree(that); }
3250         public void visitAssign(JCAssign that)               { visitTree(that); }
3251         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
3252         public void visitUnary(JCUnary that)                 { visitTree(that); }
3253         public void visitBinary(JCBinary that)               { visitTree(that); }
3254         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
3255         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
3256         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
3257         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
3258         public void visitReference(JCMemberReference that)   { visitTree(that); }
3259         public void visitIdent(JCIdent that)                 { visitTree(that); }
3260         public void visitLiteral(JCLiteral that)             { visitTree(that); }
3261         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
3262         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
3263         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
3264         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
3265         public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
3266         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
3267         public void visitWildcard(JCWildcard that)           { visitTree(that); }
3268         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
3269         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
3270         public void visitModifiers(JCModifiers that)         { visitTree(that); }
3271         public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
3272         public void visitErroneous(JCErroneous that)         { visitTree(that); }
3273         public void visitModuleDef(JCModuleDecl that)        { visitTree(that); }
3274         public void visitExports(JCExports that)             { visitTree(that); }
3275         public void visitOpens(JCOpens that)                 { visitTree(that); }
3276         public void visitProvides(JCProvides that)           { visitTree(that); }
3277         public void visitRequires(JCRequires that)           { visitTree(that); }
3278         public void visitUses(JCUses that)                   { visitTree(that); }
3279         public void visitLetExpr(LetExpr that)               { visitTree(that); }
3280 
3281         public void visitTree(JCTree that)                   { Assert.error(); }
3282     }
3283 
3284 }