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