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