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