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