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