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