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