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