1 /*
   2  * Copyright (c) 1999, 2024, 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         /** Line starting positions, defined only if option -g is set. */
 542         public Position.LineMap lineMap = null;
 543         /** A table that stores all documentation comments indexed by the tree
 544          * nodes they refer to. defined only if option -s is set. */
 545         public DocCommentTable docComments = null;
 546         /* An object encapsulating ending positions of source ranges indexed by
 547          * the tree nodes they belong to. Defined only if option -Xjcov is set. */
 548         public EndPosTable endPositions = null;
 549         protected JCCompilationUnit(List<JCTree> defs) {
 550             this.defs = defs;
 551         }
 552         @Override
 553         public void accept(Visitor v) { v.visitTopLevel(this); }
 554 
 555         @DefinedBy(Api.COMPILER_TREE)
 556         public Kind getKind() { return Kind.COMPILATION_UNIT; }
 557 
 558         public JCModuleDecl getModuleDecl() {
 559             for (JCTree tree : defs) {
 560                 if (tree.hasTag(MODULEDEF)) {
 561                     return (JCModuleDecl) tree;
 562                 }
 563             }
 564 
 565             return null;
 566         }
 567 
 568         @DefinedBy(Api.COMPILER_TREE)
 569         public JCModuleDecl getModule() {
 570             return getModuleDecl();
 571         }
 572 
 573         @DefinedBy(Api.COMPILER_TREE)
 574         public JCPackageDecl getPackage() {
 575             // PackageDecl must be the first entry if it exists
 576             if (!defs.isEmpty() && defs.head.hasTag(PACKAGEDEF))
 577                 return (JCPackageDecl)defs.head;
 578             return null;
 579         }
 580         @DefinedBy(Api.COMPILER_TREE)
 581         public List<JCAnnotation> getPackageAnnotations() {
 582             JCPackageDecl pd = getPackage();
 583             return pd != null ? pd.getAnnotations() : List.nil();
 584         }
 585         @DefinedBy(Api.COMPILER_TREE)
 586         public ExpressionTree getPackageName() {
 587             JCPackageDecl pd = getPackage();
 588             return pd != null ? pd.getPackageName() : null;
 589         }
 590 
 591         @DefinedBy(Api.COMPILER_TREE)
 592         public List<JCImportBase> getImports() {
 593             ListBuffer<JCImportBase> imports = new ListBuffer<>();
 594             for (JCTree tree : defs) {
 595                 if (tree instanceof JCImportBase imp)
 596                     imports.append(imp);
 597                 else if (!tree.hasTag(PACKAGEDEF) && !tree.hasTag(SKIP))
 598                     break;
 599             }
 600             return imports.toList();
 601         }
 602         @DefinedBy(Api.COMPILER_TREE)
 603         public JavaFileObject getSourceFile() {
 604             return sourcefile;
 605         }
 606         @DefinedBy(Api.COMPILER_TREE)
 607         public Position.LineMap getLineMap() {
 608             return lineMap;
 609         }
 610         @DefinedBy(Api.COMPILER_TREE)
 611         public List<JCTree> getTypeDecls() {
 612             List<JCTree> typeDefs;
 613             for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail) {
 614                 if (!typeDefs.head.hasTag(MODULEDEF)
 615                         && !typeDefs.head.hasTag(PACKAGEDEF)
 616                         && !typeDefs.head.hasTag(IMPORT)
 617                         && !typeDefs.head.hasTag(MODULEIMPORT)) {
 618                     break;
 619                 }
 620             }
 621             return typeDefs;
 622         }
 623         @Override @DefinedBy(Api.COMPILER_TREE)
 624         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 625             return v.visitCompilationUnit(this, d);
 626         }
 627 
 628         @Override
 629         public Tag getTag() {
 630             return TOPLEVEL;
 631         }
 632     }
 633 
 634     /**
 635      * Package definition.
 636      */
 637     public static class JCPackageDecl extends JCTree implements PackageTree {
 638         public List<JCAnnotation> annotations;
 639         /** The tree representing the package clause. */
 640         public JCExpression pid;
 641         public PackageSymbol packge;
 642         public JCPackageDecl(List<JCAnnotation> annotations, JCExpression pid) {
 643             this.annotations = annotations;
 644             this.pid = pid;
 645         }
 646         @Override
 647         public void accept(Visitor v) { v.visitPackageDef(this); }
 648         @DefinedBy(Api.COMPILER_TREE)
 649         public Kind getKind() {
 650             return Kind.PACKAGE;
 651         }
 652         @DefinedBy(Api.COMPILER_TREE)
 653         public List<JCAnnotation> getAnnotations() {
 654             return annotations;
 655         }
 656         @DefinedBy(Api.COMPILER_TREE)
 657         public JCExpression getPackageName() {
 658             return pid;
 659         }
 660         @Override @DefinedBy(Api.COMPILER_TREE)
 661         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 662             return v.visitPackage(this, d);
 663         }
 664         @Override
 665         public Tag getTag() {
 666             return PACKAGEDEF;
 667         }
 668     }
 669 
 670     public static abstract class JCImportBase extends JCTree implements ImportTree {
 671 
 672         @DefinedBy(Api.COMPILER_TREE)
 673         public Kind getKind() { return Kind.IMPORT; }
 674         @Override @DefinedBy(Api.COMPILER_TREE)
 675         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 676             return v.visitImport(this, d);
 677         }
 678 
 679         public abstract JCTree getQualifiedIdentifier();
 680     }
 681 
 682     /**
 683      * An import clause.
 684      */
 685     public static class JCImport extends JCImportBase {
 686         public boolean staticImport;
 687         /** The imported class(es). */
 688         public JCFieldAccess qualid;
 689         public com.sun.tools.javac.code.Scope importScope;
 690         protected JCImport(JCFieldAccess qualid, boolean importStatic) {
 691             this.qualid = qualid;
 692             this.staticImport = importStatic;
 693         }
 694         @Override
 695         public void accept(Visitor v) { v.visitImport(this); }
 696 
 697         @DefinedBy(Api.COMPILER_TREE)
 698         public boolean isStatic() { return staticImport; }
 699         @DefinedBy(Api.COMPILER_TREE)
 700         public boolean isModule() { return false; }
 701         @DefinedBy(Api.COMPILER_TREE)
 702         public JCFieldAccess getQualifiedIdentifier() { return qualid; }
 703 
 704         @Override
 705         public Tag getTag() {
 706             return IMPORT;
 707         }
 708     }
 709 
 710     /**
 711      * A module import clause.
 712      */
 713     public static class JCModuleImport extends JCImportBase {
 714         /** The module name. */
 715         public JCExpression module;
 716         protected JCModuleImport(JCExpression module) {
 717             this.module = module;
 718         }
 719         @Override
 720         public void accept(Visitor v) { v.visitModuleImport(this); }
 721 
 722         @DefinedBy(Api.COMPILER_TREE)
 723         public boolean isStatic() { return false; }
 724         @DefinedBy(Api.COMPILER_TREE)
 725         public boolean isModule() { return true; }
 726         @DefinedBy(Api.COMPILER_TREE)
 727         public JCExpression getQualifiedIdentifier() { return module; }
 728 
 729         @DefinedBy(Api.COMPILER_TREE)
 730         public Kind getKind() { return Kind.IMPORT; }
 731         @Override @DefinedBy(Api.COMPILER_TREE)
 732         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 733             return v.visitImport(this, d);
 734         }
 735 
 736         @Override
 737         public Tag getTag() {
 738             return MODULEIMPORT;
 739         }
 740     }
 741 
 742     public abstract static class JCStatement extends JCTree implements StatementTree {
 743         @Override
 744         public JCStatement setType(Type type) {
 745             super.setType(type);
 746             return this;
 747         }
 748         @Override
 749         public JCStatement setPos(int pos) {
 750             super.setPos(pos);
 751             return this;
 752         }
 753     }
 754 
 755     public abstract static class JCCaseLabel extends JCTree implements CaseLabelTree {
 756     }
 757 
 758     public abstract static class JCExpression extends JCTree implements ExpressionTree {
 759         @Override
 760         public JCExpression setType(Type type) {
 761             super.setType(type);
 762             return this;
 763         }
 764         @Override
 765         public JCExpression setPos(int pos) {
 766             super.setPos(pos);
 767             return this;
 768         }
 769 
 770         public boolean isPoly() { return false; }
 771         public boolean isStandalone() { return true; }
 772 
 773     }
 774 
 775     /**
 776      * Common supertype for all poly expression trees (lambda, method references,
 777      * conditionals, method and constructor calls)
 778      */
 779     public abstract static class JCPolyExpression extends JCExpression {
 780 
 781         /**
 782          * A poly expression can only be truly 'poly' in certain contexts
 783          */
 784         public enum PolyKind {
 785             /** poly expression to be treated as a standalone expression */
 786             STANDALONE,
 787             /** true poly expression */
 788             POLY
 789         }
 790 
 791         /** is this poly expression a 'true' poly expression? */
 792         public PolyKind polyKind;
 793 
 794         @Override public boolean isPoly() { return polyKind == PolyKind.POLY; }
 795         @Override public boolean isStandalone() { return polyKind == PolyKind.STANDALONE; }
 796     }
 797 
 798     /**
 799      * Common supertype for all functional expression trees (lambda and method references)
 800      */
 801     public abstract static sealed class JCFunctionalExpression extends JCPolyExpression
 802                                                                permits JCLambda, JCMemberReference {
 803 
 804         public JCFunctionalExpression() {
 805             //a functional expression is always a 'true' poly
 806             polyKind = PolyKind.POLY;
 807         }
 808 
 809         /** list of target types inferred for this functional expression. */
 810         public Type target;
 811         /** The owner of this functional expression. */
 812         public Symbol owner;
 813         /** code reflection specific metadata. */
 814         public Symbol codeModel;
 815 
 816         public Type getDescriptorType(Types types) {
 817             if (target == null) {
 818                 return types.createErrorType(null);
 819             } else if (target.hasTag(TypeTag.METHOD)) {
 820                 // this is a quoted expression
 821                 return target;
 822             } else {
 823                 return types.findDescriptorType(target);
 824             }
 825         }
 826     }
 827 
 828     /**
 829      * A class definition.
 830      */
 831     public static class JCClassDecl extends JCStatement implements ClassTree {
 832         /** the modifiers */
 833         public JCModifiers mods;
 834         /** the name of the class */
 835         public Name name;
 836         /** formal class parameters */
 837         public List<JCTypeParameter> typarams;
 838         /** the classes this class extends */
 839         public JCExpression extending;
 840         /** the interfaces implemented by this class */
 841         public List<JCExpression> implementing;
 842         /** the subclasses allowed to extend this class, if sealed */
 843         public List<JCExpression> permitting;
 844         /** all variables and methods defined in this class */
 845         public List<JCTree> defs;
 846         /** the symbol */
 847         public ClassSymbol sym;
 848         protected JCClassDecl(JCModifiers mods,
 849                            Name name,
 850                            List<JCTypeParameter> typarams,
 851                            JCExpression extending,
 852                            List<JCExpression> implementing,
 853                            List<JCExpression> permitting,
 854                            List<JCTree> defs,
 855                            ClassSymbol sym)
 856         {
 857             this.mods = mods;
 858             this.name = name;
 859             this.typarams = typarams;
 860             this.extending = extending;
 861             this.implementing = implementing;
 862             this.permitting = permitting;
 863             this.defs = defs;
 864             this.sym = sym;
 865         }
 866         @Override
 867         public void accept(Visitor v) { v.visitClassDef(this); }
 868 
 869         @DefinedBy(Api.COMPILER_TREE)
 870         public Kind getKind() {
 871             if ((mods.flags & Flags.ANNOTATION) != 0)
 872                 return Kind.ANNOTATION_TYPE;
 873             else if ((mods.flags & Flags.INTERFACE) != 0)
 874                 return Kind.INTERFACE;
 875             else if ((mods.flags & Flags.ENUM) != 0)
 876                 return Kind.ENUM;
 877             else if ((mods.flags & Flags.RECORD) != 0)
 878                 return Kind.RECORD;
 879             else
 880                 return Kind.CLASS;
 881         }
 882 
 883         @DefinedBy(Api.COMPILER_TREE)
 884         public JCModifiers getModifiers() { return mods; }
 885         @DefinedBy(Api.COMPILER_TREE)
 886         public Name getSimpleName() { return name; }
 887         @DefinedBy(Api.COMPILER_TREE)
 888         public List<JCTypeParameter> getTypeParameters() {
 889             return typarams;
 890         }
 891         @DefinedBy(Api.COMPILER_TREE)
 892         public JCExpression getExtendsClause() { return extending; }
 893         @DefinedBy(Api.COMPILER_TREE)
 894         public List<JCExpression> getImplementsClause() {
 895             return implementing;
 896         }
 897         @SuppressWarnings("removal")
 898         @DefinedBy(Api.COMPILER_TREE)
 899         public List<JCExpression> getPermitsClause() {
 900             return permitting;
 901         }
 902         @DefinedBy(Api.COMPILER_TREE)
 903         public List<JCTree> getMembers() {
 904             return defs;
 905         }
 906         @Override @DefinedBy(Api.COMPILER_TREE)
 907         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 908             return v.visitClass(this, d);
 909         }
 910 
 911         @Override
 912         public Tag getTag() {
 913             return CLASSDEF;
 914         }
 915     }
 916 
 917     /**
 918      * A method definition.
 919      */
 920     public static class JCMethodDecl extends JCTree implements MethodTree {
 921         /** method modifiers */
 922         public JCModifiers mods;
 923         /** method name */
 924         public Name name;
 925         /** type of method return value */
 926         public JCExpression restype;
 927         /** type parameters */
 928         public List<JCTypeParameter> typarams;
 929         /** receiver parameter */
 930         public JCVariableDecl recvparam;
 931         /** value parameters */
 932         public List<JCVariableDecl> params;
 933         /** exceptions thrown by this method */
 934         public List<JCExpression> thrown;
 935         /** statements in the method */
 936         public JCBlock body;
 937         /** default value, for annotation types */
 938         public JCExpression defaultValue;
 939         /** method symbol */
 940         public MethodSymbol sym;
 941         /** does this method completes normally */
 942         public boolean completesNormally;
 943 
 944         protected JCMethodDecl(JCModifiers mods,
 945                             Name name,
 946                             JCExpression restype,
 947                             List<JCTypeParameter> typarams,
 948                             JCVariableDecl recvparam,
 949                             List<JCVariableDecl> params,
 950                             List<JCExpression> thrown,
 951                             JCBlock body,
 952                             JCExpression defaultValue,
 953                             MethodSymbol sym)
 954         {
 955             this.mods = mods;
 956             this.name = name;
 957             this.restype = restype;
 958             this.typarams = typarams;
 959             this.params = params;
 960             this.recvparam = recvparam;
 961             // TODO: do something special if the given type is null?
 962             // receiver != null ? receiver : List.<JCTypeAnnotation>nil());
 963             this.thrown = thrown;
 964             this.body = body;
 965             this.defaultValue = defaultValue;
 966             this.sym = sym;
 967         }
 968         @Override
 969         public void accept(Visitor v) { v.visitMethodDef(this); }
 970 
 971         @DefinedBy(Api.COMPILER_TREE)
 972         public Kind getKind() { return Kind.METHOD; }
 973         @DefinedBy(Api.COMPILER_TREE)
 974         public JCModifiers getModifiers() { return mods; }
 975         @DefinedBy(Api.COMPILER_TREE)
 976         public Name getName() { return name; }
 977         @DefinedBy(Api.COMPILER_TREE)
 978         public JCTree getReturnType() { return restype; }
 979         @DefinedBy(Api.COMPILER_TREE)
 980         public List<JCTypeParameter> getTypeParameters() {
 981             return typarams;
 982         }
 983         @DefinedBy(Api.COMPILER_TREE)
 984         public List<JCVariableDecl> getParameters() {
 985             return params;
 986         }
 987         @DefinedBy(Api.COMPILER_TREE)
 988         public JCVariableDecl getReceiverParameter() { return recvparam; }
 989         @DefinedBy(Api.COMPILER_TREE)
 990         public List<JCExpression> getThrows() {
 991             return thrown;
 992         }
 993         @DefinedBy(Api.COMPILER_TREE)
 994         public JCBlock getBody() { return body; }
 995         @DefinedBy(Api.COMPILER_TREE)
 996         public JCTree getDefaultValue() { // for annotation types
 997             return defaultValue;
 998         }
 999         @Override @DefinedBy(Api.COMPILER_TREE)
1000         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1001             return v.visitMethod(this, d);
1002         }
1003 
1004         @Override
1005         public Tag getTag() {
1006             return METHODDEF;
1007         }
1008   }
1009 
1010     /**
1011      * A variable definition.
1012      */
1013     public static class JCVariableDecl extends JCStatement implements VariableTree {
1014         /** variable modifiers */
1015         public JCModifiers mods;
1016         /** variable name */
1017         public Name name;
1018         /** variable name expression */
1019         public JCExpression nameexpr;
1020         /** type of the variable */
1021         public JCExpression vartype;
1022         /** variable's initial value */
1023         public JCExpression init;
1024         /** symbol */
1025         public VarSymbol sym;
1026         /** explicit start pos */
1027         public int startPos = Position.NOPOS;
1028         /** declared using `var` */
1029         private boolean declaredUsingVar;
1030 
1031         protected JCVariableDecl(JCModifiers mods,
1032                          Name name,
1033                          JCExpression vartype,
1034                          JCExpression init,
1035                          VarSymbol sym) {
1036             this(mods, name, vartype, init, sym, false);
1037         }
1038 
1039         protected JCVariableDecl(JCModifiers mods,
1040                                  Name name,
1041                                  JCExpression vartype,
1042                                  JCExpression init,
1043                                  VarSymbol sym,
1044                                  boolean declaredUsingVar) {
1045             this.mods = mods;
1046             this.name = name;
1047             this.vartype = vartype;
1048             this.init = init;
1049             this.sym = sym;
1050             this.declaredUsingVar = declaredUsingVar;
1051         }
1052 
1053         protected JCVariableDecl(JCModifiers mods,
1054                          JCExpression nameexpr,
1055                          JCExpression vartype) {
1056             this(mods, null, vartype, null, null, false);
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 declaredUsingVar;
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 endpos = 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 endpos = 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 endpos = 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 final 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         protected JCInstanceOf(JCExpression expr, JCTree pattern) {
2286             this.expr = expr;
2287             this.pattern = pattern;
2288         }
2289         @Override
2290         public void accept(Visitor v) { v.visitTypeTest(this); }
2291 
2292         @DefinedBy(Api.COMPILER_TREE)
2293         public Kind getKind() { return Kind.INSTANCE_OF; }
2294         @DefinedBy(Api.COMPILER_TREE)
2295         public JCTree getType() { return pattern instanceof JCPattern ? pattern.hasTag(BINDINGPATTERN) ? ((JCBindingPattern) pattern).var.vartype : null : pattern; }
2296 
2297         @Override @DefinedBy(Api.COMPILER_TREE)
2298         public JCPattern getPattern() {
2299             return pattern instanceof JCPattern jcPattern ? jcPattern : null;
2300         }
2301 
2302         @DefinedBy(Api.COMPILER_TREE)
2303         public JCExpression getExpression() { return expr; }
2304         @Override @DefinedBy(Api.COMPILER_TREE)
2305         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2306             return v.visitInstanceOf(this, d);
2307         }
2308         @Override
2309         public Tag getTag() {
2310             return TYPETEST;
2311         }
2312     }
2313 
2314     /**
2315      * Pattern matching forms.
2316      */
2317     public abstract static class JCPattern extends JCTree
2318             implements PatternTree {
2319     }
2320 
2321     public static class JCAnyPattern extends JCPattern
2322             implements AnyPatternTree {
2323 
2324         protected JCAnyPattern() {
2325         }
2326 
2327         @Override
2328         public void accept(Visitor v) {
2329             v.visitAnyPattern(this);
2330         }
2331 
2332         @DefinedBy(Api.COMPILER_TREE)
2333         public Kind getKind() {
2334             return Kind.ANY_PATTERN;
2335         }
2336 
2337         @Override
2338         @DefinedBy(Api.COMPILER_TREE)
2339         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2340             return v.visitAnyPattern(this, d);
2341         }
2342 
2343         @Override
2344         public Tag getTag() {
2345             return ANYPATTERN;
2346         }
2347     }
2348 
2349     public static class JCBindingPattern extends JCPattern
2350             implements BindingPatternTree {
2351         public JCVariableDecl var;
2352 
2353         protected JCBindingPattern(JCVariableDecl var) {
2354             this.var = var;
2355         }
2356 
2357         @Override @DefinedBy(Api.COMPILER_TREE)
2358         public VariableTree getVariable() {
2359             return var;
2360         }
2361 
2362         @Override
2363         public void accept(Visitor v) {
2364             v.visitBindingPattern(this);
2365         }
2366 
2367         @DefinedBy(Api.COMPILER_TREE)
2368         public Kind getKind() {
2369             return Kind.BINDING_PATTERN;
2370         }
2371 
2372         @Override
2373         @DefinedBy(Api.COMPILER_TREE)
2374         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2375             return v.visitBindingPattern(this, d);
2376         }
2377 
2378         @Override
2379         public Tag getTag() {
2380             return BINDINGPATTERN;
2381         }
2382     }
2383 
2384     public static class JCDefaultCaseLabel extends JCCaseLabel
2385             implements DefaultCaseLabelTree {
2386 
2387         protected JCDefaultCaseLabel() {
2388         }
2389 
2390         @Override
2391         public void accept(Visitor v) {
2392             v.visitDefaultCaseLabel(this);
2393         }
2394 
2395         @DefinedBy(Api.COMPILER_TREE)
2396         public Kind getKind() {
2397             return Kind.DEFAULT_CASE_LABEL;
2398         }
2399 
2400         @Override
2401         @DefinedBy(Api.COMPILER_TREE)
2402         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2403             return v.visitDefaultCaseLabel(this, d);
2404         }
2405 
2406         @Override
2407         public Tag getTag() {
2408             return DEFAULTCASELABEL;
2409         }
2410 
2411     }
2412 
2413     public static class JCConstantCaseLabel extends JCCaseLabel
2414             implements ConstantCaseLabelTree {
2415 
2416         public JCExpression expr;
2417 
2418         protected JCConstantCaseLabel(JCExpression expr) {
2419             this.expr = expr;
2420         }
2421 
2422         @Override @DefinedBy(Api.COMPILER_TREE)
2423         public JCExpression getConstantExpression() {
2424             return expr;
2425         }
2426 
2427         @Override
2428         public void accept(Visitor v) {
2429             v.visitConstantCaseLabel(this);
2430         }
2431 
2432         @DefinedBy(Api.COMPILER_TREE)
2433         public Kind getKind() {
2434             return Kind.CONSTANT_CASE_LABEL;
2435         }
2436 
2437         @Override
2438         @DefinedBy(Api.COMPILER_TREE)
2439         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2440             return v.visitConstantCaseLabel(this, d);
2441         }
2442 
2443         @Override
2444         public Tag getTag() {
2445             return CONSTANTCASELABEL;
2446         }
2447 
2448     }
2449 
2450     public static class JCPatternCaseLabel extends JCCaseLabel
2451             implements PatternCaseLabelTree {
2452 
2453         public JCPattern pat;
2454         public JCExpression syntheticGuard;
2455 
2456         protected JCPatternCaseLabel(JCPattern pat) {
2457             this.pat = pat;
2458         }
2459 
2460         @Override @DefinedBy(Api.COMPILER_TREE)
2461         public JCPattern getPattern() {
2462             return pat;
2463         }
2464 
2465         @Override
2466         public void accept(Visitor v) {
2467             v.visitPatternCaseLabel(this);
2468         }
2469 
2470         @DefinedBy(Api.COMPILER_TREE)
2471         public Kind getKind() {
2472             return Kind.PATTERN_CASE_LABEL;
2473         }
2474 
2475         @Override
2476         @DefinedBy(Api.COMPILER_TREE)
2477         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2478             return v.visitPatternCaseLabel(this, d);
2479         }
2480 
2481         @Override
2482         public Tag getTag() {
2483             return PATTERNCASELABEL;
2484         }
2485 
2486     }
2487 
2488     public static class JCRecordPattern extends JCPattern
2489             implements DeconstructionPatternTree {
2490         public JCExpression deconstructor;
2491         public List<JCPattern> nested;
2492         public ClassSymbol record;
2493         public List<Type> fullComponentTypes;
2494 
2495         protected JCRecordPattern(JCExpression deconstructor, List<JCPattern> nested) {
2496             this.deconstructor = deconstructor;
2497             this.nested = nested;
2498         }
2499 
2500         @DefinedBy(Api.COMPILER_TREE)
2501         public Name getBinding() {
2502             return null;
2503         }
2504 
2505         @Override @DefinedBy(Api.COMPILER_TREE)
2506         public ExpressionTree getDeconstructor() {
2507             return deconstructor;
2508         }
2509 
2510         @Override @DefinedBy(Api.COMPILER_TREE)
2511         public List<? extends JCPattern> getNestedPatterns() {
2512             return nested;
2513         }
2514 
2515         @Override
2516         public void accept(Visitor v) {
2517             v.visitRecordPattern(this);
2518         }
2519 
2520         @DefinedBy(Api.COMPILER_TREE)
2521         public Kind getKind() {
2522             return Kind.DECONSTRUCTION_PATTERN;
2523         }
2524 
2525         @Override
2526         @DefinedBy(Api.COMPILER_TREE)
2527         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2528             return v.visitDeconstructionPattern(this, d);
2529         }
2530 
2531         @Override
2532         public Tag getTag() {
2533             return RECORDPATTERN;
2534         }
2535 
2536     }
2537 
2538     /**
2539      * An array selection
2540      */
2541     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
2542         public JCExpression indexed;
2543         public JCExpression index;
2544         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
2545             this.indexed = indexed;
2546             this.index = index;
2547         }
2548         @Override
2549         public void accept(Visitor v) { v.visitIndexed(this); }
2550 
2551         @DefinedBy(Api.COMPILER_TREE)
2552         public Kind getKind() { return Kind.ARRAY_ACCESS; }
2553         @DefinedBy(Api.COMPILER_TREE)
2554         public JCExpression getExpression() { return indexed; }
2555         @DefinedBy(Api.COMPILER_TREE)
2556         public JCExpression getIndex() { return index; }
2557         @Override @DefinedBy(Api.COMPILER_TREE)
2558         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2559             return v.visitArrayAccess(this, d);
2560         }
2561         @Override
2562         public Tag getTag() {
2563             return INDEXED;
2564         }
2565     }
2566 
2567     /**
2568      * Selects through packages and classes
2569      */
2570     public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
2571         /** selected Tree hierarchy */
2572         public JCExpression selected;
2573         /** name of field to select thru */
2574         public Name name;
2575         /** symbol of the selected class */
2576         public Symbol sym;
2577         protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
2578             this.selected = selected;
2579             this.name = name;
2580             this.sym = sym;
2581         }
2582         @Override
2583         public void accept(Visitor v) { v.visitSelect(this); }
2584 
2585         @DefinedBy(Api.COMPILER_TREE)
2586         public Kind getKind() { return Kind.MEMBER_SELECT; }
2587         @DefinedBy(Api.COMPILER_TREE)
2588         public JCExpression getExpression() { return selected; }
2589         @Override @DefinedBy(Api.COMPILER_TREE)
2590         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2591             return v.visitMemberSelect(this, d);
2592         }
2593         @DefinedBy(Api.COMPILER_TREE)
2594         public Name getIdentifier() { return name; }
2595         @Override
2596         public Tag getTag() {
2597             return SELECT;
2598         }
2599     }
2600 
2601     /**
2602      * Selects a member expression.
2603      */
2604     public static non-sealed class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
2605 
2606         public ReferenceMode mode;
2607         public ReferenceKind kind;
2608         public Name name;
2609         public JCExpression expr;
2610         public List<JCExpression> typeargs;
2611         public Symbol sym;
2612         public Type varargsElement;
2613         public PolyKind refPolyKind;
2614         public boolean ownerAccessible;
2615         private OverloadKind overloadKind;
2616         public Type referentType;
2617 
2618         public enum OverloadKind {
2619             OVERLOADED,
2620             UNOVERLOADED,
2621             ERROR
2622         }
2623 
2624         /**
2625          * Javac-dependent classification for member references, based
2626          * on relevant properties w.r.t. code-generation
2627          */
2628         public enum ReferenceKind {
2629             /** super # instMethod */
2630             SUPER(ReferenceMode.INVOKE, false),
2631             /** Type # instMethod */
2632             UNBOUND(ReferenceMode.INVOKE, true),
2633             /** Type # staticMethod */
2634             STATIC(ReferenceMode.INVOKE, false),
2635             /** Expr # instMethod */
2636             BOUND(ReferenceMode.INVOKE, false),
2637             /** Inner # new */
2638             IMPLICIT_INNER(ReferenceMode.NEW, false),
2639             /** Toplevel # new */
2640             TOPLEVEL(ReferenceMode.NEW, false),
2641             /** ArrayType # new */
2642             ARRAY_CTOR(ReferenceMode.NEW, false);
2643 
2644             final ReferenceMode mode;
2645             final boolean unbound;
2646 
2647             private ReferenceKind(ReferenceMode mode, boolean unbound) {
2648                 this.mode = mode;
2649                 this.unbound = unbound;
2650             }
2651 
2652             public boolean isUnbound() {
2653                 return unbound;
2654             }
2655         }
2656 
2657         public JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
2658             this.mode = mode;
2659             this.name = name;
2660             this.expr = expr;
2661             this.typeargs = typeargs;
2662         }
2663         @Override
2664         public void accept(Visitor v) { v.visitReference(this); }
2665 
2666         @DefinedBy(Api.COMPILER_TREE)
2667         public Kind getKind() { return Kind.MEMBER_REFERENCE; }
2668         @Override @DefinedBy(Api.COMPILER_TREE)
2669         public ReferenceMode getMode() { return mode; }
2670         @Override @DefinedBy(Api.COMPILER_TREE)
2671         public JCExpression getQualifierExpression() { return expr; }
2672         @Override @DefinedBy(Api.COMPILER_TREE)
2673         public Name getName() { return name; }
2674         @Override @DefinedBy(Api.COMPILER_TREE)
2675         public List<JCExpression> getTypeArguments() { return typeargs; }
2676 
2677         @Override @DefinedBy(Api.COMPILER_TREE)
2678         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2679             return v.visitMemberReference(this, d);
2680         }
2681         @Override
2682         public Tag getTag() {
2683             return REFERENCE;
2684         }
2685         public boolean hasKind(ReferenceKind kind) {
2686             return this.kind == kind;
2687         }
2688 
2689         /**
2690          * @return the overloadKind
2691          */
2692         public OverloadKind getOverloadKind() {
2693             return overloadKind;
2694         }
2695 
2696         /**
2697          * @param overloadKind the overloadKind to set
2698          */
2699         public void setOverloadKind(OverloadKind overloadKind) {
2700             this.overloadKind = overloadKind;
2701         }
2702     }
2703 
2704     /**
2705      * An identifier
2706      */
2707     public static class JCIdent extends JCExpression implements IdentifierTree {
2708         /** the name */
2709         public Name name;
2710         /** the symbol */
2711         public Symbol sym;
2712         protected JCIdent(Name name, Symbol sym) {
2713             this.name = name;
2714             this.sym = sym;
2715         }
2716         @Override
2717         public void accept(Visitor v) { v.visitIdent(this); }
2718 
2719         @DefinedBy(Api.COMPILER_TREE)
2720         public Kind getKind() { return Kind.IDENTIFIER; }
2721         @DefinedBy(Api.COMPILER_TREE)
2722         public Name getName() { return name; }
2723         @Override @DefinedBy(Api.COMPILER_TREE)
2724         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2725             return v.visitIdentifier(this, d);
2726         }
2727         @Override
2728         public Tag getTag() {
2729             return IDENT;
2730         }
2731     }
2732 
2733     /**
2734      * A constant value given literally.
2735      */
2736     public static class JCLiteral extends JCExpression implements LiteralTree {
2737         public TypeTag typetag;
2738         /** value representation */
2739         public Object value;
2740         protected JCLiteral(TypeTag typetag, Object value) {
2741             this.typetag = typetag;
2742             this.value = value;
2743         }
2744         @Override
2745         public void accept(Visitor v) { v.visitLiteral(this); }
2746 
2747         @DefinedBy(Api.COMPILER_TREE)
2748         public Kind getKind() {
2749             return typetag.getKindLiteral();
2750         }
2751 
2752         @DefinedBy(Api.COMPILER_TREE)
2753         public Object getValue() {
2754             switch (typetag) {
2755                 case BOOLEAN:
2756                     int bi = (Integer) value;
2757                     return (bi != 0);
2758                 case CHAR:
2759                     int ci = (Integer) value;
2760                     char c = (char) ci;
2761                     if (c != ci)
2762                         throw new AssertionError("bad value for char literal");
2763                     return c;
2764                 default:
2765                     return value;
2766             }
2767         }
2768         @Override @DefinedBy(Api.COMPILER_TREE)
2769         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2770             return v.visitLiteral(this, d);
2771         }
2772         @Override
2773         public JCLiteral setType(Type type) {
2774             super.setType(type);
2775             return this;
2776         }
2777         @Override
2778         public Tag getTag() {
2779             return LITERAL;
2780         }
2781     }
2782 
2783     /**
2784      * Identifies a basic type.
2785      * @see TypeTag
2786      */
2787     public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
2788         /** the basic type id */
2789         public TypeTag typetag;
2790         protected JCPrimitiveTypeTree(TypeTag typetag) {
2791             this.typetag = typetag;
2792         }
2793         @Override
2794         public void accept(Visitor v) { v.visitTypeIdent(this); }
2795 
2796         @DefinedBy(Api.COMPILER_TREE)
2797         public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
2798         @DefinedBy(Api.COMPILER_TREE)
2799         public TypeKind getPrimitiveTypeKind() {
2800             return typetag.getPrimitiveTypeKind();
2801         }
2802 
2803         @Override @DefinedBy(Api.COMPILER_TREE)
2804         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2805             return v.visitPrimitiveType(this, d);
2806         }
2807         @Override
2808         public Tag getTag() {
2809             return TYPEIDENT;
2810         }
2811     }
2812 
2813     /**
2814      * An array type, A[]
2815      */
2816     public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
2817         public JCExpression elemtype;
2818         protected JCArrayTypeTree(JCExpression elemtype) {
2819             this.elemtype = elemtype;
2820         }
2821         @Override
2822         public void accept(Visitor v) { v.visitTypeArray(this); }
2823 
2824         @DefinedBy(Api.COMPILER_TREE)
2825         public Kind getKind() { return Kind.ARRAY_TYPE; }
2826         @DefinedBy(Api.COMPILER_TREE)
2827         public JCTree getType() { return elemtype; }
2828         @Override @DefinedBy(Api.COMPILER_TREE)
2829         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2830             return v.visitArrayType(this, d);
2831         }
2832         @Override
2833         public Tag getTag() {
2834             return TYPEARRAY;
2835         }
2836     }
2837 
2838     /**
2839      * A parameterized type, {@literal T<...>}
2840      */
2841     public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
2842         public JCExpression clazz;
2843         public List<JCExpression> arguments;
2844         protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
2845             this.clazz = clazz;
2846             this.arguments = arguments;
2847         }
2848         @Override
2849         public void accept(Visitor v) { v.visitTypeApply(this); }
2850 
2851         @DefinedBy(Api.COMPILER_TREE)
2852         public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
2853         @DefinedBy(Api.COMPILER_TREE)
2854         public JCTree getType() { return clazz; }
2855         @DefinedBy(Api.COMPILER_TREE)
2856         public List<JCExpression> getTypeArguments() {
2857             return arguments;
2858         }
2859         @Override @DefinedBy(Api.COMPILER_TREE)
2860         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2861             return v.visitParameterizedType(this, d);
2862         }
2863         @Override
2864         public Tag getTag() {
2865             return TYPEAPPLY;
2866         }
2867     }
2868 
2869     /**
2870      * A union type, T1 | T2 | ... Tn (used in multicatch statements)
2871      */
2872     public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
2873 
2874         public List<JCExpression> alternatives;
2875 
2876         protected JCTypeUnion(List<JCExpression> components) {
2877             this.alternatives = components;
2878         }
2879         @Override
2880         public void accept(Visitor v) { v.visitTypeUnion(this); }
2881 
2882         @DefinedBy(Api.COMPILER_TREE)
2883         public Kind getKind() { return Kind.UNION_TYPE; }
2884 
2885         @DefinedBy(Api.COMPILER_TREE)
2886         public List<JCExpression> getTypeAlternatives() {
2887             return alternatives;
2888         }
2889         @Override @DefinedBy(Api.COMPILER_TREE)
2890         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2891             return v.visitUnionType(this, d);
2892         }
2893         @Override
2894         public Tag getTag() {
2895             return TYPEUNION;
2896         }
2897     }
2898 
2899     /**
2900      * An intersection type, {@code T1 & T2 & ... Tn} (used in cast expressions)
2901      */
2902     public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree {
2903 
2904         public List<JCExpression> bounds;
2905 
2906         protected JCTypeIntersection(List<JCExpression> bounds) {
2907             this.bounds = bounds;
2908         }
2909         @Override
2910         public void accept(Visitor v) { v.visitTypeIntersection(this); }
2911 
2912         @DefinedBy(Api.COMPILER_TREE)
2913         public Kind getKind() { return Kind.INTERSECTION_TYPE; }
2914 
2915         @DefinedBy(Api.COMPILER_TREE)
2916         public List<JCExpression> getBounds() {
2917             return bounds;
2918         }
2919         @Override @DefinedBy(Api.COMPILER_TREE)
2920         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2921             return v.visitIntersectionType(this, d);
2922         }
2923         @Override
2924         public Tag getTag() {
2925             return TYPEINTERSECTION;
2926         }
2927     }
2928 
2929     /**
2930      * A formal class parameter.
2931      */
2932     public static class JCTypeParameter extends JCTree implements TypeParameterTree {
2933         /** name */
2934         public Name name;
2935         /** bounds */
2936         public List<JCExpression> bounds;
2937         /** type annotations on type parameter */
2938         public List<JCAnnotation> annotations;
2939         protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) {
2940             this.name = name;
2941             this.bounds = bounds;
2942             this.annotations = annotations;
2943         }
2944         @Override
2945         public void accept(Visitor v) { v.visitTypeParameter(this); }
2946 
2947         @DefinedBy(Api.COMPILER_TREE)
2948         public Kind getKind() { return Kind.TYPE_PARAMETER; }
2949         @DefinedBy(Api.COMPILER_TREE)
2950         public Name getName() { return name; }
2951         @DefinedBy(Api.COMPILER_TREE)
2952         public List<JCExpression> getBounds() {
2953             return bounds;
2954         }
2955         @DefinedBy(Api.COMPILER_TREE)
2956         public List<JCAnnotation> getAnnotations() {
2957             return annotations;
2958         }
2959         @Override @DefinedBy(Api.COMPILER_TREE)
2960         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2961             return v.visitTypeParameter(this, d);
2962         }
2963         @Override
2964         public Tag getTag() {
2965             return TYPEPARAMETER;
2966         }
2967     }
2968 
2969     public static class JCWildcard extends JCExpression implements WildcardTree {
2970         public TypeBoundKind kind;
2971         public JCTree inner;
2972         protected JCWildcard(TypeBoundKind kind, JCTree inner) {
2973             this.kind = Assert.checkNonNull(kind);
2974             this.inner = inner;
2975         }
2976         @Override
2977         public void accept(Visitor v) { v.visitWildcard(this); }
2978 
2979         @DefinedBy(Api.COMPILER_TREE)
2980         public Kind getKind() {
2981             switch (kind.kind) {
2982             case UNBOUND:
2983                 return Kind.UNBOUNDED_WILDCARD;
2984             case EXTENDS:
2985                 return Kind.EXTENDS_WILDCARD;
2986             case SUPER:
2987                 return Kind.SUPER_WILDCARD;
2988             default:
2989                 throw new AssertionError("Unknown wildcard bound " + kind);
2990             }
2991         }
2992         @DefinedBy(Api.COMPILER_TREE)
2993         public JCTree getBound() { return inner; }
2994         @Override @DefinedBy(Api.COMPILER_TREE)
2995         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2996             return v.visitWildcard(this, d);
2997         }
2998         @Override
2999         public Tag getTag() {
3000             return Tag.WILDCARD;
3001         }
3002     }
3003 
3004     public static class TypeBoundKind extends JCTree {
3005         public BoundKind kind;
3006         protected TypeBoundKind(BoundKind kind) {
3007             this.kind = kind;
3008         }
3009         @Override
3010         public void accept(Visitor v) { v.visitTypeBoundKind(this); }
3011 
3012         @DefinedBy(Api.COMPILER_TREE)
3013         public Kind getKind() {
3014             throw new AssertionError("TypeBoundKind is not part of a public API");
3015         }
3016         @Override @DefinedBy(Api.COMPILER_TREE)
3017         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3018             throw new AssertionError("TypeBoundKind is not part of a public API");
3019         }
3020         @Override
3021         public Tag getTag() {
3022             return TYPEBOUNDKIND;
3023         }
3024     }
3025 
3026     public static class JCAnnotation extends JCExpression implements AnnotationTree {
3027         // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION
3028         private Tag tag;
3029 
3030         public JCTree annotationType;
3031         public List<JCExpression> args;
3032         public Attribute.Compound attribute;
3033 
3034         protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) {
3035             this.tag = tag;
3036             this.annotationType = annotationType;
3037             this.args = args;
3038         }
3039 
3040         @Override
3041         public void accept(Visitor v) { v.visitAnnotation(this); }
3042 
3043         @DefinedBy(Api.COMPILER_TREE)
3044         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
3045 
3046         @DefinedBy(Api.COMPILER_TREE)
3047         public JCTree getAnnotationType() { return annotationType; }
3048         @DefinedBy(Api.COMPILER_TREE)
3049         public List<JCExpression> getArguments() {
3050             return args;
3051         }
3052         @Override @DefinedBy(Api.COMPILER_TREE)
3053         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3054             return v.visitAnnotation(this, d);
3055         }
3056         @Override
3057         public Tag getTag() {
3058             return tag;
3059         }
3060     }
3061 
3062     public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
3063         public long flags;
3064         public List<JCAnnotation> annotations;
3065         protected JCModifiers(long flags, List<JCAnnotation> annotations) {
3066             this.flags = flags;
3067             this.annotations = annotations;
3068         }
3069         @Override
3070         public void accept(Visitor v) { v.visitModifiers(this); }
3071 
3072         @DefinedBy(Api.COMPILER_TREE)
3073         public Kind getKind() { return Kind.MODIFIERS; }
3074         @DefinedBy(Api.COMPILER_TREE)
3075         public Set<Modifier> getFlags() {
3076             return Flags.asModifierSet(flags);
3077         }
3078         @DefinedBy(Api.COMPILER_TREE)
3079         public List<JCAnnotation> getAnnotations() {
3080             return annotations;
3081         }
3082         @Override @DefinedBy(Api.COMPILER_TREE)
3083         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3084             return v.visitModifiers(this, d);
3085         }
3086         @Override
3087         public Tag getTag() {
3088             return MODIFIERS;
3089         }
3090     }
3091 
3092     public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
3093         // type annotations
3094         public List<JCAnnotation> annotations;
3095         public JCExpression underlyingType;
3096 
3097         protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
3098             Assert.check(annotations != null && annotations.nonEmpty());
3099             this.annotations = annotations;
3100             this.underlyingType = underlyingType;
3101         }
3102         @Override
3103         public void accept(Visitor v) { v.visitAnnotatedType(this); }
3104 
3105         @DefinedBy(Api.COMPILER_TREE)
3106         public Kind getKind() { return Kind.ANNOTATED_TYPE; }
3107         @DefinedBy(Api.COMPILER_TREE)
3108         public List<JCAnnotation> getAnnotations() {
3109             return annotations;
3110         }
3111         @DefinedBy(Api.COMPILER_TREE)
3112         public JCExpression getUnderlyingType() {
3113             return underlyingType;
3114         }
3115         @Override @DefinedBy(Api.COMPILER_TREE)
3116         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3117             return v.visitAnnotatedType(this, d);
3118         }
3119         @Override
3120         public Tag getTag() {
3121             return ANNOTATED_TYPE;
3122         }
3123     }
3124 
3125     public abstract static class JCDirective extends JCTree
3126         implements DirectiveTree {
3127     }
3128 
3129     public static class JCModuleDecl extends JCTree implements ModuleTree {
3130         public JCModifiers mods;
3131         public ModuleType type;
3132         private final ModuleKind kind;
3133         public JCExpression qualId;
3134         public List<JCDirective> directives;
3135         public ModuleSymbol sym;
3136 
3137         protected JCModuleDecl(JCModifiers mods, ModuleKind kind,
3138                 JCExpression qualId, List<JCDirective> directives) {
3139             this.mods = mods;
3140             this.kind = kind;
3141             this.qualId = qualId;
3142             this.directives = directives;
3143         }
3144 
3145         @Override
3146         public void accept(Visitor v) { v.visitModuleDef(this); }
3147 
3148         @Override @DefinedBy(Api.COMPILER_TREE)
3149         public Kind getKind() {
3150             return Kind.MODULE;
3151         }
3152 
3153         @Override @DefinedBy(Api.COMPILER_TREE)
3154         public List<? extends AnnotationTree> getAnnotations() {
3155             return mods.annotations;
3156         }
3157 
3158         @Override @DefinedBy(Api.COMPILER_TREE)
3159         public ModuleKind getModuleType() {
3160             return kind;
3161         }
3162 
3163         @Override @DefinedBy(Api.COMPILER_TREE)
3164         public JCExpression getName() {
3165             return qualId;
3166         }
3167 
3168         @Override @DefinedBy(Api.COMPILER_TREE)
3169         public List<JCDirective> getDirectives() {
3170             return directives;
3171         }
3172 
3173         @Override @DefinedBy(Api.COMPILER_TREE)
3174         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3175             return v.visitModule(this, d);
3176         }
3177 
3178         @Override
3179         public Tag getTag() {
3180             return MODULEDEF;
3181         }
3182     }
3183 
3184     public static class JCExports extends JCDirective
3185             implements ExportsTree {
3186         public JCExpression qualid;
3187         public List<JCExpression> moduleNames;
3188         public ExportsDirective directive;
3189 
3190         protected JCExports(JCExpression qualId, List<JCExpression> moduleNames) {
3191             this.qualid = qualId;
3192             this.moduleNames = moduleNames;
3193         }
3194 
3195         @Override
3196         public void accept(Visitor v) { v.visitExports(this); }
3197 
3198         @Override @DefinedBy(Api.COMPILER_TREE)
3199         public Kind getKind() {
3200             return Kind.EXPORTS;
3201         }
3202 
3203         @Override @DefinedBy(Api.COMPILER_TREE)
3204         public JCExpression getPackageName() {
3205             return qualid;
3206         }
3207 
3208         @Override @DefinedBy(Api.COMPILER_TREE)
3209         public List<JCExpression> getModuleNames() {
3210             return moduleNames;
3211         }
3212 
3213         @Override @DefinedBy(Api.COMPILER_TREE)
3214         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3215             return v.visitExports(this, d);
3216         }
3217 
3218         @Override
3219         public Tag getTag() {
3220             return Tag.EXPORTS;
3221         }
3222     }
3223 
3224     public static class JCOpens extends JCDirective
3225             implements OpensTree {
3226         public JCExpression qualid;
3227         public List<JCExpression> moduleNames;
3228         public OpensDirective directive;
3229 
3230         protected JCOpens(JCExpression qualId, List<JCExpression> moduleNames) {
3231             this.qualid = qualId;
3232             this.moduleNames = moduleNames;
3233         }
3234 
3235         @Override
3236         public void accept(Visitor v) { v.visitOpens(this); }
3237 
3238         @Override @DefinedBy(Api.COMPILER_TREE)
3239         public Kind getKind() {
3240             return Kind.OPENS;
3241         }
3242 
3243         @Override @DefinedBy(Api.COMPILER_TREE)
3244         public JCExpression getPackageName() {
3245             return qualid;
3246         }
3247 
3248         @Override @DefinedBy(Api.COMPILER_TREE)
3249         public List<JCExpression> getModuleNames() {
3250             return moduleNames;
3251         }
3252 
3253         @Override @DefinedBy(Api.COMPILER_TREE)
3254         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3255             return v.visitOpens(this, d);
3256         }
3257 
3258         @Override
3259         public Tag getTag() {
3260             return Tag.OPENS;
3261         }
3262     }
3263 
3264     public static class JCProvides extends JCDirective
3265             implements ProvidesTree {
3266         public JCExpression serviceName;
3267         public List<JCExpression> implNames;
3268 
3269         protected JCProvides(JCExpression serviceName, List<JCExpression> implNames) {
3270             this.serviceName = serviceName;
3271             this.implNames = implNames;
3272         }
3273 
3274         @Override
3275         public void accept(Visitor v) { v.visitProvides(this); }
3276 
3277         @Override @DefinedBy(Api.COMPILER_TREE)
3278         public Kind getKind() {
3279             return Kind.PROVIDES;
3280         }
3281 
3282         @Override @DefinedBy(Api.COMPILER_TREE)
3283         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3284             return v.visitProvides(this, d);
3285         }
3286 
3287         @Override @DefinedBy(Api.COMPILER_TREE)
3288         public JCExpression getServiceName() {
3289             return serviceName;
3290         }
3291 
3292         @Override @DefinedBy(Api.COMPILER_TREE)
3293         public List<JCExpression> getImplementationNames() {
3294             return implNames;
3295         }
3296 
3297         @Override
3298         public Tag getTag() {
3299             return PROVIDES;
3300         }
3301     }
3302 
3303     public static class JCRequires extends JCDirective
3304             implements RequiresTree {
3305         public boolean isTransitive;
3306         public boolean isStaticPhase;
3307         public JCExpression moduleName;
3308         public RequiresDirective directive;
3309 
3310         protected JCRequires(boolean isTransitive, boolean isStaticPhase, JCExpression moduleName) {
3311             this.isTransitive = isTransitive;
3312             this.isStaticPhase = isStaticPhase;
3313             this.moduleName = moduleName;
3314         }
3315 
3316         @Override
3317         public void accept(Visitor v) { v.visitRequires(this); }
3318 
3319         @Override @DefinedBy(Api.COMPILER_TREE)
3320         public Kind getKind() {
3321             return Kind.REQUIRES;
3322         }
3323 
3324         @Override @DefinedBy(Api.COMPILER_TREE)
3325         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3326             return v.visitRequires(this, d);
3327         }
3328 
3329         @Override @DefinedBy(Api.COMPILER_TREE)
3330         public boolean isTransitive() {
3331             return isTransitive;
3332         }
3333 
3334         @Override @DefinedBy(Api.COMPILER_TREE)
3335         public boolean isStatic() {
3336             return isStaticPhase;
3337         }
3338 
3339         @Override @DefinedBy(Api.COMPILER_TREE)
3340         public JCExpression getModuleName() {
3341             return moduleName;
3342         }
3343 
3344         @Override
3345         public Tag getTag() {
3346             return REQUIRES;
3347         }
3348     }
3349 
3350     public static class JCUses extends JCDirective
3351             implements UsesTree {
3352         public JCExpression qualid;
3353 
3354         protected JCUses(JCExpression qualId) {
3355             this.qualid = qualId;
3356         }
3357 
3358         @Override
3359         public void accept(Visitor v) { v.visitUses(this); }
3360 
3361         @Override @DefinedBy(Api.COMPILER_TREE)
3362         public Kind getKind() {
3363             return Kind.USES;
3364         }
3365 
3366         @Override @DefinedBy(Api.COMPILER_TREE)
3367         public JCExpression getServiceName() {
3368             return qualid;
3369         }
3370 
3371         @Override @DefinedBy(Api.COMPILER_TREE)
3372         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3373             return v.visitUses(this, d);
3374         }
3375 
3376         @Override
3377         public Tag getTag() {
3378             return USES;
3379         }
3380     }
3381 
3382     public static class JCErroneous extends JCExpression
3383             implements ErroneousTree {
3384         public List<? extends JCTree> errs;
3385         protected JCErroneous(List<? extends JCTree> errs) {
3386             this.errs = errs;
3387         }
3388         @Override
3389         public void accept(Visitor v) { v.visitErroneous(this); }
3390 
3391         @DefinedBy(Api.COMPILER_TREE)
3392         public Kind getKind() { return Kind.ERRONEOUS; }
3393 
3394         @DefinedBy(Api.COMPILER_TREE)
3395         public List<? extends JCTree> getErrorTrees() {
3396             return errs;
3397         }
3398 
3399         @Override @DefinedBy(Api.COMPILER_TREE)
3400         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3401             return v.visitErroneous(this, d);
3402         }
3403         @Override
3404         public Tag getTag() {
3405             return ERRONEOUS;
3406         }
3407     }
3408 
3409     /** (let int x = 3; in x+2) */
3410     public static class LetExpr extends JCExpression {
3411         public List<JCStatement> defs;
3412         public JCExpression expr;
3413         /**true if a expr should be run through Gen.genCond:*/
3414         public boolean needsCond;
3415         protected LetExpr(List<JCStatement> defs, JCExpression expr) {
3416             this.defs = defs;
3417             this.expr = expr;
3418         }
3419         @Override
3420         public void accept(Visitor v) { v.visitLetExpr(this); }
3421 
3422         @DefinedBy(Api.COMPILER_TREE)
3423         public Kind getKind() {
3424             throw new AssertionError("LetExpr is not part of a public API");
3425         }
3426         @Override @DefinedBy(Api.COMPILER_TREE)
3427         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3428             throw new AssertionError("LetExpr is not part of a public API");
3429         }
3430         @Override
3431         public Tag getTag() {
3432             return LETEXPR;
3433         }
3434     }
3435 
3436     /** An interface for tree factories
3437      */
3438     public interface Factory {
3439         JCCompilationUnit TopLevel(List<JCTree> defs);
3440         JCPackageDecl PackageDecl(List<JCAnnotation> annotations,
3441                                   JCExpression pid);
3442         JCImport Import(JCFieldAccess qualid, boolean staticImport);
3443         JCClassDecl ClassDef(JCModifiers mods,
3444                           Name name,
3445                           List<JCTypeParameter> typarams,
3446                           JCExpression extending,
3447                           List<JCExpression> implementing,
3448                           List<JCTree> defs);
3449         JCMethodDecl MethodDef(JCModifiers mods,
3450                             Name name,
3451                             JCExpression restype,
3452                             List<JCTypeParameter> typarams,
3453                             JCVariableDecl recvparam,
3454                             List<JCVariableDecl> params,
3455                             List<JCExpression> thrown,
3456                             JCBlock body,
3457                             JCExpression defaultValue);
3458         JCVariableDecl VarDef(JCModifiers mods,
3459                       Name name,
3460                       JCExpression vartype,
3461                       JCExpression init);
3462         JCSkip Skip();
3463         JCBlock Block(long flags, List<JCStatement> stats);
3464         JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
3465         JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
3466         JCForLoop ForLoop(List<JCStatement> init,
3467                         JCExpression cond,
3468                         List<JCExpressionStatement> step,
3469                         JCStatement body);
3470         JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
3471         JCLabeledStatement Labelled(Name label, JCStatement body);
3472         JCSwitch Switch(JCExpression selector, List<JCCase> cases);
3473         JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases);
3474         JCCase Case(CaseTree.CaseKind caseKind, List<JCCaseLabel> labels, JCExpression guard,
3475                     List<JCStatement> stats, JCTree body);
3476         JCSynchronized Synchronized(JCExpression lock, JCBlock body);
3477         JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
3478         JCTry Try(List<JCTree> resources,
3479                   JCBlock body,
3480                   List<JCCatch> catchers,
3481                   JCBlock finalizer);
3482         JCCatch Catch(JCVariableDecl param, JCBlock body);
3483         JCConditional Conditional(JCExpression cond,
3484                                 JCExpression thenpart,
3485                                 JCExpression elsepart);
3486         JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
3487         JCExpressionStatement Exec(JCExpression expr);
3488         JCBreak Break(Name label);
3489         JCYield Yield(JCExpression value);
3490         JCContinue Continue(Name label);
3491         JCReturn Return(JCExpression expr);
3492         JCThrow Throw(JCExpression expr);
3493         JCAssert Assert(JCExpression cond, JCExpression detail);
3494         JCMethodInvocation Apply(List<JCExpression> typeargs,
3495                     JCExpression fn,
3496                     List<JCExpression> args);
3497         JCNewClass NewClass(JCExpression encl,
3498                           List<JCExpression> typeargs,
3499                           JCExpression clazz,
3500                           List<JCExpression> args,
3501                           JCClassDecl def);
3502         JCNewArray NewArray(JCExpression elemtype,
3503                           List<JCExpression> dims,
3504                           List<JCExpression> elems);
3505         JCParens Parens(JCExpression expr);
3506         JCAssign Assign(JCExpression lhs, JCExpression rhs);
3507         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3508         JCUnary Unary(Tag opcode, JCExpression arg);
3509         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3510         JCTypeCast TypeCast(JCTree expr, JCExpression type);
3511         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3512         JCBindingPattern BindingPattern(JCVariableDecl var);
3513         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3514         JCFieldAccess Select(JCExpression selected, Name selector);
3515         JCIdent Ident(Name idname);
3516         JCLiteral Literal(TypeTag tag, Object value);
3517         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3518         JCArrayTypeTree TypeArray(JCExpression elemtype);
3519         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3520         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3521         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3522         TypeBoundKind TypeBoundKind(BoundKind kind);
3523         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3524         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3525         JCErroneous Erroneous(List<? extends JCTree> errs);
3526         JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3527         JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3528         JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3529         JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3530         JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3531         JCUses Uses(JCExpression qualId);
3532         LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);
3533     }
3534 
3535     /** A generic visitor class for trees.
3536      */
3537     public abstract static class Visitor {
3538         public void visitTopLevel(JCCompilationUnit that)    { visitTree(that); }
3539         public void visitPackageDef(JCPackageDecl that)      { visitTree(that); }
3540         public void visitImport(JCImport that)               { visitTree(that); }
3541         public void visitModuleImport(JCModuleImport that)   { visitTree(that); }
3542         public void visitClassDef(JCClassDecl that)          { visitTree(that); }
3543         public void visitMethodDef(JCMethodDecl that)        { visitTree(that); }
3544         public void visitVarDef(JCVariableDecl that)         { visitTree(that); }
3545         public void visitSkip(JCSkip that)                   { visitTree(that); }
3546         public void visitBlock(JCBlock that)                 { visitTree(that); }
3547         public void visitDoLoop(JCDoWhileLoop that)          { visitTree(that); }
3548         public void visitWhileLoop(JCWhileLoop that)         { visitTree(that); }
3549         public void visitForLoop(JCForLoop that)             { visitTree(that); }
3550         public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3551         public void visitLabelled(JCLabeledStatement that)   { visitTree(that); }
3552         public void visitSwitch(JCSwitch that)               { visitTree(that); }
3553         public void visitCase(JCCase that)                   { visitTree(that); }
3554         public void visitSwitchExpression(JCSwitchExpression that)               { visitTree(that); }
3555         public void visitSynchronized(JCSynchronized that)   { visitTree(that); }
3556         public void visitTry(JCTry that)                     { visitTree(that); }
3557         public void visitCatch(JCCatch that)                 { visitTree(that); }
3558         public void visitConditional(JCConditional that)     { visitTree(that); }
3559         public void visitIf(JCIf that)                       { visitTree(that); }
3560         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
3561         public void visitBreak(JCBreak that)                 { visitTree(that); }
3562         public void visitYield(JCYield that)                 { visitTree(that); }
3563         public void visitContinue(JCContinue that)           { visitTree(that); }
3564         public void visitReturn(JCReturn that)               { visitTree(that); }
3565         public void visitThrow(JCThrow that)                 { visitTree(that); }
3566         public void visitAssert(JCAssert that)               { visitTree(that); }
3567         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
3568         public void visitNewClass(JCNewClass that)           { visitTree(that); }
3569         public void visitNewArray(JCNewArray that)           { visitTree(that); }
3570         public void visitLambda(JCLambda that)               { visitTree(that); }
3571         public void visitParens(JCParens that)               { visitTree(that); }
3572         public void visitAssign(JCAssign that)               { visitTree(that); }
3573         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
3574         public void visitUnary(JCUnary that)                 { visitTree(that); }
3575         public void visitBinary(JCBinary that)               { visitTree(that); }
3576         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
3577         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
3578         public void visitAnyPattern(JCAnyPattern that)       { visitTree(that); }
3579         public void visitBindingPattern(JCBindingPattern that) { visitTree(that); }
3580         public void visitDefaultCaseLabel(JCDefaultCaseLabel that) { visitTree(that); }
3581         public void visitConstantCaseLabel(JCConstantCaseLabel that) { visitTree(that); }
3582         public void visitPatternCaseLabel(JCPatternCaseLabel that) { visitTree(that); }
3583         public void visitRecordPattern(JCRecordPattern that) { visitTree(that); }
3584         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
3585         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
3586         public void visitReference(JCMemberReference that)   { visitTree(that); }
3587         public void visitIdent(JCIdent that)                 { visitTree(that); }
3588         public void visitLiteral(JCLiteral that)             { visitTree(that); }
3589         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
3590         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
3591         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
3592         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
3593         public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
3594         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
3595         public void visitWildcard(JCWildcard that)           { visitTree(that); }
3596         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
3597         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
3598         public void visitModifiers(JCModifiers that)         { visitTree(that); }
3599         public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
3600         public void visitErroneous(JCErroneous that)         { visitTree(that); }
3601         public void visitModuleDef(JCModuleDecl that)        { visitTree(that); }
3602         public void visitExports(JCExports that)             { visitTree(that); }
3603         public void visitOpens(JCOpens that)                 { visitTree(that); }
3604         public void visitProvides(JCProvides that)           { visitTree(that); }
3605         public void visitRequires(JCRequires that)           { visitTree(that); }
3606         public void visitUses(JCUses that)                   { visitTree(that); }
3607         public void visitLetExpr(LetExpr that)               { visitTree(that); }
3608 
3609         public void visitTree(JCTree that)                   { Assert.error(); }
3610     }
3611 
3612 }