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