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