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

Fri, 30 Nov 2012 15:14:36 +0000

author
mcimadamore
date
Fri, 30 Nov 2012 15:14:36 +0000
changeset 1435
9b26c96f5138
parent 1374
c002fdee76fd
child 1436
f6f1fd261f57
permissions
-rw-r--r--

8004101: Add checks for method reference well-formedness
Summary: Bring method reference type-checking in sync with latest EDR
Reviewed-by: jjg

     1 /*
     2  * Copyright (c) 1999, 2012, 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         /** Formal type parameters, of type TypeParameter.
   258          */
   259         TYPEPARAMETER,
   261         /** Type argument.
   262          */
   263         WILDCARD,
   265         /** Bound kind: extends, super, exact, or unbound
   266          */
   267         TYPEBOUNDKIND,
   269         /** metadata: Annotation.
   270          */
   271         ANNOTATION,
   273         /** metadata: Modifiers
   274          */
   275         MODIFIERS,
   277         ANNOTATED_TYPE,
   279         /** Error trees, of type Erroneous.
   280          */
   281         ERRONEOUS,
   283         /** Unary operators, of type Unary.
   284          */
   285         POS,                             // +
   286         NEG,                             // -
   287         NOT,                             // !
   288         COMPL,                           // ~
   289         PREINC,                          // ++ _
   290         PREDEC,                          // -- _
   291         POSTINC,                         // _ ++
   292         POSTDEC,                         // _ --
   294         /** unary operator for null reference checks, only used internally.
   295          */
   296         NULLCHK,
   298         /** Binary operators, of type Binary.
   299          */
   300         OR,                              // ||
   301         AND,                             // &&
   302         BITOR,                           // |
   303         BITXOR,                          // ^
   304         BITAND,                          // &
   305         EQ,                              // ==
   306         NE,                              // !=
   307         LT,                              // <
   308         GT,                              // >
   309         LE,                              // <=
   310         GE,                              // >=
   311         SL,                              // <<
   312         SR,                              // >>
   313         USR,                             // >>>
   314         PLUS,                            // +
   315         MINUS,                           // -
   316         MUL,                             // *
   317         DIV,                             // /
   318         MOD,                             // %
   320         /** Assignment operators, of type Assignop.
   321          */
   322         BITOR_ASG(BITOR),                // |=
   323         BITXOR_ASG(BITXOR),              // ^=
   324         BITAND_ASG(BITAND),              // &=
   326         SL_ASG(SL),                      // <<=
   327         SR_ASG(SR),                      // >>=
   328         USR_ASG(USR),                    // >>>=
   329         PLUS_ASG(PLUS),                  // +=
   330         MINUS_ASG(MINUS),                // -=
   331         MUL_ASG(MUL),                    // *=
   332         DIV_ASG(DIV),                    // /=
   333         MOD_ASG(MOD),                    // %=
   335         /** A synthetic let expression, of type LetExpr.
   336          */
   337         LETEXPR;                         // ala scheme
   339         private Tag noAssignTag;
   341         private static int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
   343         private Tag(Tag noAssignTag) {
   344             this.noAssignTag = noAssignTag;
   345         }
   347         private Tag() { }
   349         public static int getNumberOfOperators() {
   350             return numberOfOperators;
   351         }
   353         public Tag noAssignOp() {
   354             if (noAssignTag != null)
   355                 return noAssignTag;
   356             throw new AssertionError("noAssignOp() method is not available for non assignment tags");
   357         }
   359         public boolean isPostUnaryOp() {
   360             return (this == POSTINC || this == POSTDEC);
   361         }
   363         public boolean isIncOrDecUnaryOp() {
   364             return (this == PREINC || this == PREDEC || this == POSTINC || this == POSTDEC);
   365         }
   367         public boolean isAssignop() {
   368             return noAssignTag != null;
   369         }
   371         public int operatorIndex() {
   372             return (this.ordinal() - POS.ordinal());
   373         }
   374     }
   376     /* The (encoded) position in the source file. @see util.Position.
   377      */
   378     public int pos;
   380     /* The type of this node.
   381      */
   382     public Type type;
   384     /* The tag of this node -- one of the constants declared above.
   385      */
   386     public abstract Tag getTag();
   388     /* Returns true if the tag of this node is equals to tag.
   389      */
   390     public boolean hasTag(Tag tag) {
   391         return tag == getTag();
   392     }
   394     /** Convert a tree to a pretty-printed string. */
   395     @Override
   396     public String toString() {
   397         StringWriter s = new StringWriter();
   398         try {
   399             new Pretty(s, false).printExpr(this);
   400         }
   401         catch (IOException e) {
   402             // should never happen, because StringWriter is defined
   403             // never to throw any IOExceptions
   404             throw new AssertionError(e);
   405         }
   406         return s.toString();
   407     }
   409     /** Set position field and return this tree.
   410      */
   411     public JCTree setPos(int pos) {
   412         this.pos = pos;
   413         return this;
   414     }
   416     /** Set type field and return this tree.
   417      */
   418     public JCTree setType(Type type) {
   419         this.type = type;
   420         return this;
   421     }
   423     /** Visit this tree with a given visitor.
   424      */
   425     public abstract void accept(Visitor v);
   427     public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);
   429     /** Return a shallow copy of this tree.
   430      */
   431     @Override
   432     public Object clone() {
   433         try {
   434             return super.clone();
   435         } catch(CloneNotSupportedException e) {
   436             throw new RuntimeException(e);
   437         }
   438     }
   440     /** Get a default position for this tree node.
   441      */
   442     public DiagnosticPosition pos() {
   443         return this;
   444     }
   446     // for default DiagnosticPosition
   447     public JCTree getTree() {
   448         return this;
   449     }
   451     // for default DiagnosticPosition
   452     public int getStartPosition() {
   453         return TreeInfo.getStartPos(this);
   454     }
   456     // for default DiagnosticPosition
   457     public int getPreferredPosition() {
   458         return pos;
   459     }
   461     // for default DiagnosticPosition
   462     public int getEndPosition(EndPosTable endPosTable) {
   463         return TreeInfo.getEndPos(this, endPosTable);
   464     }
   466     /**
   467      * Everything in one source file is kept in a {@linkplain JCCompilationUnit} structure.
   468      */
   469     public static class JCCompilationUnit extends JCTree implements CompilationUnitTree {
   470         public List<JCAnnotation> packageAnnotations;
   471         /** The tree representing the package clause. */
   472         public JCExpression pid;
   473         /** All definitions in this file (ClassDef, Import, and Skip) */
   474         public List<JCTree> defs;
   475         /* The source file name. */
   476         public JavaFileObject sourcefile;
   477         /** The package to which this compilation unit belongs. */
   478         public PackageSymbol packge;
   479         /** A scope for all named imports. */
   480         public ImportScope namedImportScope;
   481         /** A scope for all import-on-demands. */
   482         public StarImportScope starImportScope;
   483         /** Line starting positions, defined only if option -g is set. */
   484         public Position.LineMap lineMap = null;
   485         /** A table that stores all documentation comments indexed by the tree
   486          * nodes they refer to. defined only if option -s is set. */
   487         public DocCommentTable docComments = null;
   488         /* An object encapsulating ending positions of source ranges indexed by
   489          * the tree nodes they belong to. Defined only if option -Xjcov is set. */
   490         public EndPosTable endPositions = null;
   491         protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,
   492                         JCExpression pid,
   493                         List<JCTree> defs,
   494                         JavaFileObject sourcefile,
   495                         PackageSymbol packge,
   496                         ImportScope namedImportScope,
   497                         StarImportScope starImportScope) {
   498             this.packageAnnotations = packageAnnotations;
   499             this.pid = pid;
   500             this.defs = defs;
   501             this.sourcefile = sourcefile;
   502             this.packge = packge;
   503             this.namedImportScope = namedImportScope;
   504             this.starImportScope = starImportScope;
   505         }
   506         @Override
   507         public void accept(Visitor v) { v.visitTopLevel(this); }
   509         public Kind getKind() { return Kind.COMPILATION_UNIT; }
   510         public List<JCAnnotation> getPackageAnnotations() {
   511             return packageAnnotations;
   512         }
   513         public List<JCImport> getImports() {
   514             ListBuffer<JCImport> imports = new ListBuffer<JCImport>();
   515             for (JCTree tree : defs) {
   516                 if (tree.hasTag(IMPORT))
   517                     imports.append((JCImport)tree);
   518                 else if (!tree.hasTag(SKIP))
   519                     break;
   520             }
   521             return imports.toList();
   522         }
   523         public JCExpression getPackageName() { return pid; }
   524         public JavaFileObject getSourceFile() {
   525             return sourcefile;
   526         }
   527         public Position.LineMap getLineMap() {
   528             return lineMap;
   529         }
   530         public List<JCTree> getTypeDecls() {
   531             List<JCTree> typeDefs;
   532             for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)
   533                 if (!typeDefs.head.hasTag(IMPORT))
   534                     break;
   535             return typeDefs;
   536         }
   537         @Override
   538         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   539             return v.visitCompilationUnit(this, d);
   540         }
   542         @Override
   543         public Tag getTag() {
   544             return TOPLEVEL;
   545         }
   546     }
   548     /**
   549      * An import clause.
   550      */
   551     public static class JCImport extends JCTree implements ImportTree {
   552         public boolean staticImport;
   553         /** The imported class(es). */
   554         public JCTree qualid;
   555         protected JCImport(JCTree qualid, boolean importStatic) {
   556             this.qualid = qualid;
   557             this.staticImport = importStatic;
   558         }
   559         @Override
   560         public void accept(Visitor v) { v.visitImport(this); }
   562         public boolean isStatic() { return staticImport; }
   563         public JCTree getQualifiedIdentifier() { return qualid; }
   565         public Kind getKind() { return Kind.IMPORT; }
   566         @Override
   567         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   568             return v.visitImport(this, d);
   569         }
   571         @Override
   572         public Tag getTag() {
   573             return IMPORT;
   574         }
   575     }
   577     public static abstract class JCStatement extends JCTree implements StatementTree {
   578         @Override
   579         public JCStatement setType(Type type) {
   580             super.setType(type);
   581             return this;
   582         }
   583         @Override
   584         public JCStatement setPos(int pos) {
   585             super.setPos(pos);
   586             return this;
   587         }
   588     }
   590     public static abstract class JCExpression extends JCTree implements ExpressionTree {
   591         @Override
   592         public JCExpression setType(Type type) {
   593             super.setType(type);
   594             return this;
   595         }
   596         @Override
   597         public JCExpression setPos(int pos) {
   598             super.setPos(pos);
   599             return this;
   600         }
   601     }
   603     /**
   604      * A class definition.
   605      */
   606     public static class JCClassDecl extends JCStatement implements ClassTree {
   607         /** the modifiers */
   608         public JCModifiers mods;
   609         /** the name of the class */
   610         public Name name;
   611         /** formal class parameters */
   612         public List<JCTypeParameter> typarams;
   613         /** the classes this class extends */
   614         public JCExpression extending;
   615         /** the interfaces implemented by this class */
   616         public List<JCExpression> implementing;
   617         /** all variables and methods defined in this class */
   618         public List<JCTree> defs;
   619         /** the symbol */
   620         public ClassSymbol sym;
   621         protected JCClassDecl(JCModifiers mods,
   622                            Name name,
   623                            List<JCTypeParameter> typarams,
   624                            JCExpression extending,
   625                            List<JCExpression> implementing,
   626                            List<JCTree> defs,
   627                            ClassSymbol sym)
   628         {
   629             this.mods = mods;
   630             this.name = name;
   631             this.typarams = typarams;
   632             this.extending = extending;
   633             this.implementing = implementing;
   634             this.defs = defs;
   635             this.sym = sym;
   636         }
   637         @Override
   638         public void accept(Visitor v) { v.visitClassDef(this); }
   640         public Kind getKind() {
   641             if ((mods.flags & Flags.ANNOTATION) != 0)
   642                 return Kind.ANNOTATION_TYPE;
   643             else if ((mods.flags & Flags.INTERFACE) != 0)
   644                 return Kind.INTERFACE;
   645             else if ((mods.flags & Flags.ENUM) != 0)
   646                 return Kind.ENUM;
   647             else
   648                 return Kind.CLASS;
   649         }
   651         public JCModifiers getModifiers() { return mods; }
   652         public Name getSimpleName() { return name; }
   653         public List<JCTypeParameter> getTypeParameters() {
   654             return typarams;
   655         }
   656         public JCTree getExtendsClause() { return extending; }
   657         public List<JCExpression> getImplementsClause() {
   658             return implementing;
   659         }
   660         public List<JCTree> getMembers() {
   661             return defs;
   662         }
   663         @Override
   664         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   665             return v.visitClass(this, d);
   666         }
   668         @Override
   669         public Tag getTag() {
   670             return CLASSDEF;
   671         }
   672     }
   674     /**
   675      * A method definition.
   676      */
   677     public static class JCMethodDecl extends JCTree implements MethodTree {
   678         /** method modifiers */
   679         public JCModifiers mods;
   680         /** method name */
   681         public Name name;
   682         /** type of method return value */
   683         public JCExpression restype;
   684         /** type parameters */
   685         public List<JCTypeParameter> typarams;
   686         /** value parameters */
   687         public List<JCVariableDecl> params;
   688         /** exceptions thrown by this method */
   689         public List<JCExpression> thrown;
   690         /** statements in the method */
   691         public JCBlock body;
   692         /** default value, for annotation types */
   693         public JCExpression defaultValue;
   694         /** method symbol */
   695         public MethodSymbol sym;
   696         protected JCMethodDecl(JCModifiers mods,
   697                             Name name,
   698                             JCExpression restype,
   699                             List<JCTypeParameter> typarams,
   700                             List<JCVariableDecl> params,
   701                             List<JCExpression> thrown,
   702                             JCBlock body,
   703                             JCExpression defaultValue,
   704                             MethodSymbol sym)
   705         {
   706             this.mods = mods;
   707             this.name = name;
   708             this.restype = restype;
   709             this.typarams = typarams;
   710             this.params = params;
   711             this.thrown = thrown;
   712             this.body = body;
   713             this.defaultValue = defaultValue;
   714             this.sym = sym;
   715         }
   716         @Override
   717         public void accept(Visitor v) { v.visitMethodDef(this); }
   719         public Kind getKind() { return Kind.METHOD; }
   720         public JCModifiers getModifiers() { return mods; }
   721         public Name getName() { return name; }
   722         public JCTree getReturnType() { return restype; }
   723         public List<JCTypeParameter> getTypeParameters() {
   724             return typarams;
   725         }
   726         public List<JCVariableDecl> getParameters() {
   727             return params;
   728         }
   729         public List<JCExpression> getThrows() {
   730             return thrown;
   731         }
   732         public JCBlock getBody() { return body; }
   733         public JCTree getDefaultValue() { // for annotation types
   734             return defaultValue;
   735         }
   736         @Override
   737         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   738             return v.visitMethod(this, d);
   739         }
   741         @Override
   742         public Tag getTag() {
   743             return METHODDEF;
   744         }
   745   }
   747     /**
   748      * A variable definition.
   749      */
   750     public static class JCVariableDecl extends JCStatement implements VariableTree {
   751         /** variable modifiers */
   752         public JCModifiers mods;
   753         /** variable name */
   754         public Name name;
   755         /** type of the variable */
   756         public JCExpression vartype;
   757         /** variable's initial value */
   758         public JCExpression init;
   759         /** symbol */
   760         public VarSymbol sym;
   761         protected JCVariableDecl(JCModifiers mods,
   762                          Name name,
   763                          JCExpression vartype,
   764                          JCExpression init,
   765                          VarSymbol sym) {
   766             this.mods = mods;
   767             this.name = name;
   768             this.vartype = vartype;
   769             this.init = init;
   770             this.sym = sym;
   771         }
   772         @Override
   773         public void accept(Visitor v) { v.visitVarDef(this); }
   775         public Kind getKind() { return Kind.VARIABLE; }
   776         public JCModifiers getModifiers() { return mods; }
   777         public Name getName() { return name; }
   778         public JCTree getType() { return vartype; }
   779         public JCExpression getInitializer() {
   780             return init;
   781         }
   782         @Override
   783         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   784             return v.visitVariable(this, d);
   785         }
   787         @Override
   788         public Tag getTag() {
   789             return VARDEF;
   790         }
   791     }
   793       /**
   794      * A no-op statement ";".
   795      */
   796     public static class JCSkip extends JCStatement implements EmptyStatementTree {
   797         protected JCSkip() {
   798         }
   799         @Override
   800         public void accept(Visitor v) { v.visitSkip(this); }
   802         public Kind getKind() { return Kind.EMPTY_STATEMENT; }
   803         @Override
   804         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   805             return v.visitEmptyStatement(this, d);
   806         }
   808         @Override
   809         public Tag getTag() {
   810             return SKIP;
   811         }
   812     }
   814     /**
   815      * A statement block.
   816      */
   817     public static class JCBlock extends JCStatement implements BlockTree {
   818         /** flags */
   819         public long flags;
   820         /** statements */
   821         public List<JCStatement> stats;
   822         /** Position of closing brace, optional. */
   823         public int endpos = Position.NOPOS;
   824         protected JCBlock(long flags, List<JCStatement> stats) {
   825             this.stats = stats;
   826             this.flags = flags;
   827         }
   828         @Override
   829         public void accept(Visitor v) { v.visitBlock(this); }
   831         public Kind getKind() { return Kind.BLOCK; }
   832         public List<JCStatement> getStatements() {
   833             return stats;
   834         }
   835         public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
   836         @Override
   837         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   838             return v.visitBlock(this, d);
   839         }
   841         @Override
   842         public Tag getTag() {
   843             return BLOCK;
   844         }
   845     }
   847     /**
   848      * A do loop
   849      */
   850     public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
   851         public JCStatement body;
   852         public JCExpression cond;
   853         protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
   854             this.body = body;
   855             this.cond = cond;
   856         }
   857         @Override
   858         public void accept(Visitor v) { v.visitDoLoop(this); }
   860         public Kind getKind() { return Kind.DO_WHILE_LOOP; }
   861         public JCExpression getCondition() { return cond; }
   862         public JCStatement getStatement() { return body; }
   863         @Override
   864         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   865             return v.visitDoWhileLoop(this, d);
   866         }
   868         @Override
   869         public Tag getTag() {
   870             return DOLOOP;
   871         }
   872     }
   874     /**
   875      * A while loop
   876      */
   877     public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
   878         public JCExpression cond;
   879         public JCStatement body;
   880         protected JCWhileLoop(JCExpression cond, JCStatement body) {
   881             this.cond = cond;
   882             this.body = body;
   883         }
   884         @Override
   885         public void accept(Visitor v) { v.visitWhileLoop(this); }
   887         public Kind getKind() { return Kind.WHILE_LOOP; }
   888         public JCExpression getCondition() { return cond; }
   889         public JCStatement getStatement() { return body; }
   890         @Override
   891         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   892             return v.visitWhileLoop(this, d);
   893         }
   895         @Override
   896         public Tag getTag() {
   897             return WHILELOOP;
   898         }
   899     }
   901     /**
   902      * A for loop.
   903      */
   904     public static class JCForLoop extends JCStatement implements ForLoopTree {
   905         public List<JCStatement> init;
   906         public JCExpression cond;
   907         public List<JCExpressionStatement> step;
   908         public JCStatement body;
   909         protected JCForLoop(List<JCStatement> init,
   910                           JCExpression cond,
   911                           List<JCExpressionStatement> update,
   912                           JCStatement body)
   913         {
   914             this.init = init;
   915             this.cond = cond;
   916             this.step = update;
   917             this.body = body;
   918         }
   919         @Override
   920         public void accept(Visitor v) { v.visitForLoop(this); }
   922         public Kind getKind() { return Kind.FOR_LOOP; }
   923         public JCExpression getCondition() { return cond; }
   924         public JCStatement getStatement() { return body; }
   925         public List<JCStatement> getInitializer() {
   926             return init;
   927         }
   928         public List<JCExpressionStatement> getUpdate() {
   929             return step;
   930         }
   931         @Override
   932         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   933             return v.visitForLoop(this, d);
   934         }
   936         @Override
   937         public Tag getTag() {
   938             return FORLOOP;
   939         }
   940     }
   942     /**
   943      * The enhanced for loop.
   944      */
   945     public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
   946         public JCVariableDecl var;
   947         public JCExpression expr;
   948         public JCStatement body;
   949         protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
   950             this.var = var;
   951             this.expr = expr;
   952             this.body = body;
   953         }
   954         @Override
   955         public void accept(Visitor v) { v.visitForeachLoop(this); }
   957         public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
   958         public JCVariableDecl getVariable() { return var; }
   959         public JCExpression getExpression() { return expr; }
   960         public JCStatement getStatement() { return body; }
   961         @Override
   962         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   963             return v.visitEnhancedForLoop(this, d);
   964         }
   965         @Override
   966         public Tag getTag() {
   967             return FOREACHLOOP;
   968         }
   969     }
   971     /**
   972      * A labelled expression or statement.
   973      */
   974     public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
   975         public Name label;
   976         public JCStatement body;
   977         protected JCLabeledStatement(Name label, JCStatement body) {
   978             this.label = label;
   979             this.body = body;
   980         }
   981         @Override
   982         public void accept(Visitor v) { v.visitLabelled(this); }
   983         public Kind getKind() { return Kind.LABELED_STATEMENT; }
   984         public Name getLabel() { return label; }
   985         public JCStatement getStatement() { return body; }
   986         @Override
   987         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
   988             return v.visitLabeledStatement(this, d);
   989         }
   990         @Override
   991         public Tag getTag() {
   992             return LABELLED;
   993         }
   994     }
   996     /**
   997      * A "switch ( ) { }" construction.
   998      */
   999     public static class JCSwitch extends JCStatement implements SwitchTree {
  1000         public JCExpression selector;
  1001         public List<JCCase> cases;
  1002         protected JCSwitch(JCExpression selector, List<JCCase> cases) {
  1003             this.selector = selector;
  1004             this.cases = cases;
  1006         @Override
  1007         public void accept(Visitor v) { v.visitSwitch(this); }
  1009         public Kind getKind() { return Kind.SWITCH; }
  1010         public JCExpression getExpression() { return selector; }
  1011         public List<JCCase> getCases() { return cases; }
  1012         @Override
  1013         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1014             return v.visitSwitch(this, d);
  1016         @Override
  1017         public Tag getTag() {
  1018             return SWITCH;
  1022     /**
  1023      * A "case  :" of a switch.
  1024      */
  1025     public static class JCCase extends JCStatement implements CaseTree {
  1026         public JCExpression pat;
  1027         public List<JCStatement> stats;
  1028         protected JCCase(JCExpression pat, List<JCStatement> stats) {
  1029             this.pat = pat;
  1030             this.stats = stats;
  1032         @Override
  1033         public void accept(Visitor v) { v.visitCase(this); }
  1035         public Kind getKind() { return Kind.CASE; }
  1036         public JCExpression getExpression() { return pat; }
  1037         public List<JCStatement> getStatements() { return stats; }
  1038         @Override
  1039         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1040             return v.visitCase(this, d);
  1042         @Override
  1043         public Tag getTag() {
  1044             return CASE;
  1048     /**
  1049      * A synchronized block.
  1050      */
  1051     public static class JCSynchronized extends JCStatement implements SynchronizedTree {
  1052         public JCExpression lock;
  1053         public JCBlock body;
  1054         protected JCSynchronized(JCExpression lock, JCBlock body) {
  1055             this.lock = lock;
  1056             this.body = body;
  1058         @Override
  1059         public void accept(Visitor v) { v.visitSynchronized(this); }
  1061         public Kind getKind() { return Kind.SYNCHRONIZED; }
  1062         public JCExpression getExpression() { return lock; }
  1063         public JCBlock getBlock() { return body; }
  1064         @Override
  1065         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1066             return v.visitSynchronized(this, d);
  1068         @Override
  1069         public Tag getTag() {
  1070             return SYNCHRONIZED;
  1074     /**
  1075      * A "try { } catch ( ) { } finally { }" block.
  1076      */
  1077     public static class JCTry extends JCStatement implements TryTree {
  1078         public JCBlock body;
  1079         public List<JCCatch> catchers;
  1080         public JCBlock finalizer;
  1081         public List<JCTree> resources;
  1082         public boolean finallyCanCompleteNormally;
  1083         protected JCTry(List<JCTree> resources,
  1084                         JCBlock body,
  1085                         List<JCCatch> catchers,
  1086                         JCBlock finalizer) {
  1087             this.body = body;
  1088             this.catchers = catchers;
  1089             this.finalizer = finalizer;
  1090             this.resources = resources;
  1092         @Override
  1093         public void accept(Visitor v) { v.visitTry(this); }
  1095         public Kind getKind() { return Kind.TRY; }
  1096         public JCBlock getBlock() { return body; }
  1097         public List<JCCatch> getCatches() {
  1098             return catchers;
  1100         public JCBlock getFinallyBlock() { return finalizer; }
  1101         @Override
  1102         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1103             return v.visitTry(this, d);
  1105         @Override
  1106         public List<? extends JCTree> getResources() {
  1107             return resources;
  1109         @Override
  1110         public Tag getTag() {
  1111             return TRY;
  1115     /**
  1116      * A catch block.
  1117      */
  1118     public static class JCCatch extends JCTree implements CatchTree {
  1119         public JCVariableDecl param;
  1120         public JCBlock body;
  1121         protected JCCatch(JCVariableDecl param, JCBlock body) {
  1122             this.param = param;
  1123             this.body = body;
  1125         @Override
  1126         public void accept(Visitor v) { v.visitCatch(this); }
  1128         public Kind getKind() { return Kind.CATCH; }
  1129         public JCVariableDecl getParameter() { return param; }
  1130         public JCBlock getBlock() { return body; }
  1131         @Override
  1132         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1133             return v.visitCatch(this, d);
  1135         @Override
  1136         public Tag getTag() {
  1137             return CATCH;
  1141     /**
  1142      * A ( ) ? ( ) : ( ) conditional expression
  1143      */
  1144     public static class JCConditional extends JCExpression implements ConditionalExpressionTree {
  1145         public JCExpression cond;
  1146         public JCExpression truepart;
  1147         public JCExpression falsepart;
  1148         protected JCConditional(JCExpression cond,
  1149                               JCExpression truepart,
  1150                               JCExpression falsepart)
  1152             this.cond = cond;
  1153             this.truepart = truepart;
  1154             this.falsepart = falsepart;
  1156         @Override
  1157         public void accept(Visitor v) { v.visitConditional(this); }
  1159         public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
  1160         public JCExpression getCondition() { return cond; }
  1161         public JCExpression getTrueExpression() { return truepart; }
  1162         public JCExpression getFalseExpression() { return falsepart; }
  1163         @Override
  1164         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1165             return v.visitConditionalExpression(this, d);
  1167         @Override
  1168         public Tag getTag() {
  1169             return CONDEXPR;
  1173     /**
  1174      * An "if ( ) { } else { }" block
  1175      */
  1176     public static class JCIf extends JCStatement implements IfTree {
  1177         public JCExpression cond;
  1178         public JCStatement thenpart;
  1179         public JCStatement elsepart;
  1180         protected JCIf(JCExpression cond,
  1181                      JCStatement thenpart,
  1182                      JCStatement elsepart)
  1184             this.cond = cond;
  1185             this.thenpart = thenpart;
  1186             this.elsepart = elsepart;
  1188         @Override
  1189         public void accept(Visitor v) { v.visitIf(this); }
  1191         public Kind getKind() { return Kind.IF; }
  1192         public JCExpression getCondition() { return cond; }
  1193         public JCStatement getThenStatement() { return thenpart; }
  1194         public JCStatement getElseStatement() { return elsepart; }
  1195         @Override
  1196         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1197             return v.visitIf(this, d);
  1199         @Override
  1200         public Tag getTag() {
  1201             return IF;
  1205     /**
  1206      * an expression statement
  1207      */
  1208     public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
  1209         /** expression structure */
  1210         public JCExpression expr;
  1211         protected JCExpressionStatement(JCExpression expr)
  1213             this.expr = expr;
  1215         @Override
  1216         public void accept(Visitor v) { v.visitExec(this); }
  1218         public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
  1219         public JCExpression getExpression() { return expr; }
  1220         @Override
  1221         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1222             return v.visitExpressionStatement(this, d);
  1224         @Override
  1225         public Tag getTag() {
  1226             return EXEC;
  1229         /** Convert a expression-statement tree to a pretty-printed string. */
  1230         @Override
  1231         public String toString() {
  1232             StringWriter s = new StringWriter();
  1233             try {
  1234                 new Pretty(s, false).printStat(this);
  1236             catch (IOException e) {
  1237                 // should never happen, because StringWriter is defined
  1238                 // never to throw any IOExceptions
  1239                 throw new AssertionError(e);
  1241             return s.toString();
  1245     /**
  1246      * A break from a loop or switch.
  1247      */
  1248     public static class JCBreak extends JCStatement implements BreakTree {
  1249         public Name label;
  1250         public JCTree target;
  1251         protected JCBreak(Name label, JCTree target) {
  1252             this.label = label;
  1253             this.target = target;
  1255         @Override
  1256         public void accept(Visitor v) { v.visitBreak(this); }
  1258         public Kind getKind() { return Kind.BREAK; }
  1259         public Name getLabel() { return label; }
  1260         @Override
  1261         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1262             return v.visitBreak(this, d);
  1264         @Override
  1265         public Tag getTag() {
  1266             return BREAK;
  1270     /**
  1271      * A continue of a loop.
  1272      */
  1273     public static class JCContinue extends JCStatement implements ContinueTree {
  1274         public Name label;
  1275         public JCTree target;
  1276         protected JCContinue(Name label, JCTree target) {
  1277             this.label = label;
  1278             this.target = target;
  1280         @Override
  1281         public void accept(Visitor v) { v.visitContinue(this); }
  1283         public Kind getKind() { return Kind.CONTINUE; }
  1284         public Name getLabel() { return label; }
  1285         @Override
  1286         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1287             return v.visitContinue(this, d);
  1289         @Override
  1290         public Tag getTag() {
  1291             return CONTINUE;
  1295     /**
  1296      * A return statement.
  1297      */
  1298     public static class JCReturn extends JCStatement implements ReturnTree {
  1299         public JCExpression expr;
  1300         protected JCReturn(JCExpression expr) {
  1301             this.expr = expr;
  1303         @Override
  1304         public void accept(Visitor v) { v.visitReturn(this); }
  1306         public Kind getKind() { return Kind.RETURN; }
  1307         public JCExpression getExpression() { return expr; }
  1308         @Override
  1309         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1310             return v.visitReturn(this, d);
  1312         @Override
  1313         public Tag getTag() {
  1314             return RETURN;
  1318     /**
  1319      * A throw statement.
  1320      */
  1321     public static class JCThrow extends JCStatement implements ThrowTree {
  1322         public JCExpression expr;
  1323         protected JCThrow(JCTree expr) {
  1324             this.expr = (JCExpression)expr;
  1326         @Override
  1327         public void accept(Visitor v) { v.visitThrow(this); }
  1329         public Kind getKind() { return Kind.THROW; }
  1330         public JCExpression getExpression() { return expr; }
  1331         @Override
  1332         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1333             return v.visitThrow(this, d);
  1335         @Override
  1336         public Tag getTag() {
  1337             return THROW;
  1341     /**
  1342      * An assert statement.
  1343      */
  1344     public static class JCAssert extends JCStatement implements AssertTree {
  1345         public JCExpression cond;
  1346         public JCExpression detail;
  1347         protected JCAssert(JCExpression cond, JCExpression detail) {
  1348             this.cond = cond;
  1349             this.detail = detail;
  1351         @Override
  1352         public void accept(Visitor v) { v.visitAssert(this); }
  1354         public Kind getKind() { return Kind.ASSERT; }
  1355         public JCExpression getCondition() { return cond; }
  1356         public JCExpression getDetail() { return detail; }
  1357         @Override
  1358         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1359             return v.visitAssert(this, d);
  1361         @Override
  1362         public Tag getTag() {
  1363             return ASSERT;
  1367     /**
  1368      * A method invocation
  1369      */
  1370     public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree {
  1371         public List<JCExpression> typeargs;
  1372         public JCExpression meth;
  1373         public List<JCExpression> args;
  1374         public Type varargsElement;
  1375         protected JCMethodInvocation(List<JCExpression> typeargs,
  1376                         JCExpression meth,
  1377                         List<JCExpression> args)
  1379             this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
  1380                                                : typeargs;
  1381             this.meth = meth;
  1382             this.args = args;
  1384         @Override
  1385         public void accept(Visitor v) { v.visitApply(this); }
  1387         public Kind getKind() { return Kind.METHOD_INVOCATION; }
  1388         public List<JCExpression> getTypeArguments() {
  1389             return typeargs;
  1391         public JCExpression getMethodSelect() { return meth; }
  1392         public List<JCExpression> getArguments() {
  1393             return args;
  1395         @Override
  1396         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1397             return v.visitMethodInvocation(this, d);
  1399         @Override
  1400         public JCMethodInvocation setType(Type type) {
  1401             super.setType(type);
  1402             return this;
  1404         @Override
  1405         public Tag getTag() {
  1406             return(APPLY);
  1410     /**
  1411      * A new(...) operation.
  1412      */
  1413     public static class JCNewClass extends JCExpression implements NewClassTree {
  1414         public JCExpression encl;
  1415         public List<JCExpression> typeargs;
  1416         public JCExpression clazz;
  1417         public List<JCExpression> args;
  1418         public JCClassDecl def;
  1419         public Symbol constructor;
  1420         public Type varargsElement;
  1421         public Type constructorType;
  1422         protected JCNewClass(JCExpression encl,
  1423                            List<JCExpression> typeargs,
  1424                            JCExpression clazz,
  1425                            List<JCExpression> args,
  1426                            JCClassDecl def)
  1428             this.encl = encl;
  1429             this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
  1430                                                : typeargs;
  1431             this.clazz = clazz;
  1432             this.args = args;
  1433             this.def = def;
  1435         @Override
  1436         public void accept(Visitor v) { v.visitNewClass(this); }
  1438         public Kind getKind() { return Kind.NEW_CLASS; }
  1439         public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
  1440             return encl;
  1442         public List<JCExpression> getTypeArguments() {
  1443             return typeargs;
  1445         public JCExpression getIdentifier() { return clazz; }
  1446         public List<JCExpression> getArguments() {
  1447             return args;
  1449         public JCClassDecl getClassBody() { return def; }
  1450         @Override
  1451         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1452             return v.visitNewClass(this, d);
  1454         @Override
  1455         public Tag getTag() {
  1456             return NEWCLASS;
  1460     /**
  1461      * A new[...] operation.
  1462      */
  1463     public static class JCNewArray extends JCExpression implements NewArrayTree {
  1464         public JCExpression elemtype;
  1465         public List<JCExpression> dims;
  1466         public List<JCExpression> elems;
  1467         protected JCNewArray(JCExpression elemtype,
  1468                            List<JCExpression> dims,
  1469                            List<JCExpression> elems)
  1471             this.elemtype = elemtype;
  1472             this.dims = dims;
  1473             this.elems = elems;
  1475         @Override
  1476         public void accept(Visitor v) { v.visitNewArray(this); }
  1478         public Kind getKind() { return Kind.NEW_ARRAY; }
  1479         public JCExpression getType() { return elemtype; }
  1480         public List<JCExpression> getDimensions() {
  1481             return dims;
  1483         public List<JCExpression> getInitializers() {
  1484             return elems;
  1486         @Override
  1487         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1488             return v.visitNewArray(this, d);
  1490         @Override
  1491         public Tag getTag() {
  1492             return NEWARRAY;
  1496     /**
  1497      * A lambda expression.
  1498      */
  1499     public static class JCLambda extends JCExpression implements LambdaExpressionTree {
  1501         public List<JCVariableDecl> params;
  1502         public JCTree body;
  1503         public Type targetType;
  1504         public boolean canCompleteNormally = true;
  1505         public List<Type> inferredThrownTypes;
  1507         public JCLambda(List<JCVariableDecl> params,
  1508                         JCTree body) {
  1509             this.params = params;
  1510             this.body = body;
  1512         @Override
  1513         public Tag getTag() {
  1514             return LAMBDA;
  1516         @Override
  1517         public void accept(Visitor v) {
  1518             v.visitLambda(this);
  1520         @Override
  1521         public <R, D> R accept(TreeVisitor<R, D> v, D d) {
  1522             return v.visitLambdaExpression(this, d);
  1524         public Kind getKind() {
  1525             return Kind.LAMBDA_EXPRESSION;
  1527         public JCTree getBody() {
  1528             return body;
  1530         public java.util.List<? extends VariableTree> getParameters() {
  1531             return params;
  1533         @Override
  1534         public JCLambda setType(Type type) {
  1535             super.setType(type);
  1536             return this;
  1538         @Override
  1539         public BodyKind getBodyKind() {
  1540             return body.hasTag(BLOCK) ?
  1541                     BodyKind.STATEMENT :
  1542                     BodyKind.EXPRESSION;
  1546     /**
  1547      * A parenthesized subexpression ( ... )
  1548      */
  1549     public static class JCParens extends JCExpression implements ParenthesizedTree {
  1550         public JCExpression expr;
  1551         protected JCParens(JCExpression expr) {
  1552             this.expr = expr;
  1554         @Override
  1555         public void accept(Visitor v) { v.visitParens(this); }
  1557         public Kind getKind() { return Kind.PARENTHESIZED; }
  1558         public JCExpression getExpression() { return expr; }
  1559         @Override
  1560         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1561             return v.visitParenthesized(this, d);
  1563         @Override
  1564         public Tag getTag() {
  1565             return PARENS;
  1569     /**
  1570      * A assignment with "=".
  1571      */
  1572     public static class JCAssign extends JCExpression implements AssignmentTree {
  1573         public JCExpression lhs;
  1574         public JCExpression rhs;
  1575         protected JCAssign(JCExpression lhs, JCExpression rhs) {
  1576             this.lhs = lhs;
  1577             this.rhs = rhs;
  1579         @Override
  1580         public void accept(Visitor v) { v.visitAssign(this); }
  1582         public Kind getKind() { return Kind.ASSIGNMENT; }
  1583         public JCExpression getVariable() { return lhs; }
  1584         public JCExpression getExpression() { return rhs; }
  1585         @Override
  1586         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1587             return v.visitAssignment(this, d);
  1589         @Override
  1590         public Tag getTag() {
  1591             return ASSIGN;
  1595     /**
  1596      * An assignment with "+=", "|=" ...
  1597      */
  1598     public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree {
  1599         private Tag opcode;
  1600         public JCExpression lhs;
  1601         public JCExpression rhs;
  1602         public Symbol operator;
  1603         protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, Symbol operator) {
  1604             this.opcode = opcode;
  1605             this.lhs = (JCExpression)lhs;
  1606             this.rhs = (JCExpression)rhs;
  1607             this.operator = operator;
  1609         @Override
  1610         public void accept(Visitor v) { v.visitAssignop(this); }
  1612         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1613         public JCExpression getVariable() { return lhs; }
  1614         public JCExpression getExpression() { return rhs; }
  1615         public Symbol getOperator() {
  1616             return operator;
  1618         @Override
  1619         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1620             return v.visitCompoundAssignment(this, d);
  1622         @Override
  1623         public Tag getTag() {
  1624             return opcode;
  1628     /**
  1629      * A unary operation.
  1630      */
  1631     public static class JCUnary extends JCExpression implements UnaryTree {
  1632         private Tag opcode;
  1633         public JCExpression arg;
  1634         public Symbol operator;
  1635         protected JCUnary(Tag opcode, JCExpression arg) {
  1636             this.opcode = opcode;
  1637             this.arg = arg;
  1639         @Override
  1640         public void accept(Visitor v) { v.visitUnary(this); }
  1642         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1643         public JCExpression getExpression() { return arg; }
  1644         public Symbol getOperator() {
  1645             return operator;
  1647         @Override
  1648         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1649             return v.visitUnary(this, d);
  1651         @Override
  1652         public Tag getTag() {
  1653             return opcode;
  1656         public void setTag(Tag tag) {
  1657             opcode = tag;
  1661     /**
  1662      * A binary operation.
  1663      */
  1664     public static class JCBinary extends JCExpression implements BinaryTree {
  1665         private Tag opcode;
  1666         public JCExpression lhs;
  1667         public JCExpression rhs;
  1668         public Symbol operator;
  1669         protected JCBinary(Tag opcode,
  1670                          JCExpression lhs,
  1671                          JCExpression rhs,
  1672                          Symbol operator) {
  1673             this.opcode = opcode;
  1674             this.lhs = lhs;
  1675             this.rhs = rhs;
  1676             this.operator = operator;
  1678         @Override
  1679         public void accept(Visitor v) { v.visitBinary(this); }
  1681         public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1682         public JCExpression getLeftOperand() { return lhs; }
  1683         public JCExpression getRightOperand() { return rhs; }
  1684         public Symbol getOperator() {
  1685             return operator;
  1687         @Override
  1688         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1689             return v.visitBinary(this, d);
  1691         @Override
  1692         public Tag getTag() {
  1693             return opcode;
  1697     /**
  1698      * A type cast.
  1699      */
  1700     public static class JCTypeCast extends JCExpression implements TypeCastTree {
  1701         public JCTree clazz;
  1702         public JCExpression expr;
  1703         protected JCTypeCast(JCTree clazz, JCExpression expr) {
  1704             this.clazz = clazz;
  1705             this.expr = expr;
  1707         @Override
  1708         public void accept(Visitor v) { v.visitTypeCast(this); }
  1710         public Kind getKind() { return Kind.TYPE_CAST; }
  1711         public JCTree getType() { return clazz; }
  1712         public JCExpression getExpression() { return expr; }
  1713         @Override
  1714         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1715             return v.visitTypeCast(this, d);
  1717         @Override
  1718         public Tag getTag() {
  1719             return TYPECAST;
  1723     /**
  1724      * A type test.
  1725      */
  1726     public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
  1727         public JCExpression expr;
  1728         public JCTree clazz;
  1729         protected JCInstanceOf(JCExpression expr, JCTree clazz) {
  1730             this.expr = expr;
  1731             this.clazz = clazz;
  1733         @Override
  1734         public void accept(Visitor v) { v.visitTypeTest(this); }
  1736         public Kind getKind() { return Kind.INSTANCE_OF; }
  1737         public JCTree getType() { return clazz; }
  1738         public JCExpression getExpression() { return expr; }
  1739         @Override
  1740         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1741             return v.visitInstanceOf(this, d);
  1743         @Override
  1744         public Tag getTag() {
  1745             return TYPETEST;
  1749     /**
  1750      * An array selection
  1751      */
  1752     public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
  1753         public JCExpression indexed;
  1754         public JCExpression index;
  1755         protected JCArrayAccess(JCExpression indexed, JCExpression index) {
  1756             this.indexed = indexed;
  1757             this.index = index;
  1759         @Override
  1760         public void accept(Visitor v) { v.visitIndexed(this); }
  1762         public Kind getKind() { return Kind.ARRAY_ACCESS; }
  1763         public JCExpression getExpression() { return indexed; }
  1764         public JCExpression getIndex() { return index; }
  1765         @Override
  1766         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1767             return v.visitArrayAccess(this, d);
  1769         @Override
  1770         public Tag getTag() {
  1771             return INDEXED;
  1775     /**
  1776      * Selects through packages and classes
  1777      */
  1778     public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
  1779         /** selected Tree hierarchy */
  1780         public JCExpression selected;
  1781         /** name of field to select thru */
  1782         public Name name;
  1783         /** symbol of the selected class */
  1784         public Symbol sym;
  1785         protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
  1786             this.selected = selected;
  1787             this.name = name;
  1788             this.sym = sym;
  1790         @Override
  1791         public void accept(Visitor v) { v.visitSelect(this); }
  1793         public Kind getKind() { return Kind.MEMBER_SELECT; }
  1794         public JCExpression getExpression() { return selected; }
  1795         @Override
  1796         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1797             return v.visitMemberSelect(this, d);
  1799         public Name getIdentifier() { return name; }
  1800         @Override
  1801         public Tag getTag() {
  1802             return SELECT;
  1806     /**
  1807      * Selects a member expression.
  1808      */
  1809     public static class JCMemberReference extends JCExpression implements MemberReferenceTree {
  1810         public ReferenceMode mode;
  1811         public ReferenceKind kind;
  1812         public Name name;
  1813         public JCExpression expr;
  1814         public List<JCExpression> typeargs;
  1815         public Type targetType;
  1816         public Symbol sym;
  1817         public Type varargsElement;
  1819         /**
  1820          * Javac-dependent classification for member references, based
  1821          * on relevant properties w.r.t. code-generation
  1822          */
  1823         public enum ReferenceKind {
  1824             /** super # instMethod */
  1825             SUPER(ReferenceMode.INVOKE, false),
  1826             /** Type # instMethod */
  1827             UNBOUND(ReferenceMode.INVOKE, true),
  1828             /** Type # staticMethod */
  1829             STATIC(ReferenceMode.INVOKE, false),
  1830             /** Expr # instMethod */
  1831             BOUND(ReferenceMode.INVOKE, false),
  1832             /** Inner # new */
  1833             IMPLICIT_INNER(ReferenceMode.NEW, false),
  1834             /** Toplevel # new */
  1835             TOPLEVEL(ReferenceMode.NEW, false);
  1837             ReferenceMode mode;
  1838             boolean unbound;
  1840             private ReferenceKind(ReferenceMode mode, boolean unbound) {
  1841                 this.mode = mode;
  1842                 this.unbound = unbound;
  1845             public boolean isUnbound() {
  1846                 return unbound;
  1850         protected JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
  1851             this.mode = mode;
  1852             this.name = name;
  1853             this.expr = expr;
  1854             this.typeargs = typeargs;
  1856         @Override
  1857         public void accept(Visitor v) { v.visitReference(this); }
  1859         public Kind getKind() { return Kind.MEMBER_REFERENCE; }
  1860         @Override
  1861         public ReferenceMode getMode() { return mode; }
  1862         @Override
  1863         public JCExpression getQualifierExpression() { return expr; }
  1864         @Override
  1865         public Name getName() { return name; }
  1866         @Override
  1867         public List<JCExpression> getTypeArguments() { return typeargs; }
  1869         @Override
  1870         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1871             return v.visitMemberReference(this, d);
  1873         @Override
  1874         public Tag getTag() {
  1875             return REFERENCE;
  1877         public boolean hasKind(ReferenceKind kind) {
  1878             return this.kind == kind;
  1882     /**
  1883      * An identifier
  1884      */
  1885     public static class JCIdent extends JCExpression implements IdentifierTree {
  1886         /** the name */
  1887         public Name name;
  1888         /** the symbol */
  1889         public Symbol sym;
  1890         protected JCIdent(Name name, Symbol sym) {
  1891             this.name = name;
  1892             this.sym = sym;
  1894         @Override
  1895         public void accept(Visitor v) { v.visitIdent(this); }
  1897         public Kind getKind() { return Kind.IDENTIFIER; }
  1898         public Name getName() { return name; }
  1899         @Override
  1900         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1901             return v.visitIdentifier(this, d);
  1903         @Override
  1904         public Tag getTag() {
  1905             return IDENT;
  1909     /**
  1910      * A constant value given literally.
  1911      */
  1912     public static class JCLiteral extends JCExpression implements LiteralTree {
  1913         public TypeTag typetag;
  1914         /** value representation */
  1915         public Object value;
  1916         protected JCLiteral(TypeTag typetag, Object value) {
  1917             this.typetag = typetag;
  1918             this.value = value;
  1920         @Override
  1921         public void accept(Visitor v) { v.visitLiteral(this); }
  1923         public Kind getKind() {
  1924             return typetag.getKindLiteral();
  1927         public Object getValue() {
  1928             switch (typetag) {
  1929                 case BOOLEAN:
  1930                     int bi = (Integer) value;
  1931                     return (bi != 0);
  1932                 case CHAR:
  1933                     int ci = (Integer) value;
  1934                     char c = (char) ci;
  1935                     if (c != ci)
  1936                         throw new AssertionError("bad value for char literal");
  1937                     return c;
  1938                 default:
  1939                     return value;
  1942         @Override
  1943         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1944             return v.visitLiteral(this, d);
  1946         @Override
  1947         public JCLiteral setType(Type type) {
  1948             super.setType(type);
  1949             return this;
  1951         @Override
  1952         public Tag getTag() {
  1953             return LITERAL;
  1957     /**
  1958      * Identifies a basic type.
  1959      * @see TypeTag
  1960      */
  1961     public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
  1962         /** the basic type id */
  1963         public TypeTag typetag;
  1964         protected JCPrimitiveTypeTree(TypeTag typetag) {
  1965             this.typetag = typetag;
  1967         @Override
  1968         public void accept(Visitor v) { v.visitTypeIdent(this); }
  1970         public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
  1971         public TypeKind getPrimitiveTypeKind() {
  1972             return typetag.getPrimitiveTypeKind();
  1975         @Override
  1976         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1977             return v.visitPrimitiveType(this, d);
  1979         @Override
  1980         public Tag getTag() {
  1981             return TYPEIDENT;
  1985     /**
  1986      * An array type, A[]
  1987      */
  1988     public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
  1989         public JCExpression elemtype;
  1990         protected JCArrayTypeTree(JCExpression elemtype) {
  1991             this.elemtype = elemtype;
  1993         @Override
  1994         public void accept(Visitor v) { v.visitTypeArray(this); }
  1996         public Kind getKind() { return Kind.ARRAY_TYPE; }
  1997         public JCTree getType() { return elemtype; }
  1998         @Override
  1999         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2000             return v.visitArrayType(this, d);
  2002         @Override
  2003         public Tag getTag() {
  2004             return TYPEARRAY;
  2008     /**
  2009      * A parameterized type, {@literal T<...>}
  2010      */
  2011     public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
  2012         public JCExpression clazz;
  2013         public List<JCExpression> arguments;
  2014         protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
  2015             this.clazz = clazz;
  2016             this.arguments = arguments;
  2018         @Override
  2019         public void accept(Visitor v) { v.visitTypeApply(this); }
  2021         public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
  2022         public JCTree getType() { return clazz; }
  2023         public List<JCExpression> getTypeArguments() {
  2024             return arguments;
  2026         @Override
  2027         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2028             return v.visitParameterizedType(this, d);
  2030         @Override
  2031         public Tag getTag() {
  2032             return TYPEAPPLY;
  2036     /**
  2037      * A union type, T1 | T2 | ... Tn (used in multicatch statements)
  2038      */
  2039     public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
  2041         public List<JCExpression> alternatives;
  2043         protected JCTypeUnion(List<JCExpression> components) {
  2044             this.alternatives = components;
  2046         @Override
  2047         public void accept(Visitor v) { v.visitTypeUnion(this); }
  2049         public Kind getKind() { return Kind.UNION_TYPE; }
  2051         public List<JCExpression> getTypeAlternatives() {
  2052             return alternatives;
  2054         @Override
  2055         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2056             return v.visitUnionType(this, d);
  2058         @Override
  2059         public Tag getTag() {
  2060             return TYPEUNION;
  2064     /**
  2065      * A formal class parameter.
  2066      */
  2067     public static class JCTypeParameter extends JCTree implements TypeParameterTree {
  2068         /** name */
  2069         public Name name;
  2070         /** bounds */
  2071         public List<JCExpression> bounds;
  2072         protected JCTypeParameter(Name name, List<JCExpression> bounds) {
  2073             this.name = name;
  2074             this.bounds = bounds;
  2076         @Override
  2077         public void accept(Visitor v) { v.visitTypeParameter(this); }
  2079         public Kind getKind() { return Kind.TYPE_PARAMETER; }
  2080         public Name getName() { return name; }
  2081         public List<JCExpression> getBounds() {
  2082             return bounds;
  2084         @Override
  2085         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2086             return v.visitTypeParameter(this, d);
  2088         @Override
  2089         public Tag getTag() {
  2090             return TYPEPARAMETER;
  2094     public static class JCWildcard extends JCExpression implements WildcardTree {
  2095         public TypeBoundKind kind;
  2096         public JCTree inner;
  2097         protected JCWildcard(TypeBoundKind kind, JCTree inner) {
  2098             kind.getClass(); // null-check
  2099             this.kind = kind;
  2100             this.inner = inner;
  2102         @Override
  2103         public void accept(Visitor v) { v.visitWildcard(this); }
  2105         public Kind getKind() {
  2106             switch (kind.kind) {
  2107             case UNBOUND:
  2108                 return Kind.UNBOUNDED_WILDCARD;
  2109             case EXTENDS:
  2110                 return Kind.EXTENDS_WILDCARD;
  2111             case SUPER:
  2112                 return Kind.SUPER_WILDCARD;
  2113             default:
  2114                 throw new AssertionError("Unknown wildcard bound " + kind);
  2117         public JCTree getBound() { return inner; }
  2118         @Override
  2119         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2120             return v.visitWildcard(this, d);
  2122         @Override
  2123         public Tag getTag() {
  2124             return Tag.WILDCARD;
  2128     public static class TypeBoundKind extends JCTree {
  2129         public BoundKind kind;
  2130         protected TypeBoundKind(BoundKind kind) {
  2131             this.kind = kind;
  2133         @Override
  2134         public void accept(Visitor v) { v.visitTypeBoundKind(this); }
  2136         public Kind getKind() {
  2137             throw new AssertionError("TypeBoundKind is not part of a public API");
  2139         @Override
  2140         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2141             throw new AssertionError("TypeBoundKind is not part of a public API");
  2143         @Override
  2144         public Tag getTag() {
  2145             return TYPEBOUNDKIND;
  2149     public static class JCAnnotation extends JCExpression implements AnnotationTree {
  2150         public JCTree annotationType;
  2151         public List<JCExpression> args;
  2152         protected JCAnnotation(JCTree annotationType, List<JCExpression> args) {
  2153             this.annotationType = annotationType;
  2154             this.args = args;
  2156         @Override
  2157         public void accept(Visitor v) { v.visitAnnotation(this); }
  2159         public Kind getKind() { return Kind.ANNOTATION; }
  2160         public JCTree getAnnotationType() { return annotationType; }
  2161         public List<JCExpression> getArguments() {
  2162             return args;
  2164         @Override
  2165         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2166             return v.visitAnnotation(this, d);
  2168         @Override
  2169         public Tag getTag() {
  2170             return ANNOTATION;
  2174     public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
  2175         public long flags;
  2176         public List<JCAnnotation> annotations;
  2177         protected JCModifiers(long flags, List<JCAnnotation> annotations) {
  2178             this.flags = flags;
  2179             this.annotations = annotations;
  2181         @Override
  2182         public void accept(Visitor v) { v.visitModifiers(this); }
  2184         public Kind getKind() { return Kind.MODIFIERS; }
  2185         public Set<Modifier> getFlags() {
  2186             return Flags.asModifierSet(flags);
  2188         public List<JCAnnotation> getAnnotations() {
  2189             return annotations;
  2191         @Override
  2192         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2193             return v.visitModifiers(this, d);
  2195         @Override
  2196         public Tag getTag() {
  2197             return MODIFIERS;
  2201     public static class JCErroneous extends JCExpression
  2202             implements com.sun.source.tree.ErroneousTree {
  2203         public List<? extends JCTree> errs;
  2204         protected JCErroneous(List<? extends JCTree> errs) {
  2205             this.errs = errs;
  2207         @Override
  2208         public void accept(Visitor v) { v.visitErroneous(this); }
  2210         public Kind getKind() { return Kind.ERRONEOUS; }
  2212         public List<? extends JCTree> getErrorTrees() {
  2213             return errs;
  2216         @Override
  2217         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2218             return v.visitErroneous(this, d);
  2220         @Override
  2221         public Tag getTag() {
  2222             return ERRONEOUS;
  2226     /** (let int x = 3; in x+2) */
  2227     public static class LetExpr extends JCExpression {
  2228         public List<JCVariableDecl> defs;
  2229         public JCTree expr;
  2230         protected LetExpr(List<JCVariableDecl> defs, JCTree expr) {
  2231             this.defs = defs;
  2232             this.expr = expr;
  2234         @Override
  2235         public void accept(Visitor v) { v.visitLetExpr(this); }
  2237         public Kind getKind() {
  2238             throw new AssertionError("LetExpr is not part of a public API");
  2240         @Override
  2241         public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  2242             throw new AssertionError("LetExpr is not part of a public API");
  2244         @Override
  2245         public Tag getTag() {
  2246             return LETEXPR;
  2250     /** An interface for tree factories
  2251      */
  2252     public interface Factory {
  2253         JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations,
  2254                                    JCExpression pid,
  2255                                    List<JCTree> defs);
  2256         JCImport Import(JCTree qualid, boolean staticImport);
  2257         JCClassDecl ClassDef(JCModifiers mods,
  2258                           Name name,
  2259                           List<JCTypeParameter> typarams,
  2260                           JCExpression extending,
  2261                           List<JCExpression> implementing,
  2262                           List<JCTree> defs);
  2263         JCMethodDecl MethodDef(JCModifiers mods,
  2264                             Name name,
  2265                             JCExpression restype,
  2266                             List<JCTypeParameter> typarams,
  2267                             List<JCVariableDecl> params,
  2268                             List<JCExpression> thrown,
  2269                             JCBlock body,
  2270                             JCExpression defaultValue);
  2271         JCVariableDecl VarDef(JCModifiers mods,
  2272                       Name name,
  2273                       JCExpression vartype,
  2274                       JCExpression init);
  2275         JCSkip Skip();
  2276         JCBlock Block(long flags, List<JCStatement> stats);
  2277         JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
  2278         JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
  2279         JCForLoop ForLoop(List<JCStatement> init,
  2280                         JCExpression cond,
  2281                         List<JCExpressionStatement> step,
  2282                         JCStatement body);
  2283         JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
  2284         JCLabeledStatement Labelled(Name label, JCStatement body);
  2285         JCSwitch Switch(JCExpression selector, List<JCCase> cases);
  2286         JCCase Case(JCExpression pat, List<JCStatement> stats);
  2287         JCSynchronized Synchronized(JCExpression lock, JCBlock body);
  2288         JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
  2289         JCTry Try(List<JCTree> resources,
  2290                   JCBlock body,
  2291                   List<JCCatch> catchers,
  2292                   JCBlock finalizer);
  2293         JCCatch Catch(JCVariableDecl param, JCBlock body);
  2294         JCConditional Conditional(JCExpression cond,
  2295                                 JCExpression thenpart,
  2296                                 JCExpression elsepart);
  2297         JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
  2298         JCExpressionStatement Exec(JCExpression expr);
  2299         JCBreak Break(Name label);
  2300         JCContinue Continue(Name label);
  2301         JCReturn Return(JCExpression expr);
  2302         JCThrow Throw(JCTree expr);
  2303         JCAssert Assert(JCExpression cond, JCExpression detail);
  2304         JCMethodInvocation Apply(List<JCExpression> typeargs,
  2305                     JCExpression fn,
  2306                     List<JCExpression> args);
  2307         JCNewClass NewClass(JCExpression encl,
  2308                           List<JCExpression> typeargs,
  2309                           JCExpression clazz,
  2310                           List<JCExpression> args,
  2311                           JCClassDecl def);
  2312         JCNewArray NewArray(JCExpression elemtype,
  2313                           List<JCExpression> dims,
  2314                           List<JCExpression> elems);
  2315         JCParens Parens(JCExpression expr);
  2316         JCAssign Assign(JCExpression lhs, JCExpression rhs);
  2317         JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
  2318         JCUnary Unary(Tag opcode, JCExpression arg);
  2319         JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
  2320         JCTypeCast TypeCast(JCTree expr, JCExpression type);
  2321         JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
  2322         JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
  2323         JCFieldAccess Select(JCExpression selected, Name selector);
  2324         JCIdent Ident(Name idname);
  2325         JCLiteral Literal(TypeTag tag, Object value);
  2326         JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
  2327         JCArrayTypeTree TypeArray(JCExpression elemtype);
  2328         JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
  2329         JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
  2330         JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
  2331         TypeBoundKind TypeBoundKind(BoundKind kind);
  2332         JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
  2333         JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
  2334         JCErroneous Erroneous(List<? extends JCTree> errs);
  2335         LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr);
  2338     /** A generic visitor class for trees.
  2339      */
  2340     public static abstract class Visitor {
  2341         public void visitTopLevel(JCCompilationUnit that)    { visitTree(that); }
  2342         public void visitImport(JCImport that)               { visitTree(that); }
  2343         public void visitClassDef(JCClassDecl that)          { visitTree(that); }
  2344         public void visitMethodDef(JCMethodDecl that)        { visitTree(that); }
  2345         public void visitVarDef(JCVariableDecl that)         { visitTree(that); }
  2346         public void visitSkip(JCSkip that)                   { visitTree(that); }
  2347         public void visitBlock(JCBlock that)                 { visitTree(that); }
  2348         public void visitDoLoop(JCDoWhileLoop that)          { visitTree(that); }
  2349         public void visitWhileLoop(JCWhileLoop that)         { visitTree(that); }
  2350         public void visitForLoop(JCForLoop that)             { visitTree(that); }
  2351         public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
  2352         public void visitLabelled(JCLabeledStatement that)   { visitTree(that); }
  2353         public void visitSwitch(JCSwitch that)               { visitTree(that); }
  2354         public void visitCase(JCCase that)                   { visitTree(that); }
  2355         public void visitSynchronized(JCSynchronized that)   { visitTree(that); }
  2356         public void visitTry(JCTry that)                     { visitTree(that); }
  2357         public void visitCatch(JCCatch that)                 { visitTree(that); }
  2358         public void visitConditional(JCConditional that)     { visitTree(that); }
  2359         public void visitIf(JCIf that)                       { visitTree(that); }
  2360         public void visitExec(JCExpressionStatement that)    { visitTree(that); }
  2361         public void visitBreak(JCBreak that)                 { visitTree(that); }
  2362         public void visitContinue(JCContinue that)           { visitTree(that); }
  2363         public void visitReturn(JCReturn that)               { visitTree(that); }
  2364         public void visitThrow(JCThrow that)                 { visitTree(that); }
  2365         public void visitAssert(JCAssert that)               { visitTree(that); }
  2366         public void visitApply(JCMethodInvocation that)      { visitTree(that); }
  2367         public void visitNewClass(JCNewClass that)           { visitTree(that); }
  2368         public void visitNewArray(JCNewArray that)           { visitTree(that); }
  2369         public void visitLambda(JCLambda that)               { visitTree(that); }
  2370         public void visitParens(JCParens that)               { visitTree(that); }
  2371         public void visitAssign(JCAssign that)               { visitTree(that); }
  2372         public void visitAssignop(JCAssignOp that)           { visitTree(that); }
  2373         public void visitUnary(JCUnary that)                 { visitTree(that); }
  2374         public void visitBinary(JCBinary that)               { visitTree(that); }
  2375         public void visitTypeCast(JCTypeCast that)           { visitTree(that); }
  2376         public void visitTypeTest(JCInstanceOf that)         { visitTree(that); }
  2377         public void visitIndexed(JCArrayAccess that)         { visitTree(that); }
  2378         public void visitSelect(JCFieldAccess that)          { visitTree(that); }
  2379         public void visitReference(JCMemberReference that)   { visitTree(that); }
  2380         public void visitIdent(JCIdent that)                 { visitTree(that); }
  2381         public void visitLiteral(JCLiteral that)             { visitTree(that); }
  2382         public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
  2383         public void visitTypeArray(JCArrayTypeTree that)     { visitTree(that); }
  2384         public void visitTypeApply(JCTypeApply that)         { visitTree(that); }
  2385         public void visitTypeUnion(JCTypeUnion that)         { visitTree(that); }
  2386         public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
  2387         public void visitWildcard(JCWildcard that)           { visitTree(that); }
  2388         public void visitTypeBoundKind(TypeBoundKind that)   { visitTree(that); }
  2389         public void visitAnnotation(JCAnnotation that)       { visitTree(that); }
  2390         public void visitModifiers(JCModifiers that)         { visitTree(that); }
  2391         public void visitErroneous(JCErroneous that)         { visitTree(that); }
  2392         public void visitLetExpr(LetExpr that)               { visitTree(that); }
  2394         public void visitTree(JCTree that)                   { Assert.error(); }

mercurial