Mon, 21 Jan 2013 20:13:56 +0000
8005244: Implement overload resolution as per latest spec EDR
Summary: Add support for stuck expressions and provisional applicability
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 /** 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: Modifiers
278 */
279 MODIFIERS,
281 ANNOTATED_TYPE,
283 /** Error trees, of type Erroneous.
284 */
285 ERRONEOUS,
287 /** Unary operators, of type Unary.
288 */
289 POS, // +
290 NEG, // -
291 NOT, // !
292 COMPL, // ~
293 PREINC, // ++ _
294 PREDEC, // -- _
295 POSTINC, // _ ++
296 POSTDEC, // _ --
298 /** unary operator for null reference checks, only used internally.
299 */
300 NULLCHK,
302 /** Binary operators, of type Binary.
303 */
304 OR, // ||
305 AND, // &&
306 BITOR, // |
307 BITXOR, // ^
308 BITAND, // &
309 EQ, // ==
310 NE, // !=
311 LT, // <
312 GT, // >
313 LE, // <=
314 GE, // >=
315 SL, // <<
316 SR, // >>
317 USR, // >>>
318 PLUS, // +
319 MINUS, // -
320 MUL, // *
321 DIV, // /
322 MOD, // %
324 /** Assignment operators, of type Assignop.
325 */
326 BITOR_ASG(BITOR), // |=
327 BITXOR_ASG(BITXOR), // ^=
328 BITAND_ASG(BITAND), // &=
330 SL_ASG(SL), // <<=
331 SR_ASG(SR), // >>=
332 USR_ASG(USR), // >>>=
333 PLUS_ASG(PLUS), // +=
334 MINUS_ASG(MINUS), // -=
335 MUL_ASG(MUL), // *=
336 DIV_ASG(DIV), // /=
337 MOD_ASG(MOD), // %=
339 /** A synthetic let expression, of type LetExpr.
340 */
341 LETEXPR; // ala scheme
343 private final Tag noAssignTag;
345 private static final int numberOfOperators = MOD.ordinal() - POS.ordinal() + 1;
347 private Tag(Tag noAssignTag) {
348 this.noAssignTag = noAssignTag;
349 }
351 private Tag() {
352 this(null);
353 }
355 public static int getNumberOfOperators() {
356 return numberOfOperators;
357 }
359 public Tag noAssignOp() {
360 if (noAssignTag != null)
361 return noAssignTag;
362 throw new AssertionError("noAssignOp() method is not available for non assignment tags");
363 }
365 public boolean isPostUnaryOp() {
366 return (this == POSTINC || this == POSTDEC);
367 }
369 public boolean isIncOrDecUnaryOp() {
370 return (this == PREINC || this == PREDEC || this == POSTINC || this == POSTDEC);
371 }
373 public boolean isAssignop() {
374 return noAssignTag != null;
375 }
377 public int operatorIndex() {
378 return (this.ordinal() - POS.ordinal());
379 }
380 }
382 /* The (encoded) position in the source file. @see util.Position.
383 */
384 public int pos;
386 /* The type of this node.
387 */
388 public Type type;
390 /* The tag of this node -- one of the constants declared above.
391 */
392 public abstract Tag getTag();
394 /* Returns true if the tag of this node is equals to tag.
395 */
396 public boolean hasTag(Tag tag) {
397 return tag == getTag();
398 }
400 /** Convert a tree to a pretty-printed string. */
401 @Override
402 public String toString() {
403 StringWriter s = new StringWriter();
404 try {
405 new Pretty(s, false).printExpr(this);
406 }
407 catch (IOException e) {
408 // should never happen, because StringWriter is defined
409 // never to throw any IOExceptions
410 throw new AssertionError(e);
411 }
412 return s.toString();
413 }
415 /** Set position field and return this tree.
416 */
417 public JCTree setPos(int pos) {
418 this.pos = pos;
419 return this;
420 }
422 /** Set type field and return this tree.
423 */
424 public JCTree setType(Type type) {
425 this.type = type;
426 return this;
427 }
429 /** Visit this tree with a given visitor.
430 */
431 public abstract void accept(Visitor v);
433 public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);
435 /** Return a shallow copy of this tree.
436 */
437 @Override
438 public Object clone() {
439 try {
440 return super.clone();
441 } catch(CloneNotSupportedException e) {
442 throw new RuntimeException(e);
443 }
444 }
446 /** Get a default position for this tree node.
447 */
448 public DiagnosticPosition pos() {
449 return this;
450 }
452 // for default DiagnosticPosition
453 public JCTree getTree() {
454 return this;
455 }
457 // for default DiagnosticPosition
458 public int getStartPosition() {
459 return TreeInfo.getStartPos(this);
460 }
462 // for default DiagnosticPosition
463 public int getPreferredPosition() {
464 return pos;
465 }
467 // for default DiagnosticPosition
468 public int getEndPosition(EndPosTable endPosTable) {
469 return TreeInfo.getEndPos(this, endPosTable);
470 }
472 /**
473 * Everything in one source file is kept in a {@linkplain JCCompilationUnit} structure.
474 */
475 public static class JCCompilationUnit extends JCTree implements CompilationUnitTree {
476 public List<JCAnnotation> packageAnnotations;
477 /** The tree representing the package clause. */
478 public JCExpression pid;
479 /** All definitions in this file (ClassDef, Import, and Skip) */
480 public List<JCTree> defs;
481 /* The source file name. */
482 public JavaFileObject sourcefile;
483 /** The package to which this compilation unit belongs. */
484 public PackageSymbol packge;
485 /** A scope for all named imports. */
486 public ImportScope namedImportScope;
487 /** A scope for all import-on-demands. */
488 public StarImportScope starImportScope;
489 /** Line starting positions, defined only if option -g is set. */
490 public Position.LineMap lineMap = null;
491 /** A table that stores all documentation comments indexed by the tree
492 * nodes they refer to. defined only if option -s is set. */
493 public DocCommentTable docComments = null;
494 /* An object encapsulating ending positions of source ranges indexed by
495 * the tree nodes they belong to. Defined only if option -Xjcov is set. */
496 public EndPosTable endPositions = null;
497 protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,
498 JCExpression pid,
499 List<JCTree> defs,
500 JavaFileObject sourcefile,
501 PackageSymbol packge,
502 ImportScope namedImportScope,
503 StarImportScope starImportScope) {
504 this.packageAnnotations = packageAnnotations;
505 this.pid = pid;
506 this.defs = defs;
507 this.sourcefile = sourcefile;
508 this.packge = packge;
509 this.namedImportScope = namedImportScope;
510 this.starImportScope = starImportScope;
511 }
512 @Override
513 public void accept(Visitor v) { v.visitTopLevel(this); }
515 public Kind getKind() { return Kind.COMPILATION_UNIT; }
516 public List<JCAnnotation> getPackageAnnotations() {
517 return packageAnnotations;
518 }
519 public List<JCImport> getImports() {
520 ListBuffer<JCImport> imports = new ListBuffer<JCImport>();
521 for (JCTree tree : defs) {
522 if (tree.hasTag(IMPORT))
523 imports.append((JCImport)tree);
524 else if (!tree.hasTag(SKIP))
525 break;
526 }
527 return imports.toList();
528 }
529 public JCExpression getPackageName() { return pid; }
530 public JavaFileObject getSourceFile() {
531 return sourcefile;
532 }
533 public Position.LineMap getLineMap() {
534 return lineMap;
535 }
536 public List<JCTree> getTypeDecls() {
537 List<JCTree> typeDefs;
538 for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)
539 if (!typeDefs.head.hasTag(IMPORT))
540 break;
541 return typeDefs;
542 }
543 @Override
544 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
545 return v.visitCompilationUnit(this, d);
546 }
548 @Override
549 public Tag getTag() {
550 return TOPLEVEL;
551 }
552 }
554 /**
555 * An import clause.
556 */
557 public static class JCImport extends JCTree implements ImportTree {
558 public boolean staticImport;
559 /** The imported class(es). */
560 public JCTree qualid;
561 protected JCImport(JCTree qualid, boolean importStatic) {
562 this.qualid = qualid;
563 this.staticImport = importStatic;
564 }
565 @Override
566 public void accept(Visitor v) { v.visitImport(this); }
568 public boolean isStatic() { return staticImport; }
569 public JCTree getQualifiedIdentifier() { return qualid; }
571 public Kind getKind() { return Kind.IMPORT; }
572 @Override
573 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
574 return v.visitImport(this, d);
575 }
577 @Override
578 public Tag getTag() {
579 return IMPORT;
580 }
581 }
583 public static abstract class JCStatement extends JCTree implements StatementTree {
584 @Override
585 public JCStatement setType(Type type) {
586 super.setType(type);
587 return this;
588 }
589 @Override
590 public JCStatement setPos(int pos) {
591 super.setPos(pos);
592 return this;
593 }
594 }
596 public static abstract class JCExpression extends JCTree implements ExpressionTree {
597 @Override
598 public JCExpression setType(Type type) {
599 super.setType(type);
600 return this;
601 }
602 @Override
603 public JCExpression setPos(int pos) {
604 super.setPos(pos);
605 return this;
606 }
607 }
609 /**
610 * Common supertype for all poly expression trees (lambda, method references,
611 * conditionals, method and constructor calls)
612 */
613 public static abstract class JCPolyExpression extends JCExpression {
615 /**
616 * A poly expression can only be truly 'poly' in certain contexts
617 */
618 public enum PolyKind {
619 /** poly expression to be treated as a standalone expression */
620 STANDALONE,
621 /** true poly expression */
622 POLY;
623 }
625 /** is this poly expression a 'true' poly expression? */
626 public PolyKind polyKind;
627 }
629 /**
630 * Common supertype for all functional expression trees (lambda and method references)
631 */
632 public static abstract class JCFunctionalExpression extends JCPolyExpression {
634 public JCFunctionalExpression() {
635 //a functional expression is always a 'true' poly
636 polyKind = PolyKind.POLY;
637 }
639 /** target descriptor inferred for this functional expression. */
640 public Type descriptorType;
641 /** list of target types inferred for this functional expression. */
642 public List<TypeSymbol> targets;
643 }
645 /**
646 * A class definition.
647 */
648 public static class JCClassDecl extends JCStatement implements ClassTree {
649 /** the modifiers */
650 public JCModifiers mods;
651 /** the name of the class */
652 public Name name;
653 /** formal class parameters */
654 public List<JCTypeParameter> typarams;
655 /** the classes this class extends */
656 public JCExpression extending;
657 /** the interfaces implemented by this class */
658 public List<JCExpression> implementing;
659 /** all variables and methods defined in this class */
660 public List<JCTree> defs;
661 /** the symbol */
662 public ClassSymbol sym;
663 protected JCClassDecl(JCModifiers mods,
664 Name name,
665 List<JCTypeParameter> typarams,
666 JCExpression extending,
667 List<JCExpression> implementing,
668 List<JCTree> defs,
669 ClassSymbol sym)
670 {
671 this.mods = mods;
672 this.name = name;
673 this.typarams = typarams;
674 this.extending = extending;
675 this.implementing = implementing;
676 this.defs = defs;
677 this.sym = sym;
678 }
679 @Override
680 public void accept(Visitor v) { v.visitClassDef(this); }
682 public Kind getKind() {
683 if ((mods.flags & Flags.ANNOTATION) != 0)
684 return Kind.ANNOTATION_TYPE;
685 else if ((mods.flags & Flags.INTERFACE) != 0)
686 return Kind.INTERFACE;
687 else if ((mods.flags & Flags.ENUM) != 0)
688 return Kind.ENUM;
689 else
690 return Kind.CLASS;
691 }
693 public JCModifiers getModifiers() { return mods; }
694 public Name getSimpleName() { return name; }
695 public List<JCTypeParameter> getTypeParameters() {
696 return typarams;
697 }
698 public JCTree getExtendsClause() { return extending; }
699 public List<JCExpression> getImplementsClause() {
700 return implementing;
701 }
702 public List<JCTree> getMembers() {
703 return defs;
704 }
705 @Override
706 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
707 return v.visitClass(this, d);
708 }
710 @Override
711 public Tag getTag() {
712 return CLASSDEF;
713 }
714 }
716 /**
717 * A method definition.
718 */
719 public static class JCMethodDecl extends JCTree implements MethodTree {
720 /** method modifiers */
721 public JCModifiers mods;
722 /** method name */
723 public Name name;
724 /** type of method return value */
725 public JCExpression restype;
726 /** type parameters */
727 public List<JCTypeParameter> typarams;
728 /** value parameters */
729 public List<JCVariableDecl> params;
730 /** exceptions thrown by this method */
731 public List<JCExpression> thrown;
732 /** statements in the method */
733 public JCBlock body;
734 /** default value, for annotation types */
735 public JCExpression defaultValue;
736 /** method symbol */
737 public MethodSymbol sym;
738 protected JCMethodDecl(JCModifiers mods,
739 Name name,
740 JCExpression restype,
741 List<JCTypeParameter> typarams,
742 List<JCVariableDecl> params,
743 List<JCExpression> thrown,
744 JCBlock body,
745 JCExpression defaultValue,
746 MethodSymbol sym)
747 {
748 this.mods = mods;
749 this.name = name;
750 this.restype = restype;
751 this.typarams = typarams;
752 this.params = params;
753 this.thrown = thrown;
754 this.body = body;
755 this.defaultValue = defaultValue;
756 this.sym = sym;
757 }
758 @Override
759 public void accept(Visitor v) { v.visitMethodDef(this); }
761 public Kind getKind() { return Kind.METHOD; }
762 public JCModifiers getModifiers() { return mods; }
763 public Name getName() { return name; }
764 public JCTree getReturnType() { return restype; }
765 public List<JCTypeParameter> getTypeParameters() {
766 return typarams;
767 }
768 public List<JCVariableDecl> getParameters() {
769 return params;
770 }
771 public List<JCExpression> getThrows() {
772 return thrown;
773 }
774 public JCBlock getBody() { return body; }
775 public JCTree getDefaultValue() { // for annotation types
776 return defaultValue;
777 }
778 @Override
779 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
780 return v.visitMethod(this, d);
781 }
783 @Override
784 public Tag getTag() {
785 return METHODDEF;
786 }
787 }
789 /**
790 * A variable definition.
791 */
792 public static class JCVariableDecl extends JCStatement implements VariableTree {
793 /** variable modifiers */
794 public JCModifiers mods;
795 /** variable name */
796 public Name name;
797 /** type of the variable */
798 public JCExpression vartype;
799 /** variable's initial value */
800 public JCExpression init;
801 /** symbol */
802 public VarSymbol sym;
803 protected JCVariableDecl(JCModifiers mods,
804 Name name,
805 JCExpression vartype,
806 JCExpression init,
807 VarSymbol sym) {
808 this.mods = mods;
809 this.name = name;
810 this.vartype = vartype;
811 this.init = init;
812 this.sym = sym;
813 }
814 @Override
815 public void accept(Visitor v) { v.visitVarDef(this); }
817 public Kind getKind() { return Kind.VARIABLE; }
818 public JCModifiers getModifiers() { return mods; }
819 public Name getName() { return name; }
820 public JCTree getType() { return vartype; }
821 public JCExpression getInitializer() {
822 return init;
823 }
824 @Override
825 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
826 return v.visitVariable(this, d);
827 }
829 @Override
830 public Tag getTag() {
831 return VARDEF;
832 }
833 }
835 /**
836 * A no-op statement ";".
837 */
838 public static class JCSkip extends JCStatement implements EmptyStatementTree {
839 protected JCSkip() {
840 }
841 @Override
842 public void accept(Visitor v) { v.visitSkip(this); }
844 public Kind getKind() { return Kind.EMPTY_STATEMENT; }
845 @Override
846 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
847 return v.visitEmptyStatement(this, d);
848 }
850 @Override
851 public Tag getTag() {
852 return SKIP;
853 }
854 }
856 /**
857 * A statement block.
858 */
859 public static class JCBlock extends JCStatement implements BlockTree {
860 /** flags */
861 public long flags;
862 /** statements */
863 public List<JCStatement> stats;
864 /** Position of closing brace, optional. */
865 public int endpos = Position.NOPOS;
866 protected JCBlock(long flags, List<JCStatement> stats) {
867 this.stats = stats;
868 this.flags = flags;
869 }
870 @Override
871 public void accept(Visitor v) { v.visitBlock(this); }
873 public Kind getKind() { return Kind.BLOCK; }
874 public List<JCStatement> getStatements() {
875 return stats;
876 }
877 public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
878 @Override
879 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
880 return v.visitBlock(this, d);
881 }
883 @Override
884 public Tag getTag() {
885 return BLOCK;
886 }
887 }
889 /**
890 * A do loop
891 */
892 public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
893 public JCStatement body;
894 public JCExpression cond;
895 protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
896 this.body = body;
897 this.cond = cond;
898 }
899 @Override
900 public void accept(Visitor v) { v.visitDoLoop(this); }
902 public Kind getKind() { return Kind.DO_WHILE_LOOP; }
903 public JCExpression getCondition() { return cond; }
904 public JCStatement getStatement() { return body; }
905 @Override
906 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
907 return v.visitDoWhileLoop(this, d);
908 }
910 @Override
911 public Tag getTag() {
912 return DOLOOP;
913 }
914 }
916 /**
917 * A while loop
918 */
919 public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
920 public JCExpression cond;
921 public JCStatement body;
922 protected JCWhileLoop(JCExpression cond, JCStatement body) {
923 this.cond = cond;
924 this.body = body;
925 }
926 @Override
927 public void accept(Visitor v) { v.visitWhileLoop(this); }
929 public Kind getKind() { return Kind.WHILE_LOOP; }
930 public JCExpression getCondition() { return cond; }
931 public JCStatement getStatement() { return body; }
932 @Override
933 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
934 return v.visitWhileLoop(this, d);
935 }
937 @Override
938 public Tag getTag() {
939 return WHILELOOP;
940 }
941 }
943 /**
944 * A for loop.
945 */
946 public static class JCForLoop extends JCStatement implements ForLoopTree {
947 public List<JCStatement> init;
948 public JCExpression cond;
949 public List<JCExpressionStatement> step;
950 public JCStatement body;
951 protected JCForLoop(List<JCStatement> init,
952 JCExpression cond,
953 List<JCExpressionStatement> update,
954 JCStatement body)
955 {
956 this.init = init;
957 this.cond = cond;
958 this.step = update;
959 this.body = body;
960 }
961 @Override
962 public void accept(Visitor v) { v.visitForLoop(this); }
964 public Kind getKind() { return Kind.FOR_LOOP; }
965 public JCExpression getCondition() { return cond; }
966 public JCStatement getStatement() { return body; }
967 public List<JCStatement> getInitializer() {
968 return init;
969 }
970 public List<JCExpressionStatement> getUpdate() {
971 return step;
972 }
973 @Override
974 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
975 return v.visitForLoop(this, d);
976 }
978 @Override
979 public Tag getTag() {
980 return FORLOOP;
981 }
982 }
984 /**
985 * The enhanced for loop.
986 */
987 public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
988 public JCVariableDecl var;
989 public JCExpression expr;
990 public JCStatement body;
991 protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
992 this.var = var;
993 this.expr = expr;
994 this.body = body;
995 }
996 @Override
997 public void accept(Visitor v) { v.visitForeachLoop(this); }
999 public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
1000 public JCVariableDecl getVariable() { return var; }
1001 public JCExpression getExpression() { return expr; }
1002 public JCStatement getStatement() { return body; }
1003 @Override
1004 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1005 return v.visitEnhancedForLoop(this, d);
1006 }
1007 @Override
1008 public Tag getTag() {
1009 return FOREACHLOOP;
1010 }
1011 }
1013 /**
1014 * A labelled expression or statement.
1015 */
1016 public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
1017 public Name label;
1018 public JCStatement body;
1019 protected JCLabeledStatement(Name label, JCStatement body) {
1020 this.label = label;
1021 this.body = body;
1022 }
1023 @Override
1024 public void accept(Visitor v) { v.visitLabelled(this); }
1025 public Kind getKind() { return Kind.LABELED_STATEMENT; }
1026 public Name getLabel() { return label; }
1027 public JCStatement getStatement() { return body; }
1028 @Override
1029 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1030 return v.visitLabeledStatement(this, d);
1031 }
1032 @Override
1033 public Tag getTag() {
1034 return LABELLED;
1035 }
1036 }
1038 /**
1039 * A "switch ( ) { }" construction.
1040 */
1041 public static class JCSwitch extends JCStatement implements SwitchTree {
1042 public JCExpression selector;
1043 public List<JCCase> cases;
1044 protected JCSwitch(JCExpression selector, List<JCCase> cases) {
1045 this.selector = selector;
1046 this.cases = cases;
1047 }
1048 @Override
1049 public void accept(Visitor v) { v.visitSwitch(this); }
1051 public Kind getKind() { return Kind.SWITCH; }
1052 public JCExpression getExpression() { return selector; }
1053 public List<JCCase> getCases() { return cases; }
1054 @Override
1055 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1056 return v.visitSwitch(this, d);
1057 }
1058 @Override
1059 public Tag getTag() {
1060 return SWITCH;
1061 }
1062 }
1064 /**
1065 * A "case :" of a switch.
1066 */
1067 public static class JCCase extends JCStatement implements CaseTree {
1068 public JCExpression pat;
1069 public List<JCStatement> stats;
1070 protected JCCase(JCExpression pat, List<JCStatement> stats) {
1071 this.pat = pat;
1072 this.stats = stats;
1073 }
1074 @Override
1075 public void accept(Visitor v) { v.visitCase(this); }
1077 public Kind getKind() { return Kind.CASE; }
1078 public JCExpression getExpression() { return pat; }
1079 public List<JCStatement> getStatements() { return stats; }
1080 @Override
1081 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1082 return v.visitCase(this, d);
1083 }
1084 @Override
1085 public Tag getTag() {
1086 return CASE;
1087 }
1088 }
1090 /**
1091 * A synchronized block.
1092 */
1093 public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1094 public JCExpression lock;
1095 public JCBlock body;
1096 protected JCSynchronized(JCExpression lock, JCBlock body) {
1097 this.lock = lock;
1098 this.body = body;
1099 }
1100 @Override
1101 public void accept(Visitor v) { v.visitSynchronized(this); }
1103 public Kind getKind() { return Kind.SYNCHRONIZED; }
1104 public JCExpression getExpression() { return lock; }
1105 public JCBlock getBlock() { return body; }
1106 @Override
1107 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1108 return v.visitSynchronized(this, d);
1109 }
1110 @Override
1111 public Tag getTag() {
1112 return SYNCHRONIZED;
1113 }
1114 }
1116 /**
1117 * A "try { } catch ( ) { } finally { }" block.
1118 */
1119 public static class JCTry extends JCStatement implements TryTree {
1120 public JCBlock body;
1121 public List<JCCatch> catchers;
1122 public JCBlock finalizer;
1123 public List<JCTree> resources;
1124 public boolean finallyCanCompleteNormally;
1125 protected JCTry(List<JCTree> resources,
1126 JCBlock body,
1127 List<JCCatch> catchers,
1128 JCBlock finalizer) {
1129 this.body = body;
1130 this.catchers = catchers;
1131 this.finalizer = finalizer;
1132 this.resources = resources;
1133 }
1134 @Override
1135 public void accept(Visitor v) { v.visitTry(this); }
1137 public Kind getKind() { return Kind.TRY; }
1138 public JCBlock getBlock() { return body; }
1139 public List<JCCatch> getCatches() {
1140 return catchers;
1141 }
1142 public JCBlock getFinallyBlock() { return finalizer; }
1143 @Override
1144 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1145 return v.visitTry(this, d);
1146 }
1147 @Override
1148 public List<? extends JCTree> getResources() {
1149 return resources;
1150 }
1151 @Override
1152 public Tag getTag() {
1153 return TRY;
1154 }
1155 }
1157 /**
1158 * A catch block.
1159 */
1160 public static class JCCatch extends JCTree implements CatchTree {
1161 public JCVariableDecl param;
1162 public JCBlock body;
1163 protected JCCatch(JCVariableDecl param, JCBlock body) {
1164 this.param = param;
1165 this.body = body;
1166 }
1167 @Override
1168 public void accept(Visitor v) { v.visitCatch(this); }
1170 public Kind getKind() { return Kind.CATCH; }
1171 public JCVariableDecl getParameter() { return param; }
1172 public JCBlock getBlock() { return body; }
1173 @Override
1174 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1175 return v.visitCatch(this, d);
1176 }
1177 @Override
1178 public Tag getTag() {
1179 return CATCH;
1180 }
1181 }
1183 /**
1184 * A ( ) ? ( ) : ( ) conditional expression
1185 */
1186 public static class JCConditional extends JCPolyExpression implements ConditionalExpressionTree {
1187 public JCExpression cond;
1188 public JCExpression truepart;
1189 public JCExpression falsepart;
1190 protected JCConditional(JCExpression cond,
1191 JCExpression truepart,
1192 JCExpression falsepart)
1193 {
1194 this.cond = cond;
1195 this.truepart = truepart;
1196 this.falsepart = falsepart;
1197 }
1198 @Override
1199 public void accept(Visitor v) { v.visitConditional(this); }
1201 public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
1202 public JCExpression getCondition() { return cond; }
1203 public JCExpression getTrueExpression() { return truepart; }
1204 public JCExpression getFalseExpression() { return falsepart; }
1205 @Override
1206 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1207 return v.visitConditionalExpression(this, d);
1208 }
1209 @Override
1210 public Tag getTag() {
1211 return CONDEXPR;
1212 }
1213 }
1215 /**
1216 * An "if ( ) { } else { }" block
1217 */
1218 public static class JCIf extends JCStatement implements IfTree {
1219 public JCExpression cond;
1220 public JCStatement thenpart;
1221 public JCStatement elsepart;
1222 protected JCIf(JCExpression cond,
1223 JCStatement thenpart,
1224 JCStatement elsepart)
1225 {
1226 this.cond = cond;
1227 this.thenpart = thenpart;
1228 this.elsepart = elsepart;
1229 }
1230 @Override
1231 public void accept(Visitor v) { v.visitIf(this); }
1233 public Kind getKind() { return Kind.IF; }
1234 public JCExpression getCondition() { return cond; }
1235 public JCStatement getThenStatement() { return thenpart; }
1236 public JCStatement getElseStatement() { return elsepart; }
1237 @Override
1238 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1239 return v.visitIf(this, d);
1240 }
1241 @Override
1242 public Tag getTag() {
1243 return IF;
1244 }
1245 }
1247 /**
1248 * an expression statement
1249 */
1250 public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
1251 /** expression structure */
1252 public JCExpression expr;
1253 protected JCExpressionStatement(JCExpression expr)
1254 {
1255 this.expr = expr;
1256 }
1257 @Override
1258 public void accept(Visitor v) { v.visitExec(this); }
1260 public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
1261 public JCExpression getExpression() { return expr; }
1262 @Override
1263 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1264 return v.visitExpressionStatement(this, d);
1265 }
1266 @Override
1267 public Tag getTag() {
1268 return EXEC;
1269 }
1271 /** Convert a expression-statement tree to a pretty-printed string. */
1272 @Override
1273 public String toString() {
1274 StringWriter s = new StringWriter();
1275 try {
1276 new Pretty(s, false).printStat(this);
1277 }
1278 catch (IOException e) {
1279 // should never happen, because StringWriter is defined
1280 // never to throw any IOExceptions
1281 throw new AssertionError(e);
1282 }
1283 return s.toString();
1284 }
1285 }
1287 /**
1288 * A break from a loop or switch.
1289 */
1290 public static class JCBreak extends JCStatement implements BreakTree {
1291 public Name label;
1292 public JCTree target;
1293 protected JCBreak(Name label, JCTree target) {
1294 this.label = label;
1295 this.target = target;
1296 }
1297 @Override
1298 public void accept(Visitor v) { v.visitBreak(this); }
1300 public Kind getKind() { return Kind.BREAK; }
1301 public Name getLabel() { return label; }
1302 @Override
1303 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1304 return v.visitBreak(this, d);
1305 }
1306 @Override
1307 public Tag getTag() {
1308 return BREAK;
1309 }
1310 }
1312 /**
1313 * A continue of a loop.
1314 */
1315 public static class JCContinue extends JCStatement implements ContinueTree {
1316 public Name label;
1317 public JCTree target;
1318 protected JCContinue(Name label, JCTree target) {
1319 this.label = label;
1320 this.target = target;
1321 }
1322 @Override
1323 public void accept(Visitor v) { v.visitContinue(this); }
1325 public Kind getKind() { return Kind.CONTINUE; }
1326 public Name getLabel() { return label; }
1327 @Override
1328 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1329 return v.visitContinue(this, d);
1330 }
1331 @Override
1332 public Tag getTag() {
1333 return CONTINUE;
1334 }
1335 }
1337 /**
1338 * A return statement.
1339 */
1340 public static class JCReturn extends JCStatement implements ReturnTree {
1341 public JCExpression expr;
1342 protected JCReturn(JCExpression expr) {
1343 this.expr = expr;
1344 }
1345 @Override
1346 public void accept(Visitor v) { v.visitReturn(this); }
1348 public Kind getKind() { return Kind.RETURN; }
1349 public JCExpression getExpression() { return expr; }
1350 @Override
1351 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1352 return v.visitReturn(this, d);
1353 }
1354 @Override
1355 public Tag getTag() {
1356 return RETURN;
1357 }
1358 }
1360 /**
1361 * A throw statement.
1362 */
1363 public static class JCThrow extends JCStatement implements ThrowTree {
1364 public JCExpression expr;
1365 protected JCThrow(JCTree expr) {
1366 this.expr = (JCExpression)expr;
1367 }
1368 @Override
1369 public void accept(Visitor v) { v.visitThrow(this); }
1371 public Kind getKind() { return Kind.THROW; }
1372 public JCExpression getExpression() { return expr; }
1373 @Override
1374 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1375 return v.visitThrow(this, d);
1376 }
1377 @Override
1378 public Tag getTag() {
1379 return THROW;
1380 }
1381 }
1383 /**
1384 * An assert statement.
1385 */
1386 public static class JCAssert extends JCStatement implements AssertTree {
1387 public JCExpression cond;
1388 public JCExpression detail;
1389 protected JCAssert(JCExpression cond, JCExpression detail) {
1390 this.cond = cond;
1391 this.detail = detail;
1392 }
1393 @Override
1394 public void accept(Visitor v) { v.visitAssert(this); }
1396 public Kind getKind() { return Kind.ASSERT; }
1397 public JCExpression getCondition() { return cond; }
1398 public JCExpression getDetail() { return detail; }
1399 @Override
1400 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1401 return v.visitAssert(this, d);
1402 }
1403 @Override
1404 public Tag getTag() {
1405 return ASSERT;
1406 }
1407 }
1409 /**
1410 * A method invocation
1411 */
1412 public static class JCMethodInvocation extends JCPolyExpression implements MethodInvocationTree {
1413 public List<JCExpression> typeargs;
1414 public JCExpression meth;
1415 public List<JCExpression> args;
1416 public Type varargsElement;
1417 protected JCMethodInvocation(List<JCExpression> typeargs,
1418 JCExpression meth,
1419 List<JCExpression> args)
1420 {
1421 this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
1422 : typeargs;
1423 this.meth = meth;
1424 this.args = args;
1425 }
1426 @Override
1427 public void accept(Visitor v) { v.visitApply(this); }
1429 public Kind getKind() { return Kind.METHOD_INVOCATION; }
1430 public List<JCExpression> getTypeArguments() {
1431 return typeargs;
1432 }
1433 public JCExpression getMethodSelect() { return meth; }
1434 public List<JCExpression> getArguments() {
1435 return args;
1436 }
1437 @Override
1438 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1439 return v.visitMethodInvocation(this, d);
1440 }
1441 @Override
1442 public JCMethodInvocation setType(Type type) {
1443 super.setType(type);
1444 return this;
1445 }
1446 @Override
1447 public Tag getTag() {
1448 return(APPLY);
1449 }
1450 }
1452 /**
1453 * A new(...) operation.
1454 */
1455 public static class JCNewClass extends JCPolyExpression implements NewClassTree {
1456 public JCExpression encl;
1457 public List<JCExpression> typeargs;
1458 public JCExpression clazz;
1459 public List<JCExpression> args;
1460 public JCClassDecl def;
1461 public Symbol constructor;
1462 public Type varargsElement;
1463 public Type constructorType;
1464 protected JCNewClass(JCExpression encl,
1465 List<JCExpression> typeargs,
1466 JCExpression clazz,
1467 List<JCExpression> args,
1468 JCClassDecl def)
1469 {
1470 this.encl = encl;
1471 this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
1472 : typeargs;
1473 this.clazz = clazz;
1474 this.args = args;
1475 this.def = def;
1476 }
1477 @Override
1478 public void accept(Visitor v) { v.visitNewClass(this); }
1480 public Kind getKind() { return Kind.NEW_CLASS; }
1481 public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
1482 return encl;
1483 }
1484 public List<JCExpression> getTypeArguments() {
1485 return typeargs;
1486 }
1487 public JCExpression getIdentifier() { return clazz; }
1488 public List<JCExpression> getArguments() {
1489 return args;
1490 }
1491 public JCClassDecl getClassBody() { return def; }
1492 @Override
1493 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1494 return v.visitNewClass(this, d);
1495 }
1496 @Override
1497 public Tag getTag() {
1498 return NEWCLASS;
1499 }
1500 }
1502 /**
1503 * A new[...] operation.
1504 */
1505 public static class JCNewArray extends JCExpression implements NewArrayTree {
1506 public JCExpression elemtype;
1507 public List<JCExpression> dims;
1508 public List<JCExpression> elems;
1509 protected JCNewArray(JCExpression elemtype,
1510 List<JCExpression> dims,
1511 List<JCExpression> elems)
1512 {
1513 this.elemtype = elemtype;
1514 this.dims = dims;
1515 this.elems = elems;
1516 }
1517 @Override
1518 public void accept(Visitor v) { v.visitNewArray(this); }
1520 public Kind getKind() { return Kind.NEW_ARRAY; }
1521 public JCExpression getType() { return elemtype; }
1522 public List<JCExpression> getDimensions() {
1523 return dims;
1524 }
1525 public List<JCExpression> getInitializers() {
1526 return elems;
1527 }
1528 @Override
1529 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1530 return v.visitNewArray(this, d);
1531 }
1532 @Override
1533 public Tag getTag() {
1534 return NEWARRAY;
1535 }
1536 }
1538 /**
1539 * A lambda expression.
1540 */
1541 public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree {
1543 public enum ParameterKind {
1544 IMPLICIT,
1545 EXPLICIT;
1546 }
1548 public List<JCVariableDecl> params;
1549 public JCTree body;
1550 public boolean canCompleteNormally = true;
1551 public List<Type> inferredThrownTypes;
1552 public ParameterKind paramKind;
1554 public JCLambda(List<JCVariableDecl> params,
1555 JCTree body) {
1556 this.params = params;
1557 this.body = body;
1558 if (params.isEmpty() ||
1559 params.head.vartype != null) {
1560 paramKind = ParameterKind.EXPLICIT;
1561 } else {
1562 paramKind = ParameterKind.IMPLICIT;
1563 }
1564 }
1565 @Override
1566 public Tag getTag() {
1567 return LAMBDA;
1568 }
1569 @Override
1570 public void accept(Visitor v) {
1571 v.visitLambda(this);
1572 }
1573 @Override
1574 public <R, D> R accept(TreeVisitor<R, D> v, D d) {
1575 return v.visitLambdaExpression(this, d);
1576 }
1577 public Kind getKind() {
1578 return Kind.LAMBDA_EXPRESSION;
1579 }
1580 public JCTree getBody() {
1581 return body;
1582 }
1583 public java.util.List<? extends VariableTree> getParameters() {
1584 return params;
1585 }
1586 @Override
1587 public JCLambda setType(Type type) {
1588 super.setType(type);
1589 return this;
1590 }
1591 @Override
1592 public BodyKind getBodyKind() {
1593 return body.hasTag(BLOCK) ?
1594 BodyKind.STATEMENT :
1595 BodyKind.EXPRESSION;
1596 }
1597 }
1599 /**
1600 * A parenthesized subexpression ( ... )
1601 */
1602 public static class JCParens extends JCExpression implements ParenthesizedTree {
1603 public JCExpression expr;
1604 protected JCParens(JCExpression expr) {
1605 this.expr = expr;
1606 }
1607 @Override
1608 public void accept(Visitor v) { v.visitParens(this); }
1610 public Kind getKind() { return Kind.PARENTHESIZED; }
1611 public JCExpression getExpression() { return expr; }
1612 @Override
1613 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1614 return v.visitParenthesized(this, d);
1615 }
1616 @Override
1617 public Tag getTag() {
1618 return PARENS;
1619 }
1620 }
1622 /**
1623 * A assignment with "=".
1624 */
1625 public static class JCAssign extends JCExpression implements AssignmentTree {
1626 public JCExpression lhs;
1627 public JCExpression rhs;
1628 protected JCAssign(JCExpression lhs, JCExpression rhs) {
1629 this.lhs = lhs;
1630 this.rhs = rhs;
1631 }
1632 @Override
1633 public void accept(Visitor v) { v.visitAssign(this); }
1635 public Kind getKind() { return Kind.ASSIGNMENT; }
1636 public JCExpression getVariable() { return lhs; }
1637 public JCExpression getExpression() { return rhs; }
1638 @Override
1639 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1640 return v.visitAssignment(this, d);
1641 }
1642 @Override
1643 public Tag getTag() {
1644 return ASSIGN;
1645 }
1646 }
1648 /**
1649 * An assignment with "+=", "|=" ...
1650 */
1651 public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree {
1652 private Tag opcode;
1653 public JCExpression lhs;
1654 public JCExpression rhs;
1655 public Symbol operator;
1656 protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, Symbol operator) {
1657 this.opcode = opcode;
1658 this.lhs = (JCExpression)lhs;
1659 this.rhs = (JCExpression)rhs;
1660 this.operator = operator;
1661 }
1662 @Override
1663 public void accept(Visitor v) { v.visitAssignop(this); }
1665 public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1666 public JCExpression getVariable() { return lhs; }
1667 public JCExpression getExpression() { return rhs; }
1668 public Symbol getOperator() {
1669 return operator;
1670 }
1671 @Override
1672 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1673 return v.visitCompoundAssignment(this, d);
1674 }
1675 @Override
1676 public Tag getTag() {
1677 return opcode;
1678 }
1679 }
1681 /**
1682 * A unary operation.
1683 */
1684 public static class JCUnary extends JCExpression implements UnaryTree {
1685 private Tag opcode;
1686 public JCExpression arg;
1687 public Symbol operator;
1688 protected JCUnary(Tag opcode, JCExpression arg) {
1689 this.opcode = opcode;
1690 this.arg = arg;
1691 }
1692 @Override
1693 public void accept(Visitor v) { v.visitUnary(this); }
1695 public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1696 public JCExpression getExpression() { return arg; }
1697 public Symbol getOperator() {
1698 return operator;
1699 }
1700 @Override
1701 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1702 return v.visitUnary(this, d);
1703 }
1704 @Override
1705 public Tag getTag() {
1706 return opcode;
1707 }
1709 public void setTag(Tag tag) {
1710 opcode = tag;
1711 }
1712 }
1714 /**
1715 * A binary operation.
1716 */
1717 public static class JCBinary extends JCExpression implements BinaryTree {
1718 private Tag opcode;
1719 public JCExpression lhs;
1720 public JCExpression rhs;
1721 public Symbol operator;
1722 protected JCBinary(Tag opcode,
1723 JCExpression lhs,
1724 JCExpression rhs,
1725 Symbol operator) {
1726 this.opcode = opcode;
1727 this.lhs = lhs;
1728 this.rhs = rhs;
1729 this.operator = operator;
1730 }
1731 @Override
1732 public void accept(Visitor v) { v.visitBinary(this); }
1734 public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1735 public JCExpression getLeftOperand() { return lhs; }
1736 public JCExpression getRightOperand() { return rhs; }
1737 public Symbol getOperator() {
1738 return operator;
1739 }
1740 @Override
1741 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1742 return v.visitBinary(this, d);
1743 }
1744 @Override
1745 public Tag getTag() {
1746 return opcode;
1747 }
1748 }
1750 /**
1751 * A type cast.
1752 */
1753 public static class JCTypeCast extends JCExpression implements TypeCastTree {
1754 public JCTree clazz;
1755 public JCExpression expr;
1756 protected JCTypeCast(JCTree clazz, JCExpression expr) {
1757 this.clazz = clazz;
1758 this.expr = expr;
1759 }
1760 @Override
1761 public void accept(Visitor v) { v.visitTypeCast(this); }
1763 public Kind getKind() { return Kind.TYPE_CAST; }
1764 public JCTree getType() { return clazz; }
1765 public JCExpression getExpression() { return expr; }
1766 @Override
1767 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1768 return v.visitTypeCast(this, d);
1769 }
1770 @Override
1771 public Tag getTag() {
1772 return TYPECAST;
1773 }
1774 }
1776 /**
1777 * A type test.
1778 */
1779 public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
1780 public JCExpression expr;
1781 public JCTree clazz;
1782 protected JCInstanceOf(JCExpression expr, JCTree clazz) {
1783 this.expr = expr;
1784 this.clazz = clazz;
1785 }
1786 @Override
1787 public void accept(Visitor v) { v.visitTypeTest(this); }
1789 public Kind getKind() { return Kind.INSTANCE_OF; }
1790 public JCTree getType() { return clazz; }
1791 public JCExpression getExpression() { return expr; }
1792 @Override
1793 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1794 return v.visitInstanceOf(this, d);
1795 }
1796 @Override
1797 public Tag getTag() {
1798 return TYPETEST;
1799 }
1800 }
1802 /**
1803 * An array selection
1804 */
1805 public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
1806 public JCExpression indexed;
1807 public JCExpression index;
1808 protected JCArrayAccess(JCExpression indexed, JCExpression index) {
1809 this.indexed = indexed;
1810 this.index = index;
1811 }
1812 @Override
1813 public void accept(Visitor v) { v.visitIndexed(this); }
1815 public Kind getKind() { return Kind.ARRAY_ACCESS; }
1816 public JCExpression getExpression() { return indexed; }
1817 public JCExpression getIndex() { return index; }
1818 @Override
1819 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1820 return v.visitArrayAccess(this, d);
1821 }
1822 @Override
1823 public Tag getTag() {
1824 return INDEXED;
1825 }
1826 }
1828 /**
1829 * Selects through packages and classes
1830 */
1831 public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
1832 /** selected Tree hierarchy */
1833 public JCExpression selected;
1834 /** name of field to select thru */
1835 public Name name;
1836 /** symbol of the selected class */
1837 public Symbol sym;
1838 protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
1839 this.selected = selected;
1840 this.name = name;
1841 this.sym = sym;
1842 }
1843 @Override
1844 public void accept(Visitor v) { v.visitSelect(this); }
1846 public Kind getKind() { return Kind.MEMBER_SELECT; }
1847 public JCExpression getExpression() { return selected; }
1848 @Override
1849 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1850 return v.visitMemberSelect(this, d);
1851 }
1852 public Name getIdentifier() { return name; }
1853 @Override
1854 public Tag getTag() {
1855 return SELECT;
1856 }
1857 }
1859 /**
1860 * Selects a member expression.
1861 */
1862 public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree {
1863 public ReferenceMode mode;
1864 public ReferenceKind kind;
1865 public Name name;
1866 public JCExpression expr;
1867 public List<JCExpression> typeargs;
1868 public Symbol sym;
1869 public Type varargsElement;
1870 public PolyKind refPolyKind;
1872 /**
1873 * Javac-dependent classification for member references, based
1874 * on relevant properties w.r.t. code-generation
1875 */
1876 public enum ReferenceKind {
1877 /** super # instMethod */
1878 SUPER(ReferenceMode.INVOKE, false),
1879 /** Type # instMethod */
1880 UNBOUND(ReferenceMode.INVOKE, true),
1881 /** Type # staticMethod */
1882 STATIC(ReferenceMode.INVOKE, false),
1883 /** Expr # instMethod */
1884 BOUND(ReferenceMode.INVOKE, false),
1885 /** Inner # new */
1886 IMPLICIT_INNER(ReferenceMode.NEW, false),
1887 /** Toplevel # new */
1888 TOPLEVEL(ReferenceMode.NEW, false),
1889 /** ArrayType # new */
1890 ARRAY_CTOR(ReferenceMode.NEW, false);
1892 final ReferenceMode mode;
1893 final boolean unbound;
1895 private ReferenceKind(ReferenceMode mode, boolean unbound) {
1896 this.mode = mode;
1897 this.unbound = unbound;
1898 }
1900 public boolean isUnbound() {
1901 return unbound;
1902 }
1903 }
1905 protected JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) {
1906 this.mode = mode;
1907 this.name = name;
1908 this.expr = expr;
1909 this.typeargs = typeargs;
1910 }
1911 @Override
1912 public void accept(Visitor v) { v.visitReference(this); }
1914 public Kind getKind() { return Kind.MEMBER_REFERENCE; }
1915 @Override
1916 public ReferenceMode getMode() { return mode; }
1917 @Override
1918 public JCExpression getQualifierExpression() { return expr; }
1919 @Override
1920 public Name getName() { return name; }
1921 @Override
1922 public List<JCExpression> getTypeArguments() { return typeargs; }
1924 @Override
1925 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1926 return v.visitMemberReference(this, d);
1927 }
1928 @Override
1929 public Tag getTag() {
1930 return REFERENCE;
1931 }
1932 public boolean hasKind(ReferenceKind kind) {
1933 return this.kind == kind;
1934 }
1935 }
1937 /**
1938 * An identifier
1939 */
1940 public static class JCIdent extends JCExpression implements IdentifierTree {
1941 /** the name */
1942 public Name name;
1943 /** the symbol */
1944 public Symbol sym;
1945 protected JCIdent(Name name, Symbol sym) {
1946 this.name = name;
1947 this.sym = sym;
1948 }
1949 @Override
1950 public void accept(Visitor v) { v.visitIdent(this); }
1952 public Kind getKind() { return Kind.IDENTIFIER; }
1953 public Name getName() { return name; }
1954 @Override
1955 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1956 return v.visitIdentifier(this, d);
1957 }
1958 @Override
1959 public Tag getTag() {
1960 return IDENT;
1961 }
1962 }
1964 /**
1965 * A constant value given literally.
1966 */
1967 public static class JCLiteral extends JCExpression implements LiteralTree {
1968 public TypeTag typetag;
1969 /** value representation */
1970 public Object value;
1971 protected JCLiteral(TypeTag typetag, Object value) {
1972 this.typetag = typetag;
1973 this.value = value;
1974 }
1975 @Override
1976 public void accept(Visitor v) { v.visitLiteral(this); }
1978 public Kind getKind() {
1979 return typetag.getKindLiteral();
1980 }
1982 public Object getValue() {
1983 switch (typetag) {
1984 case BOOLEAN:
1985 int bi = (Integer) value;
1986 return (bi != 0);
1987 case CHAR:
1988 int ci = (Integer) value;
1989 char c = (char) ci;
1990 if (c != ci)
1991 throw new AssertionError("bad value for char literal");
1992 return c;
1993 default:
1994 return value;
1995 }
1996 }
1997 @Override
1998 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1999 return v.visitLiteral(this, d);
2000 }
2001 @Override
2002 public JCLiteral setType(Type type) {
2003 super.setType(type);
2004 return this;
2005 }
2006 @Override
2007 public Tag getTag() {
2008 return LITERAL;
2009 }
2010 }
2012 /**
2013 * Identifies a basic type.
2014 * @see TypeTag
2015 */
2016 public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
2017 /** the basic type id */
2018 public TypeTag typetag;
2019 protected JCPrimitiveTypeTree(TypeTag typetag) {
2020 this.typetag = typetag;
2021 }
2022 @Override
2023 public void accept(Visitor v) { v.visitTypeIdent(this); }
2025 public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
2026 public TypeKind getPrimitiveTypeKind() {
2027 return typetag.getPrimitiveTypeKind();
2028 }
2030 @Override
2031 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2032 return v.visitPrimitiveType(this, d);
2033 }
2034 @Override
2035 public Tag getTag() {
2036 return TYPEIDENT;
2037 }
2038 }
2040 /**
2041 * An array type, A[]
2042 */
2043 public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
2044 public JCExpression elemtype;
2045 protected JCArrayTypeTree(JCExpression elemtype) {
2046 this.elemtype = elemtype;
2047 }
2048 @Override
2049 public void accept(Visitor v) { v.visitTypeArray(this); }
2051 public Kind getKind() { return Kind.ARRAY_TYPE; }
2052 public JCTree getType() { return elemtype; }
2053 @Override
2054 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2055 return v.visitArrayType(this, d);
2056 }
2057 @Override
2058 public Tag getTag() {
2059 return TYPEARRAY;
2060 }
2061 }
2063 /**
2064 * A parameterized type, {@literal T<...>}
2065 */
2066 public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
2067 public JCExpression clazz;
2068 public List<JCExpression> arguments;
2069 protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
2070 this.clazz = clazz;
2071 this.arguments = arguments;
2072 }
2073 @Override
2074 public void accept(Visitor v) { v.visitTypeApply(this); }
2076 public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
2077 public JCTree getType() { return clazz; }
2078 public List<JCExpression> getTypeArguments() {
2079 return arguments;
2080 }
2081 @Override
2082 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2083 return v.visitParameterizedType(this, d);
2084 }
2085 @Override
2086 public Tag getTag() {
2087 return TYPEAPPLY;
2088 }
2089 }
2091 /**
2092 * A union type, T1 | T2 | ... Tn (used in multicatch statements)
2093 */
2094 public static class JCTypeUnion extends JCExpression implements UnionTypeTree {
2096 public List<JCExpression> alternatives;
2098 protected JCTypeUnion(List<JCExpression> components) {
2099 this.alternatives = components;
2100 }
2101 @Override
2102 public void accept(Visitor v) { v.visitTypeUnion(this); }
2104 public Kind getKind() { return Kind.UNION_TYPE; }
2106 public List<JCExpression> getTypeAlternatives() {
2107 return alternatives;
2108 }
2109 @Override
2110 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2111 return v.visitUnionType(this, d);
2112 }
2113 @Override
2114 public Tag getTag() {
2115 return TYPEUNION;
2116 }
2117 }
2119 /**
2120 * An intersection type, T1 & T2 & ... Tn (used in cast expressions)
2121 */
2122 public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree {
2124 public List<JCExpression> bounds;
2126 protected JCTypeIntersection(List<JCExpression> bounds) {
2127 this.bounds = bounds;
2128 }
2129 @Override
2130 public void accept(Visitor v) { v.visitTypeIntersection(this); }
2132 public Kind getKind() { return Kind.INTERSECTION_TYPE; }
2134 public List<JCExpression> getBounds() {
2135 return bounds;
2136 }
2137 @Override
2138 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2139 return v.visitIntersectionType(this, d);
2140 }
2141 @Override
2142 public Tag getTag() {
2143 return TYPEINTERSECTION;
2144 }
2145 }
2147 /**
2148 * A formal class parameter.
2149 */
2150 public static class JCTypeParameter extends JCTree implements TypeParameterTree {
2151 /** name */
2152 public Name name;
2153 /** bounds */
2154 public List<JCExpression> bounds;
2155 protected JCTypeParameter(Name name, List<JCExpression> bounds) {
2156 this.name = name;
2157 this.bounds = bounds;
2158 }
2159 @Override
2160 public void accept(Visitor v) { v.visitTypeParameter(this); }
2162 public Kind getKind() { return Kind.TYPE_PARAMETER; }
2163 public Name getName() { return name; }
2164 public List<JCExpression> getBounds() {
2165 return bounds;
2166 }
2167 @Override
2168 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2169 return v.visitTypeParameter(this, d);
2170 }
2171 @Override
2172 public Tag getTag() {
2173 return TYPEPARAMETER;
2174 }
2175 }
2177 public static class JCWildcard extends JCExpression implements WildcardTree {
2178 public TypeBoundKind kind;
2179 public JCTree inner;
2180 protected JCWildcard(TypeBoundKind kind, JCTree inner) {
2181 kind.getClass(); // null-check
2182 this.kind = kind;
2183 this.inner = inner;
2184 }
2185 @Override
2186 public void accept(Visitor v) { v.visitWildcard(this); }
2188 public Kind getKind() {
2189 switch (kind.kind) {
2190 case UNBOUND:
2191 return Kind.UNBOUNDED_WILDCARD;
2192 case EXTENDS:
2193 return Kind.EXTENDS_WILDCARD;
2194 case SUPER:
2195 return Kind.SUPER_WILDCARD;
2196 default:
2197 throw new AssertionError("Unknown wildcard bound " + kind);
2198 }
2199 }
2200 public JCTree getBound() { return inner; }
2201 @Override
2202 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2203 return v.visitWildcard(this, d);
2204 }
2205 @Override
2206 public Tag getTag() {
2207 return Tag.WILDCARD;
2208 }
2209 }
2211 public static class TypeBoundKind extends JCTree {
2212 public BoundKind kind;
2213 protected TypeBoundKind(BoundKind kind) {
2214 this.kind = kind;
2215 }
2216 @Override
2217 public void accept(Visitor v) { v.visitTypeBoundKind(this); }
2219 public Kind getKind() {
2220 throw new AssertionError("TypeBoundKind is not part of a public API");
2221 }
2222 @Override
2223 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2224 throw new AssertionError("TypeBoundKind is not part of a public API");
2225 }
2226 @Override
2227 public Tag getTag() {
2228 return TYPEBOUNDKIND;
2229 }
2230 }
2232 public static class JCAnnotation extends JCExpression implements AnnotationTree {
2233 public JCTree annotationType;
2234 public List<JCExpression> args;
2235 protected JCAnnotation(JCTree annotationType, List<JCExpression> args) {
2236 this.annotationType = annotationType;
2237 this.args = args;
2238 }
2239 @Override
2240 public void accept(Visitor v) { v.visitAnnotation(this); }
2242 public Kind getKind() { return Kind.ANNOTATION; }
2243 public JCTree getAnnotationType() { return annotationType; }
2244 public List<JCExpression> getArguments() {
2245 return args;
2246 }
2247 @Override
2248 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2249 return v.visitAnnotation(this, d);
2250 }
2251 @Override
2252 public Tag getTag() {
2253 return ANNOTATION;
2254 }
2255 }
2257 public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
2258 public long flags;
2259 public List<JCAnnotation> annotations;
2260 protected JCModifiers(long flags, List<JCAnnotation> annotations) {
2261 this.flags = flags;
2262 this.annotations = annotations;
2263 }
2264 @Override
2265 public void accept(Visitor v) { v.visitModifiers(this); }
2267 public Kind getKind() { return Kind.MODIFIERS; }
2268 public Set<Modifier> getFlags() {
2269 return Flags.asModifierSet(flags);
2270 }
2271 public List<JCAnnotation> getAnnotations() {
2272 return annotations;
2273 }
2274 @Override
2275 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2276 return v.visitModifiers(this, d);
2277 }
2278 @Override
2279 public Tag getTag() {
2280 return MODIFIERS;
2281 }
2282 }
2284 public static class JCErroneous extends JCExpression
2285 implements com.sun.source.tree.ErroneousTree {
2286 public List<? extends JCTree> errs;
2287 protected JCErroneous(List<? extends JCTree> errs) {
2288 this.errs = errs;
2289 }
2290 @Override
2291 public void accept(Visitor v) { v.visitErroneous(this); }
2293 public Kind getKind() { return Kind.ERRONEOUS; }
2295 public List<? extends JCTree> getErrorTrees() {
2296 return errs;
2297 }
2299 @Override
2300 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2301 return v.visitErroneous(this, d);
2302 }
2303 @Override
2304 public Tag getTag() {
2305 return ERRONEOUS;
2306 }
2307 }
2309 /** (let int x = 3; in x+2) */
2310 public static class LetExpr extends JCExpression {
2311 public List<JCVariableDecl> defs;
2312 public JCTree expr;
2313 protected LetExpr(List<JCVariableDecl> defs, JCTree expr) {
2314 this.defs = defs;
2315 this.expr = expr;
2316 }
2317 @Override
2318 public void accept(Visitor v) { v.visitLetExpr(this); }
2320 public Kind getKind() {
2321 throw new AssertionError("LetExpr is not part of a public API");
2322 }
2323 @Override
2324 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2325 throw new AssertionError("LetExpr is not part of a public API");
2326 }
2327 @Override
2328 public Tag getTag() {
2329 return LETEXPR;
2330 }
2331 }
2333 /** An interface for tree factories
2334 */
2335 public interface Factory {
2336 JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations,
2337 JCExpression pid,
2338 List<JCTree> defs);
2339 JCImport Import(JCTree qualid, boolean staticImport);
2340 JCClassDecl ClassDef(JCModifiers mods,
2341 Name name,
2342 List<JCTypeParameter> typarams,
2343 JCExpression extending,
2344 List<JCExpression> implementing,
2345 List<JCTree> defs);
2346 JCMethodDecl MethodDef(JCModifiers mods,
2347 Name name,
2348 JCExpression restype,
2349 List<JCTypeParameter> typarams,
2350 List<JCVariableDecl> params,
2351 List<JCExpression> thrown,
2352 JCBlock body,
2353 JCExpression defaultValue);
2354 JCVariableDecl VarDef(JCModifiers mods,
2355 Name name,
2356 JCExpression vartype,
2357 JCExpression init);
2358 JCSkip Skip();
2359 JCBlock Block(long flags, List<JCStatement> stats);
2360 JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
2361 JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
2362 JCForLoop ForLoop(List<JCStatement> init,
2363 JCExpression cond,
2364 List<JCExpressionStatement> step,
2365 JCStatement body);
2366 JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
2367 JCLabeledStatement Labelled(Name label, JCStatement body);
2368 JCSwitch Switch(JCExpression selector, List<JCCase> cases);
2369 JCCase Case(JCExpression pat, List<JCStatement> stats);
2370 JCSynchronized Synchronized(JCExpression lock, JCBlock body);
2371 JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
2372 JCTry Try(List<JCTree> resources,
2373 JCBlock body,
2374 List<JCCatch> catchers,
2375 JCBlock finalizer);
2376 JCCatch Catch(JCVariableDecl param, JCBlock body);
2377 JCConditional Conditional(JCExpression cond,
2378 JCExpression thenpart,
2379 JCExpression elsepart);
2380 JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
2381 JCExpressionStatement Exec(JCExpression expr);
2382 JCBreak Break(Name label);
2383 JCContinue Continue(Name label);
2384 JCReturn Return(JCExpression expr);
2385 JCThrow Throw(JCTree expr);
2386 JCAssert Assert(JCExpression cond, JCExpression detail);
2387 JCMethodInvocation Apply(List<JCExpression> typeargs,
2388 JCExpression fn,
2389 List<JCExpression> args);
2390 JCNewClass NewClass(JCExpression encl,
2391 List<JCExpression> typeargs,
2392 JCExpression clazz,
2393 List<JCExpression> args,
2394 JCClassDecl def);
2395 JCNewArray NewArray(JCExpression elemtype,
2396 List<JCExpression> dims,
2397 List<JCExpression> elems);
2398 JCParens Parens(JCExpression expr);
2399 JCAssign Assign(JCExpression lhs, JCExpression rhs);
2400 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
2401 JCUnary Unary(Tag opcode, JCExpression arg);
2402 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
2403 JCTypeCast TypeCast(JCTree expr, JCExpression type);
2404 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
2405 JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
2406 JCFieldAccess Select(JCExpression selected, Name selector);
2407 JCIdent Ident(Name idname);
2408 JCLiteral Literal(TypeTag tag, Object value);
2409 JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
2410 JCArrayTypeTree TypeArray(JCExpression elemtype);
2411 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
2412 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
2413 JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
2414 TypeBoundKind TypeBoundKind(BoundKind kind);
2415 JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
2416 JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
2417 JCErroneous Erroneous(List<? extends JCTree> errs);
2418 LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr);
2419 }
2421 /** A generic visitor class for trees.
2422 */
2423 public static abstract class Visitor {
2424 public void visitTopLevel(JCCompilationUnit that) { visitTree(that); }
2425 public void visitImport(JCImport that) { visitTree(that); }
2426 public void visitClassDef(JCClassDecl that) { visitTree(that); }
2427 public void visitMethodDef(JCMethodDecl that) { visitTree(that); }
2428 public void visitVarDef(JCVariableDecl that) { visitTree(that); }
2429 public void visitSkip(JCSkip that) { visitTree(that); }
2430 public void visitBlock(JCBlock that) { visitTree(that); }
2431 public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); }
2432 public void visitWhileLoop(JCWhileLoop that) { visitTree(that); }
2433 public void visitForLoop(JCForLoop that) { visitTree(that); }
2434 public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
2435 public void visitLabelled(JCLabeledStatement that) { visitTree(that); }
2436 public void visitSwitch(JCSwitch that) { visitTree(that); }
2437 public void visitCase(JCCase that) { visitTree(that); }
2438 public void visitSynchronized(JCSynchronized that) { visitTree(that); }
2439 public void visitTry(JCTry that) { visitTree(that); }
2440 public void visitCatch(JCCatch that) { visitTree(that); }
2441 public void visitConditional(JCConditional that) { visitTree(that); }
2442 public void visitIf(JCIf that) { visitTree(that); }
2443 public void visitExec(JCExpressionStatement that) { visitTree(that); }
2444 public void visitBreak(JCBreak that) { visitTree(that); }
2445 public void visitContinue(JCContinue that) { visitTree(that); }
2446 public void visitReturn(JCReturn that) { visitTree(that); }
2447 public void visitThrow(JCThrow that) { visitTree(that); }
2448 public void visitAssert(JCAssert that) { visitTree(that); }
2449 public void visitApply(JCMethodInvocation that) { visitTree(that); }
2450 public void visitNewClass(JCNewClass that) { visitTree(that); }
2451 public void visitNewArray(JCNewArray that) { visitTree(that); }
2452 public void visitLambda(JCLambda that) { visitTree(that); }
2453 public void visitParens(JCParens that) { visitTree(that); }
2454 public void visitAssign(JCAssign that) { visitTree(that); }
2455 public void visitAssignop(JCAssignOp that) { visitTree(that); }
2456 public void visitUnary(JCUnary that) { visitTree(that); }
2457 public void visitBinary(JCBinary that) { visitTree(that); }
2458 public void visitTypeCast(JCTypeCast that) { visitTree(that); }
2459 public void visitTypeTest(JCInstanceOf that) { visitTree(that); }
2460 public void visitIndexed(JCArrayAccess that) { visitTree(that); }
2461 public void visitSelect(JCFieldAccess that) { visitTree(that); }
2462 public void visitReference(JCMemberReference that) { visitTree(that); }
2463 public void visitIdent(JCIdent that) { visitTree(that); }
2464 public void visitLiteral(JCLiteral that) { visitTree(that); }
2465 public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
2466 public void visitTypeArray(JCArrayTypeTree that) { visitTree(that); }
2467 public void visitTypeApply(JCTypeApply that) { visitTree(that); }
2468 public void visitTypeUnion(JCTypeUnion that) { visitTree(that); }
2469 public void visitTypeIntersection(JCTypeIntersection that) { visitTree(that); }
2470 public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
2471 public void visitWildcard(JCWildcard that) { visitTree(that); }
2472 public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); }
2473 public void visitAnnotation(JCAnnotation that) { visitTree(that); }
2474 public void visitModifiers(JCModifiers that) { visitTree(that); }
2475 public void visitErroneous(JCErroneous that) { visitTree(that); }
2476 public void visitLetExpr(LetExpr that) { visitTree(that); }
2478 public void visitTree(JCTree that) { Assert.error(); }
2479 }
2481 }