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