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