Thu, 09 Oct 2008 16:07:38 +0100
6406133: JCDiagnostic.getMessage ignores locale argument
Summary: Compiler API should take into account locale settings
Reviewed-by: jjg
1 /*
2 * Copyright 1999-2008 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
26 package com.sun.tools.javac.tree;
28 import java.util.*;
30 import java.io.IOException;
31 import java.io.StringWriter;
32 import javax.lang.model.element.Modifier;
33 import javax.lang.model.type.TypeKind;
34 import javax.tools.JavaFileObject;
36 import com.sun.tools.javac.util.*;
37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
38 import com.sun.tools.javac.util.List;
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.source.tree.*;
44 import static com.sun.tools.javac.code.BoundKind.*;
46 /**
47 * Root class for abstract syntax tree nodes. It provides definitions
48 * for specific tree nodes as subclasses nested inside.
49 *
50 * <p>Each subclass is highly standardized. It generally contains
51 * only tree fields for the syntactic subcomponents of the node. Some
52 * classes that represent identifier uses or definitions also define a
53 * Symbol field that denotes the represented identifier. Classes for
54 * non-local jumps also carry the jump target as a field. The root
55 * class Tree itself defines fields for the tree's type and position.
56 * No other fields are kept in a tree node; instead parameters are
57 * passed to methods accessing the node.
58 *
59 * <p>Except for the methods defined by com.sun.source, the only
60 * method defined in subclasses is `visit' which applies a given
61 * visitor to the tree. The actual tree processing is done by visitor
62 * classes in other packages. The abstract class Visitor, as well as
63 * an Factory interface for trees, are defined as inner classes in
64 * Tree.
65 *
66 * <p>To avoid ambiguities with the Tree API in com.sun.source all sub
67 * classes should, by convention, start with JC (javac).
68 *
69 * <p><b>This is NOT part of any API supported by Sun Microsystems.
70 * If you write code that depends on this, you do so at your own risk.
71 * This code and its internal interfaces are subject to change or
72 * deletion without notice.</b>
73 *
74 * @see TreeMaker
75 * @see TreeInfo
76 * @see TreeTranslator
77 * @see Pretty
78 */
79 public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
81 /* Tree tag values, identifying kinds of trees */
83 /** Toplevel nodes, of type TopLevel, representing entire source files.
84 */
85 public static final int TOPLEVEL = 1;
87 /** Import clauses, of type Import.
88 */
89 public static final int IMPORT = TOPLEVEL + 1;
91 /** Class definitions, of type ClassDef.
92 */
93 public static final int CLASSDEF = IMPORT + 1;
95 /** Method definitions, of type MethodDef.
96 */
97 public static final int METHODDEF = CLASSDEF + 1;
99 /** Variable definitions, of type VarDef.
100 */
101 public static final int VARDEF = METHODDEF + 1;
103 /** The no-op statement ";", of type Skip
104 */
105 public static final int SKIP = VARDEF + 1;
107 /** Blocks, of type Block.
108 */
109 public static final int BLOCK = SKIP + 1;
111 /** Do-while loops, of type DoLoop.
112 */
113 public static final int DOLOOP = BLOCK + 1;
115 /** While-loops, of type WhileLoop.
116 */
117 public static final int WHILELOOP = DOLOOP + 1;
119 /** For-loops, of type ForLoop.
120 */
121 public static final int FORLOOP = WHILELOOP + 1;
123 /** Foreach-loops, of type ForeachLoop.
124 */
125 public static final int FOREACHLOOP = FORLOOP + 1;
127 /** Labelled statements, of type Labelled.
128 */
129 public static final int LABELLED = FOREACHLOOP + 1;
131 /** Switch statements, of type Switch.
132 */
133 public static final int SWITCH = LABELLED + 1;
135 /** Case parts in switch statements, of type Case.
136 */
137 public static final int CASE = SWITCH + 1;
139 /** Synchronized statements, of type Synchonized.
140 */
141 public static final int SYNCHRONIZED = CASE + 1;
143 /** Try statements, of type Try.
144 */
145 public static final int TRY = SYNCHRONIZED + 1;
147 /** Catch clauses in try statements, of type Catch.
148 */
149 public static final int CATCH = TRY + 1;
151 /** Conditional expressions, of type Conditional.
152 */
153 public static final int CONDEXPR = CATCH + 1;
155 /** Conditional statements, of type If.
156 */
157 public static final int IF = CONDEXPR + 1;
159 /** Expression statements, of type Exec.
160 */
161 public static final int EXEC = IF + 1;
163 /** Break statements, of type Break.
164 */
165 public static final int BREAK = EXEC + 1;
167 /** Continue statements, of type Continue.
168 */
169 public static final int CONTINUE = BREAK + 1;
171 /** Return statements, of type Return.
172 */
173 public static final int RETURN = CONTINUE + 1;
175 /** Throw statements, of type Throw.
176 */
177 public static final int THROW = RETURN + 1;
179 /** Assert statements, of type Assert.
180 */
181 public static final int ASSERT = THROW + 1;
183 /** Method invocation expressions, of type Apply.
184 */
185 public static final int APPLY = ASSERT + 1;
187 /** Class instance creation expressions, of type NewClass.
188 */
189 public static final int NEWCLASS = APPLY + 1;
191 /** Array creation expressions, of type NewArray.
192 */
193 public static final int NEWARRAY = NEWCLASS + 1;
195 /** Parenthesized subexpressions, of type Parens.
196 */
197 public static final int PARENS = NEWARRAY + 1;
199 /** Assignment expressions, of type Assign.
200 */
201 public static final int ASSIGN = PARENS + 1;
203 /** Type cast expressions, of type TypeCast.
204 */
205 public static final int TYPECAST = ASSIGN + 1;
207 /** Type test expressions, of type TypeTest.
208 */
209 public static final int TYPETEST = TYPECAST + 1;
211 /** Indexed array expressions, of type Indexed.
212 */
213 public static final int INDEXED = TYPETEST + 1;
215 /** Selections, of type Select.
216 */
217 public static final int SELECT = INDEXED + 1;
219 /** Simple identifiers, of type Ident.
220 */
221 public static final int IDENT = SELECT + 1;
223 /** Literals, of type Literal.
224 */
225 public static final int LITERAL = IDENT + 1;
227 /** Basic type identifiers, of type TypeIdent.
228 */
229 public static final int TYPEIDENT = LITERAL + 1;
231 /** Array types, of type TypeArray.
232 */
233 public static final int TYPEARRAY = TYPEIDENT + 1;
235 /** Parameterized types, of type TypeApply.
236 */
237 public static final int TYPEAPPLY = TYPEARRAY + 1;
239 /** Formal type parameters, of type TypeParameter.
240 */
241 public static final int TYPEPARAMETER = TYPEAPPLY + 1;
243 /** Type argument.
244 */
245 public static final int WILDCARD = TYPEPARAMETER + 1;
247 /** Bound kind: extends, super, exact, or unbound
248 */
249 public static final int TYPEBOUNDKIND = WILDCARD + 1;
251 /** metadata: Annotation.
252 */
253 public static final int ANNOTATION = TYPEBOUNDKIND + 1;
255 /** metadata: Modifiers
256 */
257 public static final int MODIFIERS = ANNOTATION + 1;
259 /** Error trees, of type Erroneous.
260 */
261 public static final int ERRONEOUS = MODIFIERS + 1;
263 /** Unary operators, of type Unary.
264 */
265 public static final int POS = ERRONEOUS + 1; // +
266 public static final int NEG = POS + 1; // -
267 public static final int NOT = NEG + 1; // !
268 public static final int COMPL = NOT + 1; // ~
269 public static final int PREINC = COMPL + 1; // ++ _
270 public static final int PREDEC = PREINC + 1; // -- _
271 public static final int POSTINC = PREDEC + 1; // _ ++
272 public static final int POSTDEC = POSTINC + 1; // _ --
274 /** unary operator for null reference checks, only used internally.
275 */
276 public static final int NULLCHK = POSTDEC + 1;
278 /** Binary operators, of type Binary.
279 */
280 public static final int OR = NULLCHK + 1; // ||
281 public static final int AND = OR + 1; // &&
282 public static final int BITOR = AND + 1; // |
283 public static final int BITXOR = BITOR + 1; // ^
284 public static final int BITAND = BITXOR + 1; // &
285 public static final int EQ = BITAND + 1; // ==
286 public static final int NE = EQ + 1; // !=
287 public static final int LT = NE + 1; // <
288 public static final int GT = LT + 1; // >
289 public static final int LE = GT + 1; // <=
290 public static final int GE = LE + 1; // >=
291 public static final int SL = GE + 1; // <<
292 public static final int SR = SL + 1; // >>
293 public static final int USR = SR + 1; // >>>
294 public static final int PLUS = USR + 1; // +
295 public static final int MINUS = PLUS + 1; // -
296 public static final int MUL = MINUS + 1; // *
297 public static final int DIV = MUL + 1; // /
298 public static final int MOD = DIV + 1; // %
300 /** Assignment operators, of type Assignop.
301 */
302 public static final int BITOR_ASG = MOD + 1; // |=
303 public static final int BITXOR_ASG = BITOR_ASG + 1; // ^=
304 public static final int BITAND_ASG = BITXOR_ASG + 1; // &=
306 public static final int SL_ASG = SL + BITOR_ASG - BITOR; // <<=
307 public static final int SR_ASG = SL_ASG + 1; // >>=
308 public static final int USR_ASG = SR_ASG + 1; // >>>=
309 public static final int PLUS_ASG = USR_ASG + 1; // +=
310 public static final int MINUS_ASG = PLUS_ASG + 1; // -=
311 public static final int MUL_ASG = MINUS_ASG + 1; // *=
312 public static final int DIV_ASG = MUL_ASG + 1; // /=
313 public static final int MOD_ASG = DIV_ASG + 1; // %=
315 /** A synthetic let expression, of type LetExpr.
316 */
317 public static final int LETEXPR = MOD_ASG + 1; // ala scheme
320 /** The offset between assignment operators and normal operators.
321 */
322 public static final int ASGOffset = BITOR_ASG - BITOR;
324 /* The (encoded) position in the source file. @see util.Position.
325 */
326 public int pos;
328 /* The type of this node.
329 */
330 public Type type;
332 /* The tag of this node -- one of the constants declared above.
333 */
334 public abstract int getTag();
336 /** Convert a tree to a pretty-printed string. */
337 public String toString() {
338 StringWriter s = new StringWriter();
339 try {
340 new Pretty(s, false).printExpr(this);
341 }
342 catch (IOException e) {
343 // should never happen, because StringWriter is defined
344 // never to throw any IOExceptions
345 throw new AssertionError(e);
346 }
347 return s.toString();
348 }
350 /** Set position field and return this tree.
351 */
352 public JCTree setPos(int pos) {
353 this.pos = pos;
354 return this;
355 }
357 /** Set type field and return this tree.
358 */
359 public JCTree setType(Type type) {
360 this.type = type;
361 return this;
362 }
364 /** Visit this tree with a given visitor.
365 */
366 public abstract void accept(Visitor v);
368 public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);
370 /** Return a shallow copy of this tree.
371 */
372 public Object clone() {
373 try {
374 return super.clone();
375 } catch(CloneNotSupportedException e) {
376 throw new RuntimeException(e);
377 }
378 }
380 /** Get a default position for this tree node.
381 */
382 public DiagnosticPosition pos() {
383 return this;
384 }
386 // for default DiagnosticPosition
387 public JCTree getTree() {
388 return this;
389 }
391 // for default DiagnosticPosition
392 public int getStartPosition() {
393 return TreeInfo.getStartPos(this);
394 }
396 // for default DiagnosticPosition
397 public int getPreferredPosition() {
398 return pos;
399 }
401 // for default DiagnosticPosition
402 public int getEndPosition(Map<JCTree, Integer> endPosTable) {
403 return TreeInfo.getEndPos(this, endPosTable);
404 }
406 /**
407 * Everything in one source file is kept in a TopLevel structure.
408 * @param pid The tree representing the package clause.
409 * @param sourcefile The source file name.
410 * @param defs All definitions in this file (ClassDef, Import, and Skip)
411 * @param packge The package it belongs to.
412 * @param namedImportScope A scope for all named imports.
413 * @param starImportScope A scope for all import-on-demands.
414 * @param lineMap Line starting positions, defined only
415 * if option -g is set.
416 * @param docComments A hashtable that stores all documentation comments
417 * indexed by the tree nodes they refer to.
418 * defined only if option -s is set.
419 * @param endPositions A hashtable that stores ending positions of source
420 * ranges indexed by the tree nodes they belong to.
421 * Defined only if option -Xjcov is set.
422 */
423 public static class JCCompilationUnit extends JCTree implements CompilationUnitTree {
424 public List<JCAnnotation> packageAnnotations;
425 public JCExpression pid;
426 public List<JCTree> defs;
427 public JavaFileObject sourcefile;
428 public PackageSymbol packge;
429 public Scope namedImportScope;
430 public Scope starImportScope;
431 public long flags;
432 public Position.LineMap lineMap = null;
433 public Map<JCTree, String> docComments = null;
434 public Map<JCTree, Integer> endPositions = null;
435 protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,
436 JCExpression pid,
437 List<JCTree> defs,
438 JavaFileObject sourcefile,
439 PackageSymbol packge,
440 Scope namedImportScope,
441 Scope starImportScope) {
442 this.packageAnnotations = packageAnnotations;
443 this.pid = pid;
444 this.defs = defs;
445 this.sourcefile = sourcefile;
446 this.packge = packge;
447 this.namedImportScope = namedImportScope;
448 this.starImportScope = starImportScope;
449 }
450 @Override
451 public void accept(Visitor v) { v.visitTopLevel(this); }
453 public Kind getKind() { return Kind.COMPILATION_UNIT; }
454 public List<JCAnnotation> getPackageAnnotations() {
455 return packageAnnotations;
456 }
457 public List<JCImport> getImports() {
458 ListBuffer<JCImport> imports = new ListBuffer<JCImport>();
459 for (JCTree tree : defs) {
460 if (tree.getTag() == IMPORT)
461 imports.append((JCImport)tree);
462 else
463 break;
464 }
465 return imports.toList();
466 }
467 public JCExpression getPackageName() { return pid; }
468 public JavaFileObject getSourceFile() {
469 return sourcefile;
470 }
471 public Position.LineMap getLineMap() {
472 return lineMap;
473 }
474 public List<JCTree> getTypeDecls() {
475 List<JCTree> typeDefs;
476 for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)
477 if (typeDefs.head.getTag() != IMPORT)
478 break;
479 return typeDefs;
480 }
481 @Override
482 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
483 return v.visitCompilationUnit(this, d);
484 }
486 @Override
487 public int getTag() {
488 return TOPLEVEL;
489 }
490 }
492 /**
493 * An import clause.
494 * @param qualid The imported class(es).
495 */
496 public static class JCImport extends JCTree implements ImportTree {
497 public boolean staticImport;
498 public JCTree qualid;
499 protected JCImport(JCTree qualid, boolean importStatic) {
500 this.qualid = qualid;
501 this.staticImport = importStatic;
502 }
503 @Override
504 public void accept(Visitor v) { v.visitImport(this); }
506 public boolean isStatic() { return staticImport; }
507 public JCTree getQualifiedIdentifier() { return qualid; }
509 public Kind getKind() { return Kind.IMPORT; }
510 @Override
511 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
512 return v.visitImport(this, d);
513 }
515 @Override
516 public int getTag() {
517 return IMPORT;
518 }
519 }
521 public static abstract class JCStatement extends JCTree implements StatementTree {
522 @Override
523 public JCStatement setType(Type type) {
524 super.setType(type);
525 return this;
526 }
527 @Override
528 public JCStatement setPos(int pos) {
529 super.setPos(pos);
530 return this;
531 }
532 }
534 public static abstract class JCExpression extends JCTree implements ExpressionTree {
535 @Override
536 public JCExpression setType(Type type) {
537 super.setType(type);
538 return this;
539 }
540 @Override
541 public JCExpression setPos(int pos) {
542 super.setPos(pos);
543 return this;
544 }
545 }
547 /**
548 * A class definition.
549 * @param modifiers the modifiers
550 * @param name the name of the class
551 * @param typarams formal class parameters
552 * @param extending the classes this class extends
553 * @param implementing the interfaces implemented by this class
554 * @param defs all variables and methods defined in this class
555 * @param sym the symbol
556 */
557 public static class JCClassDecl extends JCStatement implements ClassTree {
558 public JCModifiers mods;
559 public Name name;
560 public List<JCTypeParameter> typarams;
561 public JCTree extending;
562 public List<JCExpression> implementing;
563 public List<JCTree> defs;
564 public ClassSymbol sym;
565 protected JCClassDecl(JCModifiers mods,
566 Name name,
567 List<JCTypeParameter> typarams,
568 JCTree extending,
569 List<JCExpression> implementing,
570 List<JCTree> defs,
571 ClassSymbol sym)
572 {
573 this.mods = mods;
574 this.name = name;
575 this.typarams = typarams;
576 this.extending = extending;
577 this.implementing = implementing;
578 this.defs = defs;
579 this.sym = sym;
580 }
581 @Override
582 public void accept(Visitor v) { v.visitClassDef(this); }
584 public Kind getKind() { return Kind.CLASS; }
585 public JCModifiers getModifiers() { return mods; }
586 public Name getSimpleName() { return name; }
587 public List<JCTypeParameter> getTypeParameters() {
588 return typarams;
589 }
590 public JCTree getExtendsClause() { return extending; }
591 public List<JCExpression> getImplementsClause() {
592 return implementing;
593 }
594 public List<JCTree> getMembers() {
595 return defs;
596 }
597 @Override
598 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
599 return v.visitClass(this, d);
600 }
602 @Override
603 public int getTag() {
604 return CLASSDEF;
605 }
606 }
608 /**
609 * A method definition.
610 * @param modifiers method modifiers
611 * @param name method name
612 * @param restype type of method return value
613 * @param typarams type parameters
614 * @param params value parameters
615 * @param thrown exceptions thrown by this method
616 * @param stats statements in the method
617 * @param sym method symbol
618 */
619 public static class JCMethodDecl extends JCTree implements MethodTree {
620 public JCModifiers mods;
621 public Name name;
622 public JCExpression restype;
623 public List<JCTypeParameter> typarams;
624 public List<JCVariableDecl> params;
625 public List<JCExpression> thrown;
626 public JCBlock body;
627 public JCExpression defaultValue; // for annotation types
628 public MethodSymbol sym;
629 protected JCMethodDecl(JCModifiers mods,
630 Name name,
631 JCExpression restype,
632 List<JCTypeParameter> typarams,
633 List<JCVariableDecl> params,
634 List<JCExpression> thrown,
635 JCBlock body,
636 JCExpression defaultValue,
637 MethodSymbol sym)
638 {
639 this.mods = mods;
640 this.name = name;
641 this.restype = restype;
642 this.typarams = typarams;
643 this.params = params;
644 this.thrown = thrown;
645 this.body = body;
646 this.defaultValue = defaultValue;
647 this.sym = sym;
648 }
649 @Override
650 public void accept(Visitor v) { v.visitMethodDef(this); }
652 public Kind getKind() { return Kind.METHOD; }
653 public JCModifiers getModifiers() { return mods; }
654 public Name getName() { return name; }
655 public JCTree getReturnType() { return restype; }
656 public List<JCTypeParameter> getTypeParameters() {
657 return typarams;
658 }
659 public List<JCVariableDecl> getParameters() {
660 return params;
661 }
662 public List<JCExpression> getThrows() {
663 return thrown;
664 }
665 public JCBlock getBody() { return body; }
666 public JCTree getDefaultValue() { // for annotation types
667 return defaultValue;
668 }
669 @Override
670 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
671 return v.visitMethod(this, d);
672 }
674 @Override
675 public int getTag() {
676 return METHODDEF;
677 }
678 }
680 /**
681 * A variable definition.
682 * @param modifiers variable modifiers
683 * @param name variable name
684 * @param vartype type of the variable
685 * @param init variables initial value
686 * @param sym symbol
687 */
688 public static class JCVariableDecl extends JCStatement implements VariableTree {
689 public JCModifiers mods;
690 public Name name;
691 public JCExpression vartype;
692 public JCExpression init;
693 public VarSymbol sym;
694 protected JCVariableDecl(JCModifiers mods,
695 Name name,
696 JCExpression vartype,
697 JCExpression init,
698 VarSymbol sym) {
699 this.mods = mods;
700 this.name = name;
701 this.vartype = vartype;
702 this.init = init;
703 this.sym = sym;
704 }
705 @Override
706 public void accept(Visitor v) { v.visitVarDef(this); }
708 public Kind getKind() { return Kind.VARIABLE; }
709 public JCModifiers getModifiers() { return mods; }
710 public Name getName() { return name; }
711 public JCTree getType() { return vartype; }
712 public JCExpression getInitializer() {
713 return init;
714 }
715 @Override
716 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
717 return v.visitVariable(this, d);
718 }
720 @Override
721 public int getTag() {
722 return VARDEF;
723 }
724 }
726 /**
727 * A no-op statement ";".
728 */
729 public static class JCSkip extends JCStatement implements EmptyStatementTree {
730 protected JCSkip() {
731 }
732 @Override
733 public void accept(Visitor v) { v.visitSkip(this); }
735 public Kind getKind() { return Kind.EMPTY_STATEMENT; }
736 @Override
737 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
738 return v.visitEmptyStatement(this, d);
739 }
741 @Override
742 public int getTag() {
743 return SKIP;
744 }
745 }
747 /**
748 * A statement block.
749 * @param stats statements
750 * @param flags flags
751 */
752 public static class JCBlock extends JCStatement implements BlockTree {
753 public long flags;
754 public List<JCStatement> stats;
755 /** Position of closing brace, optional. */
756 public int endpos = Position.NOPOS;
757 protected JCBlock(long flags, List<JCStatement> stats) {
758 this.stats = stats;
759 this.flags = flags;
760 }
761 @Override
762 public void accept(Visitor v) { v.visitBlock(this); }
764 public Kind getKind() { return Kind.BLOCK; }
765 public List<JCStatement> getStatements() {
766 return stats;
767 }
768 public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
769 @Override
770 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
771 return v.visitBlock(this, d);
772 }
774 @Override
775 public int getTag() {
776 return BLOCK;
777 }
778 }
780 /**
781 * A do loop
782 */
783 public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
784 public JCStatement body;
785 public JCExpression cond;
786 protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
787 this.body = body;
788 this.cond = cond;
789 }
790 @Override
791 public void accept(Visitor v) { v.visitDoLoop(this); }
793 public Kind getKind() { return Kind.DO_WHILE_LOOP; }
794 public JCExpression getCondition() { return cond; }
795 public JCStatement getStatement() { return body; }
796 @Override
797 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
798 return v.visitDoWhileLoop(this, d);
799 }
801 @Override
802 public int getTag() {
803 return DOLOOP;
804 }
805 }
807 /**
808 * A while loop
809 */
810 public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
811 public JCExpression cond;
812 public JCStatement body;
813 protected JCWhileLoop(JCExpression cond, JCStatement body) {
814 this.cond = cond;
815 this.body = body;
816 }
817 @Override
818 public void accept(Visitor v) { v.visitWhileLoop(this); }
820 public Kind getKind() { return Kind.WHILE_LOOP; }
821 public JCExpression getCondition() { return cond; }
822 public JCStatement getStatement() { return body; }
823 @Override
824 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
825 return v.visitWhileLoop(this, d);
826 }
828 @Override
829 public int getTag() {
830 return WHILELOOP;
831 }
832 }
834 /**
835 * A for loop.
836 */
837 public static class JCForLoop extends JCStatement implements ForLoopTree {
838 public List<JCStatement> init;
839 public JCExpression cond;
840 public List<JCExpressionStatement> step;
841 public JCStatement body;
842 protected JCForLoop(List<JCStatement> init,
843 JCExpression cond,
844 List<JCExpressionStatement> update,
845 JCStatement body)
846 {
847 this.init = init;
848 this.cond = cond;
849 this.step = update;
850 this.body = body;
851 }
852 @Override
853 public void accept(Visitor v) { v.visitForLoop(this); }
855 public Kind getKind() { return Kind.FOR_LOOP; }
856 public JCExpression getCondition() { return cond; }
857 public JCStatement getStatement() { return body; }
858 public List<JCStatement> getInitializer() {
859 return init;
860 }
861 public List<JCExpressionStatement> getUpdate() {
862 return step;
863 }
864 @Override
865 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
866 return v.visitForLoop(this, d);
867 }
869 @Override
870 public int getTag() {
871 return FORLOOP;
872 }
873 }
875 /**
876 * The enhanced for loop.
877 */
878 public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
879 public JCVariableDecl var;
880 public JCExpression expr;
881 public JCStatement body;
882 protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
883 this.var = var;
884 this.expr = expr;
885 this.body = body;
886 }
887 @Override
888 public void accept(Visitor v) { v.visitForeachLoop(this); }
890 public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
891 public JCVariableDecl getVariable() { return var; }
892 public JCExpression getExpression() { return expr; }
893 public JCStatement getStatement() { return body; }
894 @Override
895 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
896 return v.visitEnhancedForLoop(this, d);
897 }
898 @Override
899 public int getTag() {
900 return FOREACHLOOP;
901 }
902 }
904 /**
905 * A labelled expression or statement.
906 */
907 public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
908 public Name label;
909 public JCStatement body;
910 protected JCLabeledStatement(Name label, JCStatement body) {
911 this.label = label;
912 this.body = body;
913 }
914 @Override
915 public void accept(Visitor v) { v.visitLabelled(this); }
916 public Kind getKind() { return Kind.LABELED_STATEMENT; }
917 public Name getLabel() { return label; }
918 public JCStatement getStatement() { return body; }
919 @Override
920 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
921 return v.visitLabeledStatement(this, d);
922 }
923 @Override
924 public int getTag() {
925 return LABELLED;
926 }
927 }
929 /**
930 * A "switch ( ) { }" construction.
931 */
932 public static class JCSwitch extends JCStatement implements SwitchTree {
933 public JCExpression selector;
934 public List<JCCase> cases;
935 protected JCSwitch(JCExpression selector, List<JCCase> cases) {
936 this.selector = selector;
937 this.cases = cases;
938 }
939 @Override
940 public void accept(Visitor v) { v.visitSwitch(this); }
942 public Kind getKind() { return Kind.SWITCH; }
943 public JCExpression getExpression() { return selector; }
944 public List<JCCase> getCases() { return cases; }
945 @Override
946 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
947 return v.visitSwitch(this, d);
948 }
949 @Override
950 public int getTag() {
951 return SWITCH;
952 }
953 }
955 /**
956 * A "case :" of a switch.
957 */
958 public static class JCCase extends JCStatement implements CaseTree {
959 public JCExpression pat;
960 public List<JCStatement> stats;
961 protected JCCase(JCExpression pat, List<JCStatement> stats) {
962 this.pat = pat;
963 this.stats = stats;
964 }
965 @Override
966 public void accept(Visitor v) { v.visitCase(this); }
968 public Kind getKind() { return Kind.CASE; }
969 public JCExpression getExpression() { return pat; }
970 public List<JCStatement> getStatements() { return stats; }
971 @Override
972 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
973 return v.visitCase(this, d);
974 }
975 @Override
976 public int getTag() {
977 return CASE;
978 }
979 }
981 /**
982 * A synchronized block.
983 */
984 public static class JCSynchronized extends JCStatement implements SynchronizedTree {
985 public JCExpression lock;
986 public JCBlock body;
987 protected JCSynchronized(JCExpression lock, JCBlock body) {
988 this.lock = lock;
989 this.body = body;
990 }
991 @Override
992 public void accept(Visitor v) { v.visitSynchronized(this); }
994 public Kind getKind() { return Kind.SYNCHRONIZED; }
995 public JCExpression getExpression() { return lock; }
996 public JCBlock getBlock() { return body; }
997 @Override
998 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
999 return v.visitSynchronized(this, d);
1000 }
1001 @Override
1002 public int getTag() {
1003 return SYNCHRONIZED;
1004 }
1005 }
1007 /**
1008 * A "try { } catch ( ) { } finally { }" block.
1009 */
1010 public static class JCTry extends JCStatement implements TryTree {
1011 public JCBlock body;
1012 public List<JCCatch> catchers;
1013 public JCBlock finalizer;
1014 protected JCTry(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
1015 this.body = body;
1016 this.catchers = catchers;
1017 this.finalizer = finalizer;
1018 }
1019 @Override
1020 public void accept(Visitor v) { v.visitTry(this); }
1022 public Kind getKind() { return Kind.TRY; }
1023 public JCBlock getBlock() { return body; }
1024 public List<JCCatch> getCatches() {
1025 return catchers;
1026 }
1027 public JCBlock getFinallyBlock() { return finalizer; }
1028 @Override
1029 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1030 return v.visitTry(this, d);
1031 }
1032 @Override
1033 public int getTag() {
1034 return TRY;
1035 }
1036 }
1038 /**
1039 * A catch block.
1040 */
1041 public static class JCCatch extends JCTree implements CatchTree {
1042 public JCVariableDecl param;
1043 public JCBlock body;
1044 protected JCCatch(JCVariableDecl param, JCBlock body) {
1045 this.param = param;
1046 this.body = body;
1047 }
1048 @Override
1049 public void accept(Visitor v) { v.visitCatch(this); }
1051 public Kind getKind() { return Kind.CATCH; }
1052 public JCVariableDecl getParameter() { return param; }
1053 public JCBlock getBlock() { return body; }
1054 @Override
1055 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1056 return v.visitCatch(this, d);
1057 }
1058 @Override
1059 public int getTag() {
1060 return CATCH;
1061 }
1062 }
1064 /**
1065 * A ( ) ? ( ) : ( ) conditional expression
1066 */
1067 public static class JCConditional extends JCExpression implements ConditionalExpressionTree {
1068 public JCExpression cond;
1069 public JCExpression truepart;
1070 public JCExpression falsepart;
1071 protected JCConditional(JCExpression cond,
1072 JCExpression truepart,
1073 JCExpression falsepart)
1074 {
1075 this.cond = cond;
1076 this.truepart = truepart;
1077 this.falsepart = falsepart;
1078 }
1079 @Override
1080 public void accept(Visitor v) { v.visitConditional(this); }
1082 public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
1083 public JCExpression getCondition() { return cond; }
1084 public JCExpression getTrueExpression() { return truepart; }
1085 public JCExpression getFalseExpression() { return falsepart; }
1086 @Override
1087 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1088 return v.visitConditionalExpression(this, d);
1089 }
1090 @Override
1091 public int getTag() {
1092 return CONDEXPR;
1093 }
1094 }
1096 /**
1097 * An "if ( ) { } else { }" block
1098 */
1099 public static class JCIf extends JCStatement implements IfTree {
1100 public JCExpression cond;
1101 public JCStatement thenpart;
1102 public JCStatement elsepart;
1103 protected JCIf(JCExpression cond,
1104 JCStatement thenpart,
1105 JCStatement elsepart)
1106 {
1107 this.cond = cond;
1108 this.thenpart = thenpart;
1109 this.elsepart = elsepart;
1110 }
1111 @Override
1112 public void accept(Visitor v) { v.visitIf(this); }
1114 public Kind getKind() { return Kind.IF; }
1115 public JCExpression getCondition() { return cond; }
1116 public JCStatement getThenStatement() { return thenpart; }
1117 public JCStatement getElseStatement() { return elsepart; }
1118 @Override
1119 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1120 return v.visitIf(this, d);
1121 }
1122 @Override
1123 public int getTag() {
1124 return IF;
1125 }
1126 }
1128 /**
1129 * an expression statement
1130 * @param expr expression structure
1131 */
1132 public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
1133 public JCExpression expr;
1134 protected JCExpressionStatement(JCExpression expr)
1135 {
1136 this.expr = expr;
1137 }
1138 @Override
1139 public void accept(Visitor v) { v.visitExec(this); }
1141 public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
1142 public JCExpression getExpression() { return expr; }
1143 @Override
1144 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1145 return v.visitExpressionStatement(this, d);
1146 }
1147 @Override
1148 public int getTag() {
1149 return EXEC;
1150 }
1151 }
1153 /**
1154 * A break from a loop or switch.
1155 */
1156 public static class JCBreak extends JCStatement implements BreakTree {
1157 public Name label;
1158 public JCTree target;
1159 protected JCBreak(Name label, JCTree target) {
1160 this.label = label;
1161 this.target = target;
1162 }
1163 @Override
1164 public void accept(Visitor v) { v.visitBreak(this); }
1166 public Kind getKind() { return Kind.BREAK; }
1167 public Name getLabel() { return label; }
1168 @Override
1169 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1170 return v.visitBreak(this, d);
1171 }
1172 @Override
1173 public int getTag() {
1174 return BREAK;
1175 }
1176 }
1178 /**
1179 * A continue of a loop.
1180 */
1181 public static class JCContinue extends JCStatement implements ContinueTree {
1182 public Name label;
1183 public JCTree target;
1184 protected JCContinue(Name label, JCTree target) {
1185 this.label = label;
1186 this.target = target;
1187 }
1188 @Override
1189 public void accept(Visitor v) { v.visitContinue(this); }
1191 public Kind getKind() { return Kind.CONTINUE; }
1192 public Name getLabel() { return label; }
1193 @Override
1194 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1195 return v.visitContinue(this, d);
1196 }
1197 @Override
1198 public int getTag() {
1199 return CONTINUE;
1200 }
1201 }
1203 /**
1204 * A return statement.
1205 */
1206 public static class JCReturn extends JCStatement implements ReturnTree {
1207 public JCExpression expr;
1208 protected JCReturn(JCExpression expr) {
1209 this.expr = expr;
1210 }
1211 @Override
1212 public void accept(Visitor v) { v.visitReturn(this); }
1214 public Kind getKind() { return Kind.RETURN; }
1215 public JCExpression getExpression() { return expr; }
1216 @Override
1217 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1218 return v.visitReturn(this, d);
1219 }
1220 @Override
1221 public int getTag() {
1222 return RETURN;
1223 }
1224 }
1226 /**
1227 * A throw statement.
1228 */
1229 public static class JCThrow extends JCStatement implements ThrowTree {
1230 public JCExpression expr;
1231 protected JCThrow(JCTree expr) {
1232 this.expr = (JCExpression)expr;
1233 }
1234 @Override
1235 public void accept(Visitor v) { v.visitThrow(this); }
1237 public Kind getKind() { return Kind.THROW; }
1238 public JCExpression getExpression() { return expr; }
1239 @Override
1240 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1241 return v.visitThrow(this, d);
1242 }
1243 @Override
1244 public int getTag() {
1245 return THROW;
1246 }
1247 }
1249 /**
1250 * An assert statement.
1251 */
1252 public static class JCAssert extends JCStatement implements AssertTree {
1253 public JCExpression cond;
1254 public JCExpression detail;
1255 protected JCAssert(JCExpression cond, JCExpression detail) {
1256 this.cond = cond;
1257 this.detail = detail;
1258 }
1259 @Override
1260 public void accept(Visitor v) { v.visitAssert(this); }
1262 public Kind getKind() { return Kind.ASSERT; }
1263 public JCExpression getCondition() { return cond; }
1264 public JCExpression getDetail() { return detail; }
1265 @Override
1266 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1267 return v.visitAssert(this, d);
1268 }
1269 @Override
1270 public int getTag() {
1271 return ASSERT;
1272 }
1273 }
1275 /**
1276 * A method invocation
1277 */
1278 public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree {
1279 public List<JCExpression> typeargs;
1280 public JCExpression meth;
1281 public List<JCExpression> args;
1282 public Type varargsElement;
1283 protected JCMethodInvocation(List<JCExpression> typeargs,
1284 JCExpression meth,
1285 List<JCExpression> args)
1286 {
1287 this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
1288 : typeargs;
1289 this.meth = meth;
1290 this.args = args;
1291 }
1292 @Override
1293 public void accept(Visitor v) { v.visitApply(this); }
1295 public Kind getKind() { return Kind.METHOD_INVOCATION; }
1296 public List<JCExpression> getTypeArguments() {
1297 return typeargs;
1298 }
1299 public JCExpression getMethodSelect() { return meth; }
1300 public List<JCExpression> getArguments() {
1301 return args;
1302 }
1303 @Override
1304 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1305 return v.visitMethodInvocation(this, d);
1306 }
1307 @Override
1308 public JCMethodInvocation setType(Type type) {
1309 super.setType(type);
1310 return this;
1311 }
1312 @Override
1313 public int getTag() {
1314 return(APPLY);
1315 }
1316 }
1318 /**
1319 * A new(...) operation.
1320 */
1321 public static class JCNewClass extends JCExpression implements NewClassTree {
1322 public JCExpression encl;
1323 public List<JCExpression> typeargs;
1324 public JCExpression clazz;
1325 public List<JCExpression> args;
1326 public JCClassDecl def;
1327 public Symbol constructor;
1328 public Type varargsElement;
1329 protected JCNewClass(JCExpression encl,
1330 List<JCExpression> typeargs,
1331 JCExpression clazz,
1332 List<JCExpression> args,
1333 JCClassDecl def)
1334 {
1335 this.encl = encl;
1336 this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
1337 : typeargs;
1338 this.clazz = clazz;
1339 this.args = args;
1340 this.def = def;
1341 }
1342 @Override
1343 public void accept(Visitor v) { v.visitNewClass(this); }
1345 public Kind getKind() { return Kind.NEW_CLASS; }
1346 public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
1347 return encl;
1348 }
1349 public List<JCExpression> getTypeArguments() {
1350 return typeargs;
1351 }
1352 public JCExpression getIdentifier() { return clazz; }
1353 public List<JCExpression> getArguments() {
1354 return args;
1355 }
1356 public JCClassDecl getClassBody() { return def; }
1357 @Override
1358 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1359 return v.visitNewClass(this, d);
1360 }
1361 @Override
1362 public int getTag() {
1363 return NEWCLASS;
1364 }
1365 }
1367 /**
1368 * A new[...] operation.
1369 */
1370 public static class JCNewArray extends JCExpression implements NewArrayTree {
1371 public JCExpression elemtype;
1372 public List<JCExpression> dims;
1373 public List<JCExpression> elems;
1374 protected JCNewArray(JCExpression elemtype,
1375 List<JCExpression> dims,
1376 List<JCExpression> elems)
1377 {
1378 this.elemtype = elemtype;
1379 this.dims = dims;
1380 this.elems = elems;
1381 }
1382 @Override
1383 public void accept(Visitor v) { v.visitNewArray(this); }
1385 public Kind getKind() { return Kind.NEW_ARRAY; }
1386 public JCExpression getType() { return elemtype; }
1387 public List<JCExpression> getDimensions() {
1388 return dims;
1389 }
1390 public List<JCExpression> getInitializers() {
1391 return elems;
1392 }
1393 @Override
1394 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1395 return v.visitNewArray(this, d);
1396 }
1397 @Override
1398 public int getTag() {
1399 return NEWARRAY;
1400 }
1401 }
1403 /**
1404 * A parenthesized subexpression ( ... )
1405 */
1406 public static class JCParens extends JCExpression implements ParenthesizedTree {
1407 public JCExpression expr;
1408 protected JCParens(JCExpression expr) {
1409 this.expr = expr;
1410 }
1411 @Override
1412 public void accept(Visitor v) { v.visitParens(this); }
1414 public Kind getKind() { return Kind.PARENTHESIZED; }
1415 public JCExpression getExpression() { return expr; }
1416 @Override
1417 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1418 return v.visitParenthesized(this, d);
1419 }
1420 @Override
1421 public int getTag() {
1422 return PARENS;
1423 }
1424 }
1426 /**
1427 * A assignment with "=".
1428 */
1429 public static class JCAssign extends JCExpression implements AssignmentTree {
1430 public JCExpression lhs;
1431 public JCExpression rhs;
1432 protected JCAssign(JCExpression lhs, JCExpression rhs) {
1433 this.lhs = lhs;
1434 this.rhs = rhs;
1435 }
1436 @Override
1437 public void accept(Visitor v) { v.visitAssign(this); }
1439 public Kind getKind() { return Kind.ASSIGNMENT; }
1440 public JCExpression getVariable() { return lhs; }
1441 public JCExpression getExpression() { return rhs; }
1442 @Override
1443 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1444 return v.visitAssignment(this, d);
1445 }
1446 @Override
1447 public int getTag() {
1448 return ASSIGN;
1449 }
1450 }
1452 /**
1453 * An assignment with "+=", "|=" ...
1454 */
1455 public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree {
1456 private int opcode;
1457 public JCExpression lhs;
1458 public JCExpression rhs;
1459 public Symbol operator;
1460 protected JCAssignOp(int opcode, JCTree lhs, JCTree rhs, Symbol operator) {
1461 this.opcode = opcode;
1462 this.lhs = (JCExpression)lhs;
1463 this.rhs = (JCExpression)rhs;
1464 this.operator = operator;
1465 }
1466 @Override
1467 public void accept(Visitor v) { v.visitAssignop(this); }
1469 public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1470 public JCExpression getVariable() { return lhs; }
1471 public JCExpression getExpression() { return rhs; }
1472 public Symbol getOperator() {
1473 return operator;
1474 }
1475 @Override
1476 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1477 return v.visitCompoundAssignment(this, d);
1478 }
1479 @Override
1480 public int getTag() {
1481 return opcode;
1482 }
1483 }
1485 /**
1486 * A unary operation.
1487 */
1488 public static class JCUnary extends JCExpression implements UnaryTree {
1489 private int opcode;
1490 public JCExpression arg;
1491 public Symbol operator;
1492 protected JCUnary(int opcode, JCExpression arg) {
1493 this.opcode = opcode;
1494 this.arg = arg;
1495 }
1496 @Override
1497 public void accept(Visitor v) { v.visitUnary(this); }
1499 public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1500 public JCExpression getExpression() { return arg; }
1501 public Symbol getOperator() {
1502 return operator;
1503 }
1504 @Override
1505 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1506 return v.visitUnary(this, d);
1507 }
1508 @Override
1509 public int getTag() {
1510 return opcode;
1511 }
1513 public void setTag(int tag) {
1514 opcode = tag;
1515 }
1516 }
1518 /**
1519 * A binary operation.
1520 */
1521 public static class JCBinary extends JCExpression implements BinaryTree {
1522 private int opcode;
1523 public JCExpression lhs;
1524 public JCExpression rhs;
1525 public Symbol operator;
1526 protected JCBinary(int opcode,
1527 JCExpression lhs,
1528 JCExpression rhs,
1529 Symbol operator) {
1530 this.opcode = opcode;
1531 this.lhs = lhs;
1532 this.rhs = rhs;
1533 this.operator = operator;
1534 }
1535 @Override
1536 public void accept(Visitor v) { v.visitBinary(this); }
1538 public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
1539 public JCExpression getLeftOperand() { return lhs; }
1540 public JCExpression getRightOperand() { return rhs; }
1541 public Symbol getOperator() {
1542 return operator;
1543 }
1544 @Override
1545 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1546 return v.visitBinary(this, d);
1547 }
1548 @Override
1549 public int getTag() {
1550 return opcode;
1551 }
1552 }
1554 /**
1555 * A type cast.
1556 */
1557 public static class JCTypeCast extends JCExpression implements TypeCastTree {
1558 public JCTree clazz;
1559 public JCExpression expr;
1560 protected JCTypeCast(JCTree clazz, JCExpression expr) {
1561 this.clazz = clazz;
1562 this.expr = expr;
1563 }
1564 @Override
1565 public void accept(Visitor v) { v.visitTypeCast(this); }
1567 public Kind getKind() { return Kind.TYPE_CAST; }
1568 public JCTree getType() { return clazz; }
1569 public JCExpression getExpression() { return expr; }
1570 @Override
1571 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1572 return v.visitTypeCast(this, d);
1573 }
1574 @Override
1575 public int getTag() {
1576 return TYPECAST;
1577 }
1578 }
1580 /**
1581 * A type test.
1582 */
1583 public static class JCInstanceOf extends JCExpression implements InstanceOfTree {
1584 public JCExpression expr;
1585 public JCTree clazz;
1586 protected JCInstanceOf(JCExpression expr, JCTree clazz) {
1587 this.expr = expr;
1588 this.clazz = clazz;
1589 }
1590 @Override
1591 public void accept(Visitor v) { v.visitTypeTest(this); }
1593 public Kind getKind() { return Kind.INSTANCE_OF; }
1594 public JCTree getType() { return clazz; }
1595 public JCExpression getExpression() { return expr; }
1596 @Override
1597 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1598 return v.visitInstanceOf(this, d);
1599 }
1600 @Override
1601 public int getTag() {
1602 return TYPETEST;
1603 }
1604 }
1606 /**
1607 * An array selection
1608 */
1609 public static class JCArrayAccess extends JCExpression implements ArrayAccessTree {
1610 public JCExpression indexed;
1611 public JCExpression index;
1612 protected JCArrayAccess(JCExpression indexed, JCExpression index) {
1613 this.indexed = indexed;
1614 this.index = index;
1615 }
1616 @Override
1617 public void accept(Visitor v) { v.visitIndexed(this); }
1619 public Kind getKind() { return Kind.ARRAY_ACCESS; }
1620 public JCExpression getExpression() { return indexed; }
1621 public JCExpression getIndex() { return index; }
1622 @Override
1623 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1624 return v.visitArrayAccess(this, d);
1625 }
1626 @Override
1627 public int getTag() {
1628 return INDEXED;
1629 }
1630 }
1632 /**
1633 * Selects through packages and classes
1634 * @param selected selected Tree hierarchie
1635 * @param selector name of field to select thru
1636 * @param sym symbol of the selected class
1637 */
1638 public static class JCFieldAccess extends JCExpression implements MemberSelectTree {
1639 public JCExpression selected;
1640 public Name name;
1641 public Symbol sym;
1642 protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) {
1643 this.selected = selected;
1644 this.name = name;
1645 this.sym = sym;
1646 }
1647 @Override
1648 public void accept(Visitor v) { v.visitSelect(this); }
1650 public Kind getKind() { return Kind.MEMBER_SELECT; }
1651 public JCExpression getExpression() { return selected; }
1652 @Override
1653 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1654 return v.visitMemberSelect(this, d);
1655 }
1656 public Name getIdentifier() { return name; }
1657 @Override
1658 public int getTag() {
1659 return SELECT;
1660 }
1661 }
1663 /**
1664 * An identifier
1665 * @param idname the name
1666 * @param sym the symbol
1667 */
1668 public static class JCIdent extends JCExpression implements IdentifierTree {
1669 public Name name;
1670 public Symbol sym;
1671 protected JCIdent(Name name, Symbol sym) {
1672 this.name = name;
1673 this.sym = sym;
1674 }
1675 @Override
1676 public void accept(Visitor v) { v.visitIdent(this); }
1678 public Kind getKind() { return Kind.IDENTIFIER; }
1679 public Name getName() { return name; }
1680 @Override
1681 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1682 return v.visitIdentifier(this, d);
1683 }
1684 public int getTag() {
1685 return IDENT;
1686 }
1687 }
1689 /**
1690 * A constant value given literally.
1691 * @param value value representation
1692 */
1693 public static class JCLiteral extends JCExpression implements LiteralTree {
1694 public int typetag;
1695 public Object value;
1696 protected JCLiteral(int typetag, Object value) {
1697 this.typetag = typetag;
1698 this.value = value;
1699 }
1700 @Override
1701 public void accept(Visitor v) { v.visitLiteral(this); }
1703 public Kind getKind() {
1704 switch (typetag) {
1705 case TypeTags.INT:
1706 return Kind.INT_LITERAL;
1707 case TypeTags.LONG:
1708 return Kind.LONG_LITERAL;
1709 case TypeTags.FLOAT:
1710 return Kind.FLOAT_LITERAL;
1711 case TypeTags.DOUBLE:
1712 return Kind.DOUBLE_LITERAL;
1713 case TypeTags.BOOLEAN:
1714 return Kind.BOOLEAN_LITERAL;
1715 case TypeTags.CHAR:
1716 return Kind.CHAR_LITERAL;
1717 case TypeTags.CLASS:
1718 return Kind.STRING_LITERAL;
1719 case TypeTags.BOT:
1720 return Kind.NULL_LITERAL;
1721 default:
1722 throw new AssertionError("unknown literal kind " + this);
1723 }
1724 }
1725 public Object getValue() {
1726 switch (typetag) {
1727 case TypeTags.BOOLEAN:
1728 int bi = (Integer) value;
1729 return (bi != 0);
1730 case TypeTags.CHAR:
1731 int ci = (Integer) value;
1732 char c = (char) ci;
1733 if (c != ci)
1734 throw new AssertionError("bad value for char literal");
1735 return c;
1736 default:
1737 return value;
1738 }
1739 }
1740 @Override
1741 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1742 return v.visitLiteral(this, d);
1743 }
1744 @Override
1745 public JCLiteral setType(Type type) {
1746 super.setType(type);
1747 return this;
1748 }
1749 @Override
1750 public int getTag() {
1751 return LITERAL;
1752 }
1753 }
1755 /**
1756 * Identifies a basic type.
1757 * @param tag the basic type id
1758 * @see TypeTags
1759 */
1760 public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree {
1761 public int typetag;
1762 protected JCPrimitiveTypeTree(int typetag) {
1763 this.typetag = typetag;
1764 }
1765 @Override
1766 public void accept(Visitor v) { v.visitTypeIdent(this); }
1768 public Kind getKind() { return Kind.PRIMITIVE_TYPE; }
1769 public TypeKind getPrimitiveTypeKind() {
1770 switch (typetag) {
1771 case TypeTags.BOOLEAN:
1772 return TypeKind.BOOLEAN;
1773 case TypeTags.BYTE:
1774 return TypeKind.BYTE;
1775 case TypeTags.SHORT:
1776 return TypeKind.SHORT;
1777 case TypeTags.INT:
1778 return TypeKind.INT;
1779 case TypeTags.LONG:
1780 return TypeKind.LONG;
1781 case TypeTags.CHAR:
1782 return TypeKind.CHAR;
1783 case TypeTags.FLOAT:
1784 return TypeKind.FLOAT;
1785 case TypeTags.DOUBLE:
1786 return TypeKind.DOUBLE;
1787 case TypeTags.VOID:
1788 return TypeKind.VOID;
1789 default:
1790 throw new AssertionError("unknown primitive type " + this);
1791 }
1792 }
1793 @Override
1794 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1795 return v.visitPrimitiveType(this, d);
1796 }
1797 @Override
1798 public int getTag() {
1799 return TYPEIDENT;
1800 }
1801 }
1803 /**
1804 * An array type, A[]
1805 */
1806 public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree {
1807 public JCExpression elemtype;
1808 protected JCArrayTypeTree(JCExpression elemtype) {
1809 this.elemtype = elemtype;
1810 }
1811 @Override
1812 public void accept(Visitor v) { v.visitTypeArray(this); }
1814 public Kind getKind() { return Kind.ARRAY_TYPE; }
1815 public JCTree getType() { return elemtype; }
1816 @Override
1817 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1818 return v.visitArrayType(this, d);
1819 }
1820 @Override
1821 public int getTag() {
1822 return TYPEARRAY;
1823 }
1824 }
1826 /**
1827 * A parameterized type, T<...>
1828 */
1829 public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree {
1830 public JCExpression clazz;
1831 public List<JCExpression> arguments;
1832 protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) {
1833 this.clazz = clazz;
1834 this.arguments = arguments;
1835 }
1836 @Override
1837 public void accept(Visitor v) { v.visitTypeApply(this); }
1839 public Kind getKind() { return Kind.PARAMETERIZED_TYPE; }
1840 public JCTree getType() { return clazz; }
1841 public List<JCExpression> getTypeArguments() {
1842 return arguments;
1843 }
1844 @Override
1845 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1846 return v.visitParameterizedType(this, d);
1847 }
1848 @Override
1849 public int getTag() {
1850 return TYPEAPPLY;
1851 }
1852 }
1854 /**
1855 * A formal class parameter.
1856 * @param name name
1857 * @param bounds bounds
1858 */
1859 public static class JCTypeParameter extends JCTree implements TypeParameterTree {
1860 public Name name;
1861 public List<JCExpression> bounds;
1862 protected JCTypeParameter(Name name, List<JCExpression> bounds) {
1863 this.name = name;
1864 this.bounds = bounds;
1865 }
1866 @Override
1867 public void accept(Visitor v) { v.visitTypeParameter(this); }
1869 public Kind getKind() { return Kind.TYPE_PARAMETER; }
1870 public Name getName() { return name; }
1871 public List<JCExpression> getBounds() {
1872 return bounds;
1873 }
1874 @Override
1875 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1876 return v.visitTypeParameter(this, d);
1877 }
1878 @Override
1879 public int getTag() {
1880 return TYPEPARAMETER;
1881 }
1882 }
1884 public static class JCWildcard extends JCExpression implements WildcardTree {
1885 public TypeBoundKind kind;
1886 public JCTree inner;
1887 protected JCWildcard(TypeBoundKind kind, JCTree inner) {
1888 kind.getClass(); // null-check
1889 this.kind = kind;
1890 this.inner = inner;
1891 }
1892 @Override
1893 public void accept(Visitor v) { v.visitWildcard(this); }
1895 public Kind getKind() {
1896 switch (kind.kind) {
1897 case UNBOUND:
1898 return Kind.UNBOUNDED_WILDCARD;
1899 case EXTENDS:
1900 return Kind.EXTENDS_WILDCARD;
1901 case SUPER:
1902 return Kind.SUPER_WILDCARD;
1903 default:
1904 throw new AssertionError("Unknown wildcard bound " + kind);
1905 }
1906 }
1907 public JCTree getBound() { return inner; }
1908 @Override
1909 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1910 return v.visitWildcard(this, d);
1911 }
1912 @Override
1913 public int getTag() {
1914 return WILDCARD;
1915 }
1916 }
1918 public static class TypeBoundKind extends JCTree {
1919 public BoundKind kind;
1920 protected TypeBoundKind(BoundKind kind) {
1921 this.kind = kind;
1922 }
1923 @Override
1924 public void accept(Visitor v) { v.visitTypeBoundKind(this); }
1926 public Kind getKind() {
1927 throw new AssertionError("TypeBoundKind is not part of a public API");
1928 }
1929 @Override
1930 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1931 throw new AssertionError("TypeBoundKind is not part of a public API");
1932 }
1933 @Override
1934 public int getTag() {
1935 return TYPEBOUNDKIND;
1936 }
1937 }
1939 public static class JCAnnotation extends JCExpression implements AnnotationTree {
1940 public JCTree annotationType;
1941 public List<JCExpression> args;
1942 protected JCAnnotation(JCTree annotationType, List<JCExpression> args) {
1943 this.annotationType = annotationType;
1944 this.args = args;
1945 }
1946 @Override
1947 public void accept(Visitor v) { v.visitAnnotation(this); }
1949 public Kind getKind() { return Kind.ANNOTATION; }
1950 public JCTree getAnnotationType() { return annotationType; }
1951 public List<JCExpression> getArguments() {
1952 return args;
1953 }
1954 @Override
1955 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1956 return v.visitAnnotation(this, d);
1957 }
1958 @Override
1959 public int getTag() {
1960 return ANNOTATION;
1961 }
1962 }
1964 public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree {
1965 public long flags;
1966 public List<JCAnnotation> annotations;
1967 protected JCModifiers(long flags, List<JCAnnotation> annotations) {
1968 this.flags = flags;
1969 this.annotations = annotations;
1970 }
1971 @Override
1972 public void accept(Visitor v) { v.visitModifiers(this); }
1974 public Kind getKind() { return Kind.MODIFIERS; }
1975 public Set<Modifier> getFlags() {
1976 return Flags.asModifierSet(flags);
1977 }
1978 public List<JCAnnotation> getAnnotations() {
1979 return annotations;
1980 }
1981 @Override
1982 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1983 return v.visitModifiers(this, d);
1984 }
1985 @Override
1986 public int getTag() {
1987 return MODIFIERS;
1988 }
1989 }
1991 public static class JCErroneous extends JCExpression
1992 implements com.sun.source.tree.ErroneousTree {
1993 public List<? extends JCTree> errs;
1994 protected JCErroneous(List<? extends JCTree> errs) {
1995 this.errs = errs;
1996 }
1997 @Override
1998 public void accept(Visitor v) { v.visitErroneous(this); }
2000 public Kind getKind() { return Kind.ERRONEOUS; }
2002 public List<? extends JCTree> getErrorTrees() {
2003 return errs;
2004 }
2006 @Override
2007 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2008 return v.visitErroneous(this, d);
2009 }
2010 @Override
2011 public int getTag() {
2012 return ERRONEOUS;
2013 }
2014 }
2016 /** (let int x = 3; in x+2) */
2017 public static class LetExpr extends JCExpression {
2018 public List<JCVariableDecl> defs;
2019 public JCTree expr;
2020 protected LetExpr(List<JCVariableDecl> defs, JCTree expr) {
2021 this.defs = defs;
2022 this.expr = expr;
2023 }
2024 @Override
2025 public void accept(Visitor v) { v.visitLetExpr(this); }
2027 public Kind getKind() {
2028 throw new AssertionError("LetExpr is not part of a public API");
2029 }
2030 @Override
2031 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2032 throw new AssertionError("LetExpr is not part of a public API");
2033 }
2034 @Override
2035 public int getTag() {
2036 return LETEXPR;
2037 }
2038 }
2040 /** An interface for tree factories
2041 */
2042 public interface Factory {
2043 JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations,
2044 JCExpression pid,
2045 List<JCTree> defs);
2046 JCImport Import(JCTree qualid, boolean staticImport);
2047 JCClassDecl ClassDef(JCModifiers mods,
2048 Name name,
2049 List<JCTypeParameter> typarams,
2050 JCTree extending,
2051 List<JCExpression> implementing,
2052 List<JCTree> defs);
2053 JCMethodDecl MethodDef(JCModifiers mods,
2054 Name name,
2055 JCExpression restype,
2056 List<JCTypeParameter> typarams,
2057 List<JCVariableDecl> params,
2058 List<JCExpression> thrown,
2059 JCBlock body,
2060 JCExpression defaultValue);
2061 JCVariableDecl VarDef(JCModifiers mods,
2062 Name name,
2063 JCExpression vartype,
2064 JCExpression init);
2065 JCSkip Skip();
2066 JCBlock Block(long flags, List<JCStatement> stats);
2067 JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
2068 JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
2069 JCForLoop ForLoop(List<JCStatement> init,
2070 JCExpression cond,
2071 List<JCExpressionStatement> step,
2072 JCStatement body);
2073 JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
2074 JCLabeledStatement Labelled(Name label, JCStatement body);
2075 JCSwitch Switch(JCExpression selector, List<JCCase> cases);
2076 JCCase Case(JCExpression pat, List<JCStatement> stats);
2077 JCSynchronized Synchronized(JCExpression lock, JCBlock body);
2078 JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
2079 JCCatch Catch(JCVariableDecl param, JCBlock body);
2080 JCConditional Conditional(JCExpression cond,
2081 JCExpression thenpart,
2082 JCExpression elsepart);
2083 JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
2084 JCExpressionStatement Exec(JCExpression expr);
2085 JCBreak Break(Name label);
2086 JCContinue Continue(Name label);
2087 JCReturn Return(JCExpression expr);
2088 JCThrow Throw(JCTree expr);
2089 JCAssert Assert(JCExpression cond, JCExpression detail);
2090 JCMethodInvocation Apply(List<JCExpression> typeargs,
2091 JCExpression fn,
2092 List<JCExpression> args);
2093 JCNewClass NewClass(JCExpression encl,
2094 List<JCExpression> typeargs,
2095 JCExpression clazz,
2096 List<JCExpression> args,
2097 JCClassDecl def);
2098 JCNewArray NewArray(JCExpression elemtype,
2099 List<JCExpression> dims,
2100 List<JCExpression> elems);
2101 JCParens Parens(JCExpression expr);
2102 JCAssign Assign(JCExpression lhs, JCExpression rhs);
2103 JCAssignOp Assignop(int opcode, JCTree lhs, JCTree rhs);
2104 JCUnary Unary(int opcode, JCExpression arg);
2105 JCBinary Binary(int opcode, JCExpression lhs, JCExpression rhs);
2106 JCTypeCast TypeCast(JCTree expr, JCExpression type);
2107 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
2108 JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
2109 JCFieldAccess Select(JCExpression selected, Name selector);
2110 JCIdent Ident(Name idname);
2111 JCLiteral Literal(int tag, Object value);
2112 JCPrimitiveTypeTree TypeIdent(int typetag);
2113 JCArrayTypeTree TypeArray(JCExpression elemtype);
2114 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
2115 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
2116 JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
2117 TypeBoundKind TypeBoundKind(BoundKind kind);
2118 JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
2119 JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
2120 JCErroneous Erroneous(List<? extends JCTree> errs);
2121 LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr);
2122 }
2124 /** A generic visitor class for trees.
2125 */
2126 public static abstract class Visitor {
2127 public void visitTopLevel(JCCompilationUnit that) { visitTree(that); }
2128 public void visitImport(JCImport that) { visitTree(that); }
2129 public void visitClassDef(JCClassDecl that) { visitTree(that); }
2130 public void visitMethodDef(JCMethodDecl that) { visitTree(that); }
2131 public void visitVarDef(JCVariableDecl that) { visitTree(that); }
2132 public void visitSkip(JCSkip that) { visitTree(that); }
2133 public void visitBlock(JCBlock that) { visitTree(that); }
2134 public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); }
2135 public void visitWhileLoop(JCWhileLoop that) { visitTree(that); }
2136 public void visitForLoop(JCForLoop that) { visitTree(that); }
2137 public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
2138 public void visitLabelled(JCLabeledStatement that) { visitTree(that); }
2139 public void visitSwitch(JCSwitch that) { visitTree(that); }
2140 public void visitCase(JCCase that) { visitTree(that); }
2141 public void visitSynchronized(JCSynchronized that) { visitTree(that); }
2142 public void visitTry(JCTry that) { visitTree(that); }
2143 public void visitCatch(JCCatch that) { visitTree(that); }
2144 public void visitConditional(JCConditional that) { visitTree(that); }
2145 public void visitIf(JCIf that) { visitTree(that); }
2146 public void visitExec(JCExpressionStatement that) { visitTree(that); }
2147 public void visitBreak(JCBreak that) { visitTree(that); }
2148 public void visitContinue(JCContinue that) { visitTree(that); }
2149 public void visitReturn(JCReturn that) { visitTree(that); }
2150 public void visitThrow(JCThrow that) { visitTree(that); }
2151 public void visitAssert(JCAssert that) { visitTree(that); }
2152 public void visitApply(JCMethodInvocation that) { visitTree(that); }
2153 public void visitNewClass(JCNewClass that) { visitTree(that); }
2154 public void visitNewArray(JCNewArray that) { visitTree(that); }
2155 public void visitParens(JCParens that) { visitTree(that); }
2156 public void visitAssign(JCAssign that) { visitTree(that); }
2157 public void visitAssignop(JCAssignOp that) { visitTree(that); }
2158 public void visitUnary(JCUnary that) { visitTree(that); }
2159 public void visitBinary(JCBinary that) { visitTree(that); }
2160 public void visitTypeCast(JCTypeCast that) { visitTree(that); }
2161 public void visitTypeTest(JCInstanceOf that) { visitTree(that); }
2162 public void visitIndexed(JCArrayAccess that) { visitTree(that); }
2163 public void visitSelect(JCFieldAccess that) { visitTree(that); }
2164 public void visitIdent(JCIdent that) { visitTree(that); }
2165 public void visitLiteral(JCLiteral that) { visitTree(that); }
2166 public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); }
2167 public void visitTypeArray(JCArrayTypeTree that) { visitTree(that); }
2168 public void visitTypeApply(JCTypeApply that) { visitTree(that); }
2169 public void visitTypeParameter(JCTypeParameter that) { visitTree(that); }
2170 public void visitWildcard(JCWildcard that) { visitTree(that); }
2171 public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); }
2172 public void visitAnnotation(JCAnnotation that) { visitTree(that); }
2173 public void visitModifiers(JCModifiers that) { visitTree(that); }
2174 public void visitErroneous(JCErroneous that) { visitTree(that); }
2175 public void visitLetExpr(LetExpr that) { visitTree(that); }
2177 public void visitTree(JCTree that) { assert false; }
2178 }
2180 }