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