src/share/classes/com/sun/tools/javac/tree/JCTree.java

Mon, 22 Aug 2016 11:06:41 -0700

author
asaha
date
Mon, 22 Aug 2016 11:06:41 -0700
changeset 3277
458d4cd8d984
parent 2395
9c577131ffa6
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8164453: 8u112 L10n resource file update - msgdrop 20
Summary: 8u112 L10n resource file update - msgdrop 20
Reviewed-by: coffeys
Contributed-by: li.jiang@oracle.com

     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  */
    26 package com.sun.tools.javac.tree;
    28 import java.io.IOException;
    29 import java.io.StringWriter;
    30 import java.util.*;
    32 import javax.lang.model.element.Modifier;
    33 import javax.lang.model.type.TypeKind;
    34 import javax.tools.JavaFileObject;
    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.*;
    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 {
    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,
    88         /** Toplevel nodes, of type TopLevel, representing entire source files.
    89         */
    90         TOPLEVEL,
    92         /** Import clauses, of type Import.
    93          */
    94         IMPORT,
    96         /** Class definitions, of type ClassDef.
    97          */
    98         CLASSDEF,
   100         /** Method definitions, of type MethodDef.
   101          */
   102         METHODDEF,
   104         /** Variable definitions, of type VarDef.
   105          */
   106         VARDEF,
   108         /** The no-op statement ";", of type Skip
   109          */
   110         SKIP,
   112         /** Blocks, of type Block.
   113          */
   114         BLOCK,
   116         /** Do-while loops, of type DoLoop.
   117          */
   118         DOLOOP,
   120         /** While-loops, of type WhileLoop.
   121          */
   122         WHILELOOP,
   124         /** For-loops, of type ForLoop.
   125          */
   126         FORLOOP,
   128         /** Foreach-loops, of type ForeachLoop.
   129          */
   130         FOREACHLOOP,
   132         /** Labelled statements, of type Labelled.
   133          */
   134         LABELLED,
   136         /** Switch statements, of type Switch.
   137          */
   138         SWITCH,
   140         /** Case parts in switch statements, of type Case.
   141          */
   142         CASE,
   144         /** Synchronized statements, of type Synchonized.
   145          */
   146         SYNCHRONIZED,
   148         /** Try statements, of type Try.
   149          */
   150         TRY,
   152         /** Catch clauses in try statements, of type Catch.
   153          */
   154         CATCH,
   156         /** Conditional expressions, of type Conditional.
   157          */
   158         CONDEXPR,
   160         /** Conditional statements, of type If.
   161          */
   162         IF,
   164         /** Expression statements, of type Exec.
   165          */
   166         EXEC,
   168         /** Break statements, of type Break.
   169          */
   170         BREAK,
   172         /** Continue statements, of type Continue.
   173          */
   174         CONTINUE,
   176         /** Return statements, of type Return.
   177          */
   178         RETURN,
   180         /** Throw statements, of type Throw.
   181          */
   182         THROW,
   184         /** Assert statements, of type Assert.
   185          */
   186         ASSERT,
   188         /** Method invocation expressions, of type Apply.
   189          */
   190         APPLY,
   192         /** Class instance creation expressions, of type NewClass.
   193          */
   194         NEWCLASS,
   196         /** Array creation expressions, of type NewArray.
   197          */
   198         NEWARRAY,
   200         /** Lambda expression, of type Lambda.
   201          */
   202         LAMBDA,
   204         /** Parenthesized subexpressions, of type Parens.
   205          */
   206         PARENS,
   208         /** Assignment expressions, of type Assign.
   209          */
   210         ASSIGN,
   212         /** Type cast expressions, of type TypeCast.
   213          */
   214         TYPECAST,
   216         /** Type test expressions, of type TypeTest.
   217          */
   218         TYPETEST,
   220         /** Indexed array expressions, of type Indexed.
   221          */
   222         INDEXED,
   224         /** Selections, of type Select.
   225          */
   226         SELECT,
   228         /** Member references, of type Reference.
   229          */
   230         REFERENCE,
   232         /** Simple identifiers, of type Ident.
   233          */
   234         IDENT,
   236         /** Literals, of type Literal.
   237          */
   238         LITERAL,
   240         /** Basic type identifiers, of type TypeIdent.
   241          */
   242         TYPEIDENT,
   244         /** Array types, of type TypeArray.
   245          */
   246         TYPEARRAY,
   248         /** Parameterized types, of type TypeApply.
   249          */
   250         TYPEAPPLY,
   252         /** Union types, of type TypeUnion.
   253          */
   254         TYPEUNION,
   256         /** Intersection types, of type TypeIntersection.
   257          */
   258         TYPEINTERSECTION,
   260         /** Formal type parameters, of type TypeParameter.
   261          */
   262         TYPEPARAMETER,
   264         /** Type argument.
   265          */
   266         WILDCARD,
   268         /** Bound kind: extends, super, exact, or unbound
   269          */
   270         TYPEBOUNDKIND,
   272         /** metadata: Annotation.
   273          */
   274         ANNOTATION,
   276         /** metadata: Type annotation.
   277          */
   278         TYPE_ANNOTATION,
   280         /** metadata: Modifiers
   281          */
   282         MODIFIERS,
   284         /** An annotated type tree.
   285          */
   286         ANNOTATED_TYPE,
   288         /** Error trees, of type Erroneous.
   289          */
   290         ERRONEOUS,
   292         /** Unary operators, of type Unary.
   293          */
   294         POS,                             // +
   295         NEG,                             // -
   296         NOT,                             // !
   297         COMPL,                           // ~
   298         PREINC,                          // ++ _
   299         PREDEC,                          // -- _
   300         POSTINC,                         // _ ++
   301         POSTDEC,                         // _ --
   303         /** unary operator for null reference checks, only used internally.
   304          */
   305         NULLCHK,
   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,                             // %
   329         /** Assignment operators, of type Assignop.
   330          */
   331         BITOR_ASG(BITOR),                // |=
   332         BITXOR_ASG(BITXOR),              // ^=
   333         BITAND_ASG(BITAND),              // &=
   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),                    // %=
   344         /** A synthetic let expression, of type LetExpr.
   345          */
   346         LETEXPR;                         // ala scheme
   348         private final Tag noAssignTag;
   350         private static final int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
   352         private Tag(Tag noAssignTag) {
   353             this.noAssignTag = noAssignTag;
   354         }
   356         private Tag() {
   357             this(null);
   358         }
   360         public static int getNumberOfOperators() {
   361             return numberOfOperators;
   362         }
   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         }
   370         public boolean isPostUnaryOp() {
   371             return (this == POSTINC || this == POSTDEC);
   372         }
   374         public boolean isIncOrDecUnaryOp() {
   375             return (this == PREINC || this == PREDEC || this == POSTINC || this == POSTDEC);
   376         }
   378         public boolean isAssignop() {
   379             return noAssignTag != null;
   380         }
   382         public int operatorIndex() {
   383             return (this.ordinal() - POS.ordinal());
   384         }
   385     }
   387     /* The (encoded) position in the source file. @see util.Position.
   388      */
   389     public int pos;
   391     /* The type of this node.
   392      */
   393     public Type type;
   395     /* The tag of this node -- one of the constants declared above.
   396      */
   397     public abstract Tag getTag();
   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     }
   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     }
   420     /** Set position field and return this tree.
   421      */
   422     public JCTree setPos(int pos) {
   423         this.pos = pos;
   424         return this;
   425     }
   427     /** Set type field and return this tree.
   428      */
   429     public JCTree setType(Type type) {
   430         this.type = type;
   431         return this;
   432     }
   434     /** Visit this tree with a given visitor.
   435      */
   436     public abstract void accept(Visitor v);
   438     public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);
   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     }
   451     /** Get a default position for this tree node.
   452      */
   453     public DiagnosticPosition pos() {
   454         return this;
   455     }
   457     // for default DiagnosticPosition
   458     public JCTree getTree() {
   459         return this;
   460     }
   462     // for default DiagnosticPosition
   463     public int getStartPosition() {
   464         return TreeInfo.getStartPos(this);
   465     }
   467     // for default DiagnosticPosition
   468     public int getPreferredPosition() {
   469         return pos;
   470     }
   472     // for default DiagnosticPosition
   473     public int getEndPosition(EndPosTable endPosTable) {
   474         return TreeInfo.getEndPos(this, endPosTable);
   475     }
   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); }
   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         }
   553         @Override
   554         public Tag getTag() {
   555             return TOPLEVEL;
   556         }
   557     }
   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); }
   573         public boolean isStatic() { return staticImport; }
   574         public JCTree getQualifiedIdentifier() { return qualid; }
   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         }
   582         @Override
   583         public Tag getTag() {
   584             return IMPORT;
   585         }
   586     }
   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     }
   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         }
   613         public boolean isPoly() { return false; }
   614         public boolean isStandalone() { return true; }
   615     }
   617     /**
   618      * Common supertype for all poly expression trees (lambda, method references,
   619      * conditionals, method and constructor calls)
   620      */
   621     public static abstract class JCPolyExpression extends JCExpression {
   623         /**
   624          * A poly expression can only be truly 'poly' in certain contexts
   625          */
   626         public enum PolyKind {
   627             /** poly expression to be treated as a standalone expression */
   628             STANDALONE,
   629             /** true poly expression */
   630             POLY;
   631         }
   633         /** is this poly expression a 'true' poly expression? */
   634         public PolyKind polyKind;
   636         @Override public boolean isPoly() { return polyKind == PolyKind.POLY; }
   637         @Override public boolean isStandalone() { return polyKind == PolyKind.STANDALONE; }
   638     }
   640     /**
   641      * Common supertype for all functional expression trees (lambda and method references)
   642      */
   643     public static abstract class JCFunctionalExpression extends JCPolyExpression {
   645         public JCFunctionalExpression() {
   646             //a functional expression is always a 'true' poly
   647             polyKind = PolyKind.POLY;
   648         }
   650         /** list of target types inferred for this functional expression. */
   651         public List<Type> targets;
   653         public Type getDescriptorType(Types types) {
   654             return targets.nonEmpty() ? types.findDescriptorType(targets.head) : types.createErrorType(null);
   655         }
   656     }
   658     /**
   659      * A class definition.
   660      */
   661     public static class JCClassDecl extends JCStatement implements ClassTree {
   662         /** the modifiers */
   663         public JCModifiers mods;
   664         /** the name of the class */
   665         public Name name;
   666         /** formal class parameters */
   667         public List<JCTypeParameter> typarams;
   668         /** the classes this class extends */
   669         public JCExpression extending;
   670         /** the interfaces implemented by this class */
   671         public List<JCExpression> implementing;
   672         /** all variables and methods defined in this class */
   673         public List<JCTree> defs;
   674         /** the symbol */
   675         public ClassSymbol sym;
   676         protected JCClassDecl(JCModifiers mods,
   677                            Name name,
   678                            List<JCTypeParameter> typarams,
   679                            JCExpression extending,
   680                            List<JCExpression> implementing,
   681                            List<JCTree> defs,
   682                            ClassSymbol sym)
   683         {
   684             this.mods = mods;
   685             this.name = name;
   686             this.typarams = typarams;
   687             this.extending = extending;
   688             this.implementing = implementing;
   689             this.defs = defs;
   690             this.sym = sym;
   691         }
   692         @Override
   693         public void accept(Visitor v) { v.visitClassDef(this); }
   695         public Kind getKind() {
   696             if ((mods.flags & Flags.ANNOTATION) != 0)
   697                 return Kind.ANNOTATION_TYPE;
   698             else if ((mods.flags & Flags.INTERFACE) != 0)
   699                 return Kind.INTERFACE;
   700             else if ((mods.flags & Flags.ENUM) != 0)
   701                 return Kind.ENUM;
   702             else
   703                 return Kind.CLASS;
   704         }
   706         public JCModifiers getModifiers() { return mods; }
   707         public Name getSimpleName() { return name; }
   708         public List<JCTypeParameter> getTypeParameters() {
   709             return typarams;
   710         }
   711         public JCExpression getExtendsClause() { return extending; }
   712         public List<JCExpression> getImplementsClause() {
   713             return implementing;
   714         }
   715         public List<JCTree> getMembers() {
   716             return defs;
   717         }
   718         @Override
   719         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   720             return v.visitClass(this, d);
   721         }
   723         @Override
   724         public Tag getTag() {
   725             return CLASSDEF;
   726         }
   727     }
   729     /**
   730      * A method definition.
   731      */
   732     public static class JCMethodDecl extends JCTree implements MethodTree {
   733         /** method modifiers */
   734         public JCModifiers mods;
   735         /** method name */
   736         public Name name;
   737         /** type of method return value */
   738         public JCExpression restype;
   739         /** type parameters */
   740         public List<JCTypeParameter> typarams;
   741         /** receiver parameter */
   742         public JCVariableDecl recvparam;
   743         /** value parameters */
   744         public List<JCVariableDecl> params;
   745         /** exceptions thrown by this method */
   746         public List<JCExpression> thrown;
   747         /** statements in the method */
   748         public JCBlock body;
   749         /** default value, for annotation types */
   750         public JCExpression defaultValue;
   751         /** method symbol */
   752         public MethodSymbol sym;
   753         protected JCMethodDecl(JCModifiers mods,
   754                             Name name,
   755                             JCExpression restype,
   756                             List<JCTypeParameter> typarams,
   757                             JCVariableDecl recvparam,
   758                             List<JCVariableDecl> params,
   759                             List<JCExpression> thrown,
   760                             JCBlock body,
   761                             JCExpression defaultValue,
   762                             MethodSymbol sym)
   763         {
   764             this.mods = mods;
   765             this.name = name;
   766             this.restype = restype;
   767             this.typarams = typarams;
   768             this.params = params;
   769             this.recvparam = recvparam;
   770             // TODO: do something special if the given type is null?
   771             // receiver != null ? receiver : List.<JCTypeAnnotation>nil());
   772             this.thrown = thrown;
   773             this.body = body;
   774             this.defaultValue = defaultValue;
   775             this.sym = sym;
   776         }
   777         @Override
   778         public void accept(Visitor v) { v.visitMethodDef(this); }
   780         public Kind getKind() { return Kind.METHOD; }
   781         public JCModifiers getModifiers() { return mods; }
   782         public Name getName() { return name; }
   783         public JCTree getReturnType() { return restype; }
   784         public List<JCTypeParameter> getTypeParameters() {
   785             return typarams;
   786         }
   787         public List<JCVariableDecl> getParameters() {
   788             return params;
   789         }
   790         public JCVariableDecl getReceiverParameter() { return recvparam; }
   791         public List<JCExpression> getThrows() {
   792             return thrown;
   793         }
   794         public JCBlock getBody() { return body; }
   795         public JCTree getDefaultValue() { // for annotation types
   796             return defaultValue;
   797         }
   798         @Override
   799         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   800             return v.visitMethod(this, d);
   801         }
   803         @Override
   804         public Tag getTag() {
   805             return METHODDEF;
   806         }
   807   }
   809     /**
   810      * A variable definition.
   811      */
   812     public static class JCVariableDecl extends JCStatement implements VariableTree {
   813         /** variable modifiers */
   814         public JCModifiers mods;
   815         /** variable name */
   816         public Name name;
   817         /** variable name expression */
   818         public JCExpression nameexpr;
   819         /** type of the variable */
   820         public JCExpression vartype;
   821         /** variable's initial value */
   822         public JCExpression init;
   823         /** symbol */
   824         public VarSymbol sym;
   826         protected JCVariableDecl(JCModifiers mods,
   827                          Name name,
   828                          JCExpression vartype,
   829                          JCExpression init,
   830                          VarSymbol sym) {
   831             this.mods = mods;
   832             this.name = name;
   833             this.vartype = vartype;
   834             this.init = init;
   835             this.sym = sym;
   836         }
   838         protected JCVariableDecl(JCModifiers mods,
   839                          JCExpression nameexpr,
   840                          JCExpression vartype) {
   841             this(mods, null, vartype, null, null);
   842             this.nameexpr = nameexpr;
   843             if (nameexpr.hasTag(Tag.IDENT)) {
   844                 this.name = ((JCIdent)nameexpr).name;
   845             } else {
   846                 // Only other option is qualified name x.y.this;
   847                 this.name = ((JCFieldAccess)nameexpr).name;
   848             }
   849         }
   851         @Override
   852         public void accept(Visitor v) { v.visitVarDef(this); }
   854         public Kind getKind() { return Kind.VARIABLE; }
   855         public JCModifiers getModifiers() { return mods; }
   856         public Name getName() { return name; }
   857         public JCExpression getNameExpression() { return nameexpr; }
   858         public JCTree getType() { return vartype; }
   859         public JCExpression getInitializer() {
   860             return init;
   861         }
   862         @Override
   863         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   864             return v.visitVariable(this, d);
   865         }
   867         @Override
   868         public Tag getTag() {
   869             return VARDEF;
   870         }
   871     }
   873     /**
   874      * A no-op statement ";".
   875      */
   876     public static class JCSkip extends JCStatement implements EmptyStatementTree {
   877         protected JCSkip() {
   878         }
   879         @Override
   880         public void accept(Visitor v) { v.visitSkip(this); }
   882         public Kind getKind() { return Kind.EMPTY_STATEMENT; }
   883         @Override
   884         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   885             return v.visitEmptyStatement(this, d);
   886         }
   888         @Override
   889         public Tag getTag() {
   890             return SKIP;
   891         }
   892     }
   894     /**
   895      * A statement block.
   896      */
   897     public static class JCBlock extends JCStatement implements BlockTree {
   898         /** flags */
   899         public long flags;
   900         /** statements */
   901         public List<JCStatement> stats;
   902         /** Position of closing brace, optional. */
   903         public int endpos = Position.NOPOS;
   904         protected JCBlock(long flags, List<JCStatement> stats) {
   905             this.stats = stats;
   906             this.flags = flags;
   907         }
   908         @Override
   909         public void accept(Visitor v) { v.visitBlock(this); }
   911         public Kind getKind() { return Kind.BLOCK; }
   912         public List<JCStatement> getStatements() {
   913             return stats;
   914         }
   915         public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
   916         @Override
   917         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   918             return v.visitBlock(this, d);
   919         }
   921         @Override
   922         public Tag getTag() {
   923             return BLOCK;
   924         }
   925     }
   927     /**
   928      * A do loop
   929      */
   930     public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
   931         public JCStatement body;
   932         public JCExpression cond;
   933         protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
   934             this.body = body;
   935             this.cond = cond;
   936         }
   937         @Override
   938         public void accept(Visitor v) { v.visitDoLoop(this); }
   940         public Kind getKind() { return Kind.DO_WHILE_LOOP; }
   941         public JCExpression getCondition() { return cond; }
   942         public JCStatement getStatement() { return body; }
   943         @Override
   944         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   945             return v.visitDoWhileLoop(this, d);
   946         }
   948         @Override
   949         public Tag getTag() {
   950             return DOLOOP;
   951         }
   952     }
   954     /**
   955      * A while loop
   956      */
   957     public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
   958         public JCExpression cond;
   959         public JCStatement body;
   960         protected JCWhileLoop(JCExpression cond, JCStatement body) {
   961             this.cond = cond;
   962             this.body = body;
   963         }
   964         @Override
   965         public void accept(Visitor v) { v.visitWhileLoop(this); }
   967         public Kind getKind() { return Kind.WHILE_LOOP; }
   968         public JCExpression getCondition() { return cond; }
   969         public JCStatement getStatement() { return body; }
   970         @Override
   971         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   972             return v.visitWhileLoop(this, d);
   973         }
   975         @Override
   976         public Tag getTag() {
   977             return WHILELOOP;
   978         }
   979     }
   981     /**
   982      * A for loop.
   983      */
   984     public static class JCForLoop extends JCStatement implements ForLoopTree {
   985         public List<JCStatement> init;
   986         public JCExpression cond;
   987         public List<JCExpressionStatement> step;
   988         public JCStatement body;
   989         protected JCForLoop(List<JCStatement> init,
   990                           JCExpression cond,
   991                           List<JCExpressionStatement> update,
   992                           JCStatement body)
   993         {
   994             this.init = init;
   995             this.cond = cond;
   996             this.step = update;
   997             this.body = body;
   998         }
   999         @Override
  1000         public void accept(Visitor v) { v.visitForLoop(this); }
  1002         public Kind getKind() { return Kind.FOR_LOOP; }
  1003         public JCExpression getCondition() { return cond; }
  1004         public JCStatement getStatement() { return body; }
  1005         public List<JCStatement> getInitializer() {
  1006             return init;
  1008         public List<JCExpressionStatement> getUpdate() {
  1009             return step;
  1011         @Override
  1012         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1013             return v.visitForLoop(this, d);
  1016         @Override
  1017         public Tag getTag() {
  1018             return FORLOOP;
  1022     /**
  1023      * The enhanced for loop.
  1024      */
  1025     public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
  1026         public JCVariableDecl var;
  1027         public JCExpression expr;
  1028         public JCStatement body;
  1029         protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
  1030             this.var = var;
  1031             this.expr = expr;
  1032             this.body = body;
  1034         @Override
  1035         public void accept(Visitor v) { v.visitForeachLoop(this); }
  1037         public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
  1038         public JCVariableDecl getVariable() { return var; }
  1039         public JCExpression getExpression() { return expr; }
  1040         public JCStatement getStatement() { return body; }
  1041         @Override
  1042         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1043             return v.visitEnhancedForLoop(this, d);
  1045         @Override
  1046         public Tag getTag() {
  1047             return FOREACHLOOP;
  1051     /**
  1052      * A labelled expression or statement.
  1053      */
  1054     public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
  1055         public Name label;
  1056         public JCStatement body;
  1057         protected JCLabeledStatement(Name label, JCStatement body) {
  1058             this.label = label;
  1059             this.body = body;
  1061         @Override
  1062         public void accept(Visitor v) { v.visitLabelled(this); }
  1063         public Kind getKind() { return Kind.LABELED_STATEMENT; }
  1064         public Name getLabel() { return label; }
  1065         public JCStatement getStatement() { return body; }
  1066         @Override
  1067         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1068             return v.visitLabeledStatement(this, d);
  1070         @Override
  1071         public Tag getTag() {
  1072             return LABELLED;
  1076     /**
  1077      * A "switch ( ) { }" construction.
  1078      */
  1079     public static class JCSwitch extends JCStatement implements SwitchTree {
  1080         public JCExpression selector;
  1081         public List<JCCase> cases;
  1082         protected JCSwitch(JCExpression selector, List<JCCase> cases) {
  1083             this.selector = selector;
  1084             this.cases = cases;
  1086         @Override
  1087         public void accept(Visitor v) { v.visitSwitch(this); }
  1089         public Kind getKind() { return Kind.SWITCH; }
  1090         public JCExpression getExpression() { return selector; }
  1091         public List<JCCase> getCases() { return cases; }
  1092         @Override
  1093         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1094             return v.visitSwitch(this, d);
  1096         @Override
  1097         public Tag getTag() {
  1098             return SWITCH;
  1102     /**
  1103      * A "case  :" of a switch.
  1104      */
  1105     public static class JCCase extends JCStatement implements CaseTree {
  1106         public JCExpression pat;
  1107         public List<JCStatement> stats;
  1108         protected JCCase(JCExpression pat, List<JCStatement> stats) {
  1109             this.pat = pat;
  1110             this.stats = stats;
  1112         @Override
  1113         public void accept(Visitor v) { v.visitCase(this); }
  1115         public Kind getKind() { return Kind.CASE; }
  1116         public JCExpression getExpression() { return pat; }
  1117         public List<JCStatement> getStatements() { return stats; }
  1118         @Override
  1119         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1120             return v.visitCase(this, d);
  1122         @Override
  1123         public Tag getTag() {
  1124             return CASE;
  1128     /**
  1129      * A synchronized block.
  1130      */
  1131     public static class JCSynchronized extends JCStatement implements SynchronizedTree {
  1132         public JCExpression lock;
  1133         public JCBlock body;
  1134         protected JCSynchronized(JCExpression lock, JCBlock body) {
  1135             this.lock = lock;
  1136             this.body = body;
  1138         @Override
  1139         public void accept(Visitor v) { v.visitSynchronized(this); }
  1141         public Kind getKind() { return Kind.SYNCHRONIZED; }
  1142         public JCExpression getExpression() { return lock; }
  1143         public JCBlock getBlock() { return body; }
  1144         @Override
  1145         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1146             return v.visitSynchronized(this, d);
  1148         @Override
  1149         public Tag getTag() {
  1150             return SYNCHRONIZED;
  1154     /**
  1155      * A "try { } catch ( ) { } finally { }" block.
  1156      */
  1157     public static class JCTry extends JCStatement implements TryTree {
  1158         public JCBlock body;
  1159         public List<JCCatch> catchers;
  1160         public JCBlock finalizer;
  1161         public List<JCTree> resources;
  1162         public boolean finallyCanCompleteNormally;
  1163         protected JCTry(List<JCTree> resources,
  1164                         JCBlock body,
  1165                         List<JCCatch> catchers,
  1166                         JCBlock finalizer) {
  1167             this.body = body;
  1168             this.catchers = catchers;
  1169             this.finalizer = finalizer;
  1170             this.resources = resources;
  1172         @Override
  1173         public void accept(Visitor v) { v.visitTry(this); }
  1175         public Kind getKind() { return Kind.TRY; }
  1176         public JCBlock getBlock() { return body; }
  1177         public List<JCCatch> getCatches() {
  1178             return catchers;
  1180         public JCBlock getFinallyBlock() { return finalizer; }
  1181         @Override
  1182         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1183             return v.visitTry(this, d);
  1185         @Override
  1186         public List<JCTree> getResources() {
  1187             return resources;
  1189         @Override
  1190         public Tag getTag() {
  1191             return TRY;
  1195     /**
  1196      * A catch block.
  1197      */
  1198     public static class JCCatch extends JCTree implements CatchTree {
  1199         public JCVariableDecl param;
  1200         public JCBlock body;
  1201         protected JCCatch(JCVariableDecl param, JCBlock body) {
  1202             this.param = param;
  1203             this.body = body;
  1205         @Override
  1206         public void accept(Visitor v) { v.visitCatch(this); }
  1208         public Kind getKind() { return Kind.CATCH; }
  1209         public JCVariableDecl getParameter() { return param; }
  1210         public JCBlock getBlock() { return body; }
  1211         @Override
  1212         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1213             return v.visitCatch(this, d);
  1215         @Override
  1216         public Tag getTag() {
  1217             return CATCH;
  1221     /**
  1222      * A ( ) ? ( ) : ( ) conditional expression
  1223      */
  1224     public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree {
  1225         public JCExpression cond;
  1226         public JCExpression truepart;
  1227         public JCExpression falsepart;
  1228         protected JCConditional(JCExpression cond,
  1229                               JCExpression truepart,
  1230                               JCExpression falsepart)
  1232             this.cond = cond;
  1233             this.truepart = truepart;
  1234             this.falsepart = falsepart;
  1236         @Override
  1237         public void accept(Visitor v) { v.visitConditional(this); }
  1239         public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
  1240         public JCExpression getCondition() { return cond; }
  1241         public JCExpression getTrueExpression() { return truepart; }
  1242         public JCExpression getFalseExpression() { return falsepart; }
  1243         @Override
  1244         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1245             return v.visitConditionalExpression(this, d);
  1247         @Override
  1248         public Tag getTag() {
  1249             return CONDEXPR;
  1253     /**
  1254      * An "if ( ) { } else { }" block
  1255      */
  1256     public static class JCIf extends JCStatement implements IfTree {
  1257         public JCExpression cond;
  1258         public JCStatement thenpart;
  1259         public JCStatement elsepart;
  1260         protected JCIf(JCExpression cond,
  1261                      JCStatement thenpart,
  1262                      JCStatement elsepart)
  1264             this.cond = cond;
  1265             this.thenpart = thenpart;
  1266             this.elsepart = elsepart;
  1268         @Override
  1269         public void accept(Visitor v) { v.visitIf(this); }
  1271         public Kind getKind() { return Kind.IF; }
  1272         public JCExpression getCondition() { return cond; }
  1273         public JCStatement getThenStatement() { return thenpart; }
  1274         public JCStatement getElseStatement() { return elsepart; }
  1275         @Override
  1276         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1277             return v.visitIf(this, d);
  1279         @Override
  1280         public Tag getTag() {
  1281             return IF;
  1285     /**
  1286      * an expression statement
  1287      */
  1288     public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
  1289         /** expression structure */
  1290         public JCExpression expr;
  1291         protected JCExpressionStatement(JCExpression expr)
  1293             this.expr = expr;
  1295         @Override
  1296         public void accept(Visitor v) { v.visitExec(this); }
  1298         public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
  1299         public JCExpression getExpression() { return expr; }
  1300         @Override
  1301         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1302             return v.visitExpressionStatement(this, d);
  1304         @Override
  1305         public Tag getTag() {
  1306             return EXEC;
  1309         /** Convert a expression-statement tree to a pretty-printed string. */
  1310         @Override
  1311         public String toString() {
  1312             StringWriter s = new StringWriter();
  1313             try {
  1314                 new Pretty(s, false).printStat(this);
  1316             catch (IOException e) {
  1317                 // should never happen, because StringWriter is defined
  1318                 // never to throw any IOExceptions
  1319                 throw new AssertionError(e);
  1321             return s.toString();
  1325     /**
  1326      * A break from a loop or switch.
  1327      */
  1328     public static class JCBreak extends JCStatement implements BreakTree {
  1329         public Name label;
  1330         public JCTree target;
  1331         protected JCBreak(Name label, JCTree target) {
  1332             this.label = label;
  1333             this.target = target;
  1335         @Override
  1336         public void accept(Visitor v) { v.visitBreak(this); }
  1338         public Kind getKind() { return Kind.BREAK; }
  1339         public Name getLabel() { return label; }
  1340         @Override
  1341         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1342             return v.visitBreak(this, d);
  1344         @Override
  1345         public Tag getTag() {
  1346             return BREAK;
  1350     /**
  1351      * A continue of a loop.
  1352      */
  1353     public static class JCContinue extends JCStatement implements ContinueTree {
  1354         public Name label;
  1355         public JCTree target;
  1356         protected JCContinue(Name label, JCTree target) {
  1357             this.label = label;
  1358             this.target = target;
  1360         @Override
  1361         public void accept(Visitor v) { v.visitContinue(this); }
  1363         public Kind getKind() { return Kind.CONTINUE; }
  1364         public Name getLabel() { return label; }
  1365         @Override
  1366         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1367             return v.visitContinue(this, d);
  1369         @Override
  1370         public Tag getTag() {
  1371             return CONTINUE;
  1375     /**
  1376      * A return statement.
  1377      */
  1378     public static class JCReturn extends JCStatement implements ReturnTree {
  1379         public JCExpression expr;
  1380         protected JCReturn(JCExpression expr) {
  1381             this.expr = expr;
  1383         @Override
  1384         public void accept(Visitor v) { v.visitReturn(this); }
  1386         public Kind getKind() { return Kind.RETURN; }
  1387         public JCExpression getExpression() { return expr; }
  1388         @Override
  1389         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1390             return v.visitReturn(this, d);
  1392         @Override
  1393         public Tag getTag() {
  1394             return RETURN;
  1398     /**
  1399      * A throw statement.
  1400      */
  1401     public static class JCThrow extends JCStatement implements ThrowTree {
  1402         public JCExpression expr;
  1403         protected JCThrow(JCExpression expr) {
  1404             this.expr = expr;
  1406         @Override
  1407         public void accept(Visitor v) { v.visitThrow(this); }
  1409         public Kind getKind() { return Kind.THROW; }
  1410         public JCExpression getExpression() { return expr; }
  1411         @Override
  1412         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1413             return v.visitThrow(this, d);
  1415         @Override
  1416         public Tag getTag() {
  1417             return THROW;
  1421     /**
  1422      * An assert statement.
  1423      */
  1424     public static class JCAssert extends JCStatement implements AssertTree {
  1425         public JCExpression cond;
  1426         public JCExpression detail;
  1427         protected JCAssert(JCExpression cond, JCExpression detail) {
  1428             this.cond = cond;
  1429             this.detail = detail;
  1431         @Override
  1432         public void accept(Visitor v) { v.visitAssert(this); }
  1434         public Kind getKind() { return Kind.ASSERT; }
  1435         public JCExpression getCondition() { return cond; }
  1436         public JCExpression getDetail() { return detail; }
  1437         @Override
  1438         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1439             return v.visitAssert(this, d);
  1441         @Override
  1442         public Tag getTag() {
  1443             return ASSERT;
  1447     /**
  1448      * A method invocation
  1449      */
  1450     public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree {
  1451         public List<JCExpression> typeargs;
  1452         public JCExpression meth;
  1453         public List<JCExpression> args;
  1454         public Type varargsElement;
  1455         protected JCMethodInvocation(List<JCExpression> typeargs,
  1456                         JCExpression meth,
  1457                         List<JCExpression> args)
  1459             this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
  1460                                                : typeargs;
  1461             this.meth = meth;
  1462             this.args = args;
  1464         @Override
  1465         public void accept(Visitor v) { v.visitApply(this); }
  1467         public Kind getKind() { return Kind.METHOD_INVOCATION; }
  1468         public List<JCExpression> getTypeArguments() {
  1469             return typeargs;
  1471         public JCExpression getMethodSelect() { return meth; }
  1472         public List<JCExpression> getArguments() {
  1473             return args;
  1475         @Override
  1476         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1477             return v.visitMethodInvocation(this, d);
  1479         @Override
  1480         public JCMethodInvocation setType(Type type) {
  1481             super.setType(type);
  1482             return this;
  1484         @Override
  1485         public Tag getTag() {
  1486             return(APPLY);
  1490     /**
  1491      * A new(...) operation.
  1492      */
  1493     public static class JCNewClass extends JCPolyExpression implements NewClassTree {
  1494         public JCExpression encl;
  1495         public List<JCExpression> typeargs;
  1496         public JCExpression clazz;
  1497         public List<JCExpression> args;
  1498         public JCClassDecl def;
  1499         public Symbol constructor;
  1500         public Type varargsElement;
  1501         public Type constructorType;
  1502         protected JCNewClass(JCExpression encl,
  1503                            List<JCExpression> typeargs,
  1504                            JCExpression clazz,
  1505                            List<JCExpression> args,
  1506                            JCClassDecl def)
  1508             this.encl = encl;
  1509             this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
  1510                                                : typeargs;
  1511             this.clazz = clazz;
  1512             this.args = args;
  1513             this.def = def;
  1515         @Override
  1516         public void accept(Visitor v) { v.visitNewClass(this); }
  1518         public Kind getKind() { return Kind.NEW_CLASS; }
  1519         public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
  1520             return encl;
  1522         public List<JCExpression> getTypeArguments() {
  1523             return typeargs;
  1525         public JCExpression getIdentifier() { return clazz; }
  1526         public List<JCExpression> getArguments() {
  1527             return args;
  1529         public JCClassDecl getClassBody() { return def; }
  1530         @Override
  1531         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1532             return v.visitNewClass(this, d);
  1534         @Override
  1535         public Tag getTag() {
  1536             return NEWCLASS;
  1540     /**
  1541      * A new[...] operation.
  1542      */
  1543     public static class JCNewArray extends JCExpression implements NewArrayTree {
  1544         public JCExpression elemtype;
  1545         public List<JCExpression> dims;
  1546         // type annotations on inner-most component
  1547         public List<JCAnnotation> annotations;
  1548         // type annotations on dimensions
  1549         public List<List<JCAnnotation>> dimAnnotations;
  1550         public List<JCExpression> elems;
  1551         protected JCNewArray(JCExpression elemtype,
  1552                            List<JCExpression> dims,
  1553                            List<JCExpression> elems)
  1555             this.elemtype = elemtype;
  1556             this.dims = dims;
  1557             this.annotations = List.nil();
  1558             this.dimAnnotations = List.nil();
  1559             this.elems = elems;
  1561         @Override
  1562         public void accept(Visitor v) { v.visitNewArray(this); }
  1564         public Kind getKind() { return Kind.NEW_ARRAY; }
  1565         public JCExpression getType() { return elemtype; }
  1566         public List<JCExpression> getDimensions() {
  1567             return dims;
  1569         public List<JCExpression> getInitializers() {
  1570             return elems;
  1572         @Override
  1573         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1574             return v.visitNewArray(this, d);
  1576         @Override
  1577         public Tag getTag() {
  1578             return NEWARRAY;
  1581         @Override
  1582         public List<JCAnnotation> getAnnotations() {
  1583             return annotations;
  1586         @Override
  1587         public List<List<JCAnnotation>> getDimAnnotations() {
  1588             return dimAnnotations;
  1592     /**
  1593      * A lambda expression.
  1594      */
  1595     public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
  1597         public enum ParameterKind {
  1598             IMPLICIT,
  1599             EXPLICIT;
  1602         public List<JCVariableDecl> params;
  1603         public JCTree body;
  1604         public boolean canCompleteNormally = true;
  1605         public ParameterKind paramKind;
  1607         public JCLambda(List<JCVariableDecl> params,
  1608                         JCTree body) {
  1609             this.params = params;
  1610             this.body = body;
  1611             if (params.isEmpty() ||
  1612                 params.head.vartype != null) {
  1613                 paramKind = ParameterKind.EXPLICIT;
  1614             } else {
  1615                 paramKind = ParameterKind.IMPLICIT;
  1618         @Override
  1619         public Tag getTag() {
  1620             return LAMBDA;
  1622         @Override
  1623         public void accept(Visitor v) {
  1624             v.visitLambda(this);
  1626         @Override
  1627         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
  1628             return v.visitLambdaExpression(this, d);
  1630         public Kind getKind() {
  1631             return Kind.LAMBDA_EXPRESSION;
  1633         public JCTree getBody() {
  1634             return body;
  1636         public java.util.List<? extends VariableTree> getParameters() {
  1637             return params;
  1639         @Override
  1640         public JCLambda setType(Type type) {
  1641             super.setType(type);
  1642             return this;
  1644         @Override
  1645         public BodyKind getBodyKind() {
  1646             return body.hasTag(BLOCK) ?
  1647                     BodyKind.STATEMENT :
  1648                     BodyKind.EXPRESSION;
  1652     /**
  1653      * A parenthesized subexpression ( ... )
  1654      */
  1655     public static class JCParens extends JCExpression implements ParenthesizedTree {
  1656         public JCExpression expr;
  1657         protected JCParens(JCExpression expr) {
  1658             this.expr = expr;
  1660         @Override
  1661         public void accept(Visitor v) { v.visitParens(this); }
  1663         public Kind getKind() { return Kind.PARENTHESIZED; }
  1664         public JCExpression getExpression() { return expr; }
  1665         @Override
  1666         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1667             return v.visitParenthesized(this, d);
  1669         @Override
  1670         public Tag getTag() {
  1671             return PARENS;
  1675     /**
  1676      * A assignment with "=".
  1677      */
  1678     public static class JCAssign extends JCExpression implements AssignmentTree {
  1679         public JCExpression lhs;
  1680         public JCExpression rhs;
  1681         protected JCAssign(JCExpression lhs, JCExpression rhs) {
  1682             this.lhs = lhs;
  1683             this.rhs = rhs;
  1685         @Override
  1686         public void accept(Visitor v) { v.visitAssign(this); }
  1688         public Kind getKind() { return Kind.ASSIGNMENT; }
  1689         public JCExpression getVariable() { return lhs; }
  1690         public JCExpression getExpression() { return rhs; }
  1691         @Override
  1692         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1693             return v.visitAssignment(this, d);
  1695         @Override
  1696         public Tag getTag() {
  1697             return ASSIGN;
  1701     /**
  1702      * An assignment with "+=", "|=" ...
  1703      */
  1704     public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree {
  1705         private Tag opcode;
  1706         public JCExpression lhs;
  1707         public JCExpression rhs;
  1708         public Symbol operator;
  1709         protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, Symbol operator) {
  1710             this.opcode = opcode;
  1711             this.lhs = (JCExpression)lhs;
  1712             this.rhs = (JCExpression)rhs;
  1713             this.operator = operator;
  1715         @Override
  1716         public void accept(Visitor v) { v.visitAssignop(this); }
  1718         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1719         public JCExpression getVariable() { return lhs; }
  1720         public JCExpression getExpression() { return rhs; }
  1721         public Symbol getOperator() {
  1722             return operator;
  1724         @Override
  1725         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1726             return v.visitCompoundAssignment(this, d);
  1728         @Override
  1729         public Tag getTag() {
  1730             return opcode;
  1734     /**
  1735      * A unary operation.
  1736      */
  1737     public static class JCUnary extends JCExpression implements UnaryTree {
  1738         private Tag opcode;
  1739         public JCExpression arg;
  1740         public Symbol operator;
  1741         protected JCUnary(Tag opcode, JCExpression arg) {
  1742             this.opcode = opcode;
  1743             this.arg = arg;
  1745         @Override
  1746         public void accept(Visitor v) { v.visitUnary(this); }
  1748         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1749         public JCExpression getExpression() { return arg; }
  1750         public Symbol getOperator() {
  1751             return operator;
  1753         @Override
  1754         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1755             return v.visitUnary(this, d);
  1757         @Override
  1758         public Tag getTag() {
  1759             return opcode;
  1762         public void setTag(Tag tag) {
  1763             opcode = tag;
  1767     /**
  1768      * A binary operation.
  1769      */
  1770     public static class JCBinary extends JCExpression implements BinaryTree {
  1771         private Tag opcode;
  1772         public JCExpression lhs;
  1773         public JCExpression rhs;
  1774         public Symbol operator;
  1775         protected JCBinary(Tag opcode,
  1776                          JCExpression lhs,
  1777                          JCExpression rhs,
  1778                          Symbol operator) {
  1779             this.opcode = opcode;
  1780             this.lhs = lhs;
  1781             this.rhs = rhs;
  1782             this.operator = operator;
  1784         @Override
  1785         public void accept(Visitor v) { v.visitBinary(this); }
  1787         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1788         public JCExpression getLeftOperand() { return lhs; }
  1789         public JCExpression getRightOperand() { return rhs; }
  1790         public Symbol getOperator() {
  1791             return operator;
  1793         @Override
  1794         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1795             return v.visitBinary(this, d);
  1797         @Override
  1798         public Tag getTag() {
  1799             return opcode;
  1803     /**
  1804      * A type cast.
  1805      */
  1806     public static class JCTypeCast extends JCExpression implements TypeCastTree {
  1807         public JCTree clazz;
  1808         public JCExpression expr;
  1809         protected JCTypeCast(JCTree clazz, JCExpression expr) {
  1810             this.clazz = clazz;
  1811             this.expr = expr;
  1813         @Override
  1814         public void accept(Visitor v) { v.visitTypeCast(this); }
  1816         public Kind getKind() { return Kind.TYPE_CAST; }
  1817         public JCTree getType() { return clazz; }
  1818         public JCExpression getExpression() { return expr; }
  1819         @Override
  1820         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1821             return v.visitTypeCast(this, d);
  1823         @Override
  1824         public Tag getTag() {
  1825             return TYPECAST;
  1829     /**
  1830      * A type test.
  1831      */
  1832     public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
  1833         public JCExpression expr;
  1834         public JCTree clazz;
  1835         protected JCInstanceOf(JCExpression expr, JCTree clazz) {
  1836             this.expr = expr;
  1837             this.clazz = clazz;
  1839         @Override
  1840         public void accept(Visitor v) { v.visitTypeTest(this); }
  1842         public Kind getKind() { return Kind.INSTANCE_OF; }
  1843         public JCTree getType() { return clazz; }
  1844         public JCExpression getExpression() { return expr; }
  1845         @Override
  1846         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1847             return v.visitInstanceOf(this, d);
  1849         @Override
  1850         public Tag getTag() {
  1851             return TYPETEST;
  1855     /**
  1856      * An array selection
  1857      */
  1858     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
  1859         public JCExpression indexed;
  1860         public JCExpression index;
  1861         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
  1862             this.indexed = indexed;
  1863             this.index = index;
  1865         @Override
  1866         public void accept(Visitor v) { v.visitIndexed(this); }
  1868         public Kind getKind() { return Kind.ARRAY_ACCESS; }
  1869         public JCExpression getExpression() { return indexed; }
  1870         public JCExpression getIndex() { return index; }
  1871         @Override
  1872         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1873             return v.visitArrayAccess(this, d);
  1875         @Override
  1876         public Tag getTag() {
  1877             return INDEXED;
  1881     /**
  1882      * Selects through packages and classes
  1883      */
  1884     public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
  1885         /** selected Tree hierarchy */
  1886         public JCExpression selected;
  1887         /** name of field to select thru */
  1888         public Name name;
  1889         /** symbol of the selected class */
  1890         public Symbol sym;
  1891         protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
  1892             this.selected = selected;
  1893             this.name = name;
  1894             this.sym = sym;
  1896         @Override
  1897         public void accept(Visitor v) { v.visitSelect(this); }
  1899         public Kind getKind() { return Kind.MEMBER_SELECT; }
  1900         public JCExpression getExpression() { return selected; }
  1901         @Override
  1902         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1903             return v.visitMemberSelect(this, d);
  1905         public Name getIdentifier() { return name; }
  1906         @Override
  1907         public Tag getTag() {
  1908             return SELECT;
  1912     /**
  1913      * Selects a member expression.
  1914      */
  1915     public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
  1917         public ReferenceMode mode;
  1918         public ReferenceKind kind;
  1919         public Name name;
  1920         public JCExpression expr;
  1921         public List<JCExpression> typeargs;
  1922         public Symbol sym;
  1923         public Type varargsElement;
  1924         public PolyKind refPolyKind;
  1925         public boolean ownerAccessible;
  1926         public OverloadKind overloadKind;
  1928         public enum OverloadKind {
  1929             OVERLOADED,
  1930             UNOVERLOADED;
  1933         /**
  1934          * Javac-dependent classification for member references, based
  1935          * on relevant properties w.r.t. code-generation
  1936          */
  1937         public enum ReferenceKind {
  1938             /** super # instMethod */
  1939             SUPER(ReferenceMode.INVOKE, false),
  1940             /** Type # instMethod */
  1941             UNBOUND(ReferenceMode.INVOKE, true),
  1942             /** Type # staticMethod */
  1943             STATIC(ReferenceMode.INVOKE, false),
  1944             /** Expr # instMethod */
  1945             BOUND(ReferenceMode.INVOKE, false),
  1946             /** Inner # new */
  1947             IMPLICIT_INNER(ReferenceMode.NEW, false),
  1948             /** Toplevel # new */
  1949             TOPLEVEL(ReferenceMode.NEW, false),
  1950             /** ArrayType # new */
  1951             ARRAY_CTOR(ReferenceMode.NEW, false);
  1953             final ReferenceMode mode;
  1954             final boolean unbound;
  1956             private ReferenceKind(ReferenceMode mode, boolean unbound) {
  1957                 this.mode = mode;
  1958                 this.unbound = unbound;
  1961             public boolean isUnbound() {
  1962                 return unbound;
  1966         protected JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
  1967             this.mode = mode;
  1968             this.name = name;
  1969             this.expr = expr;
  1970             this.typeargs = typeargs;
  1972         @Override
  1973         public void accept(Visitor v) { v.visitReference(this); }
  1975         public Kind getKind() { return Kind.MEMBER_REFERENCE; }
  1976         @Override
  1977         public ReferenceMode getMode() { return mode; }
  1978         @Override
  1979         public JCExpression getQualifierExpression() { return expr; }
  1980         @Override
  1981         public Name getName() { return name; }
  1982         @Override
  1983         public List<JCExpression> getTypeArguments() { return typeargs; }
  1985         @Override
  1986         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1987             return v.visitMemberReference(this, d);
  1989         @Override
  1990         public Tag getTag() {
  1991             return REFERENCE;
  1993         public boolean hasKind(ReferenceKind kind) {
  1994             return this.kind == kind;
  1998     /**
  1999      * An identifier
  2000      */
  2001     public static class JCIdent extends JCExpression implements IdentifierTree {
  2002         /** the name */
  2003         public Name name;
  2004         /** the symbol */
  2005         public Symbol sym;
  2006         protected JCIdent(Name name, Symbol sym) {
  2007             this.name = name;
  2008             this.sym = sym;
  2010         @Override
  2011         public void accept(Visitor v) { v.visitIdent(this); }
  2013         public Kind getKind() { return Kind.IDENTIFIER; }
  2014         public Name getName() { return name; }
  2015         @Override
  2016         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2017             return v.visitIdentifier(this, d);
  2019         @Override
  2020         public Tag getTag() {
  2021             return IDENT;
  2025     /**
  2026      * A constant value given literally.
  2027      */
  2028     public static class JCLiteral extends JCExpression implements LiteralTree {
  2029         public TypeTag typetag;
  2030         /** value representation */
  2031         public Object value;
  2032         protected JCLiteral(TypeTag typetag, Object value) {
  2033             this.typetag = typetag;
  2034             this.value = value;
  2036         @Override
  2037         public void accept(Visitor v) { v.visitLiteral(this); }
  2039         public Kind getKind() {
  2040             return typetag.getKindLiteral();
  2043         public Object getValue() {
  2044             switch (typetag) {
  2045                 case BOOLEAN:
  2046                     int bi = (Integer) value;
  2047                     return (bi != 0);
  2048                 case CHAR:
  2049                     int ci = (Integer) value;
  2050                     char c = (char) ci;
  2051                     if (c != ci)
  2052                         throw new AssertionError("bad value for char literal");
  2053                     return c;
  2054                 default:
  2055                     return value;
  2058         @Override
  2059         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2060             return v.visitLiteral(this, d);
  2062         @Override
  2063         public JCLiteral setType(Type type) {
  2064             super.setType(type);
  2065             return this;
  2067         @Override
  2068         public Tag getTag() {
  2069             return LITERAL;
  2073     /**
  2074      * Identifies a basic type.
  2075      * @see TypeTag
  2076      */
  2077     public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
  2078         /** the basic type id */
  2079         public TypeTag typetag;
  2080         protected JCPrimitiveTypeTree(TypeTag typetag) {
  2081             this.typetag = typetag;
  2083         @Override
  2084         public void accept(Visitor v) { v.visitTypeIdent(this); }
  2086         public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
  2087         public TypeKind getPrimitiveTypeKind() {
  2088             return typetag.getPrimitiveTypeKind();
  2091         @Override
  2092         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2093             return v.visitPrimitiveType(this, d);
  2095         @Override
  2096         public Tag getTag() {
  2097             return TYPEIDENT;
  2101     /**
  2102      * An array type, A[]
  2103      */
  2104     public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
  2105         public JCExpression elemtype;
  2106         protected JCArrayTypeTree(JCExpression elemtype) {
  2107             this.elemtype = elemtype;
  2109         @Override
  2110         public void accept(Visitor v) { v.visitTypeArray(this); }
  2112         public Kind getKind() { return Kind.ARRAY_TYPE; }
  2113         public JCTree getType() { return elemtype; }
  2114         @Override
  2115         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2116             return v.visitArrayType(this, d);
  2118         @Override
  2119         public Tag getTag() {
  2120             return TYPEARRAY;
  2124     /**
  2125      * A parameterized type, {@literal T<...>}
  2126      */
  2127     public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
  2128         public JCExpression clazz;
  2129         public List<JCExpression> arguments;
  2130         protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
  2131             this.clazz = clazz;
  2132             this.arguments = arguments;
  2134         @Override
  2135         public void accept(Visitor v) { v.visitTypeApply(this); }
  2137         public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
  2138         public JCTree getType() { return clazz; }
  2139         public List<JCExpression> getTypeArguments() {
  2140             return arguments;
  2142         @Override
  2143         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2144             return v.visitParameterizedType(this, d);
  2146         @Override
  2147         public Tag getTag() {
  2148             return TYPEAPPLY;
  2152     /**
  2153      * A union type, T1 | T2 | ... Tn (used in multicatch statements)
  2154      */
  2155     public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
  2157         public List<JCExpression> alternatives;
  2159         protected JCTypeUnion(List<JCExpression> components) {
  2160             this.alternatives = components;
  2162         @Override
  2163         public void accept(Visitor v) { v.visitTypeUnion(this); }
  2165         public Kind getKind() { return Kind.UNION_TYPE; }
  2167         public List<JCExpression> getTypeAlternatives() {
  2168             return alternatives;
  2170         @Override
  2171         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2172             return v.visitUnionType(this, d);
  2174         @Override
  2175         public Tag getTag() {
  2176             return TYPEUNION;
  2180     /**
  2181      * An intersection type, T1 & T2 & ... Tn (used in cast expressions)
  2182      */
  2183     public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree {
  2185         public List<JCExpression> bounds;
  2187         protected JCTypeIntersection(List<JCExpression> bounds) {
  2188             this.bounds = bounds;
  2190         @Override
  2191         public void accept(Visitor v) { v.visitTypeIntersection(this); }
  2193         public Kind getKind() { return Kind.INTERSECTION_TYPE; }
  2195         public List<JCExpression> getBounds() {
  2196             return bounds;
  2198         @Override
  2199         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2200             return v.visitIntersectionType(this, d);
  2202         @Override
  2203         public Tag getTag() {
  2204             return TYPEINTERSECTION;
  2208     /**
  2209      * A formal class parameter.
  2210      */
  2211     public static class JCTypeParameter extends JCTree implements TypeParameterTree {
  2212         /** name */
  2213         public Name name;
  2214         /** bounds */
  2215         public List<JCExpression> bounds;
  2216         /** type annotations on type parameter */
  2217         public List<JCAnnotation> annotations;
  2218         protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) {
  2219             this.name = name;
  2220             this.bounds = bounds;
  2221             this.annotations = annotations;
  2223         @Override
  2224         public void accept(Visitor v) { v.visitTypeParameter(this); }
  2226         public Kind getKind() { return Kind.TYPE_PARAMETER; }
  2227         public Name getName() { return name; }
  2228         public List<JCExpression> getBounds() {
  2229             return bounds;
  2231         public List<JCAnnotation> getAnnotations() {
  2232             return annotations;
  2234         @Override
  2235         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2236             return v.visitTypeParameter(this, d);
  2238         @Override
  2239         public Tag getTag() {
  2240             return TYPEPARAMETER;
  2244     public static class JCWildcard extends JCExpression implements WildcardTree {
  2245         public TypeBoundKind kind;
  2246         public JCTree inner;
  2247         protected JCWildcard(TypeBoundKind kind, JCTree inner) {
  2248             kind.getClass(); // null-check
  2249             this.kind = kind;
  2250             this.inner = inner;
  2252         @Override
  2253         public void accept(Visitor v) { v.visitWildcard(this); }
  2255         public Kind getKind() {
  2256             switch (kind.kind) {
  2257             case UNBOUND:
  2258                 return Kind.UNBOUNDED_WILDCARD;
  2259             case EXTENDS:
  2260                 return Kind.EXTENDS_WILDCARD;
  2261             case SUPER:
  2262                 return Kind.SUPER_WILDCARD;
  2263             default:
  2264                 throw new AssertionError("Unknown wildcard bound " + kind);
  2267         public JCTree getBound() { return inner; }
  2268         @Override
  2269         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2270             return v.visitWildcard(this, d);
  2272         @Override
  2273         public Tag getTag() {
  2274             return Tag.WILDCARD;
  2278     public static class TypeBoundKind extends JCTree {
  2279         public BoundKind kind;
  2280         protected TypeBoundKind(BoundKind kind) {
  2281             this.kind = kind;
  2283         @Override
  2284         public void accept(Visitor v) { v.visitTypeBoundKind(this); }
  2286         public Kind getKind() {
  2287             throw new AssertionError("TypeBoundKind is not part of a public API");
  2289         @Override
  2290         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2291             throw new AssertionError("TypeBoundKind is not part of a public API");
  2293         @Override
  2294         public Tag getTag() {
  2295             return TYPEBOUNDKIND;
  2299     public static class JCAnnotation extends JCExpression implements AnnotationTree {
  2300         // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION
  2301         private Tag tag;
  2303         public JCTree annotationType;
  2304         public List<JCExpression> args;
  2306         // Attribute.Compound if tag is ANNOTATION
  2307         // Attribute.TypeCompound if tag is TYPE_ANNOTATION
  2308         public Attribute.Compound attribute;
  2310         protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) {
  2311             this.tag = tag;
  2312             this.annotationType = annotationType;
  2313             this.args = args;
  2316         @Override
  2317         public void accept(Visitor v) { v.visitAnnotation(this); }
  2319         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  2321         public JCTree getAnnotationType() { return annotationType; }
  2322         public List<JCExpression> getArguments() {
  2323             return args;
  2325         @Override
  2326         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2327             return v.visitAnnotation(this, d);
  2329         @Override
  2330         public Tag getTag() {
  2331             return tag;
  2335     public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
  2336         public long flags;
  2337         public List<JCAnnotation> annotations;
  2338         protected JCModifiers(long flags, List<JCAnnotation> annotations) {
  2339             this.flags = flags;
  2340             this.annotations = annotations;
  2342         @Override
  2343         public void accept(Visitor v) { v.visitModifiers(this); }
  2345         public Kind getKind() { return Kind.MODIFIERS; }
  2346         public Set<Modifier> getFlags() {
  2347             return Flags.asModifierSet(flags);
  2349         public List<JCAnnotation> getAnnotations() {
  2350             return annotations;
  2352         @Override
  2353         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2354             return v.visitModifiers(this, d);
  2356         @Override
  2357         public Tag getTag() {
  2358             return MODIFIERS;
  2362     public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree {
  2363         // type annotations
  2364         public List<JCAnnotation> annotations;
  2365         public JCExpression underlyingType;
  2367         protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) {
  2368             Assert.check(annotations != null && annotations.nonEmpty());
  2369             this.annotations = annotations;
  2370             this.underlyingType = underlyingType;
  2372         @Override
  2373         public void accept(Visitor v) { v.visitAnnotatedType(this); }
  2375         public Kind getKind() { return Kind.ANNOTATED_TYPE; }
  2376         public List<JCAnnotation> getAnnotations() {
  2377             return annotations;
  2379         public JCExpression getUnderlyingType() {
  2380             return underlyingType;
  2382         @Override
  2383         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2384             return v.visitAnnotatedType(this, d);
  2386         @Override
  2387         public Tag getTag() {
  2388             return ANNOTATED_TYPE;
  2392     public static class JCErroneous extends JCExpression
  2393             implements com.sun.source.tree.ErroneousTree {
  2394         public List<? extends JCTree> errs;
  2395         protected JCErroneous(List<? extends JCTree> errs) {
  2396             this.errs = errs;
  2398         @Override
  2399         public void accept(Visitor v) { v.visitErroneous(this); }
  2401         public Kind getKind() { return Kind.ERRONEOUS; }
  2403         public List<? extends JCTree> getErrorTrees() {
  2404             return errs;
  2407         @Override
  2408         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2409             return v.visitErroneous(this, d);
  2411         @Override
  2412         public Tag getTag() {
  2413             return ERRONEOUS;
  2417     /** (let int x = 3; in x+2) */
  2418     public static class LetExpr extends JCExpression {
  2419         public List<JCVariableDecl> defs;
  2420         public JCTree expr;
  2421         protected LetExpr(List<JCVariableDecl> defs, JCTree expr) {
  2422             this.defs = defs;
  2423             this.expr = expr;
  2425         @Override
  2426         public void accept(Visitor v) { v.visitLetExpr(this); }
  2428         public Kind getKind() {
  2429             throw new AssertionError("LetExpr is not part of a public API");
  2431         @Override
  2432         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2433             throw new AssertionError("LetExpr is not part of a public API");
  2435         @Override
  2436         public Tag getTag() {
  2437             return LETEXPR;
  2441     /** An interface for tree factories
  2442      */
  2443     public interface Factory {
  2444         JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations,
  2445                                    JCExpression pid,
  2446                                    List<JCTree> defs);
  2447         JCImport Import(JCTree qualid, boolean staticImport);
  2448         JCClassDecl ClassDef(JCModifiers mods,
  2449                           Name name,
  2450                           List<JCTypeParameter> typarams,
  2451                           JCExpression extending,
  2452                           List<JCExpression> implementing,
  2453                           List<JCTree> defs);
  2454         JCMethodDecl MethodDef(JCModifiers mods,
  2455                             Name name,
  2456                             JCExpression restype,
  2457                             List<JCTypeParameter> typarams,
  2458                             JCVariableDecl recvparam,
  2459                             List<JCVariableDecl> params,
  2460                             List<JCExpression> thrown,
  2461                             JCBlock body,
  2462                             JCExpression defaultValue);
  2463         JCVariableDecl VarDef(JCModifiers mods,
  2464                       Name name,
  2465                       JCExpression vartype,
  2466                       JCExpression init);
  2467         JCSkip Skip();
  2468         JCBlock Block(long flags, List<JCStatement> stats);
  2469         JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
  2470         JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
  2471         JCForLoop ForLoop(List<JCStatement> init,
  2472                         JCExpression cond,
  2473                         List<JCExpressionStatement> step,
  2474                         JCStatement body);
  2475         JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
  2476         JCLabeledStatement Labelled(Name label, JCStatement body);
  2477         JCSwitch Switch(JCExpression selector, List<JCCase> cases);
  2478         JCCase Case(JCExpression pat, List<JCStatement> stats);
  2479         JCSynchronized Synchronized(JCExpression lock, JCBlock body);
  2480         JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
  2481         JCTry Try(List<JCTree> resources,
  2482                   JCBlock body,
  2483                   List<JCCatch> catchers,
  2484                   JCBlock finalizer);
  2485         JCCatch Catch(JCVariableDecl param, JCBlock body);
  2486         JCConditional Conditional(JCExpression cond,
  2487                                 JCExpression thenpart,
  2488                                 JCExpression elsepart);
  2489         JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
  2490         JCExpressionStatement Exec(JCExpression expr);
  2491         JCBreak Break(Name label);
  2492         JCContinue Continue(Name label);
  2493         JCReturn Return(JCExpression expr);
  2494         JCThrow Throw(JCExpression expr);
  2495         JCAssert Assert(JCExpression cond, JCExpression detail);
  2496         JCMethodInvocation Apply(List<JCExpression> typeargs,
  2497                     JCExpression fn,
  2498                     List<JCExpression> args);
  2499         JCNewClass NewClass(JCExpression encl,
  2500                           List<JCExpression> typeargs,
  2501                           JCExpression clazz,
  2502                           List<JCExpression> args,
  2503                           JCClassDecl def);
  2504         JCNewArray NewArray(JCExpression elemtype,
  2505                           List<JCExpression> dims,
  2506                           List<JCExpression> elems);
  2507         JCParens Parens(JCExpression expr);
  2508         JCAssign Assign(JCExpression lhs, JCExpression rhs);
  2509         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
  2510         JCUnary Unary(Tag opcode, JCExpression arg);
  2511         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
  2512         JCTypeCast TypeCast(JCTree expr, JCExpression type);
  2513         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
  2514         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
  2515         JCFieldAccess Select(JCExpression selected, Name selector);
  2516         JCIdent Ident(Name idname);
  2517         JCLiteral Literal(TypeTag tag, Object value);
  2518         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
  2519         JCArrayTypeTree TypeArray(JCExpression elemtype);
  2520         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
  2521         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
  2522         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
  2523         TypeBoundKind TypeBoundKind(BoundKind kind);
  2524         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
  2525         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
  2526         JCErroneous Erroneous(List<? extends JCTree> errs);
  2527         LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr);
  2530     /** A generic visitor class for trees.
  2531      */
  2532     public static abstract class Visitor {
  2533         public void visitTopLevel(JCCompilationUnit that)    { visitTree(that); }
  2534         public void visitImport(JCImport that)               { visitTree(that); }
  2535         public void visitClassDef(JCClassDecl that)          { visitTree(that); }
  2536         public void visitMethodDef(JCMethodDecl that)        { visitTree(that); }
  2537         public void visitVarDef(JCVariableDecl that)         { visitTree(that); }
  2538         public void visitSkip(JCSkip that)                   { visitTree(that); }
  2539         public void visitBlock(JCBlock that)                 { visitTree(that); }
  2540         public void visitDoLoop(JCDoWhileLoop that)          { visitTree(that); }
  2541         public void visitWhileLoop(JCWhileLoop that)         { visitTree(that); }
  2542         public void visitForLoop(JCForLoop that)             { visitTree(that); }
  2543         public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
  2544         public void visitLabelled(JCLabeledStatement that)   { visitTree(that); }
  2545         public void visitSwitch(JCSwitch that)               { visitTree(that); }
  2546         public void visitCase(JCCase that)                   { visitTree(that); }
  2547         public void visitSynchronized(JCSynchronized that)   { visitTree(that); }
  2548         public void visitTry(JCTry that)                     { visitTree(that); }
  2549         public void visitCatch(JCCatch that)                 { visitTree(that); }
  2550         public void visitConditional(JCConditional that)     { visitTree(that); }
  2551         public void visitIf(JCIf that)                       { visitTree(that); }
  2552         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
  2553         public void visitBreak(JCBreak that)                 { visitTree(that); }
  2554         public void visitContinue(JCContinue that)           { visitTree(that); }
  2555         public void visitReturn(JCReturn that)               { visitTree(that); }
  2556         public void visitThrow(JCThrow that)                 { visitTree(that); }
  2557         public void visitAssert(JCAssert that)               { visitTree(that); }
  2558         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
  2559         public void visitNewClass(JCNewClass that)           { visitTree(that); }
  2560         public void visitNewArray(JCNewArray that)           { visitTree(that); }
  2561         public void visitLambda(JCLambda that)               { visitTree(that); }
  2562         public void visitParens(JCParens that)               { visitTree(that); }
  2563         public void visitAssign(JCAssign that)               { visitTree(that); }
  2564         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
  2565         public void visitUnary(JCUnary that)                 { visitTree(that); }
  2566         public void visitBinary(JCBinary that)               { visitTree(that); }
  2567         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
  2568         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
  2569         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
  2570         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
  2571         public void visitReference(JCMemberReference that)   { visitTree(that); }
  2572         public void visitIdent(JCIdent that)                 { visitTree(that); }
  2573         public void visitLiteral(JCLiteral that)             { visitTree(that); }
  2574         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
  2575         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
  2576         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
  2577         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
  2578         public void visitTypeIntersection(JCTypeIntersection that)  { visitTree(that); }
  2579         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
  2580         public void visitWildcard(JCWildcard that)           { visitTree(that); }
  2581         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
  2582         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
  2583         public void visitModifiers(JCModifiers that)         { visitTree(that); }
  2584         public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); }
  2585         public void visitErroneous(JCErroneous that)         { visitTree(that); }
  2586         public void visitLetExpr(LetExpr that)               { visitTree(that); }
  2588         public void visitTree(JCTree that)                   { Assert.error(); }

mercurial