JCTree.java revision 3828:d30434bde0a8
1/*
2 * Copyright (c) 1999, 2016, 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
26package com.sun.tools.javac.tree;
27
28import java.io.IOException;
29import java.io.StringWriter;
30import java.util.*;
31
32import javax.lang.model.element.Modifier;
33import javax.lang.model.type.TypeKind;
34import javax.tools.JavaFileObject;
35
36import com.sun.source.tree.*;
37import com.sun.tools.javac.code.*;
38import com.sun.tools.javac.code.Directive.RequiresDirective;
39import com.sun.tools.javac.code.Scope.*;
40import com.sun.tools.javac.code.Symbol.*;
41import com.sun.tools.javac.util.*;
42import com.sun.tools.javac.util.DefinedBy.Api;
43import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
44import com.sun.tools.javac.util.List;
45
46import static com.sun.tools.javac.tree.JCTree.Tag.*;
47
48import javax.tools.JavaFileManager.Location;
49
50import com.sun.source.tree.ModuleTree.ModuleKind;
51import com.sun.tools.javac.code.Directive.ExportsDirective;
52import com.sun.tools.javac.code.Directive.OpensDirective;
53import 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 */
88public 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 List<Type> targets;
733
734        public Type getDescriptorType(Types types) {
735            return targets.nonEmpty() ? types.findDescriptorType(targets.head) : 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
924        protected JCVariableDecl(JCModifiers mods,
925                         Name name,
926                         JCExpression vartype,
927                         JCExpression init,
928                         VarSymbol sym) {
929            this.mods = mods;
930            this.name = name;
931            this.vartype = vartype;
932            this.init = init;
933            this.sym = sym;
934        }
935
936        protected JCVariableDecl(JCModifiers mods,
937                         JCExpression nameexpr,
938                         JCExpression vartype) {
939            this(mods, null, vartype, null, null);
940            this.nameexpr = nameexpr;
941            if (nameexpr.hasTag(Tag.IDENT)) {
942                this.name = ((JCIdent)nameexpr).name;
943            } else {
944                // Only other option is qualified name x.y.this;
945                this.name = ((JCFieldAccess)nameexpr).name;
946            }
947        }
948
949        @Override
950        public void accept(Visitor v) { v.visitVarDef(this); }
951
952        @DefinedBy(Api.COMPILER_TREE)
953        public Kind getKind() { return Kind.VARIABLE; }
954        @DefinedBy(Api.COMPILER_TREE)
955        public JCModifiers getModifiers() { return mods; }
956        @DefinedBy(Api.COMPILER_TREE)
957        public Name getName() { return name; }
958        @DefinedBy(Api.COMPILER_TREE)
959        public JCExpression getNameExpression() { return nameexpr; }
960        @DefinedBy(Api.COMPILER_TREE)
961        public JCTree getType() { return vartype; }
962        @DefinedBy(Api.COMPILER_TREE)
963        public JCExpression getInitializer() {
964            return init;
965        }
966        @Override @DefinedBy(Api.COMPILER_TREE)
967        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
968            return v.visitVariable(this, d);
969        }
970
971        @Override
972        public Tag getTag() {
973            return VARDEF;
974        }
975    }
976
977    /**
978     * A no-op statement ";".
979     */
980    public static class JCSkip extends JCStatement implements EmptyStatementTree {
981        protected JCSkip() {
982        }
983        @Override
984        public void accept(Visitor v) { v.visitSkip(this); }
985
986        @DefinedBy(Api.COMPILER_TREE)
987        public Kind getKind() { return Kind.EMPTY_STATEMENT; }
988        @Override @DefinedBy(Api.COMPILER_TREE)
989        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
990            return v.visitEmptyStatement(this, d);
991        }
992
993        @Override
994        public Tag getTag() {
995            return SKIP;
996        }
997    }
998
999    /**
1000     * A statement block.
1001     */
1002    public static class JCBlock extends JCStatement implements BlockTree {
1003        /** flags */
1004        public long flags;
1005        /** statements */
1006        public List<JCStatement> stats;
1007        /** Position of closing brace, optional. */
1008        public int endpos = Position.NOPOS;
1009        protected JCBlock(long flags, List<JCStatement> stats) {
1010            this.stats = stats;
1011            this.flags = flags;
1012        }
1013        @Override
1014        public void accept(Visitor v) { v.visitBlock(this); }
1015
1016        @DefinedBy(Api.COMPILER_TREE)
1017        public Kind getKind() { return Kind.BLOCK; }
1018        @DefinedBy(Api.COMPILER_TREE)
1019        public List<JCStatement> getStatements() {
1020            return stats;
1021        }
1022        @DefinedBy(Api.COMPILER_TREE)
1023        public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
1024        @Override @DefinedBy(Api.COMPILER_TREE)
1025        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1026            return v.visitBlock(this, d);
1027        }
1028
1029        @Override
1030        public Tag getTag() {
1031            return BLOCK;
1032        }
1033    }
1034
1035    /**
1036     * A do loop
1037     */
1038    public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
1039        public JCStatement body;
1040        public JCExpression cond;
1041        protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
1042            this.body = body;
1043            this.cond = cond;
1044        }
1045        @Override
1046        public void accept(Visitor v) { v.visitDoLoop(this); }
1047
1048        @DefinedBy(Api.COMPILER_TREE)
1049        public Kind getKind() { return Kind.DO_WHILE_LOOP; }
1050        @DefinedBy(Api.COMPILER_TREE)
1051        public JCExpression getCondition() { return cond; }
1052        @DefinedBy(Api.COMPILER_TREE)
1053        public JCStatement getStatement() { return body; }
1054        @Override @DefinedBy(Api.COMPILER_TREE)
1055        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1056            return v.visitDoWhileLoop(this, d);
1057        }
1058
1059        @Override
1060        public Tag getTag() {
1061            return DOLOOP;
1062        }
1063    }
1064
1065    /**
1066     * A while loop
1067     */
1068    public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
1069        public JCExpression cond;
1070        public JCStatement body;
1071        protected JCWhileLoop(JCExpression cond, JCStatement body) {
1072            this.cond = cond;
1073            this.body = body;
1074        }
1075        @Override
1076        public void accept(Visitor v) { v.visitWhileLoop(this); }
1077
1078        @DefinedBy(Api.COMPILER_TREE)
1079        public Kind getKind() { return Kind.WHILE_LOOP; }
1080        @DefinedBy(Api.COMPILER_TREE)
1081        public JCExpression getCondition() { return cond; }
1082        @DefinedBy(Api.COMPILER_TREE)
1083        public JCStatement getStatement() { return body; }
1084        @Override @DefinedBy(Api.COMPILER_TREE)
1085        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1086            return v.visitWhileLoop(this, d);
1087        }
1088
1089        @Override
1090        public Tag getTag() {
1091            return WHILELOOP;
1092        }
1093    }
1094
1095    /**
1096     * A for loop.
1097     */
1098    public static class JCForLoop extends JCStatement implements ForLoopTree {
1099        public List<JCStatement> init;
1100        public JCExpression cond;
1101        public List<JCExpressionStatement> step;
1102        public JCStatement body;
1103        protected JCForLoop(List<JCStatement> init,
1104                          JCExpression cond,
1105                          List<JCExpressionStatement> update,
1106                          JCStatement body)
1107        {
1108            this.init = init;
1109            this.cond = cond;
1110            this.step = update;
1111            this.body = body;
1112        }
1113        @Override
1114        public void accept(Visitor v) { v.visitForLoop(this); }
1115
1116        @DefinedBy(Api.COMPILER_TREE)
1117        public Kind getKind() { return Kind.FOR_LOOP; }
1118        @DefinedBy(Api.COMPILER_TREE)
1119        public JCExpression getCondition() { return cond; }
1120        @DefinedBy(Api.COMPILER_TREE)
1121        public JCStatement getStatement() { return body; }
1122        @DefinedBy(Api.COMPILER_TREE)
1123        public List<JCStatement> getInitializer() {
1124            return init;
1125        }
1126        @DefinedBy(Api.COMPILER_TREE)
1127        public List<JCExpressionStatement> getUpdate() {
1128            return step;
1129        }
1130        @Override @DefinedBy(Api.COMPILER_TREE)
1131        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1132            return v.visitForLoop(this, d);
1133        }
1134
1135        @Override
1136        public Tag getTag() {
1137            return FORLOOP;
1138        }
1139    }
1140
1141    /**
1142     * The enhanced for loop.
1143     */
1144    public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
1145        public JCVariableDecl var;
1146        public JCExpression expr;
1147        public JCStatement body;
1148        protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
1149            this.var = var;
1150            this.expr = expr;
1151            this.body = body;
1152        }
1153        @Override
1154        public void accept(Visitor v) { v.visitForeachLoop(this); }
1155
1156        @DefinedBy(Api.COMPILER_TREE)
1157        public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
1158        @DefinedBy(Api.COMPILER_TREE)
1159        public JCVariableDecl getVariable() { return var; }
1160        @DefinedBy(Api.COMPILER_TREE)
1161        public JCExpression getExpression() { return expr; }
1162        @DefinedBy(Api.COMPILER_TREE)
1163        public JCStatement getStatement() { return body; }
1164        @Override @DefinedBy(Api.COMPILER_TREE)
1165        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1166            return v.visitEnhancedForLoop(this, d);
1167        }
1168        @Override
1169        public Tag getTag() {
1170            return FOREACHLOOP;
1171        }
1172    }
1173
1174    /**
1175     * A labelled expression or statement.
1176     */
1177    public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
1178        public Name label;
1179        public JCStatement body;
1180        protected JCLabeledStatement(Name label, JCStatement body) {
1181            this.label = label;
1182            this.body = body;
1183        }
1184        @Override
1185        public void accept(Visitor v) { v.visitLabelled(this); }
1186        @DefinedBy(Api.COMPILER_TREE)
1187        public Kind getKind() { return Kind.LABELED_STATEMENT; }
1188        @DefinedBy(Api.COMPILER_TREE)
1189        public Name getLabel() { return label; }
1190        @DefinedBy(Api.COMPILER_TREE)
1191        public JCStatement getStatement() { return body; }
1192        @Override @DefinedBy(Api.COMPILER_TREE)
1193        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1194            return v.visitLabeledStatement(this, d);
1195        }
1196        @Override
1197        public Tag getTag() {
1198            return LABELLED;
1199        }
1200    }
1201
1202    /**
1203     * A "switch ( ) { }" construction.
1204     */
1205    public static class JCSwitch extends JCStatement implements SwitchTree {
1206        public JCExpression selector;
1207        public List<JCCase> cases;
1208        protected JCSwitch(JCExpression selector, List<JCCase> cases) {
1209            this.selector = selector;
1210            this.cases = cases;
1211        }
1212        @Override
1213        public void accept(Visitor v) { v.visitSwitch(this); }
1214
1215        @DefinedBy(Api.COMPILER_TREE)
1216        public Kind getKind() { return Kind.SWITCH; }
1217        @DefinedBy(Api.COMPILER_TREE)
1218        public JCExpression getExpression() { return selector; }
1219        @DefinedBy(Api.COMPILER_TREE)
1220        public List<JCCase> getCases() { return cases; }
1221        @Override @DefinedBy(Api.COMPILER_TREE)
1222        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1223            return v.visitSwitch(this, d);
1224        }
1225        @Override
1226        public Tag getTag() {
1227            return SWITCH;
1228        }
1229    }
1230
1231    /**
1232     * A "case  :" of a switch.
1233     */
1234    public static class JCCase extends JCStatement implements CaseTree {
1235        public JCExpression pat;
1236        public List<JCStatement> stats;
1237        protected JCCase(JCExpression pat, List<JCStatement> stats) {
1238            this.pat = pat;
1239            this.stats = stats;
1240        }
1241        @Override
1242        public void accept(Visitor v) { v.visitCase(this); }
1243
1244        @DefinedBy(Api.COMPILER_TREE)
1245        public Kind getKind() { return Kind.CASE; }
1246        @DefinedBy(Api.COMPILER_TREE)
1247        public JCExpression getExpression() { return pat; }
1248        @DefinedBy(Api.COMPILER_TREE)
1249        public List<JCStatement> getStatements() { return stats; }
1250        @Override @DefinedBy(Api.COMPILER_TREE)
1251        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1252            return v.visitCase(this, d);
1253        }
1254        @Override
1255        public Tag getTag() {
1256            return CASE;
1257        }
1258    }
1259
1260    /**
1261     * A synchronized block.
1262     */
1263    public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1264        public JCExpression lock;
1265        public JCBlock body;
1266        protected JCSynchronized(JCExpression lock, JCBlock body) {
1267            this.lock = lock;
1268            this.body = body;
1269        }
1270        @Override
1271        public void accept(Visitor v) { v.visitSynchronized(this); }
1272
1273        @DefinedBy(Api.COMPILER_TREE)
1274        public Kind getKind() { return Kind.SYNCHRONIZED; }
1275        @DefinedBy(Api.COMPILER_TREE)
1276        public JCExpression getExpression() { return lock; }
1277        @DefinedBy(Api.COMPILER_TREE)
1278        public JCBlock getBlock() { return body; }
1279        @Override @DefinedBy(Api.COMPILER_TREE)
1280        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1281            return v.visitSynchronized(this, d);
1282        }
1283        @Override
1284        public Tag getTag() {
1285            return SYNCHRONIZED;
1286        }
1287    }
1288
1289    /**
1290     * A "try { } catch ( ) { } finally { }" block.
1291     */
1292    public static class JCTry extends JCStatement implements TryTree {
1293        public JCBlock body;
1294        public List<JCCatch> catchers;
1295        public JCBlock finalizer;
1296        public List<JCTree> resources;
1297        public boolean finallyCanCompleteNormally;
1298        protected JCTry(List<JCTree> resources,
1299                        JCBlock body,
1300                        List<JCCatch> catchers,
1301                        JCBlock finalizer) {
1302            this.body = body;
1303            this.catchers = catchers;
1304            this.finalizer = finalizer;
1305            this.resources = resources;
1306        }
1307        @Override
1308        public void accept(Visitor v) { v.visitTry(this); }
1309
1310        @DefinedBy(Api.COMPILER_TREE)
1311        public Kind getKind() { return Kind.TRY; }
1312        @DefinedBy(Api.COMPILER_TREE)
1313        public JCBlock getBlock() { return body; }
1314        @DefinedBy(Api.COMPILER_TREE)
1315        public List<JCCatch> getCatches() {
1316            return catchers;
1317        }
1318        @DefinedBy(Api.COMPILER_TREE)
1319        public JCBlock getFinallyBlock() { return finalizer; }
1320        @Override @DefinedBy(Api.COMPILER_TREE)
1321        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1322            return v.visitTry(this, d);
1323        }
1324        @Override @DefinedBy(Api.COMPILER_TREE)
1325        public List<JCTree> getResources() {
1326            return resources;
1327        }
1328        @Override
1329        public Tag getTag() {
1330            return TRY;
1331        }
1332    }
1333
1334    /**
1335     * A catch block.
1336     */
1337    public static class JCCatch extends JCTree implements CatchTree {
1338        public JCVariableDecl param;
1339        public JCBlock body;
1340        protected JCCatch(JCVariableDecl param, JCBlock body) {
1341            this.param = param;
1342            this.body = body;
1343        }
1344        @Override
1345        public void accept(Visitor v) { v.visitCatch(this); }
1346
1347        @DefinedBy(Api.COMPILER_TREE)
1348        public Kind getKind() { return Kind.CATCH; }
1349        @DefinedBy(Api.COMPILER_TREE)
1350        public JCVariableDecl getParameter() { return param; }
1351        @DefinedBy(Api.COMPILER_TREE)
1352        public JCBlock getBlock() { return body; }
1353        @Override @DefinedBy(Api.COMPILER_TREE)
1354        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1355            return v.visitCatch(this, d);
1356        }
1357        @Override
1358        public Tag getTag() {
1359            return CATCH;
1360        }
1361    }
1362
1363    /**
1364     * A ( ) ? ( ) : ( ) conditional expression
1365     */
1366    public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree {
1367        public JCExpression cond;
1368        public JCExpression truepart;
1369        public JCExpression falsepart;
1370        protected JCConditional(JCExpression cond,
1371                              JCExpression truepart,
1372                              JCExpression falsepart)
1373        {
1374            this.cond = cond;
1375            this.truepart = truepart;
1376            this.falsepart = falsepart;
1377        }
1378        @Override
1379        public void accept(Visitor v) { v.visitConditional(this); }
1380
1381        @DefinedBy(Api.COMPILER_TREE)
1382        public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
1383        @DefinedBy(Api.COMPILER_TREE)
1384        public JCExpression getCondition() { return cond; }
1385        @DefinedBy(Api.COMPILER_TREE)
1386        public JCExpression getTrueExpression() { return truepart; }
1387        @DefinedBy(Api.COMPILER_TREE)
1388        public JCExpression getFalseExpression() { return falsepart; }
1389        @Override @DefinedBy(Api.COMPILER_TREE)
1390        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1391            return v.visitConditionalExpression(this, d);
1392        }
1393        @Override
1394        public Tag getTag() {
1395            return CONDEXPR;
1396        }
1397    }
1398
1399    /**
1400     * An "if ( ) { } else { }" block
1401     */
1402    public static class JCIf extends JCStatement implements IfTree {
1403        public JCExpression cond;
1404        public JCStatement thenpart;
1405        public JCStatement elsepart;
1406        protected JCIf(JCExpression cond,
1407                     JCStatement thenpart,
1408                     JCStatement elsepart)
1409        {
1410            this.cond = cond;
1411            this.thenpart = thenpart;
1412            this.elsepart = elsepart;
1413        }
1414        @Override
1415        public void accept(Visitor v) { v.visitIf(this); }
1416
1417        @DefinedBy(Api.COMPILER_TREE)
1418        public Kind getKind() { return Kind.IF; }
1419        @DefinedBy(Api.COMPILER_TREE)
1420        public JCExpression getCondition() { return cond; }
1421        @DefinedBy(Api.COMPILER_TREE)
1422        public JCStatement getThenStatement() { return thenpart; }
1423        @DefinedBy(Api.COMPILER_TREE)
1424        public JCStatement getElseStatement() { return elsepart; }
1425        @Override @DefinedBy(Api.COMPILER_TREE)
1426        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1427            return v.visitIf(this, d);
1428        }
1429        @Override
1430        public Tag getTag() {
1431            return IF;
1432        }
1433    }
1434
1435    /**
1436     * an expression statement
1437     */
1438    public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
1439        /** expression structure */
1440        public JCExpression expr;
1441        protected JCExpressionStatement(JCExpression expr)
1442        {
1443            this.expr = expr;
1444        }
1445        @Override
1446        public void accept(Visitor v) { v.visitExec(this); }
1447
1448        @DefinedBy(Api.COMPILER_TREE)
1449        public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
1450        @DefinedBy(Api.COMPILER_TREE)
1451        public JCExpression getExpression() { return expr; }
1452        @Override @DefinedBy(Api.COMPILER_TREE)
1453        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1454            return v.visitExpressionStatement(this, d);
1455        }
1456        @Override
1457        public Tag getTag() {
1458            return EXEC;
1459        }
1460
1461        /** Convert a expression-statement tree to a pretty-printed string. */
1462        @Override
1463        public String toString() {
1464            StringWriter s = new StringWriter();
1465            try {
1466                new Pretty(s, false).printStat(this);
1467            }
1468            catch (IOException e) {
1469                // should never happen, because StringWriter is defined
1470                // never to throw any IOExceptions
1471                throw new AssertionError(e);
1472            }
1473            return s.toString();
1474        }
1475    }
1476
1477    /**
1478     * A break from a loop or switch.
1479     */
1480    public static class JCBreak extends JCStatement implements BreakTree {
1481        public Name label;
1482        public JCTree target;
1483        protected JCBreak(Name label, JCTree target) {
1484            this.label = label;
1485            this.target = target;
1486        }
1487        @Override
1488        public void accept(Visitor v) { v.visitBreak(this); }
1489
1490        @DefinedBy(Api.COMPILER_TREE)
1491        public Kind getKind() { return Kind.BREAK; }
1492        @DefinedBy(Api.COMPILER_TREE)
1493        public Name getLabel() { return label; }
1494        @Override @DefinedBy(Api.COMPILER_TREE)
1495        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1496            return v.visitBreak(this, d);
1497        }
1498        @Override
1499        public Tag getTag() {
1500            return BREAK;
1501        }
1502    }
1503
1504    /**
1505     * A continue of a loop.
1506     */
1507    public static class JCContinue extends JCStatement implements ContinueTree {
1508        public Name label;
1509        public JCTree target;
1510        protected JCContinue(Name label, JCTree target) {
1511            this.label = label;
1512            this.target = target;
1513        }
1514        @Override
1515        public void accept(Visitor v) { v.visitContinue(this); }
1516
1517        @DefinedBy(Api.COMPILER_TREE)
1518        public Kind getKind() { return Kind.CONTINUE; }
1519        @DefinedBy(Api.COMPILER_TREE)
1520        public Name getLabel() { return label; }
1521        @Override @DefinedBy(Api.COMPILER_TREE)
1522        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1523            return v.visitContinue(this, d);
1524        }
1525        @Override
1526        public Tag getTag() {
1527            return CONTINUE;
1528        }
1529    }
1530
1531    /**
1532     * A return statement.
1533     */
1534    public static class JCReturn extends JCStatement implements ReturnTree {
1535        public JCExpression expr;
1536        protected JCReturn(JCExpression expr) {
1537            this.expr = expr;
1538        }
1539        @Override
1540        public void accept(Visitor v) { v.visitReturn(this); }
1541
1542        @DefinedBy(Api.COMPILER_TREE)
1543        public Kind getKind() { return Kind.RETURN; }
1544        @DefinedBy(Api.COMPILER_TREE)
1545        public JCExpression getExpression() { return expr; }
1546        @Override @DefinedBy(Api.COMPILER_TREE)
1547        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1548            return v.visitReturn(this, d);
1549        }
1550        @Override
1551        public Tag getTag() {
1552            return RETURN;
1553        }
1554    }
1555
1556    /**
1557     * A throw statement.
1558     */
1559    public static class JCThrow extends JCStatement implements ThrowTree {
1560        public JCExpression expr;
1561        protected JCThrow(JCExpression expr) {
1562            this.expr = expr;
1563        }
1564        @Override
1565        public void accept(Visitor v) { v.visitThrow(this); }
1566
1567        @DefinedBy(Api.COMPILER_TREE)
1568        public Kind getKind() { return Kind.THROW; }
1569        @DefinedBy(Api.COMPILER_TREE)
1570        public JCExpression getExpression() { return expr; }
1571        @Override @DefinedBy(Api.COMPILER_TREE)
1572        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1573            return v.visitThrow(this, d);
1574        }
1575        @Override
1576        public Tag getTag() {
1577            return THROW;
1578        }
1579    }
1580
1581    /**
1582     * An assert statement.
1583     */
1584    public static class JCAssert extends JCStatement implements AssertTree {
1585        public JCExpression cond;
1586        public JCExpression detail;
1587        protected JCAssert(JCExpression cond, JCExpression detail) {
1588            this.cond = cond;
1589            this.detail = detail;
1590        }
1591        @Override
1592        public void accept(Visitor v) { v.visitAssert(this); }
1593
1594        @DefinedBy(Api.COMPILER_TREE)
1595        public Kind getKind() { return Kind.ASSERT; }
1596        @DefinedBy(Api.COMPILER_TREE)
1597        public JCExpression getCondition() { return cond; }
1598        @DefinedBy(Api.COMPILER_TREE)
1599        public JCExpression getDetail() { return detail; }
1600        @Override @DefinedBy(Api.COMPILER_TREE)
1601        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1602            return v.visitAssert(this, d);
1603        }
1604        @Override
1605        public Tag getTag() {
1606            return ASSERT;
1607        }
1608    }
1609
1610    /**
1611     * A method invocation
1612     */
1613    public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree {
1614        public List<JCExpression> typeargs;
1615        public JCExpression meth;
1616        public List<JCExpression> args;
1617        public Type varargsElement;
1618        protected JCMethodInvocation(List<JCExpression> typeargs,
1619                        JCExpression meth,
1620                        List<JCExpression> args)
1621        {
1622            this.typeargs = (typeargs == null) ? List.nil()
1623                                               : typeargs;
1624            this.meth = meth;
1625            this.args = args;
1626        }
1627        @Override
1628        public void accept(Visitor v) { v.visitApply(this); }
1629
1630        @DefinedBy(Api.COMPILER_TREE)
1631        public Kind getKind() { return Kind.METHOD_INVOCATION; }
1632        @DefinedBy(Api.COMPILER_TREE)
1633        public List<JCExpression> getTypeArguments() {
1634            return typeargs;
1635        }
1636        @DefinedBy(Api.COMPILER_TREE)
1637        public JCExpression getMethodSelect() { return meth; }
1638        @DefinedBy(Api.COMPILER_TREE)
1639        public List<JCExpression> getArguments() {
1640            return args;
1641        }
1642        @Override @DefinedBy(Api.COMPILER_TREE)
1643        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1644            return v.visitMethodInvocation(this, d);
1645        }
1646        @Override
1647        public JCMethodInvocation setType(Type type) {
1648            super.setType(type);
1649            return this;
1650        }
1651        @Override
1652        public Tag getTag() {
1653            return(APPLY);
1654        }
1655    }
1656
1657    /**
1658     * A new(...) operation.
1659     */
1660    public static class JCNewClass extends JCPolyExpression implements NewClassTree {
1661        public JCExpression encl;
1662        public List<JCExpression> typeargs;
1663        public JCExpression clazz;
1664        public List<JCExpression> args;
1665        public JCClassDecl def;
1666        public Symbol constructor;
1667        public Type varargsElement;
1668        public Type constructorType;
1669        protected JCNewClass(JCExpression encl,
1670                           List<JCExpression> typeargs,
1671                           JCExpression clazz,
1672                           List<JCExpression> args,
1673                           JCClassDecl def)
1674        {
1675            this.encl = encl;
1676            this.typeargs = (typeargs == null) ? List.nil()
1677                                               : typeargs;
1678            this.clazz = clazz;
1679            this.args = args;
1680            this.def = def;
1681        }
1682        @Override
1683        public void accept(Visitor v) { v.visitNewClass(this); }
1684
1685        @DefinedBy(Api.COMPILER_TREE)
1686        public Kind getKind() { return Kind.NEW_CLASS; }
1687        @DefinedBy(Api.COMPILER_TREE)
1688        public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
1689            return encl;
1690        }
1691        @DefinedBy(Api.COMPILER_TREE)
1692        public List<JCExpression> getTypeArguments() {
1693            return typeargs;
1694        }
1695        @DefinedBy(Api.COMPILER_TREE)
1696        public JCExpression getIdentifier() { return clazz; }
1697        @DefinedBy(Api.COMPILER_TREE)
1698        public List<JCExpression> getArguments() {
1699            return args;
1700        }
1701        @DefinedBy(Api.COMPILER_TREE)
1702        public JCClassDecl getClassBody() { return def; }
1703        @Override @DefinedBy(Api.COMPILER_TREE)
1704        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1705            return v.visitNewClass(this, d);
1706        }
1707        @Override
1708        public Tag getTag() {
1709            return NEWCLASS;
1710        }
1711    }
1712
1713    /**
1714     * A new[...] operation.
1715     */
1716    public static class JCNewArray extends JCExpression implements NewArrayTree {
1717        public JCExpression elemtype;
1718        public List<JCExpression> dims;
1719        // type annotations on inner-most component
1720        public List<JCAnnotation> annotations;
1721        // type annotations on dimensions
1722        public List<List<JCAnnotation>> dimAnnotations;
1723        public List<JCExpression> elems;
1724        protected JCNewArray(JCExpression elemtype,
1725                           List<JCExpression> dims,
1726                           List<JCExpression> elems)
1727        {
1728            this.elemtype = elemtype;
1729            this.dims = dims;
1730            this.annotations = List.nil();
1731            this.dimAnnotations = List.nil();
1732            this.elems = elems;
1733        }
1734        @Override
1735        public void accept(Visitor v) { v.visitNewArray(this); }
1736
1737        @DefinedBy(Api.COMPILER_TREE)
1738        public Kind getKind() { return Kind.NEW_ARRAY; }
1739        @DefinedBy(Api.COMPILER_TREE)
1740        public JCExpression getType() { return elemtype; }
1741        @DefinedBy(Api.COMPILER_TREE)
1742        public List<JCExpression> getDimensions() {
1743            return dims;
1744        }
1745        @DefinedBy(Api.COMPILER_TREE)
1746        public List<JCExpression> getInitializers() {
1747            return elems;
1748        }
1749        @Override @DefinedBy(Api.COMPILER_TREE)
1750        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1751            return v.visitNewArray(this, d);
1752        }
1753        @Override
1754        public Tag getTag() {
1755            return NEWARRAY;
1756        }
1757
1758        @Override @DefinedBy(Api.COMPILER_TREE)
1759        public List<JCAnnotation> getAnnotations() {
1760            return annotations;
1761        }
1762
1763        @Override @DefinedBy(Api.COMPILER_TREE)
1764        public List<List<JCAnnotation>> getDimAnnotations() {
1765            return dimAnnotations;
1766        }
1767    }
1768
1769    /**
1770     * A lambda expression.
1771     */
1772    public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
1773
1774        public enum ParameterKind {
1775            IMPLICIT,
1776            EXPLICIT
1777        }
1778
1779        public List<JCVariableDecl> params;
1780        public JCTree body;
1781        public boolean canCompleteNormally = true;
1782        public ParameterKind paramKind;
1783
1784        public JCLambda(List<JCVariableDecl> params,
1785                        JCTree body) {
1786            this.params = params;
1787            this.body = body;
1788            if (params.isEmpty() ||
1789                params.head.vartype != null) {
1790                paramKind = ParameterKind.EXPLICIT;
1791            } else {
1792                paramKind = ParameterKind.IMPLICIT;
1793            }
1794        }
1795        @Override
1796        public Tag getTag() {
1797            return LAMBDA;
1798        }
1799        @Override
1800        public void accept(Visitor v) {
1801            v.visitLambda(this);
1802        }
1803        @Override @DefinedBy(Api.COMPILER_TREE)
1804        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
1805            return v.visitLambdaExpression(this, d);
1806        }
1807        @DefinedBy(Api.COMPILER_TREE)
1808        public Kind getKind() {
1809            return Kind.LAMBDA_EXPRESSION;
1810        }
1811        @DefinedBy(Api.COMPILER_TREE)
1812        public JCTree getBody() {
1813            return body;
1814        }
1815        @DefinedBy(Api.COMPILER_TREE)
1816        public java.util.List<? extends VariableTree> getParameters() {
1817            return params;
1818        }
1819        @Override
1820        public JCLambda setType(Type type) {
1821            super.setType(type);
1822            return this;
1823        }
1824        @Override @DefinedBy(Api.COMPILER_TREE)
1825        public BodyKind getBodyKind() {
1826            return body.hasTag(BLOCK) ?
1827                    BodyKind.STATEMENT :
1828                    BodyKind.EXPRESSION;
1829        }
1830    }
1831
1832    /**
1833     * A parenthesized subexpression ( ... )
1834     */
1835    public static class JCParens extends JCExpression implements ParenthesizedTree {
1836        public JCExpression expr;
1837        protected JCParens(JCExpression expr) {
1838            this.expr = expr;
1839        }
1840        @Override
1841        public void accept(Visitor v) { v.visitParens(this); }
1842
1843        @DefinedBy(Api.COMPILER_TREE)
1844        public Kind getKind() { return Kind.PARENTHESIZED; }
1845        @DefinedBy(Api.COMPILER_TREE)
1846        public JCExpression getExpression() { return expr; }
1847        @Override @DefinedBy(Api.COMPILER_TREE)
1848        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1849            return v.visitParenthesized(this, d);
1850        }
1851        @Override
1852        public Tag getTag() {
1853            return PARENS;
1854        }
1855    }
1856
1857    /**
1858     * A assignment with "=".
1859     */
1860    public static class JCAssign extends JCExpression implements AssignmentTree {
1861        public JCExpression lhs;
1862        public JCExpression rhs;
1863        protected JCAssign(JCExpression lhs, JCExpression rhs) {
1864            this.lhs = lhs;
1865            this.rhs = rhs;
1866        }
1867        @Override
1868        public void accept(Visitor v) { v.visitAssign(this); }
1869
1870        @DefinedBy(Api.COMPILER_TREE)
1871        public Kind getKind() { return Kind.ASSIGNMENT; }
1872        @DefinedBy(Api.COMPILER_TREE)
1873        public JCExpression getVariable() { return lhs; }
1874        @DefinedBy(Api.COMPILER_TREE)
1875        public JCExpression getExpression() { return rhs; }
1876        @Override @DefinedBy(Api.COMPILER_TREE)
1877        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1878            return v.visitAssignment(this, d);
1879        }
1880        @Override
1881        public Tag getTag() {
1882            return ASSIGN;
1883        }
1884    }
1885
1886    public static abstract class JCOperatorExpression extends JCExpression {
1887        public enum OperandPos {
1888            LEFT,
1889            RIGHT
1890        }
1891
1892        protected Tag opcode;
1893        public OperatorSymbol operator;
1894
1895        public OperatorSymbol getOperator() {
1896            return operator;
1897        }
1898
1899        @Override
1900        public Tag getTag() {
1901            return opcode;
1902        }
1903
1904        public abstract JCExpression getOperand(OperandPos pos);
1905    }
1906
1907    /**
1908     * An assignment with "+=", "|=" ...
1909     */
1910    public static class JCAssignOp extends JCOperatorExpression implements CompoundAssignmentTree {
1911        public JCExpression lhs;
1912        public JCExpression rhs;
1913        protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, OperatorSymbol operator) {
1914            this.opcode = opcode;
1915            this.lhs = (JCExpression)lhs;
1916            this.rhs = (JCExpression)rhs;
1917            this.operator = operator;
1918        }
1919        @Override
1920        public void accept(Visitor v) { v.visitAssignop(this); }
1921
1922        @DefinedBy(Api.COMPILER_TREE)
1923        public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1924        @DefinedBy(Api.COMPILER_TREE)
1925        public JCExpression getVariable() { return lhs; }
1926        @DefinedBy(Api.COMPILER_TREE)
1927        public JCExpression getExpression() { return rhs; }
1928        @Override @DefinedBy(Api.COMPILER_TREE)
1929        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1930            return v.visitCompoundAssignment(this, d);
1931        }
1932        @Override
1933        public JCExpression getOperand(OperandPos pos) {
1934            return pos == OperandPos.LEFT ? lhs : rhs;
1935        }
1936    }
1937
1938    /**
1939     * A unary operation.
1940     */
1941    public static class JCUnary extends JCOperatorExpression implements UnaryTree {
1942        public JCExpression arg;
1943        protected JCUnary(Tag opcode, JCExpression arg) {
1944            this.opcode = opcode;
1945            this.arg = arg;
1946        }
1947        @Override
1948        public void accept(Visitor v) { v.visitUnary(this); }
1949
1950        @DefinedBy(Api.COMPILER_TREE)
1951        public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1952        @DefinedBy(Api.COMPILER_TREE)
1953        public JCExpression getExpression() { return arg; }
1954        @Override @DefinedBy(Api.COMPILER_TREE)
1955        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1956            return v.visitUnary(this, d);
1957        }
1958        public void setTag(Tag tag) {
1959            opcode = tag;
1960        }
1961        @Override
1962        public JCExpression getOperand(OperandPos pos) {
1963            return arg;
1964        }
1965    }
1966
1967    /**
1968     * A binary operation.
1969     */
1970    public static class JCBinary extends JCOperatorExpression implements BinaryTree {
1971        public JCExpression lhs;
1972        public JCExpression rhs;
1973        protected JCBinary(Tag opcode,
1974                         JCExpression lhs,
1975                         JCExpression rhs,
1976                         OperatorSymbol operator) {
1977            this.opcode = opcode;
1978            this.lhs = lhs;
1979            this.rhs = rhs;
1980            this.operator = operator;
1981        }
1982        @Override
1983        public void accept(Visitor v) { v.visitBinary(this); }
1984
1985        @DefinedBy(Api.COMPILER_TREE)
1986        public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1987        @DefinedBy(Api.COMPILER_TREE)
1988        public JCExpression getLeftOperand() { return lhs; }
1989        @DefinedBy(Api.COMPILER_TREE)
1990        public JCExpression getRightOperand() { return rhs; }
1991        @Override @DefinedBy(Api.COMPILER_TREE)
1992        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1993            return v.visitBinary(this, d);
1994        }
1995        @Override
1996        public JCExpression getOperand(OperandPos pos) {
1997            return pos == OperandPos.LEFT ? lhs : rhs;
1998        }
1999    }
2000
2001    /**
2002     * A type cast.
2003     */
2004    public static class JCTypeCast extends JCExpression implements TypeCastTree {
2005        public JCTree clazz;
2006        public JCExpression expr;
2007        protected JCTypeCast(JCTree clazz, JCExpression expr) {
2008            this.clazz = clazz;
2009            this.expr = expr;
2010        }
2011        @Override
2012        public void accept(Visitor v) { v.visitTypeCast(this); }
2013
2014        @DefinedBy(Api.COMPILER_TREE)
2015        public Kind getKind() { return Kind.TYPE_CAST; }
2016        @DefinedBy(Api.COMPILER_TREE)
2017        public JCTree getType() { return clazz; }
2018        @DefinedBy(Api.COMPILER_TREE)
2019        public JCExpression getExpression() { return expr; }
2020        @Override @DefinedBy(Api.COMPILER_TREE)
2021        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2022            return v.visitTypeCast(this, d);
2023        }
2024        @Override
2025        public Tag getTag() {
2026            return TYPECAST;
2027        }
2028    }
2029
2030    /**
2031     * A type test.
2032     */
2033    public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
2034        public JCExpression expr;
2035        public JCTree clazz;
2036        protected JCInstanceOf(JCExpression expr, JCTree clazz) {
2037            this.expr = expr;
2038            this.clazz = clazz;
2039        }
2040        @Override
2041        public void accept(Visitor v) { v.visitTypeTest(this); }
2042
2043        @DefinedBy(Api.COMPILER_TREE)
2044        public Kind getKind() { return Kind.INSTANCE_OF; }
2045        @DefinedBy(Api.COMPILER_TREE)
2046        public JCTree getType() { return clazz; }
2047        @DefinedBy(Api.COMPILER_TREE)
2048        public JCExpression getExpression() { return expr; }
2049        @Override @DefinedBy(Api.COMPILER_TREE)
2050        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2051            return v.visitInstanceOf(this, d);
2052        }
2053        @Override
2054        public Tag getTag() {
2055            return TYPETEST;
2056        }
2057    }
2058
2059    /**
2060     * An array selection
2061     */
2062    public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
2063        public JCExpression indexed;
2064        public JCExpression index;
2065        protected JCArrayAccess(JCExpression indexed, JCExpression index) {
2066            this.indexed = indexed;
2067            this.index = index;
2068        }
2069        @Override
2070        public void accept(Visitor v) { v.visitIndexed(this); }
2071
2072        @DefinedBy(Api.COMPILER_TREE)
2073        public Kind getKind() { return Kind.ARRAY_ACCESS; }
2074        @DefinedBy(Api.COMPILER_TREE)
2075        public JCExpression getExpression() { return indexed; }
2076        @DefinedBy(Api.COMPILER_TREE)
2077        public JCExpression getIndex() { return index; }
2078        @Override @DefinedBy(Api.COMPILER_TREE)
2079        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2080            return v.visitArrayAccess(this, d);
2081        }
2082        @Override
2083        public Tag getTag() {
2084            return INDEXED;
2085        }
2086    }
2087
2088    /**
2089     * Selects through packages and classes
2090     */
2091    public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
2092        /** selected Tree hierarchy */
2093        public JCExpression selected;
2094        /** name of field to select thru */
2095        public Name name;
2096        /** symbol of the selected class */
2097        public Symbol sym;
2098        protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
2099            this.selected = selected;
2100            this.name = name;
2101            this.sym = sym;
2102        }
2103        @Override
2104        public void accept(Visitor v) { v.visitSelect(this); }
2105
2106        @DefinedBy(Api.COMPILER_TREE)
2107        public Kind getKind() { return Kind.MEMBER_SELECT; }
2108        @DefinedBy(Api.COMPILER_TREE)
2109        public JCExpression getExpression() { return selected; }
2110        @Override @DefinedBy(Api.COMPILER_TREE)
2111        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2112            return v.visitMemberSelect(this, d);
2113        }
2114        @DefinedBy(Api.COMPILER_TREE)
2115        public Name getIdentifier() { return name; }
2116        @Override
2117        public Tag getTag() {
2118            return SELECT;
2119        }
2120    }
2121
2122    /**
2123     * Selects a member expression.
2124     */
2125    public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
2126
2127        public ReferenceMode mode;
2128        public ReferenceKind kind;
2129        public Name name;
2130        public JCExpression expr;
2131        public List<JCExpression> typeargs;
2132        public Symbol sym;
2133        public Type varargsElement;
2134        public PolyKind refPolyKind;
2135        public boolean ownerAccessible;
2136        public OverloadKind overloadKind;
2137        public Type referentType;
2138
2139        public enum OverloadKind {
2140            OVERLOADED,
2141            UNOVERLOADED
2142        }
2143
2144        /**
2145         * Javac-dependent classification for member references, based
2146         * on relevant properties w.r.t. code-generation
2147         */
2148        public enum ReferenceKind {
2149            /** super # instMethod */
2150            SUPER(ReferenceMode.INVOKE, false),
2151            /** Type # instMethod */
2152            UNBOUND(ReferenceMode.INVOKE, true),
2153            /** Type # staticMethod */
2154            STATIC(ReferenceMode.INVOKE, false),
2155            /** Expr # instMethod */
2156            BOUND(ReferenceMode.INVOKE, false),
2157            /** Inner # new */
2158            IMPLICIT_INNER(ReferenceMode.NEW, false),
2159            /** Toplevel # new */
2160            TOPLEVEL(ReferenceMode.NEW, false),
2161            /** ArrayType # new */
2162            ARRAY_CTOR(ReferenceMode.NEW, false);
2163
2164            final ReferenceMode mode;
2165            final boolean unbound;
2166
2167            private ReferenceKind(ReferenceMode mode, boolean unbound) {
2168                this.mode = mode;
2169                this.unbound = unbound;
2170            }
2171
2172            public boolean isUnbound() {
2173                return unbound;
2174            }
2175        }
2176
2177        protected JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
2178            this.mode = mode;
2179            this.name = name;
2180            this.expr = expr;
2181            this.typeargs = typeargs;
2182        }
2183        @Override
2184        public void accept(Visitor v) { v.visitReference(this); }
2185
2186        @DefinedBy(Api.COMPILER_TREE)
2187        public Kind getKind() { return Kind.MEMBER_REFERENCE; }
2188        @Override @DefinedBy(Api.COMPILER_TREE)
2189        public ReferenceMode getMode() { return mode; }
2190        @Override @DefinedBy(Api.COMPILER_TREE)
2191        public JCExpression getQualifierExpression() { return expr; }
2192        @Override @DefinedBy(Api.COMPILER_TREE)
2193        public Name getName() { return name; }
2194        @Override @DefinedBy(Api.COMPILER_TREE)
2195        public List<JCExpression> getTypeArguments() { return typeargs; }
2196
2197        @Override @DefinedBy(Api.COMPILER_TREE)
2198        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2199            return v.visitMemberReference(this, d);
2200        }
2201        @Override
2202        public Tag getTag() {
2203            return REFERENCE;
2204        }
2205        public boolean hasKind(ReferenceKind kind) {
2206            return this.kind == kind;
2207        }
2208    }
2209
2210    /**
2211     * An identifier
2212     */
2213    public static class JCIdent extends JCExpression implements IdentifierTree {
2214        /** the name */
2215        public Name name;
2216        /** the symbol */
2217        public Symbol sym;
2218        protected JCIdent(Name name, Symbol sym) {
2219            this.name = name;
2220            this.sym = sym;
2221        }
2222        @Override
2223        public void accept(Visitor v) { v.visitIdent(this); }
2224
2225        @DefinedBy(Api.COMPILER_TREE)
2226        public Kind getKind() { return Kind.IDENTIFIER; }
2227        @DefinedBy(Api.COMPILER_TREE)
2228        public Name getName() { return name; }
2229        @Override @DefinedBy(Api.COMPILER_TREE)
2230        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2231            return v.visitIdentifier(this, d);
2232        }
2233        @Override
2234        public Tag getTag() {
2235            return IDENT;
2236        }
2237    }
2238
2239    /**
2240     * A constant value given literally.
2241     */
2242    public static class JCLiteral extends JCExpression implements LiteralTree {
2243        public TypeTag typetag;
2244        /** value representation */
2245        public Object value;
2246        protected JCLiteral(TypeTag typetag, Object value) {
2247            this.typetag = typetag;
2248            this.value = value;
2249        }
2250        @Override
2251        public void accept(Visitor v) { v.visitLiteral(this); }
2252
2253        @DefinedBy(Api.COMPILER_TREE)
2254        public Kind getKind() {
2255            return typetag.getKindLiteral();
2256        }
2257
2258        @DefinedBy(Api.COMPILER_TREE)
2259        public Object getValue() {
2260            switch (typetag) {
2261                case BOOLEAN:
2262                    int bi = (Integer) value;
2263                    return (bi != 0);
2264                case CHAR:
2265                    int ci = (Integer) value;
2266                    char c = (char) ci;
2267                    if (c != ci)
2268                        throw new AssertionError("bad value for char literal");
2269                    return c;
2270                default:
2271                    return value;
2272            }
2273        }
2274        @Override @DefinedBy(Api.COMPILER_TREE)
2275        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2276            return v.visitLiteral(this, d);
2277        }
2278        @Override
2279        public JCLiteral setType(Type type) {
2280            super.setType(type);
2281            return this;
2282        }
2283        @Override
2284        public Tag getTag() {
2285            return LITERAL;
2286        }
2287    }
2288
2289    /**
2290     * Identifies a basic type.
2291     * @see TypeTag
2292     */
2293    public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
2294        /** the basic type id */
2295        public TypeTag typetag;
2296        protected JCPrimitiveTypeTree(TypeTag typetag) {
2297            this.typetag = typetag;
2298        }
2299        @Override
2300        public void accept(Visitor v) { v.visitTypeIdent(this); }
2301
2302        @DefinedBy(Api.COMPILER_TREE)
2303        public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
2304        @DefinedBy(Api.COMPILER_TREE)
2305        public TypeKind getPrimitiveTypeKind() {
2306            return typetag.getPrimitiveTypeKind();
2307        }
2308
2309        @Override @DefinedBy(Api.COMPILER_TREE)
2310        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2311            return v.visitPrimitiveType(this, d);
2312        }
2313        @Override
2314        public Tag getTag() {
2315            return TYPEIDENT;
2316        }
2317    }
2318
2319    /**
2320     * An array type, A[]
2321     */
2322    public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
2323        public JCExpression elemtype;
2324        protected JCArrayTypeTree(JCExpression elemtype) {
2325            this.elemtype = elemtype;
2326        }
2327        @Override
2328        public void accept(Visitor v) { v.visitTypeArray(this); }
2329
2330        @DefinedBy(Api.COMPILER_TREE)
2331        public Kind getKind() { return Kind.ARRAY_TYPE; }
2332        @DefinedBy(Api.COMPILER_TREE)
2333        public JCTree getType() { return elemtype; }
2334        @Override @DefinedBy(Api.COMPILER_TREE)
2335        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2336            return v.visitArrayType(this, d);
2337        }
2338        @Override
2339        public Tag getTag() {
2340            return TYPEARRAY;
2341        }
2342    }
2343
2344    /**
2345     * A parameterized type, {@literal T<...>}
2346     */
2347    public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
2348        public JCExpression clazz;
2349        public List<JCExpression> arguments;
2350        protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
2351            this.clazz = clazz;
2352            this.arguments = arguments;
2353        }
2354        @Override
2355        public void accept(Visitor v) { v.visitTypeApply(this); }
2356
2357        @DefinedBy(Api.COMPILER_TREE)
2358        public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
2359        @DefinedBy(Api.COMPILER_TREE)
2360        public JCTree getType() { return clazz; }
2361        @DefinedBy(Api.COMPILER_TREE)
2362        public List<JCExpression> getTypeArguments() {
2363            return arguments;
2364        }
2365        @Override @DefinedBy(Api.COMPILER_TREE)
2366        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2367            return v.visitParameterizedType(this, d);
2368        }
2369        @Override
2370        public Tag getTag() {
2371            return TYPEAPPLY;
2372        }
2373    }
2374
2375    /**
2376     * A union type, T1 | T2 | ... Tn (used in multicatch statements)
2377     */
2378    public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
2379
2380        public List<JCExpression> alternatives;
2381
2382        protected JCTypeUnion(List<JCExpression> components) {
2383            this.alternatives = components;
2384        }
2385        @Override
2386        public void accept(Visitor v) { v.visitTypeUnion(this); }
2387
2388        @DefinedBy(Api.COMPILER_TREE)
2389        public Kind getKind() { return Kind.UNION_TYPE; }
2390
2391        @DefinedBy(Api.COMPILER_TREE)
2392        public List<JCExpression> getTypeAlternatives() {
2393            return alternatives;
2394        }
2395        @Override @DefinedBy(Api.COMPILER_TREE)
2396        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2397            return v.visitUnionType(this, d);
2398        }
2399        @Override
2400        public Tag getTag() {
2401            return TYPEUNION;
2402        }
2403    }
2404
2405    /**
2406     * An intersection type, {@code T1 & T2 & ... Tn} (used in cast expressions)
2407     */
2408    public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree {
2409
2410        public List<JCExpression> bounds;
2411
2412        protected JCTypeIntersection(List<JCExpression> bounds) {
2413            this.bounds = bounds;
2414        }
2415        @Override
2416        public void accept(Visitor v) { v.visitTypeIntersection(this); }
2417
2418        @DefinedBy(Api.COMPILER_TREE)
2419        public Kind getKind() { return Kind.INTERSECTION_TYPE; }
2420
2421        @DefinedBy(Api.COMPILER_TREE)
2422        public List<JCExpression> getBounds() {
2423            return bounds;
2424        }
2425        @Override @DefinedBy(Api.COMPILER_TREE)
2426        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2427            return v.visitIntersectionType(this, d);
2428        }
2429        @Override
2430        public Tag getTag() {
2431            return TYPEINTERSECTION;
2432        }
2433    }
2434
2435    /**
2436     * A formal class parameter.
2437     */
2438    public static class JCTypeParameter extends JCTree implements TypeParameterTree {
2439        /** name */
2440        public Name name;
2441        /** bounds */
2442        public List<JCExpression> bounds;
2443        /** type annotations on type parameter */
2444        public List<JCAnnotation> annotations;
2445        protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) {
2446            this.name = name;
2447            this.bounds = bounds;
2448            this.annotations = annotations;
2449        }
2450        @Override
2451        public void accept(Visitor v) { v.visitTypeParameter(this); }
2452
2453        @DefinedBy(Api.COMPILER_TREE)
2454        public Kind getKind() { return Kind.TYPE_PARAMETER; }
2455        @DefinedBy(Api.COMPILER_TREE)
2456        public Name getName() { return name; }
2457        @DefinedBy(Api.COMPILER_TREE)
2458        public List<JCExpression> getBounds() {
2459            return bounds;
2460        }
2461        @DefinedBy(Api.COMPILER_TREE)
2462        public List<JCAnnotation> getAnnotations() {
2463            return annotations;
2464        }
2465        @Override @DefinedBy(Api.COMPILER_TREE)
2466        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2467            return v.visitTypeParameter(this, d);
2468        }
2469        @Override
2470        public Tag getTag() {
2471            return TYPEPARAMETER;
2472        }
2473    }
2474
2475    public static class JCWildcard extends JCExpression implements WildcardTree {
2476        public TypeBoundKind kind;
2477        public JCTree inner;
2478        protected JCWildcard(TypeBoundKind kind, JCTree inner) {
2479            this.kind = Assert.checkNonNull(kind);
2480            this.inner = inner;
2481        }
2482        @Override
2483        public void accept(Visitor v) { v.visitWildcard(this); }
2484
2485        @DefinedBy(Api.COMPILER_TREE)
2486        public Kind getKind() {
2487            switch (kind.kind) {
2488            case UNBOUND:
2489                return Kind.UNBOUNDED_WILDCARD;
2490            case EXTENDS:
2491                return Kind.EXTENDS_WILDCARD;
2492            case SUPER:
2493                return Kind.SUPER_WILDCARD;
2494            default:
2495                throw new AssertionError("Unknown wildcard bound " + kind);
2496            }
2497        }
2498        @DefinedBy(Api.COMPILER_TREE)
2499        public JCTree getBound() { return inner; }
2500        @Override @DefinedBy(Api.COMPILER_TREE)
2501        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2502            return v.visitWildcard(this, d);
2503        }
2504        @Override
2505        public Tag getTag() {
2506            return Tag.WILDCARD;
2507        }
2508    }
2509
2510    public static class TypeBoundKind extends JCTree {
2511        public BoundKind kind;
2512        protected TypeBoundKind(BoundKind kind) {
2513            this.kind = kind;
2514        }
2515        @Override
2516        public void accept(Visitor v) { v.visitTypeBoundKind(this); }
2517
2518        @DefinedBy(Api.COMPILER_TREE)
2519        public Kind getKind() {
2520            throw new AssertionError("TypeBoundKind is not part of a public API");
2521        }
2522        @Override @DefinedBy(Api.COMPILER_TREE)
2523        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2524            throw new AssertionError("TypeBoundKind is not part of a public API");
2525        }
2526        @Override
2527        public Tag getTag() {
2528            return TYPEBOUNDKIND;
2529        }
2530    }
2531
2532    public static class JCAnnotation extends JCExpression implements AnnotationTree {
2533        // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION
2534        private Tag tag;
2535
2536        public JCTree annotationType;
2537        public List<JCExpression> args;
2538        public Attribute.Compound attribute;
2539
2540        protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) {
2541            this.tag = tag;
2542            this.annotationType = annotationType;
2543            this.args = args;
2544        }
2545
2546        @Override
2547        public void accept(Visitor v) { v.visitAnnotation(this); }
2548
2549        @DefinedBy(Api.COMPILER_TREE)
2550        public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
2551
2552        @DefinedBy(Api.COMPILER_TREE)
2553        public JCTree getAnnotationType() { return annotationType; }
2554        @DefinedBy(Api.COMPILER_TREE)
2555        public List<JCExpression> getArguments() {
2556            return args;
2557        }
2558        @Override @DefinedBy(Api.COMPILER_TREE)
2559        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2560            return v.visitAnnotation(this, d);
2561        }
2562        @Override
2563        public Tag getTag() {
2564            return tag;
2565        }
2566    }
2567
2568    public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
2569        public long flags;
2570        public List<JCAnnotation> annotations;
2571        protected JCModifiers(long flags, List<JCAnnotation> annotations) {
2572            this.flags = flags;
2573            this.annotations = annotations;
2574        }
2575        @Override
2576        public void accept(Visitor v) { v.visitModifiers(this); }
2577
2578        @DefinedBy(Api.COMPILER_TREE)
2579        public Kind getKind() { return Kind.MODIFIERS; }
2580        @DefinedBy(Api.COMPILER_TREE)
2581        public Set<Modifier> getFlags() {
2582            return Flags.asModifierSet(flags);
2583        }
2584        @DefinedBy(Api.COMPILER_TREE)
2585        public List<JCAnnotation> getAnnotations() {
2586            return annotations;
2587        }
2588        @Override @DefinedBy(Api.COMPILER_TREE)
2589        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2590            return v.visitModifiers(this, d);
2591        }
2592        @Override
2593        public Tag getTag() {
2594            return MODIFIERS;
2595        }
2596    }
2597
2598    public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
2599        // type annotations
2600        public List<JCAnnotation> annotations;
2601        public JCExpression underlyingType;
2602
2603        protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
2604            Assert.check(annotations != null && annotations.nonEmpty());
2605            this.annotations = annotations;
2606            this.underlyingType = underlyingType;
2607        }
2608        @Override
2609        public void accept(Visitor v) { v.visitAnnotatedType(this); }
2610
2611        @DefinedBy(Api.COMPILER_TREE)
2612        public Kind getKind() { return Kind.ANNOTATED_TYPE; }
2613        @DefinedBy(Api.COMPILER_TREE)
2614        public List<JCAnnotation> getAnnotations() {
2615            return annotations;
2616        }
2617        @DefinedBy(Api.COMPILER_TREE)
2618        public JCExpression getUnderlyingType() {
2619            return underlyingType;
2620        }
2621        @Override @DefinedBy(Api.COMPILER_TREE)
2622        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2623            return v.visitAnnotatedType(this, d);
2624        }
2625        @Override
2626        public Tag getTag() {
2627            return ANNOTATED_TYPE;
2628        }
2629    }
2630
2631    public static abstract class JCDirective extends JCTree
2632        implements DirectiveTree {
2633    }
2634
2635    public static class JCModuleDecl extends JCTree implements ModuleTree {
2636        public JCModifiers mods;
2637        public ModuleType type;
2638        private final ModuleKind kind;
2639        public JCExpression qualId;
2640        public List<JCDirective> directives;
2641        public ModuleSymbol sym;
2642
2643        protected JCModuleDecl(JCModifiers mods, ModuleKind kind,
2644                JCExpression qualId, List<JCDirective> directives) {
2645            this.mods = mods;
2646            this.kind = kind;
2647            this.qualId = qualId;
2648            this.directives = directives;
2649        }
2650
2651        @Override
2652        public void accept(Visitor v) { v.visitModuleDef(this); }
2653
2654        @Override @DefinedBy(Api.COMPILER_TREE)
2655        public Kind getKind() {
2656            return Kind.MODULE;
2657        }
2658
2659        @Override @DefinedBy(Api.COMPILER_TREE)
2660        public List<? extends AnnotationTree> getAnnotations() {
2661            return mods.annotations;
2662        }
2663
2664        @Override @DefinedBy(Api.COMPILER_TREE)
2665        public ModuleKind getModuleType() {
2666            return kind;
2667        }
2668
2669        @Override @DefinedBy(Api.COMPILER_TREE)
2670        public JCExpression getName() {
2671            return qualId;
2672        }
2673
2674        @Override @DefinedBy(Api.COMPILER_TREE)
2675        public List<JCDirective> getDirectives() {
2676            return directives;
2677        }
2678
2679        @Override @DefinedBy(Api.COMPILER_TREE)
2680        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2681            return v.visitModule(this, d);
2682        }
2683
2684        @Override
2685        public Tag getTag() {
2686            return MODULEDEF;
2687        }
2688    }
2689
2690    public static class JCExports extends JCDirective
2691            implements ExportsTree {
2692        public JCExpression qualid;
2693        public List<JCExpression> moduleNames;
2694        public ExportsDirective directive;
2695
2696        protected JCExports(JCExpression qualId, List<JCExpression> moduleNames) {
2697            this.qualid = qualId;
2698            this.moduleNames = moduleNames;
2699        }
2700
2701        @Override
2702        public void accept(Visitor v) { v.visitExports(this); }
2703
2704        @Override @DefinedBy(Api.COMPILER_TREE)
2705        public Kind getKind() {
2706            return Kind.EXPORTS;
2707        }
2708
2709        @Override @DefinedBy(Api.COMPILER_TREE)
2710        public JCExpression getPackageName() {
2711            return qualid;
2712        }
2713
2714        @Override @DefinedBy(Api.COMPILER_TREE)
2715        public List<JCExpression> getModuleNames() {
2716            return moduleNames;
2717        }
2718
2719        @Override @DefinedBy(Api.COMPILER_TREE)
2720        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2721            return v.visitExports(this, d);
2722        }
2723
2724        @Override
2725        public Tag getTag() {
2726            return Tag.EXPORTS;
2727        }
2728    }
2729
2730    public static class JCOpens extends JCDirective
2731            implements OpensTree {
2732        public JCExpression qualid;
2733        public List<JCExpression> moduleNames;
2734        public OpensDirective directive;
2735
2736        protected JCOpens(JCExpression qualId, List<JCExpression> moduleNames) {
2737            this.qualid = qualId;
2738            this.moduleNames = moduleNames;
2739        }
2740
2741        @Override
2742        public void accept(Visitor v) { v.visitOpens(this); }
2743
2744        @Override @DefinedBy(Api.COMPILER_TREE)
2745        public Kind getKind() {
2746            return Kind.OPENS;
2747        }
2748
2749        @Override @DefinedBy(Api.COMPILER_TREE)
2750        public JCExpression getPackageName() {
2751            return qualid;
2752        }
2753
2754        @Override @DefinedBy(Api.COMPILER_TREE)
2755        public List<JCExpression> getModuleNames() {
2756            return moduleNames;
2757        }
2758
2759        @Override @DefinedBy(Api.COMPILER_TREE)
2760        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2761            return v.visitOpens(this, d);
2762        }
2763
2764        @Override
2765        public Tag getTag() {
2766            return Tag.OPENS;
2767        }
2768    }
2769
2770    public static class JCProvides extends JCDirective
2771            implements ProvidesTree {
2772        public JCExpression serviceName;
2773        public List<JCExpression> implNames;
2774
2775        protected JCProvides(JCExpression serviceName, List<JCExpression> implNames) {
2776            this.serviceName = serviceName;
2777            this.implNames = implNames;
2778        }
2779
2780        @Override
2781        public void accept(Visitor v) { v.visitProvides(this); }
2782
2783        @Override @DefinedBy(Api.COMPILER_TREE)
2784        public Kind getKind() {
2785            return Kind.PROVIDES;
2786        }
2787
2788        @Override @DefinedBy(Api.COMPILER_TREE)
2789        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2790            return v.visitProvides(this, d);
2791        }
2792
2793        @Override @DefinedBy(Api.COMPILER_TREE)
2794        public JCExpression getServiceName() {
2795            return serviceName;
2796        }
2797
2798        @Override @DefinedBy(Api.COMPILER_TREE)
2799        public List<JCExpression> getImplementationNames() {
2800            return implNames;
2801        }
2802
2803        @Override
2804        public Tag getTag() {
2805            return PROVIDES;
2806        }
2807    }
2808
2809    public static class JCRequires extends JCDirective
2810            implements RequiresTree {
2811        public boolean isTransitive;
2812        public boolean isStaticPhase;
2813        public JCExpression moduleName;
2814        public RequiresDirective directive;
2815
2816        protected JCRequires(boolean isTransitive, boolean isStaticPhase, JCExpression moduleName) {
2817            this.isTransitive = isTransitive;
2818            this.isStaticPhase = isStaticPhase;
2819            this.moduleName = moduleName;
2820        }
2821
2822        @Override
2823        public void accept(Visitor v) { v.visitRequires(this); }
2824
2825        @Override @DefinedBy(Api.COMPILER_TREE)
2826        public Kind getKind() {
2827            return Kind.REQUIRES;
2828        }
2829
2830        @Override @DefinedBy(Api.COMPILER_TREE)
2831        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2832            return v.visitRequires(this, d);
2833        }
2834
2835        @Override @DefinedBy(Api.COMPILER_TREE)
2836        public boolean isTransitive() {
2837            return isTransitive;
2838        }
2839
2840        @Override @DefinedBy(Api.COMPILER_TREE)
2841        public boolean isStatic() {
2842            return isStaticPhase;
2843        }
2844
2845        @Override @DefinedBy(Api.COMPILER_TREE)
2846        public JCExpression getModuleName() {
2847            return moduleName;
2848        }
2849
2850        @Override
2851        public Tag getTag() {
2852            return REQUIRES;
2853        }
2854    }
2855
2856    public static class JCUses extends JCDirective
2857            implements UsesTree {
2858        public JCExpression qualid;
2859
2860        protected JCUses(JCExpression qualId) {
2861            this.qualid = qualId;
2862        }
2863
2864        @Override
2865        public void accept(Visitor v) { v.visitUses(this); }
2866
2867        @Override @DefinedBy(Api.COMPILER_TREE)
2868        public Kind getKind() {
2869            return Kind.USES;
2870        }
2871
2872        @Override @DefinedBy(Api.COMPILER_TREE)
2873        public JCExpression getServiceName() {
2874            return qualid;
2875        }
2876
2877        @Override @DefinedBy(Api.COMPILER_TREE)
2878        public <R, D> R accept(TreeVisitor<R, D> v, D d) {
2879            return v.visitUses(this, d);
2880        }
2881
2882        @Override
2883        public Tag getTag() {
2884            return USES;
2885        }
2886    }
2887
2888    public static class JCErroneous extends JCExpression
2889            implements ErroneousTree {
2890        public List<? extends JCTree> errs;
2891        protected JCErroneous(List<? extends JCTree> errs) {
2892            this.errs = errs;
2893        }
2894        @Override
2895        public void accept(Visitor v) { v.visitErroneous(this); }
2896
2897        @DefinedBy(Api.COMPILER_TREE)
2898        public Kind getKind() { return Kind.ERRONEOUS; }
2899
2900        @DefinedBy(Api.COMPILER_TREE)
2901        public List<? extends JCTree> getErrorTrees() {
2902            return errs;
2903        }
2904
2905        @Override @DefinedBy(Api.COMPILER_TREE)
2906        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2907            return v.visitErroneous(this, d);
2908        }
2909        @Override
2910        public Tag getTag() {
2911            return ERRONEOUS;
2912        }
2913    }
2914
2915    /** (let int x = 3; in x+2) */
2916    public static class LetExpr extends JCExpression {
2917        public List<JCVariableDecl> defs;
2918        public JCExpression expr;
2919        protected LetExpr(List<JCVariableDecl> defs, JCExpression expr) {
2920            this.defs = defs;
2921            this.expr = expr;
2922        }
2923        @Override
2924        public void accept(Visitor v) { v.visitLetExpr(this); }
2925
2926        @DefinedBy(Api.COMPILER_TREE)
2927        public Kind getKind() {
2928            throw new AssertionError("LetExpr is not part of a public API");
2929        }
2930        @Override @DefinedBy(Api.COMPILER_TREE)
2931        public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2932            throw new AssertionError("LetExpr is not part of a public API");
2933        }
2934        @Override
2935        public Tag getTag() {
2936            return LETEXPR;
2937        }
2938    }
2939
2940    /** An interface for tree factories
2941     */
2942    public interface Factory {
2943        JCCompilationUnit TopLevel(List<JCTree> defs);
2944        JCPackageDecl PackageDecl(List<JCAnnotation> annotations,
2945                                  JCExpression pid);
2946        JCImport Import(JCTree qualid, boolean staticImport);
2947        JCClassDecl ClassDef(JCModifiers mods,
2948                          Name name,
2949                          List<JCTypeParameter> typarams,
2950                          JCExpression extending,
2951                          List<JCExpression> implementing,
2952                          List<JCTree> defs);
2953        JCMethodDecl MethodDef(JCModifiers mods,
2954                            Name name,
2955                            JCExpression restype,
2956                            List<JCTypeParameter> typarams,
2957                            JCVariableDecl recvparam,
2958                            List<JCVariableDecl> params,
2959                            List<JCExpression> thrown,
2960                            JCBlock body,
2961                            JCExpression defaultValue);
2962        JCVariableDecl VarDef(JCModifiers mods,
2963                      Name name,
2964                      JCExpression vartype,
2965                      JCExpression init);
2966        JCSkip Skip();
2967        JCBlock Block(long flags, List<JCStatement> stats);
2968        JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
2969        JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
2970        JCForLoop ForLoop(List<JCStatement> init,
2971                        JCExpression cond,
2972                        List<JCExpressionStatement> step,
2973                        JCStatement body);
2974        JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
2975        JCLabeledStatement Labelled(Name label, JCStatement body);
2976        JCSwitch Switch(JCExpression selector, List<JCCase> cases);
2977        JCCase Case(JCExpression pat, List<JCStatement> stats);
2978        JCSynchronized Synchronized(JCExpression lock, JCBlock body);
2979        JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
2980        JCTry Try(List<JCTree> resources,
2981                  JCBlock body,
2982                  List<JCCatch> catchers,
2983                  JCBlock finalizer);
2984        JCCatch Catch(JCVariableDecl param, JCBlock body);
2985        JCConditional Conditional(JCExpression cond,
2986                                JCExpression thenpart,
2987                                JCExpression elsepart);
2988        JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
2989        JCExpressionStatement Exec(JCExpression expr);
2990        JCBreak Break(Name label);
2991        JCContinue Continue(Name label);
2992        JCReturn Return(JCExpression expr);
2993        JCThrow Throw(JCExpression expr);
2994        JCAssert Assert(JCExpression cond, JCExpression detail);
2995        JCMethodInvocation Apply(List<JCExpression> typeargs,
2996                    JCExpression fn,
2997                    List<JCExpression> args);
2998        JCNewClass NewClass(JCExpression encl,
2999                          List<JCExpression> typeargs,
3000                          JCExpression clazz,
3001                          List<JCExpression> args,
3002                          JCClassDecl def);
3003        JCNewArray NewArray(JCExpression elemtype,
3004                          List<JCExpression> dims,
3005                          List<JCExpression> elems);
3006        JCParens Parens(JCExpression expr);
3007        JCAssign Assign(JCExpression lhs, JCExpression rhs);
3008        JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3009        JCUnary Unary(Tag opcode, JCExpression arg);
3010        JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3011        JCTypeCast TypeCast(JCTree expr, JCExpression type);
3012        JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3013        JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3014        JCFieldAccess Select(JCExpression selected, Name selector);
3015        JCIdent Ident(Name idname);
3016        JCLiteral Literal(TypeTag tag, Object value);
3017        JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3018        JCArrayTypeTree TypeArray(JCExpression elemtype);
3019        JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3020        JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3021        JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3022        TypeBoundKind TypeBoundKind(BoundKind kind);
3023        JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3024        JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3025        JCErroneous Erroneous(List<? extends JCTree> errs);
3026        JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3027        JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3028        JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3029        JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3030        JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3031        JCUses Uses(JCExpression qualId);
3032        LetExpr LetExpr(List<JCVariableDecl> defs, JCExpression expr);
3033    }
3034
3035    /** A generic visitor class for trees.
3036     */
3037    public static abstract class Visitor {
3038        public void visitTopLevel(JCCompilationUnit that)    { visitTree(that); }
3039        public void visitPackageDef(JCPackageDecl that)      { visitTree(that); }
3040        public void visitImport(JCImport that)               { visitTree(that); }
3041        public void visitClassDef(JCClassDecl that)          { visitTree(that); }
3042        public void visitMethodDef(JCMethodDecl that)        { visitTree(that); }
3043        public void visitVarDef(JCVariableDecl that)         { visitTree(that); }
3044        public void visitSkip(JCSkip that)                   { visitTree(that); }
3045        public void visitBlock(JCBlock that)                 { visitTree(that); }
3046        public void visitDoLoop(JCDoWhileLoop that)          { visitTree(that); }
3047        public void visitWhileLoop(JCWhileLoop that)         { visitTree(that); }
3048        public void visitForLoop(JCForLoop that)             { visitTree(that); }
3049        public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3050        public void visitLabelled(JCLabeledStatement that)   { visitTree(that); }
3051        public void visitSwitch(JCSwitch that)               { visitTree(that); }
3052        public void visitCase(JCCase that)                   { visitTree(that); }
3053        public void visitSynchronized(JCSynchronized that)   { visitTree(that); }
3054        public void visitTry(JCTry that)                     { visitTree(that); }
3055        public void visitCatch(JCCatch that)                 { visitTree(that); }
3056        public void visitConditional(JCConditional that)     { visitTree(that); }
3057        public void visitIf(JCIf that)                       { visitTree(that); }
3058        public void visitExec(JCExpressionStatement that)    { visitTree(that); }
3059        public void visitBreak(JCBreak that)                 { visitTree(that); }
3060        public void visitContinue(JCContinue that)           { visitTree(that); }
3061        public void visitReturn(JCReturn that)               { visitTree(that); }
3062        public void visitThrow(JCThrow that)                 { visitTree(that); }
3063        public void visitAssert(JCAssert that)               { visitTree(that); }
3064        public void visitApply(JCMethodInvocation that)      { visitTree(that); }
3065        public void visitNewClass(JCNewClass that)           { visitTree(that); }
3066        public void visitNewArray(JCNewArray that)           { visitTree(that); }
3067        public void visitLambda(JCLambda that)               { visitTree(that); }
3068        public void visitParens(JCParens that)               { visitTree(that); }
3069        public void visitAssign(JCAssign that)               { visitTree(that); }
3070        public void visitAssignop(JCAssignOp that)           { visitTree(that); }
3071        public void visitUnary(JCUnary that)                 { visitTree(that); }
3072        public void visitBinary(JCBinary that)               { visitTree(that); }
3073        public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
3074        public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
3075        public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
3076        public void visitSelect(JCFieldAccess that)          { visitTree(that); }
3077        public void visitReference(JCMemberReference that)   { visitTree(that); }
3078        public void visitIdent(JCIdent that)                 { visitTree(that); }
3079        public void visitLiteral(JCLiteral that)             { visitTree(that); }
3080        public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
3081        public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
3082        public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
3083        public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
3084        public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
3085        public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
3086        public void visitWildcard(JCWildcard that)           { visitTree(that); }
3087        public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
3088        public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
3089        public void visitModifiers(JCModifiers that)         { visitTree(that); }
3090        public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
3091        public void visitErroneous(JCErroneous that)         { visitTree(that); }
3092        public void visitModuleDef(JCModuleDecl that)        { visitTree(that); }
3093        public void visitExports(JCExports that)             { visitTree(that); }
3094        public void visitOpens(JCOpens that)                 { visitTree(that); }
3095        public void visitProvides(JCProvides that)           { visitTree(that); }
3096        public void visitRequires(JCRequires that)           { visitTree(that); }
3097        public void visitUses(JCUses that)                   { visitTree(that); }
3098        public void visitLetExpr(LetExpr that)               { visitTree(that); }
3099
3100        public void visitTree(JCTree that)                   { Assert.error(); }
3101    }
3102
3103}
3104