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 class JCFunctionalExpression extends JCPolyExpression {
 802 
 803         public JCFunctionalExpression() {
 804             //a functional expression is always a 'true' poly
 805             polyKind = PolyKind.POLY;
 806         }
 807 
 808         /** list of target types inferred for this functional expression. */
 809         public Type target;
 810         /** The owner of this functional expression. */
 811         public Symbol owner;
 812 
 813         public Type getDescriptorType(Types types) {
 814             return target != null ? types.findDescriptorType(target) : types.createErrorType(null);
 815         }
 816     }
 817 
 818     /**
 819      * A class definition.
 820      */
 821     public static class JCClassDecl extends JCStatement implements ClassTree {
 822         /** the modifiers */
 823         public JCModifiers mods;
 824         /** the name of the class */
 825         public Name name;
 826         /** formal class parameters */
 827         public List<JCTypeParameter> typarams;
 828         /** the classes this class extends */
 829         public JCExpression extending;
 830         /** the interfaces implemented by this class */
 831         public List<JCExpression> implementing;
 832         /** the subclasses allowed to extend this class, if sealed */
 833         public List<JCExpression> permitting;
 834         /** all variables and methods defined in this class */
 835         public List<JCTree> defs;
 836         /** the symbol */
 837         public ClassSymbol sym;
 838         protected JCClassDecl(JCModifiers mods,
 839                            Name name,
 840                            List<JCTypeParameter> typarams,
 841                            JCExpression extending,
 842                            List<JCExpression> implementing,
 843                            List<JCExpression> permitting,
 844                            List<JCTree> defs,
 845                            ClassSymbol sym)
 846         {
 847             this.mods = mods;
 848             this.name = name;
 849             this.typarams = typarams;
 850             this.extending = extending;
 851             this.implementing = implementing;
 852             this.permitting = permitting;
 853             this.defs = defs;
 854             this.sym = sym;
 855         }
 856         @Override
 857         public void accept(Visitor v) { v.visitClassDef(this); }
 858 
 859         @DefinedBy(Api.COMPILER_TREE)
 860         public Kind getKind() {
 861             if ((mods.flags & Flags.ANNOTATION) != 0)
 862                 return Kind.ANNOTATION_TYPE;
 863             else if ((mods.flags & Flags.INTERFACE) != 0)
 864                 return Kind.INTERFACE;
 865             else if ((mods.flags & Flags.ENUM) != 0)
 866                 return Kind.ENUM;
 867             else if ((mods.flags & Flags.RECORD) != 0)
 868                 return Kind.RECORD;
 869             else
 870                 return Kind.CLASS;
 871         }
 872 
 873         @DefinedBy(Api.COMPILER_TREE)
 874         public JCModifiers getModifiers() { return mods; }
 875         @DefinedBy(Api.COMPILER_TREE)
 876         public Name getSimpleName() { return name; }
 877         @DefinedBy(Api.COMPILER_TREE)
 878         public List<JCTypeParameter> getTypeParameters() {
 879             return typarams;
 880         }
 881         @DefinedBy(Api.COMPILER_TREE)
 882         public JCExpression getExtendsClause() { return extending; }
 883         @DefinedBy(Api.COMPILER_TREE)
 884         public List<JCExpression> getImplementsClause() {
 885             return implementing;
 886         }
 887         @SuppressWarnings("removal")
 888         @DefinedBy(Api.COMPILER_TREE)
 889         public List<JCExpression> getPermitsClause() {
 890             return permitting;
 891         }
 892         @DefinedBy(Api.COMPILER_TREE)
 893         public List<JCTree> getMembers() {
 894             return defs;
 895         }
 896         @Override @DefinedBy(Api.COMPILER_TREE)
 897         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 898             return v.visitClass(this, d);
 899         }
 900 
 901         @Override
 902         public Tag getTag() {
 903             return CLASSDEF;
 904         }
 905     }
 906 
 907     /**
 908      * A method definition.
 909      */
 910     public static class JCMethodDecl extends JCTree implements MethodTree {
 911         /** method modifiers */
 912         public JCModifiers mods;
 913         /** method name */
 914         public Name name;
 915         /** type of method return value */
 916         public JCExpression restype;
 917         /** type parameters */
 918         public List<JCTypeParameter> typarams;
 919         /** receiver parameter */
 920         public JCVariableDecl recvparam;
 921         /** value parameters */
 922         public List<JCVariableDecl> params;
 923         /** exceptions thrown by this method */
 924         public List<JCExpression> thrown;
 925         /** statements in the method */
 926         public JCBlock body;
 927         /** default value, for annotation types */
 928         public JCExpression defaultValue;
 929         /** method symbol */
 930         public MethodSymbol sym;
 931         /** does this method completes normally */
 932         public boolean completesNormally;
 933 
 934         protected JCMethodDecl(JCModifiers mods,
 935                             Name name,
 936                             JCExpression restype,
 937                             List<JCTypeParameter> typarams,
 938                             JCVariableDecl recvparam,
 939                             List<JCVariableDecl> params,
 940                             List<JCExpression> thrown,
 941                             JCBlock body,
 942                             JCExpression defaultValue,
 943                             MethodSymbol sym)
 944         {
 945             this.mods = mods;
 946             this.name = name;
 947             this.restype = restype;
 948             this.typarams = typarams;
 949             this.params = params;
 950             this.recvparam = recvparam;
 951             // TODO: do something special if the given type is null?
 952             // receiver != null ? receiver : List.<JCTypeAnnotation>nil());
 953             this.thrown = thrown;
 954             this.body = body;
 955             this.defaultValue = defaultValue;
 956             this.sym = sym;
 957         }
 958         @Override
 959         public void accept(Visitor v) { v.visitMethodDef(this); }
 960 
 961         @DefinedBy(Api.COMPILER_TREE)
 962         public Kind getKind() { return Kind.METHOD; }
 963         @DefinedBy(Api.COMPILER_TREE)
 964         public JCModifiers getModifiers() { return mods; }
 965         @DefinedBy(Api.COMPILER_TREE)
 966         public Name getName() { return name; }
 967         @DefinedBy(Api.COMPILER_TREE)
 968         public JCTree getReturnType() { return restype; }
 969         @DefinedBy(Api.COMPILER_TREE)
 970         public List<JCTypeParameter> getTypeParameters() {
 971             return typarams;
 972         }
 973         @DefinedBy(Api.COMPILER_TREE)
 974         public List<JCVariableDecl> getParameters() {
 975             return params;
 976         }
 977         @DefinedBy(Api.COMPILER_TREE)
 978         public JCVariableDecl getReceiverParameter() { return recvparam; }
 979         @DefinedBy(Api.COMPILER_TREE)
 980         public List<JCExpression> getThrows() {
 981             return thrown;
 982         }
 983         @DefinedBy(Api.COMPILER_TREE)
 984         public JCBlock getBody() { return body; }
 985         @DefinedBy(Api.COMPILER_TREE)
 986         public JCTree getDefaultValue() { // for annotation types
 987             return defaultValue;
 988         }
 989         @Override @DefinedBy(Api.COMPILER_TREE)
 990         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
 991             return v.visitMethod(this, d);
 992         }
 993 
 994         @Override
 995         public Tag getTag() {
 996             return METHODDEF;
 997         }
 998   }
 999 
