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