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