1000     /**
1001      * A variable definition.
1002      */
1003     public static class JCVariableDecl extends JCStatement implements VariableTree {
1004         /** variable modifiers */
1005         public JCModifiers mods;
1006         /** variable name */
1007         public Name name;
1008         /** variable name expression */
1009         public JCExpression nameexpr;
1010         /** type of the variable */
1011         public JCExpression vartype;
1012         /** variable's initial value */
1013         public JCExpression init;
1014         /** symbol */
1015         public VarSymbol sym;
1016         /** explicit start pos */
1017         public int startPos = Position.NOPOS;
1018         /** declared using `var` */
1019         private boolean declaredUsingVar;
1020 
1021         protected JCVariableDecl(JCModifiers mods,
1022                          Name name,
1023                          JCExpression vartype,
1024                          JCExpression init,
1025                          VarSymbol sym) {
1026             this(mods, name, vartype, init, sym, false);
1027         }
1028 
1029         protected JCVariableDecl(JCModifiers mods,
1030                                  Name name,
1031                                  JCExpression vartype,
1032                                  JCExpression init,
1033                                  VarSymbol sym,
1034                                  boolean declaredUsingVar) {
1035             this.mods = mods;
1036             this.name = name;
1037             this.vartype = vartype;
1038             this.init = init;
1039             this.sym = sym;
1040             this.declaredUsingVar = declaredUsingVar;
1041         }
1042 
1043         protected JCVariableDecl(JCModifiers mods,
1044                          JCExpression nameexpr,
1045                          JCExpression vartype) {
1046             this(mods, null, vartype, null, null, false);
1047             this.nameexpr = nameexpr;
1048             if (nameexpr.hasTag(Tag.IDENT)) {
1049                 this.name = ((JCIdent)nameexpr).name;
1050             } else {
1051                 // Only other option is qualified name x.y.this;
1052                 this.name = ((JCFieldAccess)nameexpr).name;
1053             }
1054         }
1055 
1056         public boolean isImplicitlyTyped() {
1057             return vartype == null;
1058         }
1059 
1060         public boolean declaredUsingVar() {
1061             return declaredUsingVar;
1062         }
1063 
1064         @Override
1065         public void accept(Visitor v) { v.visitVarDef(this); }
1066 
1067         @DefinedBy(Api.COMPILER_TREE)
1068         public Kind getKind() { return Kind.VARIABLE; }
1069         @DefinedBy(Api.COMPILER_TREE)
1070         public JCModifiers getModifiers() { return mods; }
1071         @DefinedBy(Api.COMPILER_TREE)
1072         public Name getName() { return name; }
1073         @DefinedBy(Api.COMPILER_TREE)
1074         public JCExpression getNameExpression() { return nameexpr; }
1075         @DefinedBy(Api.COMPILER_TREE)
1076         public JCTree getType() { return vartype; }
1077         @DefinedBy(Api.COMPILER_TREE)
1078         public JCExpression getInitializer() {
1079             return init;
1080         }
1081         @Override @DefinedBy(Api.COMPILER_TREE)
1082         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1083             return v.visitVariable(this, d);
1084         }
1085 
1086         @Override
1087         public Tag getTag() {
1088             return VARDEF;
1089         }
1090     }
1091 
1092     /**
1093      * A no-op statement ";".
1094      */
1095     public static class JCSkip extends JCStatement implements EmptyStatementTree {
1096         protected JCSkip() {
1097         }
1098         @Override
1099         public void accept(Visitor v) { v.visitSkip(this); }
1100 
1101         @DefinedBy(Api.COMPILER_TREE)
1102         public Kind getKind() { return Kind.EMPTY_STATEMENT; }
1103         @Override @DefinedBy(Api.COMPILER_TREE)
1104         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1105             return v.visitEmptyStatement(this, d);
1106         }
1107 
1108         @Override
1109         public Tag getTag() {
1110             return SKIP;
1111         }
1112     }
1113 
1114     /**
1115      * A statement block.
1116      */
1117     public static class JCBlock extends JCStatement implements BlockTree {
1118         /** flags */
1119         public long flags;
1120         /** statements */
1121         public List<JCStatement> stats;
1122         /** Position of closing brace, optional. */
1123         public int endpos = Position.NOPOS;
1124         /** If this block contains record pattern, it is necessary to catch
1125          *  exceptions from the deconstructors and wrap them.
1126          * The {@code patternMatchingCatch} keeps the list of the deconstructor
1127          * invocations, and the additional catch block that wraps the exceptions.
1128          */
1129         public PatternMatchingCatch patternMatchingCatch;
1130         protected JCBlock(long flags, List<JCStatement> stats) {
1131             this.stats = stats;
1132             this.flags = flags;
1133         }
1134         @Override
1135         public void accept(Visitor v) { v.visitBlock(this); }
1136 
1137         @DefinedBy(Api.COMPILER_TREE)
1138         public Kind getKind() { return Kind.BLOCK; }
1139         @DefinedBy(Api.COMPILER_TREE)
1140         public List<JCStatement> getStatements() {
1141             return stats;
1142         }
1143         @DefinedBy(Api.COMPILER_TREE)
1144         public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
1145         @Override @DefinedBy(Api.COMPILER_TREE)
1146         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1147             return v.visitBlock(this, d);
1148         }
1149 
1150         @Override
1151         public Tag getTag() {
1152             return BLOCK;
1153         }
1154 
1155         public record PatternMatchingCatch(JCCatch handler, Set<JCMethodInvocation> calls2Handle) {}
1156     }
1157 
1158     /**
1159      * A do loop
1160      */
1161     public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
1162         public JCStatement body;
1163         public JCExpression cond;
1164         protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
1165             this.body = body;
1166             this.cond = cond;
1167         }
1168         @Override
1169         public void accept(Visitor v) { v.visitDoLoop(this); }
1170 
1171         @DefinedBy(Api.COMPILER_TREE)
1172         public Kind getKind() { return Kind.DO_WHILE_LOOP; }
1173         @DefinedBy(Api.COMPILER_TREE)
1174         public JCExpression getCondition() { return cond; }
1175         @DefinedBy(Api.COMPILER_TREE)
1176         public JCStatement getStatement() { return body; }
1177         @Override @DefinedBy(Api.COMPILER_TREE)
1178         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1179             return v.visitDoWhileLoop(this, d);
1180         }
1181 
1182         @Override
1183         public Tag getTag() {
1184             return DOLOOP;
1185         }
1186     }
1187 
1188     /**
1189      * A while loop
1190      */
1191     public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
1192         public JCExpression cond;
1193         public JCStatement body;
1194         protected JCWhileLoop(JCExpression cond, JCStatement body) {
1195             this.cond = cond;
1196             this.body = body;
1197         }
1198         @Override
1199         public void accept(Visitor v) { v.visitWhileLoop(this); }
1200 
1201         @DefinedBy(Api.COMPILER_TREE)
1202         public Kind getKind() { return Kind.WHILE_LOOP; }
1203         @DefinedBy(Api.COMPILER_TREE)
1204         public JCExpression getCondition() { return cond; }
1205         @DefinedBy(Api.COMPILER_TREE)
1206         public JCStatement getStatement() { return body; }
1207         @Override @DefinedBy(Api.COMPILER_TREE)
1208         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1209             return v.visitWhileLoop(this, d);
1210         }
1211 
1212         @Override
1213         public Tag getTag() {
1214             return WHILELOOP;
1215         }
1216     }
1217 
1218     /**
1219      * A for loop.
1220      */
1221     public static class JCForLoop extends JCStatement implements ForLoopTree {
1222         public List<JCStatement> init;
1223         public JCExpression cond;
1224         public List<JCExpressionStatement> step;
1225         public JCStatement body;
1226         protected JCForLoop(List<JCStatement> init,
1227                           JCExpression cond,
1228                           List<JCExpressionStatement> update,
1229                           JCStatement body)
1230         {
1231             this.init = init;
1232             this.cond = cond;
1233             this.step = update;
1234             this.body = body;
1235         }
1236         @Override
1237         public void accept(Visitor v) { v.visitForLoop(this); }
1238 
1239         @DefinedBy(Api.COMPILER_TREE)
1240         public Kind getKind() { return Kind.FOR_LOOP; }
1241         @DefinedBy(Api.COMPILER_TREE)
1242         public JCExpression getCondition() { return cond; }
1243         @DefinedBy(Api.COMPILER_TREE)
1244         public JCStatement getStatement() { return body; }
1245         @DefinedBy(Api.COMPILER_TREE)
1246         public List<JCStatement> getInitializer() {
1247             return init;
1248         }
1249         @DefinedBy(Api.COMPILER_TREE)
1250         public List<JCExpressionStatement> getUpdate() {
1251             return step;
1252         }
1253         @Override @DefinedBy(Api.COMPILER_TREE)
1254         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1255             return v.visitForLoop(this, d);
1256         }
1257 
1258         @Override
1259         public Tag getTag() {
1260             return FORLOOP;
1261         }
1262     }
1263 
1264     /**
1265      * The enhanced for loop.
1266      */
1267     public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
1268         public JCVariableDecl var;
1269         public JCExpression expr;
1270         public JCStatement body;
1271         protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
1272             this.var = var;
1273             this.expr = expr;
1274             this.body = body;
1275         }
1276         @Override
1277         public void accept(Visitor v) { v.visitForeachLoop(this); }
1278 
1279         @DefinedBy(Api.COMPILER_TREE)
1280         public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
1281         @DefinedBy(Api.COMPILER_TREE)
1282         public JCVariableDecl getVariable() { return var; }
1283         @DefinedBy(Api.COMPILER_TREE)
1284         public JCExpression getExpression() { return expr; }
1285         @DefinedBy(Api.COMPILER_TREE)
1286         public JCStatement getStatement() { return body; }
1287         @Override @DefinedBy(Api.COMPILER_TREE)
1288         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1289             return v.visitEnhancedForLoop(this, d);
1290         }
1291         @Override
1292         public Tag getTag() {
1293             return FOREACHLOOP;
1294         }
1295     }
1296 
1297     /**
1298      * A labelled expression or statement.
1299      */
1300     public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
1301         public Name label;
1302         public JCStatement body;
1303         protected JCLabeledStatement(Name label, JCStatement body) {
1304             this.label = label;
1305             this.body = body;
1306         }
1307         @Override
1308         public void accept(Visitor v) { v.visitLabelled(this); }
1309         @DefinedBy(Api.COMPILER_TREE)
1310         public Kind getKind() { return Kind.LABELED_STATEMENT; }
1311         @DefinedBy(Api.COMPILER_TREE)
1312         public Name getLabel() { return label; }
1313         @DefinedBy(Api.COMPILER_TREE)
1314         public JCStatement getStatement() { return body; }
1315         @Override @DefinedBy(Api.COMPILER_TREE)
1316         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1317             return v.visitLabeledStatement(this, d);
1318         }
1319         @Override
1320         public Tag getTag() {
1321             return LABELLED;
1322         }
1323     }
1324 
1325     /**
1326      * A "switch ( ) { }" construction.
1327      */
1328     public static class JCSwitch extends JCStatement implements SwitchTree {
1329         public JCExpression selector;
1330         public List<JCCase> cases;
1331         /** Position of closing brace, optional. */
1332         public int endpos = Position.NOPOS;
1333         public boolean hasUnconditionalPattern;
1334         public boolean isExhaustive;
1335         public boolean patternSwitch;
1336         public boolean wasEnumSelector;
1337         protected JCSwitch(JCExpression selector, List<JCCase> cases) {
1338             this.selector = selector;
1339             this.cases = cases;
1340         }
1341         @Override
1342         public void accept(Visitor v) { v.visitSwitch(this); }
1343 
1344         @DefinedBy(Api.COMPILER_TREE)
1345         public Kind getKind() { return Kind.SWITCH; }
1346         @DefinedBy(Api.COMPILER_TREE)
1347         public JCExpression getExpression() { return selector; }
1348         @DefinedBy(Api.COMPILER_TREE)
1349         public List<JCCase> getCases() { return cases; }
1350         @Override @DefinedBy(Api.COMPILER_TREE)
1351         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1352             return v.visitSwitch(this, d);
1353         }
1354         @Override
1355         public Tag getTag() {
1356             return SWITCH;
1357         }
1358     }
1359 
1360     /**
1361      * A "case  :" of a switch.
1362      */
1363     public static class JCCase extends JCStatement implements CaseTree {
1364         //as CaseKind is deprecated for removal (as it is part of a preview feature),
1365         //using indirection through these fields to avoid unnecessary @SuppressWarnings:
1366         public static final CaseKind STATEMENT = CaseKind.STATEMENT;
1367         public static final CaseKind RULE = CaseKind.RULE;
1368         public final CaseKind caseKind;
1369         public List<JCCaseLabel> labels;
1370         public JCExpression guard;
1371         public List<JCStatement> stats;
1372         public JCTree body;
1373         public boolean completesNormally;
1374         protected JCCase(CaseKind caseKind, List<JCCaseLabel> labels,
1375                          JCExpression guard,
1376                          List<JCStatement> stats, JCTree body) {
1377             Assert.checkNonNull(labels);
1378             Assert.check(labels.isEmpty() || labels.head != null);
1379             this.caseKind = caseKind;
1380             this.labels = labels;
1381             this.guard = guard;
1382             this.stats = stats;
1383             this.body = body;
1384         }
1385         @Override
1386         public void accept(Visitor v) { v.visitCase(this); }
1387 
1388         @Override @DefinedBy(Api.COMPILER_TREE)
1389         public Kind getKind() { return Kind.CASE; }
1390         @Override @Deprecated @DefinedBy(Api.COMPILER_TREE)
1391         public JCExpression getExpression() { return getExpressions().head; }
1392 
1393         @Override @DefinedBy(Api.COMPILER_TREE)
1394         public List<JCExpression> getExpressions() {
1395             return labels.stream()
1396                          .filter(p -> p.hasTag(CONSTANTCASELABEL))
1397                          .map(p -> ((JCConstantCaseLabel) p).expr)
1398                          .collect(List.collector());
1399         }
1400 
1401         @Override @DefinedBy(Api.COMPILER_TREE)
1402         public List<JCCaseLabel> getLabels() { return labels; }
1403         @Override @DefinedBy(Api.COMPILER_TREE)
1404         public JCExpression getGuard() { return guard; }
1405         @Override @DefinedBy(Api.COMPILER_TREE)
1406         public List<JCStatement> getStatements() {
1407             return caseKind == CaseKind.STATEMENT ? stats : null;
1408         }
1409         @Override @DefinedBy(Api.COMPILER_TREE)
1410         public JCTree getBody() { return body; }
1411         @Override @DefinedBy(Api.COMPILER_TREE)
1412         public CaseKind getCaseKind() {
1413             return caseKind;
1414         }
1415         @Override @DefinedBy(Api.COMPILER_TREE)
1416         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1417             return v.visitCase(this, d);
1418         }
1419         @Override
1420         public Tag getTag() {
1421             return CASE;
1422         }
1423     }
1424 
1425     /**
1426      * A "switch ( ) { }" construction.
1427      */
1428     public static class JCSwitchExpression extends JCPolyExpression implements SwitchExpressionTree {
1429         public JCExpression selector;
1430         public List<JCCase> cases;
1431         /** Position of closing brace, optional. */
1432         public int endpos = Position.NOPOS;
1433         public boolean hasUnconditionalPattern;
1434         public boolean isExhaustive;
1435         public boolean patternSwitch;
1436         public boolean wasEnumSelector;
1437         protected JCSwitchExpression(JCExpression selector, List<JCCase> cases) {
1438             this.selector = selector;
1439             this.cases = cases;
1440         }
1441         @Override
1442         public void accept(Visitor v) { v.visitSwitchExpression(this); }
1443 
1444         @DefinedBy(Api.COMPILER_TREE)
1445         public Kind getKind() { return Kind.SWITCH_EXPRESSION; }
1446         @DefinedBy(Api.COMPILER_TREE)
1447         public JCExpression getExpression() { return selector; }
1448         @DefinedBy(Api.COMPILER_TREE)
1449         public List<JCCase> getCases() { return cases; }
1450         @Override @DefinedBy(Api.COMPILER_TREE)
1451         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1452             return v.visitSwitchExpression(this, d);
1453         }
1454         @Override
1455         public Tag getTag() {
1456             return SWITCH_EXPRESSION;
1457         }
1458     }
1459 
1460     /**
1461      * A synchronized block.
1462      */
1463     public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1464         public JCExpression lock;
1465         public JCBlock body;
1466         protected JCSynchronized(JCExpression lock, JCBlock body) {
1467             this.lock = lock;
1468             this.body = body;
1469         }
1470         @Override
1471         public void accept(Visitor v) { v.visitSynchronized(this); }
1472 
1473         @DefinedBy(Api.COMPILER_TREE)
1474         public Kind getKind() { return Kind.SYNCHRONIZED; }
1475         @DefinedBy(Api.COMPILER_TREE)
1476         public JCExpression getExpression() { return lock; }
1477         @DefinedBy(Api.COMPILER_TREE)
1478         public JCBlock getBlock() { return body; }
1479         @Override @DefinedBy(Api.COMPILER_TREE)
1480         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1481             return v.visitSynchronized(this, d);
1482         }
1483         @Override
1484         public Tag getTag() {
1485             return SYNCHRONIZED;
1486         }
1487     }
1488 
1489     /**
1490      * A "try { } catch ( ) { } finally { }" block.
1491      */
1492     public static class JCTry extends JCStatement implements TryTree {
1493         public JCBlock body;
1494         public List<JCCatch> catchers;
1495         public JCBlock finalizer;
1496         public List<JCTree> resources;
1497         public boolean finallyCanCompleteNormally;
1498         protected JCTry(List<JCTree> resources,
1499                         JCBlock body,
1500                         List<JCCatch> catchers,
1501                         JCBlock finalizer) {
1502             this.body = body;
1503             this.catchers = catchers;
1504             this.finalizer = finalizer;
1505             this.resources = resources;
1506         }
1507         @Override
1508         public void accept(Visitor v) { v.visitTry(this); }
1509 
1510         @DefinedBy(Api.COMPILER_TREE)
1511         public Kind getKind() { return Kind.TRY; }
1512         @DefinedBy(Api.COMPILER_TREE)
1513         public JCBlock getBlock() { return body; }
1514         @DefinedBy(Api.COMPILER_TREE)
1515         public List<JCCatch> getCatches() {
1516             return catchers;
1517         }
1518         @DefinedBy(Api.COMPILER_TREE)
1519         public JCBlock getFinallyBlock() { return finalizer; }
1520         @Override @DefinedBy(Api.COMPILER_TREE)
1521         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1522             return v.visitTry(this, d);
1523         }
1524         @Override @DefinedBy(Api.COMPILER_TREE)
1525         public List<JCTree> getResources() {
1526             return resources;
1527         }
1528         @Override
1529         public Tag getTag() {
1530             return TRY;
1531         }
1532     }
1533 
1534     /**
1535      * A catch block.
1536      */
1537     public static class JCCatch extends JCTree implements CatchTree {
1538         public JCVariableDecl param;
1539         public JCBlock body;
1540         protected JCCatch(JCVariableDecl param, JCBlock body) {
1541             this.param = param;
1542             this.body = body;
1543         }
1544         @Override
1545         public void accept(Visitor v) { v.visitCatch(this); }
1546 
1547         @DefinedBy(Api.COMPILER_TREE)
1548         public Kind getKind() { return Kind.CATCH; }
1549         @DefinedBy(Api.COMPILER_TREE)
1550         public JCVariableDecl getParameter() { return param; }
1551         @DefinedBy(Api.COMPILER_TREE)
1552         public JCBlock getBlock() { return body; }
1553         @Override @DefinedBy(Api.COMPILER_TREE)
1554         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1555             return v.visitCatch(this, d);
1556         }
1557         @Override
1558         public Tag getTag() {
1559             return CATCH;
1560         }
1561     }
1562 
1563     /**
1564      * A ( ) ? ( ) : ( ) conditional expression
1565      */
1566     public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree {
1567         public JCExpression cond;
1568         public JCExpression truepart;
1569         public JCExpression falsepart;
1570         protected JCConditional(JCExpression cond,
1571                               JCExpression truepart,
1572                               JCExpression falsepart)
1573         {
1574             this.cond = cond;
1575             this.truepart = truepart;
1576             this.falsepart = falsepart;
1577         }
1578         @Override
1579         public void accept(Visitor v) { v.visitConditional(this); }
1580 
1581         @DefinedBy(Api.COMPILER_TREE)
1582         public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
1583         @DefinedBy(Api.COMPILER_TREE)
1584         public JCExpression getCondition() { return cond; }
1585         @DefinedBy(Api.COMPILER_TREE)
1586         public JCExpression getTrueExpression() { return truepart; }
1587         @DefinedBy(Api.COMPILER_TREE)
1588         public JCExpression getFalseExpression() { return falsepart; }
1589         @Override @DefinedBy(Api.COMPILER_TREE)
1590         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1591             return v.visitConditionalExpression(this, d);
1592         }
1593         @Override
1594         public Tag getTag() {
1595             return CONDEXPR;
1596         }
1597     }
1598 
1599     /**
1600      * An "if ( ) { } else { }" block
1601      */
1602     public static class JCIf extends JCStatement implements IfTree {
1603         public JCExpression cond;
1604         public JCStatement thenpart;
1605         public JCStatement elsepart;
1606         protected JCIf(JCExpression cond,
1607                      JCStatement thenpart,
1608                      JCStatement elsepart)
1609         {
1610             this.cond = cond;
1611             this.thenpart = thenpart;
1612             this.elsepart = elsepart;
1613         }
1614         @Override
1615         public void accept(Visitor v) { v.visitIf(this); }
1616 
1617         @DefinedBy(Api.COMPILER_TREE)
1618         public Kind getKind() { return Kind.IF; }
1619         @DefinedBy(Api.COMPILER_TREE)
1620         public JCExpression getCondition() { return cond; }
1621         @DefinedBy(Api.COMPILER_TREE)
1622         public JCStatement getThenStatement() { return thenpart; }
1623         @DefinedBy(Api.COMPILER_TREE)
1624         public JCStatement getElseStatement() { return elsepart; }
1625         @Override @DefinedBy(Api.COMPILER_TREE)
1626         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1627             return v.visitIf(this, d);
1628         }
1629         @Override
1630         public Tag getTag() {
1631             return IF;
1632         }
1633     }
1634 
1635     /**
1636      * an expression statement
1637      */
1638     public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
1639         /** expression structure */
1640         public JCExpression expr;
1641         protected JCExpressionStatement(JCExpression expr)
1642         {
1643             this.expr = expr;
1644         }
1645         @Override
1646         public void accept(Visitor v) { v.visitExec(this); }
1647 
1648         @DefinedBy(Api.COMPILER_TREE)
1649         public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
1650         @DefinedBy(Api.COMPILER_TREE)
1651         public JCExpression getExpression() { return expr; }
1652         @Override @DefinedBy(Api.COMPILER_TREE)
1653         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1654             return v.visitExpressionStatement(this, d);
1655         }
1656         @Override
1657         public Tag getTag() {
1658             return EXEC;
1659         }
1660 
1661         /** Convert a expression-statement tree to a pretty-printed string. */
1662         @Override
1663         public String toString() {
1664             StringWriter s = new StringWriter();
1665             try {
1666                 new Pretty(s, false).printStat(this);
1667             }
1668             catch (IOException e) {
1669                 // should never happen, because StringWriter is defined
1670                 // never to throw any IOExceptions
1671                 throw new AssertionError(e);
1672             }
1673             return s.toString();
1674         }
1675     }
1676 
1677     /**
1678      * A break from a loop or switch.
1679      */
1680     public static class JCBreak extends JCStatement implements BreakTree {
1681         public Name label;
1682         public JCTree target;
1683         protected JCBreak(Name label, JCTree target) {
1684             this.label = label;
1685             this.target = target;
1686         }
1687         @Override
1688         public void accept(Visitor v) { v.visitBreak(this); }
1689         public boolean isValueBreak() {
1690             return target != null && target.hasTag(SWITCH_EXPRESSION);
1691         }
1692 
1693         @DefinedBy(Api.COMPILER_TREE)
1694         public Kind getKind() { return Kind.BREAK; }
1695         @DefinedBy(Api.COMPILER_TREE)
1696         public Name getLabel() {
1697             return label;
1698         }
1699         @Override @DefinedBy(Api.COMPILER_TREE)
1700         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1701             return v.visitBreak(this, d);
1702         }
1703         @Override
1704         public Tag getTag() {
1705             return BREAK;
1706         }
1707     }
1708 
1709     /**
1710      * A break-with from a switch expression.
1711      */
1712     public static class JCYield extends JCStatement implements YieldTree {
1713         public JCExpression value;
1714         public JCTree target;
1715         protected JCYield(JCExpression value, JCTree target) {
1716             this.value = value;
1717             this.target = target;
1718         }
1719         @Override
1720         public void accept(Visitor v) { v.visitYield(this); }
1721         @DefinedBy(Api.COMPILER_TREE)
1722         public Kind getKind() { return Kind.YIELD; }
1723         @DefinedBy(Api.COMPILER_TREE)
1724         public JCExpression getValue() { return value; }
1725         @Override @DefinedBy(Api.COMPILER_TREE)
1726         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1727             return v.visitYield(this, d);
1728         }
1729         @Override
1730         public Tag getTag() {
1731             return YIELD;
1732         }
1733     }
1734 
1735     /**
1736      * A continue of a loop.
1737      */
1738     public static class JCContinue extends JCStatement implements ContinueTree {
1739         public Name label;
1740         public JCTree target;
1741         protected JCContinue(Name label, JCTree target) {
1742             this.label = label;
1743             this.target = target;
1744         }
1745         @Override
1746         public void accept(Visitor v) { v.visitContinue(this); }
1747 
1748         @DefinedBy(Api.COMPILER_TREE)
1749         public Kind getKind() { return Kind.CONTINUE; }
1750         @DefinedBy(Api.COMPILER_TREE)
1751         public Name getLabel() { return label; }
1752         @Override @DefinedBy(Api.COMPILER_TREE)
1753         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1754             return v.visitContinue(this, d);
1755         }
1756         @Override
1757         public Tag getTag() {
1758             return CONTINUE;
1759         }
1760     }
1761 
1762     /**
1763      * A return statement.
1764      */
1765     public static class JCReturn extends JCStatement implements ReturnTree {
1766         public JCExpression expr;
1767         protected JCReturn(JCExpression expr) {
1768             this.expr = expr;
1769         }
1770         @Override
1771         public void accept(Visitor v) { v.visitReturn(this); }
1772 
1773         @DefinedBy(Api.COMPILER_TREE)
1774         public Kind getKind() { return Kind.RETURN; }
1775         @DefinedBy(Api.COMPILER_TREE)
1776         public JCExpression getExpression() { return expr; }
1777         @Override @DefinedBy(Api.COMPILER_TREE)
1778         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1779             return v.visitReturn(this, d);
1780         }
1781         @Override
1782         public Tag getTag() {
1783             return RETURN;
1784         }
1785     }
1786 
1787     /**
1788      * A throw statement.
1789      */
1790     public static class JCThrow extends JCStatement implements ThrowTree {
1791         public JCExpression expr;
1792         protected JCThrow(JCExpression expr) {
1793             this.expr = expr;
1794         }
1795         @Override
1796         public void accept(Visitor v) { v.visitThrow(this); }
1797 
1798         @DefinedBy(Api.COMPILER_TREE)
1799         public Kind getKind() { return Kind.THROW; }
1800         @DefinedBy(Api.COMPILER_TREE)
1801         public JCExpression getExpression() { return expr; }
1802         @Override @DefinedBy(Api.COMPILER_TREE)
1803         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1804             return v.visitThrow(this, d);
1805         }
1806         @Override
1807         public Tag getTag() {
1808             return THROW;
1809         }
1810     }
1811 
1812     /**
1813      * An assert statement.
1814      */
1815     public static class JCAssert extends JCStatement implements AssertTree {
1816         public JCExpression cond;
1817         public JCExpression detail;
1818         protected JCAssert(JCExpression cond, JCExpression detail) {
1819             this.cond = cond;
1820             this.detail = detail;
1821         }
1822         @Override
1823         public void accept(Visitor v) { v.visitAssert(this); }
1824 
1825         @DefinedBy(Api.COMPILER_TREE)
1826         public Kind getKind() { return Kind.ASSERT; }
1827         @DefinedBy(Api.COMPILER_TREE)
1828         public JCExpression getCondition() { return cond; }
1829         @DefinedBy(Api.COMPILER_TREE)
1830         public JCExpression getDetail() { return detail; }
1831         @Override @DefinedBy(Api.COMPILER_TREE)
1832         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1833             return v.visitAssert(this, d);
1834         }
1835         @Override
1836         public Tag getTag() {
1837             return ASSERT;
1838         }
1839     }
1840 
1841     /**
1842      * A method invocation
1843      */
1844     public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree {
1845         public List<JCExpression> typeargs;
1846         public JCExpression meth;
1847         public List<JCExpression> args;
1848         public Type varargsElement;
1849         protected JCMethodInvocation(List<JCExpression> typeargs,
1850                         JCExpression meth,
1851                         List<JCExpression> args)
1852         {
1853             this.typeargs = (typeargs == null) ? List.nil()
1854                                                : typeargs;
1855             this.meth = meth;
1856             this.args = args;
1857         }
1858         @Override
1859         public void accept(Visitor v) { v.visitApply(this); }
1860 
1861         @DefinedBy(Api.COMPILER_TREE)
1862         public Kind getKind() { return Kind.METHOD_INVOCATION; }
1863         @DefinedBy(Api.COMPILER_TREE)
1864         public List<JCExpression> getTypeArguments() {
1865             return typeargs;
1866         }
1867         @DefinedBy(Api.COMPILER_TREE)
1868         public JCExpression getMethodSelect() { return meth; }
1869         @DefinedBy(Api.COMPILER_TREE)
1870         public List<JCExpression> getArguments() {
1871             return args;
1872         }
1873         @Override @DefinedBy(Api.COMPILER_TREE)
1874         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1875             return v.visitMethodInvocation(this, d);
1876         }
1877         @Override
1878         public JCMethodInvocation setType(Type type) {
1879             super.setType(type);
1880             return this;
1881         }
1882         @Override
1883         public Tag getTag() {
1884             return(APPLY);
1885         }
1886     }
1887 
1888     /**
1889      * A new(...) operation.
1890      */
1891     public static class JCNewClass extends JCPolyExpression implements NewClassTree {
1892         public JCExpression encl;
1893         public List<JCExpression> typeargs;
1894         public JCExpression clazz;
1895         public List<JCExpression> args;
1896         public JCClassDecl def;
1897         public Symbol constructor;
1898         public Type varargsElement;
1899         public Type constructorType;
1900         protected JCNewClass(JCExpression encl,
1901                            List<JCExpression> typeargs,
1902                            JCExpression clazz,
1903                            List<JCExpression> args,
1904                            JCClassDecl def)
1905         {
1906             this.encl = encl;
1907             this.typeargs = (typeargs == null) ? List.nil()
1908                                                : typeargs;
1909             this.clazz = clazz;
1910             this.args = args;
1911             this.def = def;
1912         }
1913         @Override
1914         public void accept(Visitor v) { v.visitNewClass(this); }
1915 
1916         @DefinedBy(Api.COMPILER_TREE)
1917         public Kind getKind() { return Kind.NEW_CLASS; }
1918         @DefinedBy(Api.COMPILER_TREE)
1919         public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
1920             return encl;
1921         }
1922         @DefinedBy(Api.COMPILER_TREE)
1923         public List<JCExpression> getTypeArguments() {
1924             return typeargs;
1925         }
1926         @DefinedBy(Api.COMPILER_TREE)
1927         public JCExpression getIdentifier() { return clazz; }
1928         @DefinedBy(Api.COMPILER_TREE)
1929         public List<JCExpression> getArguments() {
1930             return args;
1931         }
1932         @DefinedBy(Api.COMPILER_TREE)
1933         public JCClassDecl getClassBody() { return def; }
1934         @Override @DefinedBy(Api.COMPILER_TREE)
1935         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1936             return v.visitNewClass(this, d);
1937         }
1938         @Override
1939         public Tag getTag() {
1940             return NEWCLASS;
1941         }
1942 
1943         public boolean classDeclRemoved() {
1944             return false;
1945         }
1946     }
1947 
1948     /**
1949      * A new[...] operation.
1950      */
1951     public static class JCNewArray extends JCExpression implements NewArrayTree {
1952         public JCExpression elemtype;
1953         public List<JCExpression> dims;
1954         // type annotations on inner-most component
1955         public List<JCAnnotation> annotations;
1956         // type annotations on dimensions
1957         public List<List<JCAnnotation>> dimAnnotations;
1958         public List<JCExpression> elems;
1959         protected JCNewArray(JCExpression elemtype,
1960                            List<JCExpression> dims,
1961                            List<JCExpression> elems)
1962         {
1963             this.elemtype = elemtype;
1964             this.dims = dims;
1965             this.annotations = List.nil();
1966             this.dimAnnotations = List.nil();
1967             this.elems = elems;
1968         }
1969         @Override
1970         public void accept(Visitor v) { v.visitNewArray(this); }
1971 
1972         @DefinedBy(Api.COMPILER_TREE)
1973         public Kind getKind() { return Kind.NEW_ARRAY; }
1974         @DefinedBy(Api.COMPILER_TREE)
1975         public JCExpression getType() { return elemtype; }
1976         @DefinedBy(Api.COMPILER_TREE)
1977         public List<JCExpression> getDimensions() {
1978             return dims;
1979         }
1980         @DefinedBy(Api.COMPILER_TREE)
1981         public List<JCExpression> getInitializers() {
1982             return elems;
1983         }
1984         @Override @DefinedBy(Api.COMPILER_TREE)
1985         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1986             return v.visitNewArray(this, d);
1987         }
1988         @Override
1989         public Tag getTag() {
1990             return NEWARRAY;
1991         }
1992 
1993         @Override @DefinedBy(Api.COMPILER_TREE)
1994         public List<JCAnnotation> getAnnotations() {
1995             return annotations;
1996         }
1997 
1998         @Override @DefinedBy(Api.COMPILER_TREE)
1999         public List<List<JCAnnotation>> getDimAnnotations() {
2000             return dimAnnotations;
2001         }
2002     }
2003 
2004     /**
2005      * A lambda expression.
2006      */
2007     public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
2008 
2009         public enum ParameterKind {
2010             IMPLICIT,
2011             EXPLICIT
2012         }
2013 
2014         public List<JCVariableDecl> params;
2015         public JCTree body;
2016         public boolean canCompleteNormally = true;
2017         public ParameterKind paramKind;
2018         public boolean wasMethodReference;
2019 
2020         public JCLambda(List<JCVariableDecl> params,
2021                         JCTree body) {
2022             this.params = params;
2023             this.body = body;
2024             if (params.isEmpty() ||
2025                 params.head.vartype != null) {
2026                 paramKind = ParameterKind.EXPLICIT;
2027             } else {
2028                 paramKind = ParameterKind.IMPLICIT;
2029             }
2030         }
2031         @Override
2032         public Tag getTag() {
2033             return LAMBDA;
2034         }
2035         @Override
2036         public void accept(Visitor v) {
2037             v.visitLambda(this);
2038         }
2039         @Override @DefinedBy(Api.COMPILER_TREE)
2040         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2041             return v.visitLambdaExpression(this, d);
2042         }
2043         @DefinedBy(Api.COMPILER_TREE)
2044         public Kind getKind() {
2045             return Kind.LAMBDA_EXPRESSION;
2046         }
2047         @DefinedBy(Api.COMPILER_TREE)
2048         public JCTree getBody() {
2049             return body;
2050         }
2051         @DefinedBy(Api.COMPILER_TREE)
2052         public java.util.List<? extends VariableTree> getParameters() {
2053             return params;
2054         }
2055         @Override
2056         public JCLambda setType(Type type) {
2057             super.setType(type);
2058             return this;
2059         }
2060         @Override @DefinedBy(Api.COMPILER_TREE)
2061         public BodyKind getBodyKind() {
2062             return body.hasTag(BLOCK) ?
2063                     BodyKind.STATEMENT :
2064                     BodyKind.EXPRESSION;
2065         }
2066     }
2067 
2068     /**
2069      * A parenthesized subexpression ( ... )
2070      */
2071     public static class JCParens extends JCExpression implements ParenthesizedTree {
2072         public JCExpression expr;
2073         protected JCParens(JCExpression expr) {
2074             this.expr = expr;
2075         }
2076         @Override
2077         public void accept(Visitor v) { v.visitParens(this); }
2078 
2079         @DefinedBy(Api.COMPILER_TREE)
2080         public Kind getKind() { return Kind.PARENTHESIZED; }
2081         @DefinedBy(Api.COMPILER_TREE)
2082         public JCExpression getExpression() { return expr; }
2083         @Override @DefinedBy(Api.COMPILER_TREE)
2084         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2085             return v.visitParenthesized(this, d);
2086         }
2087         @Override
2088         public Tag getTag() {
2089             return PARENS;
2090         }
2091     }
2092 
2093     /**
2094      * A assignment with "=".
2095      */
2096     public static class JCAssign extends JCExpression implements AssignmentTree {
2097         public JCExpression lhs;
2098         public JCExpression rhs;
2099         protected JCAssign(JCExpression lhs, JCExpression rhs) {
2100             this.lhs = lhs;
2101             this.rhs = rhs;
2102         }
2103         @Override
2104         public void accept(Visitor v) { v.visitAssign(this); }
2105 
2106         @DefinedBy(Api.COMPILER_TREE)
2107         public Kind getKind() { return Kind.ASSIGNMENT; }
2108         @DefinedBy(Api.COMPILER_TREE)
2109         public JCExpression getVariable() { return lhs; }
2110         @DefinedBy(Api.COMPILER_TREE)
2111         public JCExpression getExpression() { return rhs; }
2112         @Override @DefinedBy(Api.COMPILER_TREE)
2113         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2114             return v.visitAssignment(this, d);
2115         }
2116         @Override
2117         public Tag getTag() {
2118             return ASSIGN;
2119         }
2120     }
2121 
2122     public abstract static class JCOperatorExpression extends JCExpression {
2123         public enum OperandPos {
2124             LEFT,
2125             RIGHT
2126         }
2127 
2128         protected Tag opcode;
2129         public OperatorSymbol operator;
2130 
2131         public OperatorSymbol getOperator() {
2132             return operator;
2133         }
2134 
2135         @Override
2136         public Tag getTag() {
2137             return opcode;
2138         }
2139 
2140         public abstract JCExpression getOperand(OperandPos pos);
2141     }
2142 
2143     /**
2144      * An assignment with "+=", "|=" ...
2145      */
2146     public static class JCAssignOp extends JCOperatorExpression implements CompoundAssignmentTree {
2147         public JCExpression lhs;
2148         public JCExpression rhs;
2149         protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, OperatorSymbol operator) {
2150             this.opcode = opcode;
2151             this.lhs = (JCExpression)lhs;
2152             this.rhs = (JCExpression)rhs;
2153             this.operator = operator;
2154         }
2155         @Override
2156         public void accept(Visitor v) { v.visitAssignop(this); }
2157 
2158         @DefinedBy(Api.COMPILER_TREE)
2159         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2160         @DefinedBy(Api.COMPILER_TREE)
2161         public JCExpression getVariable() { return lhs; }
2162         @DefinedBy(Api.COMPILER_TREE)
2163         public JCExpression getExpression() { return rhs; }
2164         @Override @DefinedBy(Api.COMPILER_TREE)
2165         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2166             return v.visitCompoundAssignment(this, d);
2167         }
2168         @Override
2169         public JCExpression getOperand(OperandPos pos) {
2170             return pos == OperandPos.LEFT ? lhs : rhs;
2171         }
2172     }
2173 
2174     /**
2175      * A unary operation.
2176      */
2177     public static class JCUnary extends JCOperatorExpression implements UnaryTree {
2178         public JCExpression arg;
2179         protected JCUnary(Tag opcode, JCExpression arg) {
2180             this.opcode = opcode;
2181             this.arg = arg;
2182         }
2183         @Override
2184         public void accept(Visitor v) { v.visitUnary(this); }
2185 
2186         @DefinedBy(Api.COMPILER_TREE)
2187         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2188         @DefinedBy(Api.COMPILER_TREE)
2189         public JCExpression getExpression() { return arg; }
2190         @Override @DefinedBy(Api.COMPILER_TREE)
2191         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2192             return v.visitUnary(this, d);
2193         }
2194         public void setTag(Tag tag) {
2195             opcode = tag;
2196         }
2197         @Override
2198         public JCExpression getOperand(OperandPos pos) {
2199             return arg;
2200         }
2201     }
2202 
2203     /**
2204      * A binary operation.
2205      */
2206     public static class JCBinary extends JCOperatorExpression implements BinaryTree {
2207         public JCExpression lhs;
2208         public JCExpression rhs;
2209         protected JCBinary(Tag opcode,
2210                          JCExpression lhs,
2211                          JCExpression rhs,
2212                          OperatorSymbol operator) {
2213             this.opcode = opcode;
2214             this.lhs = lhs;
2215             this.rhs = rhs;
2216             this.operator = operator;
2217         }
2218         @Override
2219         public void accept(Visitor v) { v.visitBinary(this); }
2220 
2221         @DefinedBy(Api.COMPILER_TREE)
2222         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2223         @DefinedBy(Api.COMPILER_TREE)
2224         public JCExpression getLeftOperand() { return lhs; }
2225         @DefinedBy(Api.COMPILER_TREE)
2226         public JCExpression getRightOperand() { return rhs; }
2227         @Override @DefinedBy(Api.COMPILER_TREE)
2228         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2229             return v.visitBinary(this, d);
2230         }
2231         @Override
2232         public JCExpression getOperand(OperandPos pos) {
2233             return pos == OperandPos.LEFT ? lhs : rhs;
2234         }
2235     }
2236 
2237     /**
2238      * A type cast.
2239      */
2240     public static class JCTypeCast extends JCExpression implements TypeCastTree {
2241         public JCTree clazz;
2242         public JCExpression expr;
2243         protected JCTypeCast(JCTree clazz, JCExpression expr) {
2244             this.clazz = clazz;
2245             this.expr = expr;
2246         }
2247         @Override
2248         public void accept(Visitor v) { v.visitTypeCast(this); }
2249 
2250         @DefinedBy(Api.COMPILER_TREE)
2251         public Kind getKind() { return Kind.TYPE_CAST; }
2252         @DefinedBy(Api.COMPILER_TREE)
2253         public JCTree getType() { return clazz; }
2254         @DefinedBy(Api.COMPILER_TREE)
2255         public JCExpression getExpression() { return expr; }
2256         @Override @DefinedBy(Api.COMPILER_TREE)
2257         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2258             return v.visitTypeCast(this, d);
2259         }
2260         @Override
2261         public Tag getTag() {
2262             return TYPECAST;
2263         }
2264     }
2265 
2266     /**
2267      * A type test.
2268      */
2269     public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
2270         public JCExpression expr;
2271         public JCTree pattern;
2272         /**{@code true} if this instanceof test should have
2273          * value {@code true} when the {@code expr} is {@code null}.*/
2274         public boolean allowNull;
2275         protected JCInstanceOf(JCExpression expr, JCTree pattern) {
2276             this.expr = expr;
2277             this.pattern = pattern;
2278         }
2279         @Override
2280         public void accept(Visitor v) { v.visitTypeTest(this); }
2281 
2282         @DefinedBy(Api.COMPILER_TREE)
2283         public Kind getKind() { return Kind.INSTANCE_OF; }
2284         @DefinedBy(Api.COMPILER_TREE)
2285         public JCTree getType() { return pattern instanceof JCPattern ? pattern.hasTag(BINDINGPATTERN) ? ((JCBindingPattern) pattern).var.vartype : null : pattern; }
2286 
2287         @Override @DefinedBy(Api.COMPILER_TREE)
2288         public JCPattern getPattern() {
2289             return pattern instanceof JCPattern jcPattern ? jcPattern : null;
2290         }
2291 
2292         @DefinedBy(Api.COMPILER_TREE)
2293         public JCExpression getExpression() { return expr; }
2294         @Override @DefinedBy(Api.COMPILER_TREE)
2295         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2296             return v.visitInstanceOf(this, d);
2297         }
2298         @Override
2299         public Tag getTag() {
2300             return TYPETEST;
2301         }
2302     }
2303 
2304     /**
2305      * Pattern matching forms.
2306      */
2307     public abstract static class JCPattern extends JCTree
2308             implements PatternTree {
2309     }
2310 
2311     public static class JCAnyPattern extends JCPattern
2312             implements AnyPatternTree {
2313 
2314         protected JCAnyPattern() {
2315         }
2316 
2317         @Override
2318         public void accept(Visitor v) {
2319             v.visitAnyPattern(this);
2320         }
2321 
2322         @DefinedBy(Api.COMPILER_TREE)
2323         public Kind getKind() {
2324             return Kind.ANY_PATTERN;
2325         }
2326 
2327         @Override
2328         @DefinedBy(Api.COMPILER_TREE)
2329         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2330             return v.visitAnyPattern(this, d);
2331         }
2332 
2333         @Override
2334         public Tag getTag() {
2335             return ANYPATTERN;
2336         }
2337     }
2338 
2339     public static class JCBindingPattern extends JCPattern
2340             implements BindingPatternTree {
2341         public JCVariableDecl var;
2342 
2343         protected JCBindingPattern(JCVariableDecl var) {
2344             this.var = var;
2345         }
2346 
2347         @Override @DefinedBy(Api.COMPILER_TREE)
2348         public VariableTree getVariable() {
2349             return var;
2350         }
2351 
2352         @Override
2353         public void accept(Visitor v) {
2354             v.visitBindingPattern(this);
2355         }
2356 
2357         @DefinedBy(Api.COMPILER_TREE)
2358         public Kind getKind() {
2359             return Kind.BINDING_PATTERN;
2360         }
2361 
2362         @Override
2363         @DefinedBy(Api.COMPILER_TREE)
2364         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2365             return v.visitBindingPattern(this, d);
2366         }
2367 
2368         @Override
2369         public Tag getTag() {
2370             return BINDINGPATTERN;
2371         }
2372     }
2373 
2374     public static class JCDefaultCaseLabel extends JCCaseLabel
2375             implements DefaultCaseLabelTree {
2376 
2377         protected JCDefaultCaseLabel() {
2378         }
2379 
2380         @Override
2381         public void accept(Visitor v) {
2382             v.visitDefaultCaseLabel(this);
2383         }
2384 
2385         @DefinedBy(Api.COMPILER_TREE)
2386         public Kind getKind() {
2387             return Kind.DEFAULT_CASE_LABEL;
2388         }
2389 
2390         @Override
2391         @DefinedBy(Api.COMPILER_TREE)
2392         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2393             return v.visitDefaultCaseLabel(this, d);
2394         }
2395 
2396         @Override
2397         public Tag getTag() {
2398             return DEFAULTCASELABEL;
2399         }
2400 
2401     }
2402 
2403     public static class JCConstantCaseLabel extends JCCaseLabel
2404             implements ConstantCaseLabelTree {
2405 
2406         public JCExpression expr;
2407 
2408         protected JCConstantCaseLabel(JCExpression expr) {
2409             this.expr = expr;
2410         }
2411 
2412         @Override @DefinedBy(Api.COMPILER_TREE)
2413         public JCExpression getConstantExpression() {
2414             return expr;
2415         }
2416 
2417         @Override
2418         public void accept(Visitor v) {
2419             v.visitConstantCaseLabel(this);
2420         }
2421 
2422         @DefinedBy(Api.COMPILER_TREE)
2423         public Kind getKind() {
2424             return Kind.CONSTANT_CASE_LABEL;
2425         }
2426 
2427         @Override
2428         @DefinedBy(Api.COMPILER_TREE)
2429         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2430             return v.visitConstantCaseLabel(this, d);
2431         }
2432 
2433         @Override
2434         public Tag getTag() {
2435             return CONSTANTCASELABEL;
2436         }
2437 
2438     }
2439 
2440     public static class JCPatternCaseLabel extends JCCaseLabel
2441             implements PatternCaseLabelTree {
2442 
2443         public JCPattern pat;
2444         public JCExpression syntheticGuard;
2445 
2446         protected JCPatternCaseLabel(JCPattern pat) {
2447             this.pat = pat;
2448         }
2449 
2450         @Override @DefinedBy(Api.COMPILER_TREE)
2451         public JCPattern getPattern() {
2452             return pat;
2453         }
2454 
2455         @Override
2456         public void accept(Visitor v) {
2457             v.visitPatternCaseLabel(this);
2458         }
2459 
2460         @DefinedBy(Api.COMPILER_TREE)
2461         public Kind getKind() {
2462             return Kind.PATTERN_CASE_LABEL;
2463         }
2464 
2465         @Override
2466         @DefinedBy(Api.COMPILER_TREE)
2467         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2468             return v.visitPatternCaseLabel(this, d);
2469         }
2470 
2471         @Override
2472         public Tag getTag() {
2473             return PATTERNCASELABEL;
2474         }
2475 
2476     }
2477 
2478     public static class JCRecordPattern extends JCPattern
2479             implements DeconstructionPatternTree {
2480         public JCExpression deconstructor;
2481         public List<JCPattern> nested;
2482         public ClassSymbol record;
2483         public List<Type> fullComponentTypes;
2484 
2485         protected JCRecordPattern(JCExpression deconstructor, List<JCPattern> nested) {
2486             this.deconstructor = deconstructor;
2487             this.nested = nested;
2488         }
2489 
2490         @DefinedBy(Api.COMPILER_TREE)
2491         public Name getBinding() {
2492             return null;
2493         }
2494 
2495         @Override @DefinedBy(Api.COMPILER_TREE)
2496         public ExpressionTree getDeconstructor() {
2497             return deconstructor;
2498         }
2499 
2500         @Override @DefinedBy(Api.COMPILER_TREE)
2501         public List<? extends JCPattern> getNestedPatterns() {
2502             return nested;
2503         }
2504 
2505         @Override
2506         public void accept(Visitor v) {
2507             v.visitRecordPattern(this);
2508         }
2509 
2510         @DefinedBy(Api.COMPILER_TREE)
2511         public Kind getKind() {
2512             return Kind.DECONSTRUCTION_PATTERN;
2513         }
2514 
2515         @Override
2516         @DefinedBy(Api.COMPILER_TREE)
2517         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2518             return v.visitDeconstructionPattern(this, d);
2519         }
2520 
2521         @Override
2522         public Tag getTag() {
2523             return RECORDPATTERN;
2524         }
2525 
2526     }
2527 
2528     /**
2529      * An array selection
2530      */
2531     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
2532         public JCExpression indexed;
2533         public JCExpression index;
2534         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
2535             this.indexed = indexed;
2536             this.index = index;
2537         }
2538         @Override
2539         public void accept(Visitor v) { v.visitIndexed(this); }
2540 
2541         @DefinedBy(Api.COMPILER_TREE)
2542         public Kind getKind() { return Kind.ARRAY_ACCESS; }
2543         @DefinedBy(Api.COMPILER_TREE)
2544         public JCExpression getExpression() { return indexed; }
2545         @DefinedBy(Api.COMPILER_TREE)
2546         public JCExpression getIndex() { return index; }
2547         @Override @DefinedBy(Api.COMPILER_TREE)
2548         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2549             return v.visitArrayAccess(this, d);
2550         }
2551         @Override
2552         public Tag getTag() {
2553             return INDEXED;
2554         }
2555     }
2556 
2557     /**
2558      * Selects through packages and classes
2559      */
2560     public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
2561         /** selected Tree hierarchy */
2562         public JCExpression selected;
2563         /** name of field to select thru */
2564         public Name name;
2565         /** symbol of the selected class */
2566         public Symbol sym;
2567         protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
2568             this.selected = selected;
2569             this.name = name;
2570             this.sym = sym;
2571         }
2572         @Override
2573         public void accept(Visitor v) { v.visitSelect(this); }
2574 
2575         @DefinedBy(Api.COMPILER_TREE)
2576         public Kind getKind() { return Kind.MEMBER_SELECT; }
2577         @DefinedBy(Api.COMPILER_TREE)
2578         public JCExpression getExpression() { return selected; }
2579         @Override @DefinedBy(Api.COMPILER_TREE)
2580         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2581             return v.visitMemberSelect(this, d);
2582         }
2583         @DefinedBy(Api.COMPILER_TREE)
2584         public Name getIdentifier() { return name; }
2585         @Override
2586         public Tag getTag() {
2587             return SELECT;
2588         }
2589     }
2590 
2591     /**
2592      * Selects a member expression.
2593      */
2594     public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
2595 
2596         public ReferenceMode mode;
2597         public ReferenceKind kind;
2598         public Name name;
2599         public JCExpression expr;
2600         public List<JCExpression> typeargs;
2601         public Symbol sym;
2602         public Type varargsElement;
2603         public PolyKind refPolyKind;
2604         public boolean ownerAccessible;
2605         private OverloadKind overloadKind;
2606         public Type referentType;
2607 
2608         public enum OverloadKind {
2609             OVERLOADED,
2610             UNOVERLOADED,
2611             ERROR
2612         }
2613 
2614         /**
2615          * Javac-dependent classification for member references, based
2616          * on relevant properties w.r.t. code-generation
2617          */
2618         public enum ReferenceKind {
2619             /** super # instMethod */
2620             SUPER(ReferenceMode.INVOKE, false),
2621             /** Type # instMethod */
2622             UNBOUND(ReferenceMode.INVOKE, true),
2623             /** Type # staticMethod */
2624             STATIC(ReferenceMode.INVOKE, false),
2625             /** Expr # instMethod */
2626             BOUND(ReferenceMode.INVOKE, false),
2627             /** Inner # new */
2628             IMPLICIT_INNER(ReferenceMode.NEW, false),
2629             /** Toplevel # new */
2630             TOPLEVEL(ReferenceMode.NEW, false),
2631             /** ArrayType # new */
2632             ARRAY_CTOR(ReferenceMode.NEW, false);
2633 
2634             final ReferenceMode mode;
2635             final boolean unbound;
2636 
2637             private ReferenceKind(ReferenceMode mode, boolean unbound) {
2638                 this.mode = mode;
2639                 this.unbound = unbound;
2640             }
2641 
2642             public boolean isUnbound() {
2643                 return unbound;
2644             }
2645         }
2646 
2647         public JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
2648             this.mode = mode;
2649             this.name = name;
2650             this.expr = expr;
2651             this.typeargs = typeargs;
2652         }
2653         @Override
2654         public void accept(Visitor v) { v.visitReference(this); }
2655 
2656         @DefinedBy(Api.COMPILER_TREE)
2657         public Kind getKind() { return Kind.MEMBER_REFERENCE; }
2658         @Override @DefinedBy(Api.COMPILER_TREE)
2659         public ReferenceMode getMode() { return mode; }
2660         @Override @DefinedBy(Api.COMPILER_TREE)
2661         public JCExpression getQualifierExpression() { return expr; }
2662         @Override @DefinedBy(Api.COMPILER_TREE)
2663         public Name getName() { return name; }
2664         @Override @DefinedBy(Api.COMPILER_TREE)
2665         public List<JCExpression> getTypeArguments() { return typeargs; }
2666 
2667         @Override @DefinedBy(Api.COMPILER_TREE)
2668         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2669             return v.visitMemberReference(this, d);
2670         }
2671         @Override
2672         public Tag getTag() {
2673             return REFERENCE;
2674         }
2675         public boolean hasKind(ReferenceKind kind) {
2676             return this.kind == kind;
2677         }
2678 
2679         /**
2680          * @return the overloadKind
2681          */
2682         public OverloadKind getOverloadKind() {
2683             return overloadKind;
2684         }
2685 
2686         /**
2687          * @param overloadKind the overloadKind to set
2688          */
2689         public void setOverloadKind(OverloadKind overloadKind) {
2690             this.overloadKind = overloadKind;
2691         }
2692     }
2693 
2694     /**
2695      * An identifier
2696      */
2697     public static class JCIdent extends JCExpression implements IdentifierTree {
2698         /** the name */
2699         public Name name;
2700         /** the symbol */
2701         public Symbol sym;
2702         protected JCIdent(Name name, Symbol sym) {
2703             this.name = name;
2704             this.sym = sym;
2705         }
2706         @Override
2707         public void accept(Visitor v) { v.visitIdent(this); }
2708 
2709         @DefinedBy(Api.COMPILER_TREE)
2710         public Kind getKind() { return Kind.IDENTIFIER; }
2711         @DefinedBy(Api.COMPILER_TREE)
2712         public Name getName() { return name; }
2713         @Override @DefinedBy(Api.COMPILER_TREE)
2714         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2715             return v.visitIdentifier(this, d);
2716         }
2717         @Override
2718         public Tag getTag() {
2719             return IDENT;
2720         }
2721     }
2722 
2723     /**
2724      * A constant value given literally.
2725      */
2726     public static class JCLiteral extends JCExpression implements LiteralTree {
2727         public TypeTag typetag;
2728         /** value representation */
2729         public Object value;
2730         protected JCLiteral(TypeTag typetag, Object value) {
2731             this.typetag = typetag;
2732             this.value = value;
2733         }
2734         @Override
2735         public void accept(Visitor v) { v.visitLiteral(this); }
2736 
2737         @DefinedBy(Api.COMPILER_TREE)
2738         public Kind getKind() {
2739             return typetag.getKindLiteral();
2740         }
2741 
2742         @DefinedBy(Api.COMPILER_TREE)
2743         public Object getValue() {
2744             switch (typetag) {
2745                 case BOOLEAN:
2746                     int bi = (Integer) value;
2747                     return (bi != 0);
2748                 case CHAR:
2749                     int ci = (Integer) value;
2750                     char c = (char) ci;
2751                     if (c != ci)
2752                         throw new AssertionError("bad value for char literal");
2753                     return c;
2754                 default:
2755                     return value;
2756             }
2757         }
2758         @Override @DefinedBy(Api.COMPILER_TREE)
2759         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2760             return v.visitLiteral(this, d);
2761         }
2762         @Override
2763         public JCLiteral setType(Type type) {
2764             super.setType(type);
2765             return this;
2766         }
2767         @Override
2768         public Tag getTag() {
2769             return LITERAL;
2770         }
2771     }
2772 
2773     /**
2774      * Identifies a basic type.
2775      * @see TypeTag
2776      */
2777     public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
2778         /** the basic type id */
2779         public TypeTag typetag;
2780         protected JCPrimitiveTypeTree(TypeTag typetag) {
2781             this.typetag = typetag;
2782         }
2783         @Override
2784         public void accept(Visitor v) { v.visitTypeIdent(this); }
2785 
2786         @DefinedBy(Api.COMPILER_TREE)
2787         public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
2788         @DefinedBy(Api.COMPILER_TREE)
2789         public TypeKind getPrimitiveTypeKind() {
2790             return typetag.getPrimitiveTypeKind();
2791         }
2792 
2793         @Override @DefinedBy(Api.COMPILER_TREE)
2794         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2795             return v.visitPrimitiveType(this, d);
2796         }
2797         @Override
2798         public Tag getTag() {
2799             return TYPEIDENT;
2800         }
2801     }
2802 
2803     /**
2804      * An array type, A[]
2805      */
2806     public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
2807         public JCExpression elemtype;
2808         protected JCArrayTypeTree(JCExpression elemtype) {
2809             this.elemtype = elemtype;
2810         }
2811         @Override
2812         public void accept(Visitor v) { v.visitTypeArray(this); }
2813 
2814         @DefinedBy(Api.COMPILER_TREE)
2815         public Kind getKind() { return Kind.ARRAY_TYPE; }
2816         @DefinedBy(Api.COMPILER_TREE)
2817         public JCTree getType() { return elemtype; }
2818         @Override @DefinedBy(Api.COMPILER_TREE)
2819         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2820             return v.visitArrayType(this, d);
2821         }
2822         @Override
2823         public Tag getTag() {
2824             return TYPEARRAY;
2825         }
2826     }
2827 
2828     /**
2829      * A parameterized type, {@literal T<...>}
2830      */
2831     public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
2832         public JCExpression clazz;
2833         public List<JCExpression> arguments;
2834         protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
2835             this.clazz = clazz;
2836             this.arguments = arguments;
2837         }
2838         @Override
2839         public void accept(Visitor v) { v.visitTypeApply(this); }
2840 
2841         @DefinedBy(Api.COMPILER_TREE)
2842         public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
2843         @DefinedBy(Api.COMPILER_TREE)
2844         public JCTree getType() { return clazz; }
2845         @DefinedBy(Api.COMPILER_TREE)
2846         public List<JCExpression> getTypeArguments() {
2847             return arguments;
2848         }
2849         @Override @DefinedBy(Api.COMPILER_TREE)
2850         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2851             return v.visitParameterizedType(this, d);
2852         }
2853         @Override
2854         public Tag getTag() {
2855             return TYPEAPPLY;
2856         }
2857     }
2858 
2859     /**
2860      * A union type, T1 | T2 | ... Tn (used in multicatch statements)
2861      */
2862     public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
2863 
2864         public List<JCExpression> alternatives;
2865 
2866         protected JCTypeUnion(List<JCExpression> components) {
2867             this.alternatives = components;
2868         }
2869         @Override
2870         public void accept(Visitor v) { v.visitTypeUnion(this); }
2871 
2872         @DefinedBy(Api.COMPILER_TREE)
2873         public Kind getKind() { return Kind.UNION_TYPE; }
2874 
2875         @DefinedBy(Api.COMPILER_TREE)
2876         public List<JCExpression> getTypeAlternatives() {
2877             return alternatives;
2878         }
2879         @Override @DefinedBy(Api.COMPILER_TREE)
2880         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2881             return v.visitUnionType(this, d);
2882         }
2883         @Override
2884         public Tag getTag() {
2885             return TYPEUNION;
2886         }
2887     }
2888 
2889     /**
2890      * An intersection type, {@code T1 & T2 & ... Tn} (used in cast expressions)
2891      */
2892     public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree {
2893 
2894         public List<JCExpression> bounds;
2895 
2896         protected JCTypeIntersection(List<JCExpression> bounds) {
2897             this.bounds = bounds;
2898         }
2899         @Override
2900         public void accept(Visitor v) { v.visitTypeIntersection(this); }
2901 
2902         @DefinedBy(Api.COMPILER_TREE)
2903         public Kind getKind() { return Kind.INTERSECTION_TYPE; }
2904 
2905         @DefinedBy(Api.COMPILER_TREE)
2906         public List<JCExpression> getBounds() {
2907             return bounds;
2908         }
2909         @Override @DefinedBy(Api.COMPILER_TREE)
2910         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2911             return v.visitIntersectionType(this, d);
2912         }
2913         @Override
2914         public Tag getTag() {
2915             return TYPEINTERSECTION;
2916         }
2917     }
2918 
2919     /**
2920      * A formal class parameter.
2921      */
2922     public static class JCTypeParameter extends JCTree implements TypeParameterTree {
2923         /** name */
2924         public Name name;
2925         /** bounds */
2926         public List<JCExpression> bounds;
2927         /** type annotations on type parameter */
2928         public List<JCAnnotation> annotations;
2929         protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) {
2930             this.name = name;
2931             this.bounds = bounds;
2932             this.annotations = annotations;
2933         }
2934         @Override
2935         public void accept(Visitor v) { v.visitTypeParameter(this); }
2936 
2937         @DefinedBy(Api.COMPILER_TREE)
2938         public Kind getKind() { return Kind.TYPE_PARAMETER; }
2939         @DefinedBy(Api.COMPILER_TREE)
2940         public Name getName() { return name; }
2941         @DefinedBy(Api.COMPILER_TREE)
2942         public List<JCExpression> getBounds() {
2943             return bounds;
2944         }
2945         @DefinedBy(Api.COMPILER_TREE)
2946         public List<JCAnnotation> getAnnotations() {
2947             return annotations;
2948         }
2949         @Override @DefinedBy(Api.COMPILER_TREE)
2950         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2951             return v.visitTypeParameter(this, d);
2952         }
2953         @Override
2954         public Tag getTag() {
2955             return TYPEPARAMETER;
2956         }
2957     }
2958 
2959     public static class JCWildcard extends JCExpression implements WildcardTree {
2960         public TypeBoundKind kind;
2961         public JCTree inner;
2962         protected JCWildcard(TypeBoundKind kind, JCTree inner) {
2963             this.kind = Assert.checkNonNull(kind);
2964             this.inner = inner;
2965         }
2966         @Override
2967         public void accept(Visitor v) { v.visitWildcard(this); }
2968 
2969         @DefinedBy(Api.COMPILER_TREE)
2970         public Kind getKind() {
2971             switch (kind.kind) {
2972             case UNBOUND:
2973                 return Kind.UNBOUNDED_WILDCARD;
2974             case EXTENDS:
2975                 return Kind.EXTENDS_WILDCARD;
2976             case SUPER:
2977                 return Kind.SUPER_WILDCARD;
2978             default:
2979                 throw new AssertionError("Unknown wildcard bound " + kind);
2980             }
2981         }
2982         @DefinedBy(Api.COMPILER_TREE)
2983         public JCTree getBound() { return inner; }
2984         @Override @DefinedBy(Api.COMPILER_TREE)
2985         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2986             return v.visitWildcard(this, d);
2987         }
2988         @Override
2989         public Tag getTag() {
2990             return Tag.WILDCARD;
2991         }
2992     }
2993 
2994     public static class TypeBoundKind extends JCTree {
2995         public BoundKind kind;
2996         protected TypeBoundKind(BoundKind kind) {
2997             this.kind = kind;
2998         }
2999         @Override
3000         public void accept(Visitor v) { v.visitTypeBoundKind(this); }
3001 
3002         @DefinedBy(Api.COMPILER_TREE)
3003         public Kind getKind() {
3004             throw new AssertionError("TypeBoundKind is not part of a public API");
3005         }
3006         @Override @DefinedBy(Api.COMPILER_TREE)
3007         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3008             throw new AssertionError("TypeBoundKind is not part of a public API");
3009         }
3010         @Override
3011         public Tag getTag() {
3012             return TYPEBOUNDKIND;
3013         }
3014     }
3015 
3016     public static class JCAnnotation extends JCExpression implements AnnotationTree {
3017         // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION
3018         private Tag tag;
3019 
3020         public JCTree annotationType;
3021         public List<JCExpression> args;
3022         public Attribute.Compound attribute;
3023 
3024         protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) {
3025             this.tag = tag;
3026             this.annotationType = annotationType;
3027             this.args = args;
3028         }
3029 
3030         @Override
3031         public void accept(Visitor v) { v.visitAnnotation(this); }
3032 
3033         @DefinedBy(Api.COMPILER_TREE)
3034         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
3035 
3036         @DefinedBy(Api.COMPILER_TREE)
3037         public JCTree getAnnotationType() { return annotationType; }
3038         @DefinedBy(Api.COMPILER_TREE)
3039         public List<JCExpression> getArguments() {
3040             return args;
3041         }
3042         @Override @DefinedBy(Api.COMPILER_TREE)
3043         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3044             return v.visitAnnotation(this, d);
3045         }
3046         @Override
3047         public Tag getTag() {
3048             return tag;
3049         }
3050     }
3051 
3052     public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
3053         public long flags;
3054         public List<JCAnnotation> annotations;
3055         protected JCModifiers(long flags, List<JCAnnotation> annotations) {
3056             this.flags = flags;
3057             this.annotations = annotations;
3058         }
3059         @Override
3060         public void accept(Visitor v) { v.visitModifiers(this); }
3061 
3062         @DefinedBy(Api.COMPILER_TREE)
3063         public Kind getKind() { return Kind.MODIFIERS; }
3064         @DefinedBy(Api.COMPILER_TREE)
3065         public Set<Modifier> getFlags() {
3066             return Flags.asModifierSet(flags);
3067         }
3068         @DefinedBy(Api.COMPILER_TREE)
3069         public List<JCAnnotation> getAnnotations() {
3070             return annotations;
3071         }
3072         @Override @DefinedBy(Api.COMPILER_TREE)
3073         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3074             return v.visitModifiers(this, d);
3075         }
3076         @Override
3077         public Tag getTag() {
3078             return MODIFIERS;
3079         }
3080     }
3081 
3082     public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
3083         // type annotations
3084         public List<JCAnnotation> annotations;
3085         public JCExpression underlyingType;
3086 
3087         protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
3088             Assert.check(annotations != null && annotations.nonEmpty());
3089             this.annotations = annotations;
3090             this.underlyingType = underlyingType;
3091         }
3092         @Override
3093         public void accept(Visitor v) { v.visitAnnotatedType(this); }
3094 
3095         @DefinedBy(Api.COMPILER_TREE)
3096         public Kind getKind() { return Kind.ANNOTATED_TYPE; }
3097         @DefinedBy(Api.COMPILER_TREE)
3098         public List<JCAnnotation> getAnnotations() {
3099             return annotations;
3100         }
3101         @DefinedBy(Api.COMPILER_TREE)
3102         public JCExpression getUnderlyingType() {
3103             return underlyingType;
3104         }
3105         @Override @DefinedBy(Api.COMPILER_TREE)
3106         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3107             return v.visitAnnotatedType(this, d);
3108         }
3109         @Override
3110         public Tag getTag() {
3111             return ANNOTATED_TYPE;
3112         }
3113     }
3114 
3115     public abstract static class JCDirective extends JCTree
3116         implements DirectiveTree {
3117     }
3118 
3119     public static class JCModuleDecl extends JCTree implements ModuleTree {
3120         public JCModifiers mods;
3121         public ModuleType type;
3122         private final ModuleKind kind;
3123         public JCExpression qualId;
3124         public List<JCDirective> directives;
3125         public ModuleSymbol sym;
3126 
3127         protected JCModuleDecl(JCModifiers mods, ModuleKind kind,
3128                 JCExpression qualId, List<JCDirective> directives) {
3129             this.mods = mods;
3130             this.kind = kind;
3131             this.qualId = qualId;
3132             this.directives = directives;
3133         }
3134 
3135         @Override
3136         public void accept(Visitor v) { v.visitModuleDef(this); }
3137 
3138         @Override @DefinedBy(Api.COMPILER_TREE)
3139         public Kind getKind() {
3140             return Kind.MODULE;
3141         }
3142 
3143         @Override @DefinedBy(Api.COMPILER_TREE)
3144         public List<? extends AnnotationTree> getAnnotations() {
3145             return mods.annotations;
3146         }
3147 
3148         @Override @DefinedBy(Api.COMPILER_TREE)
3149         public ModuleKind getModuleType() {
3150             return kind;
3151         }
3152 
3153         @Override @DefinedBy(Api.COMPILER_TREE)
3154         public JCExpression getName() {
3155             return qualId;
3156         }
3157 
3158         @Override @DefinedBy(Api.COMPILER_TREE)
3159         public List<JCDirective> getDirectives() {
3160             return directives;
3161         }
3162 
3163         @Override @DefinedBy(Api.COMPILER_TREE)
3164         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3165             return v.visitModule(this, d);
3166         }
3167 
3168         @Override
3169         public Tag getTag() {
3170             return MODULEDEF;
3171         }
3172     }
3173 
3174     public static class JCExports extends JCDirective
3175             implements ExportsTree {
3176         public JCExpression qualid;
3177         public List<JCExpression> moduleNames;
3178         public ExportsDirective directive;
3179 
3180         protected JCExports(JCExpression qualId, List<JCExpression> moduleNames) {
3181             this.qualid = qualId;
3182             this.moduleNames = moduleNames;
3183         }
3184 
3185         @Override
3186         public void accept(Visitor v) { v.visitExports(this); }
3187 
3188         @Override @DefinedBy(Api.COMPILER_TREE)
3189         public Kind getKind() {
3190             return Kind.EXPORTS;
3191         }
3192 
3193         @Override @DefinedBy(Api.COMPILER_TREE)
3194         public JCExpression getPackageName() {
3195             return qualid;
3196         }
3197 
3198         @Override @DefinedBy(Api.COMPILER_TREE)
3199         public List<JCExpression> getModuleNames() {
3200             return moduleNames;
3201         }
3202 
3203         @Override @DefinedBy(Api.COMPILER_TREE)
3204         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3205             return v.visitExports(this, d);
3206         }
3207 
3208         @Override
3209         public Tag getTag() {
3210             return Tag.EXPORTS;
3211         }
3212     }
3213 
3214     public static class JCOpens extends JCDirective
3215             implements OpensTree {
3216         public JCExpression qualid;
3217         public List<JCExpression> moduleNames;
3218         public OpensDirective directive;
3219 
3220         protected JCOpens(JCExpression qualId, List<JCExpression> moduleNames) {
3221             this.qualid = qualId;
3222             this.moduleNames = moduleNames;
3223         }
3224 
3225         @Override
3226         public void accept(Visitor v) { v.visitOpens(this); }
3227 
3228         @Override @DefinedBy(Api.COMPILER_TREE)
3229         public Kind getKind() {
3230             return Kind.OPENS;
3231         }
3232 
3233         @Override @DefinedBy(Api.COMPILER_TREE)
3234         public JCExpression getPackageName() {
3235             return qualid;
3236         }
3237 
3238         @Override @DefinedBy(Api.COMPILER_TREE)
3239         public List<JCExpression> getModuleNames() {
3240             return moduleNames;
3241         }
3242 
3243         @Override @DefinedBy(Api.COMPILER_TREE)
3244         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3245             return v.visitOpens(this, d);
3246         }
3247 
3248         @Override
3249         public Tag getTag() {
3250             return Tag.OPENS;
3251         }
3252     }
3253 
3254     public static class JCProvides extends JCDirective
3255             implements ProvidesTree {
3256         public JCExpression serviceName;
3257         public List<JCExpression> implNames;
3258 
3259         protected JCProvides(JCExpression serviceName, List<JCExpression> implNames) {
3260             this.serviceName = serviceName;
3261             this.implNames = implNames;
3262         }
3263 
3264         @Override
3265         public void accept(Visitor v) { v.visitProvides(this); }
3266 
3267         @Override @DefinedBy(Api.COMPILER_TREE)
3268         public Kind getKind() {
3269             return Kind.PROVIDES;
3270         }
3271 
3272         @Override @DefinedBy(Api.COMPILER_TREE)
3273         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3274             return v.visitProvides(this, d);
3275         }
3276 
3277         @Override @DefinedBy(Api.COMPILER_TREE)
3278         public JCExpression getServiceName() {
3279             return serviceName;
3280         }
3281 
3282         @Override @DefinedBy(Api.COMPILER_TREE)
3283         public List<JCExpression> getImplementationNames() {
3284             return implNames;
3285         }
3286 
3287         @Override
3288         public Tag getTag() {
3289             return PROVIDES;
3290         }
3291     }
3292 
3293     public static class JCRequires extends JCDirective
3294             implements RequiresTree {
3295         public boolean isTransitive;
3296         public boolean isStaticPhase;
3297         public JCExpression moduleName;
3298         public RequiresDirective directive;
3299 
3300         protected JCRequires(boolean isTransitive, boolean isStaticPhase, JCExpression moduleName) {
3301             this.isTransitive = isTransitive;
3302             this.isStaticPhase = isStaticPhase;
3303             this.moduleName = moduleName;
3304         }
3305 
3306         @Override
3307         public void accept(Visitor v) { v.visitRequires(this); }
3308 
3309         @Override @DefinedBy(Api.COMPILER_TREE)
3310         public Kind getKind() {
3311             return Kind.REQUIRES;
3312         }
3313 
3314         @Override @DefinedBy(Api.COMPILER_TREE)
3315         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3316             return v.visitRequires(this, d);
3317         }
3318 
3319         @Override @DefinedBy(Api.COMPILER_TREE)
3320         public boolean isTransitive() {
3321             return isTransitive;
3322         }
3323 
3324         @Override @DefinedBy(Api.COMPILER_TREE)
3325         public boolean isStatic() {
3326             return isStaticPhase;
3327         }
3328 
3329         @Override @DefinedBy(Api.COMPILER_TREE)
3330         public JCExpression getModuleName() {
3331             return moduleName;
3332         }
3333 
3334         @Override
3335         public Tag getTag() {
3336             return REQUIRES;
3337         }
3338     }
3339 
3340     public static class JCUses extends JCDirective
3341             implements UsesTree {
3342         public JCExpression qualid;
3343 
3344         protected JCUses(JCExpression qualId) {
3345             this.qualid = qualId;
3346         }
3347 
3348         @Override
3349         public void accept(Visitor v) { v.visitUses(this); }
3350 
3351         @Override @DefinedBy(Api.COMPILER_TREE)
3352         public Kind getKind() {
3353             return Kind.USES;
3354         }
3355 
3356         @Override @DefinedBy(Api.COMPILER_TREE)
3357         public JCExpression getServiceName() {
3358             return qualid;
3359         }
3360 
3361         @Override @DefinedBy(Api.COMPILER_TREE)
3362         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
3363             return v.visitUses(this, d);
3364         }
3365 
3366         @Override
3367         public Tag getTag() {
3368             return USES;
3369         }
3370     }
3371 
3372     public static class JCErroneous extends JCExpression
3373             implements ErroneousTree {
3374         public List<? extends JCTree> errs;
3375         protected JCErroneous(List<? extends JCTree> errs) {
3376             this.errs = errs;
3377         }
3378         @Override
3379         public void accept(Visitor v) { v.visitErroneous(this); }
3380 
3381         @DefinedBy(Api.COMPILER_TREE)
3382         public Kind getKind() { return Kind.ERRONEOUS; }
3383 
3384         @DefinedBy(Api.COMPILER_TREE)
3385         public List<? extends JCTree> getErrorTrees() {
3386             return errs;
3387         }
3388 
3389         @Override @DefinedBy(Api.COMPILER_TREE)
3390         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3391             return v.visitErroneous(this, d);
3392         }
3393         @Override
3394         public Tag getTag() {
3395             return ERRONEOUS;
3396         }
3397     }
3398 
3399     /** (let int x = 3; in x+2) */
3400     public static class LetExpr extends JCExpression {
3401         public List<JCStatement> defs;
3402         public JCExpression expr;
3403         /**true if a expr should be run through Gen.genCond:*/
3404         public boolean needsCond;
3405         protected LetExpr(List<JCStatement> defs, JCExpression expr) {
3406             this.defs = defs;
3407             this.expr = expr;
3408         }
3409         @Override
3410         public void accept(Visitor v) { v.visitLetExpr(this); }
3411 
3412         @DefinedBy(Api.COMPILER_TREE)
3413         public Kind getKind() {
3414             throw new AssertionError("LetExpr is not part of a public API");
3415         }
3416         @Override @DefinedBy(Api.COMPILER_TREE)
3417         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3418             throw new AssertionError("LetExpr is not part of a public API");
3419         }
3420         @Override
3421         public Tag getTag() {
3422             return LETEXPR;
3423         }
3424     }
3425 
3426     /** An interface for tree factories
3427      */
3428     public interface Factory {
3429         JCCompilationUnit TopLevel(List<JCTree> defs);
3430         JCPackageDecl PackageDecl(List<JCAnnotation> annotations,
3431                                   JCExpression pid);
3432         JCImport Import(JCFieldAccess qualid, boolean staticImport);
3433         JCClassDecl ClassDef(JCModifiers mods,
3434                           Name name,
3435                           List<JCTypeParameter> typarams,
3436                           JCExpression extending,
3437                           List<JCExpression> implementing,
3438                           List<JCTree> defs);
3439         JCMethodDecl MethodDef(JCModifiers mods,
3440                             Name name,
3441                             JCExpression restype,
3442                             List<JCTypeParameter> typarams,
3443                             JCVariableDecl recvparam,
3444                             List<JCVariableDecl> params,
3445                             List<JCExpression> thrown,
3446                             JCBlock body,
3447                             JCExpression defaultValue);
3448         JCVariableDecl VarDef(JCModifiers mods,
3449                       Name name,
3450                       JCExpression vartype,
3451                       JCExpression init);
3452         JCSkip Skip();
3453         JCBlock Block(long flags, List<JCStatement> stats);
3454         JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
3455         JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
3456         JCForLoop ForLoop(List<JCStatement> init,
3457                         JCExpression cond,
3458                         List<JCExpressionStatement> step,
3459                         JCStatement body);
3460         JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
3461         JCLabeledStatement Labelled(Name label, JCStatement body);
3462         JCSwitch Switch(JCExpression selector, List<JCCase> cases);
3463         JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases);
3464         JCCase Case(CaseTree.CaseKind caseKind, List<JCCaseLabel> labels, JCExpression guard,
3465                     List<JCStatement> stats, JCTree body);
3466         JCSynchronized Synchronized(JCExpression lock, JCBlock body);
3467         JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
3468         JCTry Try(List<JCTree> resources,
3469                   JCBlock body,
3470                   List<JCCatch> catchers,
3471                   JCBlock finalizer);
3472         JCCatch Catch(JCVariableDecl param, JCBlock body);
3473         JCConditional Conditional(JCExpression cond,
3474                                 JCExpression thenpart,
3475                                 JCExpression elsepart);
3476         JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
3477         JCExpressionStatement Exec(JCExpression expr);
3478         JCBreak Break(Name label);
3479         JCYield Yield(JCExpression value);
3480         JCContinue Continue(Name label);
3481         JCReturn Return(JCExpression expr);
3482         JCThrow Throw(JCExpression expr);
3483         JCAssert Assert(JCExpression cond, JCExpression detail);
3484         JCMethodInvocation Apply(List<JCExpression> typeargs,
3485                     JCExpression fn,
3486                     List<JCExpression> args);
3487         JCNewClass NewClass(JCExpression encl,
3488                           List<JCExpression> typeargs,
3489                           JCExpression clazz,
3490                           List<JCExpression> args,
3491                           JCClassDecl def);
3492         JCNewArray NewArray(JCExpression elemtype,
3493                           List<JCExpression> dims,
3494                           List<JCExpression> elems);
3495         JCParens Parens(JCExpression expr);
3496         JCAssign Assign(JCExpression lhs, JCExpression rhs);
3497         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3498         JCUnary Unary(Tag opcode, JCExpression arg);
3499         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3500         JCTypeCast TypeCast(JCTree expr, JCExpression type);
3501         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3502         JCBindingPattern BindingPattern(JCVariableDecl var);
3503         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3504         JCFieldAccess Select(JCExpression selected, Name selector);
3505         JCIdent Ident(Name idname);
3506         JCLiteral Literal(TypeTag tag, Object value);
3507         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3508         JCArrayTypeTree TypeArray(JCExpression elemtype);
3509         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3510         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3511         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3512         TypeBoundKind TypeBoundKind(BoundKind kind);
3513         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3514         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3515         JCErroneous Erroneous(List<? extends JCTree> errs);
3516         JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3517         JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3518         JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3519         JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3520         JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3521         JCUses Uses(JCExpression qualId);
3522         LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);
3523     }
3524 
3525     /** A generic visitor class for trees.
3526      */
3527     public abstract static class Visitor {
3528         public void visitTopLevel(JCCompilationUnit that)    { visitTree(that); }
3529         public void visitPackageDef(JCPackageDecl that)      { visitTree(that); }
3530         public void visitImport(JCImport that)               { visitTree(that); }
3531         public void visitModuleImport(JCModuleImport that)   { visitTree(that); }
3532         public void visitClassDef(JCClassDecl that)          { visitTree(that); }
3533         public void visitMethodDef(JCMethodDecl that)        { visitTree(that); }
3534         public void visitVarDef(JCVariableDecl that)         { visitTree(that); }
3535         public void visitSkip(JCSkip that)                   { visitTree(that); }
3536         public void visitBlock(JCBlock that)                 { visitTree(that); }
3537         public void visitDoLoop(JCDoWhileLoop that)          { visitTree(that); }
3538         public void visitWhileLoop(JCWhileLoop that)         { visitTree(that); }
3539         public void visitForLoop(JCForLoop that)             { visitTree(that); }
3540         public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3541         public void visitLabelled(JCLabeledStatement that)   { visitTree(that); }
3542         public void visitSwitch(JCSwitch that)               { visitTree(that); }
3543         public void visitCase(JCCase that)                   { visitTree(that); }
3544         public void visitSwitchExpression(JCSwitchExpression that)               { visitTree(that); }
3545         public void visitSynchronized(JCSynchronized that)   { visitTree(that); }
3546         public void visitTry(JCTry that)                     { visitTree(that); }
3547         public void visitCatch(JCCatch that)                 { visitTree(that); }
3548         public void visitConditional(JCConditional that)     { visitTree(that); }
3549         public void visitIf(JCIf that)                       { visitTree(that); }
3550         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
3551         public void visitBreak(JCBreak that)                 { visitTree(that); }
3552         public void visitYield(JCYield that)                 { visitTree(that); }
3553         public void visitContinue(JCContinue that)           { visitTree(that); }
3554         public void visitReturn(JCReturn that)               { visitTree(that); }
3555         public void visitThrow(JCThrow that)                 { visitTree(that); }
3556         public void visitAssert(JCAssert that)               { visitTree(that); }
3557         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
3558         public void visitNewClass(JCNewClass that)           { visitTree(that); }
3559         public void visitNewArray(JCNewArray that)           { visitTree(that); }
3560         public void visitLambda(JCLambda that)               { visitTree(that); }
3561         public void visitParens(JCParens that)               { visitTree(that); }
3562         public void visitAssign(JCAssign that)               { visitTree(that); }
3563         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
3564         public void visitUnary(JCUnary that)                 { visitTree(that); }
3565         public void visitBinary(JCBinary that)               { visitTree(that); }
3566         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
3567         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
3568         public void visitAnyPattern(JCAnyPattern that)       { visitTree(that); }
3569         public void visitBindingPattern(JCBindingPattern that) { visitTree(that); }
3570         public void visitDefaultCaseLabel(JCDefaultCaseLabel that) { visitTree(that); }
3571         public void visitConstantCaseLabel(JCConstantCaseLabel that) { visitTree(that); }
3572         public void visitPatternCaseLabel(JCPatternCaseLabel that) { visitTree(that); }
3573         public void visitRecordPattern(JCRecordPattern that) { visitTree(that); }
3574         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
3575         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
3576         public void visitReference(JCMemberReference that)   { visitTree(that); }
3577         public void visitIdent(JCIdent that)                 { visitTree(that); }
3578         public void visitLiteral(JCLiteral that)             { visitTree(that); }
3579         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
3580         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
3581         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
3582         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
3583         public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
3584         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
3585         public void visitWildcard(JCWildcard that)           { visitTree(that); }
3586         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
3587         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
3588         public void visitModifiers(JCModifiers that)         { visitTree(that); }
3589         public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
3590         public void visitErroneous(JCErroneous that)         { visitTree(that); }
3591         public void visitModuleDef(JCModuleDecl that)        { visitTree(that); }
3592         public void visitExports(JCExports that)             { visitTree(that); }
3593         public void visitOpens(JCOpens that)                 { visitTree(that); }
3594         public void visitProvides(JCProvides that)           { visitTree(that); }
3595         public void visitRequires(JCRequires that)           { visitTree(that); }
3596         public void visitUses(JCUses that)                   { visitTree(that); }
3597         public void visitLetExpr(LetExpr that)               { visitTree(that); }
3598 
3599         public void visitTree(JCTree that)                   { Assert.error(); }
3600     }
3601 
3602 }