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