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