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