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