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