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