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