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

Tue, 05 Mar 2013 14:19:49 +0000

author
mcimadamore
date
Tue, 05 Mar 2013 14:19:49 +0000
changeset 1615
12202e6ab78a
parent 1521
71f35e4b93a5
child 1755
ddb4a2bfcd82
permissions
-rw-r--r--

8009129: Illegal access error when calling method reference
Summary: Javac generates method handle referencing non public type
Reviewed-by: jjg, rfield

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

mercurial