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 public boolean classDeclRemoved() { 1792 return false; 1793 } 1794 } 1795 1796 /** 1797 * A new[...] operation. 1798 */ 1799 public static class JCNewArray extends JCExpression implements NewArrayTree { 1800 public JCExpression elemtype; 1801 public List<JCExpression> dims; 1802 // type annotations on inner-most component 1803 public List<JCAnnotation> annotations; 1804 // type annotations on dimensions 1805 public List<List<JCAnnotation>> dimAnnotations; 1806 public List<JCExpression> elems; 1807 protected JCNewArray(JCExpression elemtype, 1808 List<JCExpression> dims, 1809 List<JCExpression> elems) 1810 { 1811 this.elemtype = elemtype; 1812 this.dims = dims; 1813 this.annotations = List.nil(); 1814 this.dimAnnotations = List.nil(); 1815 this.elems = elems; 1816 } 1817 @Override 1818 public void accept(Visitor v) { v.visitNewArray(this); } 1819 1820 @DefinedBy(Api.COMPILER_TREE) 1821 public Kind getKind() { return Kind.NEW_ARRAY; } 1822 @DefinedBy(Api.COMPILER_TREE) 1823 public JCExpression getType() { return elemtype; } 1824 @DefinedBy(Api.COMPILER_TREE) 1825 public List<JCExpression> getDimensions() { 1826 return dims; 1827 } 1828 @DefinedBy(Api.COMPILER_TREE) 1829 public List<JCExpression> getInitializers() { 1830 return elems; 1831 } 1832 @Override @DefinedBy(Api.COMPILER_TREE) 1833 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 1834 return v.visitNewArray(this, d); 1835 } 1836 @Override 1837 public Tag getTag() { 1838 return NEWARRAY; 1839 } 1840 1841 @Override @DefinedBy(Api.COMPILER_TREE) 1842 public List<JCAnnotation> getAnnotations() { 1843 return annotations; 1844 } 1845 1846 @Override @DefinedBy(Api.COMPILER_TREE) 1847 public List<List<JCAnnotation>> getDimAnnotations() { 1848 return dimAnnotations; 1849 } 1850 } 1851 1852 /** 1853 * A lambda expression. 1854 */ 1855 public static class JCLambda extends JCFunctionalExpression implements LambdaExpressionTree { 1856 1857 public enum ParameterKind { 1858 IMPLICIT, 1859 EXPLICIT 1860 } 1861 1862 public List<JCVariableDecl> params; 1863 public JCTree body; 1864 public boolean canCompleteNormally = true; 1865 public ParameterKind paramKind; 1866 1867 public JCLambda(List<JCVariableDecl> params, 1868 JCTree body) { 1869 this.params = params; 1870 this.body = body; 1871 if (params.isEmpty() || 1872 params.head.vartype != null) { 1873 paramKind = ParameterKind.EXPLICIT; 1874 } else { 1875 paramKind = ParameterKind.IMPLICIT; 1876 } 1877 } 1878 @Override 1879 public Tag getTag() { 1880 return LAMBDA; 1881 } 1882 @Override 1883 public void accept(Visitor v) { 1884 v.visitLambda(this); 1885 } 1886 @Override @DefinedBy(Api.COMPILER_TREE) 1887 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 1888 return v.visitLambdaExpression(this, d); 1889 } 1890 @DefinedBy(Api.COMPILER_TREE) 1891 public Kind getKind() { 1892 return Kind.LAMBDA_EXPRESSION; 1893 } 1894 @DefinedBy(Api.COMPILER_TREE) 1895 public JCTree getBody() { 1896 return body; 1897 } 1898 @DefinedBy(Api.COMPILER_TREE) 1899 public java.util.List<? extends VariableTree> getParameters() { 1900 return params; 1901 } 1902 @Override 1903 public JCLambda setType(Type type) { 1904 super.setType(type); 1905 return this; 1906 } 1907 @Override @DefinedBy(Api.COMPILER_TREE) 1908 public BodyKind getBodyKind() { 1909 return body.hasTag(BLOCK) ? 1910 BodyKind.STATEMENT : 1911 BodyKind.EXPRESSION; 1912 } 1913 } 1914 1915 /** 1916 * A parenthesized subexpression ( ... ) 1917 */ 1918 public static class JCParens extends JCExpression implements ParenthesizedTree { 1919 public JCExpression expr; 1920 protected JCParens(JCExpression expr) { 1921 this.expr = expr; 1922 } 1923 @Override 1924 public void accept(Visitor v) { v.visitParens(this); } 1925 1926 @DefinedBy(Api.COMPILER_TREE) 1927 public Kind getKind() { return Kind.PARENTHESIZED; } 1928 @DefinedBy(Api.COMPILER_TREE) 1929 public JCExpression getExpression() { return expr; } 1930 @Override @DefinedBy(Api.COMPILER_TREE) 1931 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 1932 return v.visitParenthesized(this, d); 1933 } 1934 @Override 1935 public Tag getTag() { 1936 return PARENS; 1937 } 1938 } 1939 1940 /** 1941 * A assignment with "=". 1942 */ 1943 public static class JCAssign extends JCExpression implements AssignmentTree { 1944 public JCExpression lhs; 1945 public JCExpression rhs; 1946 protected JCAssign(JCExpression lhs, JCExpression rhs) { 1947 this.lhs = lhs; 1948 this.rhs = rhs; 1949 } 1950 @Override 1951 public void accept(Visitor v) { v.visitAssign(this); } 1952 1953 @DefinedBy(Api.COMPILER_TREE) 1954 public Kind getKind() { return Kind.ASSIGNMENT; } 1955 @DefinedBy(Api.COMPILER_TREE) 1956 public JCExpression getVariable() { return lhs; } 1957 @DefinedBy(Api.COMPILER_TREE) 1958 public JCExpression getExpression() { return rhs; } 1959 @Override @DefinedBy(Api.COMPILER_TREE) 1960 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 1961 return v.visitAssignment(this, d); 1962 } 1963 @Override 1964 public Tag getTag() { 1965 return ASSIGN; 1966 } 1967 } 1968 1969 public static abstract class JCOperatorExpression extends JCExpression { 1970 public enum OperandPos { 1971 LEFT, 1972 RIGHT 1973 } 1974 1975 protected Tag opcode; 1976 public OperatorSymbol operator; 1977 1978 public OperatorSymbol getOperator() { 1979 return operator; 1980 } 1981 1982 @Override 1983 public Tag getTag() { 1984 return opcode; 1985 } 1986 1987 public abstract JCExpression getOperand(OperandPos pos); 1988 } 1989 1990 /** 1991 * An assignment with "+=", "|=" ... 1992 */ 1993 public static class JCAssignOp extends JCOperatorExpression implements CompoundAssignmentTree { 1994 public JCExpression lhs; 1995 public JCExpression rhs; 1996 protected JCAssignOp(Tag opcode, JCTree lhs, JCTree rhs, OperatorSymbol operator) { 1997 this.opcode = opcode; 1998 this.lhs = (JCExpression)lhs; 1999 this.rhs = (JCExpression)rhs; 2000 this.operator = operator; 2001 } 2002 @Override 2003 public void accept(Visitor v) { v.visitAssignop(this); } 2004 2005 @DefinedBy(Api.COMPILER_TREE) 2006 public Kind getKind() { return TreeInfo.tagToKind(getTag()); } 2007 @DefinedBy(Api.COMPILER_TREE) 2008 public JCExpression getVariable() { return lhs; } 2009 @DefinedBy(Api.COMPILER_TREE) 2010 public JCExpression getExpression() { return rhs; } 2011 @Override @DefinedBy(Api.COMPILER_TREE) 2012 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2013 return v.visitCompoundAssignment(this, d); 2014 } 2015 @Override 2016 public JCExpression getOperand(OperandPos pos) { 2017 return pos == OperandPos.LEFT ? lhs : rhs; 2018 } 2019 } 2020 2021 /** 2022 * A unary operation. 2023 */ 2024 public static class JCUnary extends JCOperatorExpression implements UnaryTree { 2025 public JCExpression arg; 2026 protected JCUnary(Tag opcode, JCExpression arg) { 2027 this.opcode = opcode; 2028 this.arg = arg; 2029 } 2030 @Override 2031 public void accept(Visitor v) { v.visitUnary(this); } 2032 2033 @DefinedBy(Api.COMPILER_TREE) 2034 public Kind getKind() { return TreeInfo.tagToKind(getTag()); } 2035 @DefinedBy(Api.COMPILER_TREE) 2036 public JCExpression getExpression() { return arg; } 2037 @Override @DefinedBy(Api.COMPILER_TREE) 2038 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2039 return v.visitUnary(this, d); 2040 } 2041 public void setTag(Tag tag) { 2042 opcode = tag; 2043 } 2044 @Override 2045 public JCExpression getOperand(OperandPos pos) { 2046 return arg; 2047 } 2048 } 2049 2050 /** 2051 * A binary operation. 2052 */ 2053 public static class JCBinary extends JCOperatorExpression implements BinaryTree { 2054 public JCExpression lhs; 2055 public JCExpression rhs; 2056 protected JCBinary(Tag opcode, 2057 JCExpression lhs, 2058 JCExpression rhs, 2059 OperatorSymbol operator) { 2060 this.opcode = opcode; 2061 this.lhs = lhs; 2062 this.rhs = rhs; 2063 this.operator = operator; 2064 } 2065 @Override 2066 public void accept(Visitor v) { v.visitBinary(this); } 2067 2068 @DefinedBy(Api.COMPILER_TREE) 2069 public Kind getKind() { return TreeInfo.tagToKind(getTag()); } 2070 @DefinedBy(Api.COMPILER_TREE) 2071 public JCExpression getLeftOperand() { return lhs; } 2072 @DefinedBy(Api.COMPILER_TREE) 2073 public JCExpression getRightOperand() { return rhs; } 2074 @Override @DefinedBy(Api.COMPILER_TREE) 2075 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2076 return v.visitBinary(this, d); 2077 } 2078 @Override 2079 public JCExpression getOperand(OperandPos pos) { 2080 return pos == OperandPos.LEFT ? lhs : rhs; 2081 } 2082 } 2083 2084 /** 2085 * A type cast. 2086 */ 2087 public static class JCTypeCast extends JCExpression implements TypeCastTree { 2088 public JCTree clazz; 2089 public JCExpression expr; 2090 protected JCTypeCast(JCTree clazz, JCExpression expr) { 2091 this.clazz = clazz; 2092 this.expr = expr; 2093 } 2094 @Override 2095 public void accept(Visitor v) { v.visitTypeCast(this); } 2096 2097 @DefinedBy(Api.COMPILER_TREE) 2098 public Kind getKind() { return Kind.TYPE_CAST; } 2099 @DefinedBy(Api.COMPILER_TREE) 2100 public JCTree getType() { return clazz; } 2101 @DefinedBy(Api.COMPILER_TREE) 2102 public JCExpression getExpression() { return expr; } 2103 @Override @DefinedBy(Api.COMPILER_TREE) 2104 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2105 return v.visitTypeCast(this, d); 2106 } 2107 @Override 2108 public Tag getTag() { 2109 return TYPECAST; 2110 } 2111 } 2112 2113 /** 2114 * A type test. 2115 */ 2116 public static class JCInstanceOf extends JCExpression implements InstanceOfTree { 2117 public JCExpression expr; 2118 public JCTree clazz; 2119 protected JCInstanceOf(JCExpression expr, JCTree clazz) { 2120 this.expr = expr; 2121 this.clazz = clazz; 2122 } 2123 @Override 2124 public void accept(Visitor v) { v.visitTypeTest(this); } 2125 2126 @DefinedBy(Api.COMPILER_TREE) 2127 public Kind getKind() { return Kind.INSTANCE_OF; } 2128 @DefinedBy(Api.COMPILER_TREE) 2129 public JCTree getType() { return clazz; } 2130 @DefinedBy(Api.COMPILER_TREE) 2131 public JCExpression getExpression() { return expr; } 2132 @Override @DefinedBy(Api.COMPILER_TREE) 2133 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2134 return v.visitInstanceOf(this, d); 2135 } 2136 @Override 2137 public Tag getTag() { 2138 return TYPETEST; 2139 } 2140 } 2141 2142 /** 2143 * An array selection 2144 */ 2145 public static class JCArrayAccess extends JCExpression implements ArrayAccessTree { 2146 public JCExpression indexed; 2147 public JCExpression index; 2148 protected JCArrayAccess(JCExpression indexed, JCExpression index) { 2149 this.indexed = indexed; 2150 this.index = index; 2151 } 2152 @Override 2153 public void accept(Visitor v) { v.visitIndexed(this); } 2154 2155 @DefinedBy(Api.COMPILER_TREE) 2156 public Kind getKind() { return Kind.ARRAY_ACCESS; } 2157 @DefinedBy(Api.COMPILER_TREE) 2158 public JCExpression getExpression() { return indexed; } 2159 @DefinedBy(Api.COMPILER_TREE) 2160 public JCExpression getIndex() { return index; } 2161 @Override @DefinedBy(Api.COMPILER_TREE) 2162 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2163 return v.visitArrayAccess(this, d); 2164 } 2165 @Override 2166 public Tag getTag() { 2167 return INDEXED; 2168 } 2169 } 2170 2171 /** 2172 * Selects through packages and classes 2173 */ 2174 public static class JCFieldAccess extends JCExpression implements MemberSelectTree { 2175 /** selected Tree hierarchy */ 2176 public JCExpression selected; 2177 /** name of field to select thru */ 2178 public Name name; 2179 /** symbol of the selected class */ 2180 public Symbol sym; 2181 protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) { 2182 this.selected = selected; 2183 this.name = name; 2184 this.sym = sym; 2185 } 2186 @Override 2187 public void accept(Visitor v) { v.visitSelect(this); } 2188 2189 @DefinedBy(Api.COMPILER_TREE) 2190 public Kind getKind() { return Kind.MEMBER_SELECT; } 2191 @DefinedBy(Api.COMPILER_TREE) 2192 public JCExpression getExpression() { return selected; } 2193 @Override @DefinedBy(Api.COMPILER_TREE) 2194 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2195 return v.visitMemberSelect(this, d); 2196 } 2197 @DefinedBy(Api.COMPILER_TREE) 2198 public Name getIdentifier() { return name; } 2199 @Override 2200 public Tag getTag() { 2201 return SELECT; 2202 } 2203 } 2204 2205 /** 2206 * Selects a member expression. 2207 */ 2208 public static class JCMemberReference extends JCFunctionalExpression implements MemberReferenceTree { 2209 2210 public ReferenceMode mode; 2211 public ReferenceKind kind; 2212 public Name name; 2213 public JCExpression expr; 2214 public List<JCExpression> typeargs; 2215 public Symbol sym; 2216 public Type varargsElement; 2217 public PolyKind refPolyKind; 2218 public boolean ownerAccessible; 2219 private OverloadKind overloadKind; 2220 public Type referentType; 2221 2222 public enum OverloadKind { 2223 OVERLOADED, 2224 UNOVERLOADED, 2225 ERROR 2226 } 2227 2228 /** 2229 * Javac-dependent classification for member references, based 2230 * on relevant properties w.r.t. code-generation 2231 */ 2232 public enum ReferenceKind { 2233 /** super # instMethod */ 2234 SUPER(ReferenceMode.INVOKE, false), 2235 /** Type # instMethod */ 2236 UNBOUND(ReferenceMode.INVOKE, true), 2237 /** Type # staticMethod */ 2238 STATIC(ReferenceMode.INVOKE, false), 2239 /** Expr # instMethod */ 2240 BOUND(ReferenceMode.INVOKE, false), 2241 /** Inner # new */ 2242 IMPLICIT_INNER(ReferenceMode.NEW, false), 2243 /** Toplevel # new */ 2244 TOPLEVEL(ReferenceMode.NEW, false), 2245 /** ArrayType # new */ 2246 ARRAY_CTOR(ReferenceMode.NEW, false); 2247 2248 final ReferenceMode mode; 2249 final boolean unbound; 2250 2251 private ReferenceKind(ReferenceMode mode, boolean unbound) { 2252 this.mode = mode; 2253 this.unbound = unbound; 2254 } 2255 2256 public boolean isUnbound() { 2257 return unbound; 2258 } 2259 } 2260 2261 public JCMemberReference(ReferenceMode mode, Name name, JCExpression expr, List<JCExpression> typeargs) { 2262 this.mode = mode; 2263 this.name = name; 2264 this.expr = expr; 2265 this.typeargs = typeargs; 2266 } 2267 @Override 2268 public void accept(Visitor v) { v.visitReference(this); } 2269 2270 @DefinedBy(Api.COMPILER_TREE) 2271 public Kind getKind() { return Kind.MEMBER_REFERENCE; } 2272 @Override @DefinedBy(Api.COMPILER_TREE) 2273 public ReferenceMode getMode() { return mode; } 2274 @Override @DefinedBy(Api.COMPILER_TREE) 2275 public JCExpression getQualifierExpression() { return expr; } 2276 @Override @DefinedBy(Api.COMPILER_TREE) 2277 public Name getName() { return name; } 2278 @Override @DefinedBy(Api.COMPILER_TREE) 2279 public List<JCExpression> getTypeArguments() { return typeargs; } 2280 2281 @Override @DefinedBy(Api.COMPILER_TREE) 2282 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2283 return v.visitMemberReference(this, d); 2284 } 2285 @Override 2286 public Tag getTag() { 2287 return REFERENCE; 2288 } 2289 public boolean hasKind(ReferenceKind kind) { 2290 return this.kind == kind; 2291 } 2292 2293 /** 2294 * @return the overloadKind 2295 */ 2296 public OverloadKind getOverloadKind() { 2297 return overloadKind; 2298 } 2299 2300 /** 2301 * @param overloadKind the overloadKind to set 2302 */ 2303 public void setOverloadKind(OverloadKind overloadKind) { 2304 this.overloadKind = overloadKind; 2305 } 2306 } 2307 2308 /** 2309 * An identifier 2310 */ 2311 public static class JCIdent extends JCExpression implements IdentifierTree { 2312 /** the name */ 2313 public Name name; 2314 /** the symbol */ 2315 public Symbol sym; 2316 protected JCIdent(Name name, Symbol sym) { 2317 this.name = name; 2318 this.sym = sym; 2319 } 2320 @Override 2321 public void accept(Visitor v) { v.visitIdent(this); } 2322 2323 @DefinedBy(Api.COMPILER_TREE) 2324 public Kind getKind() { return Kind.IDENTIFIER; } 2325 @DefinedBy(Api.COMPILER_TREE) 2326 public Name getName() { return name; } 2327 @Override @DefinedBy(Api.COMPILER_TREE) 2328 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2329 return v.visitIdentifier(this, d); 2330 } 2331 @Override 2332 public Tag getTag() { 2333 return IDENT; 2334 } 2335 } 2336 2337 /** 2338 * A constant value given literally. 2339 */ 2340 public static class JCLiteral extends JCExpression implements LiteralTree { 2341 public TypeTag typetag; 2342 /** value representation */ 2343 public Object value; 2344 protected JCLiteral(TypeTag typetag, Object value) { 2345 this.typetag = typetag; 2346 this.value = value; 2347 } 2348 @Override 2349 public void accept(Visitor v) { v.visitLiteral(this); } 2350 2351 @DefinedBy(Api.COMPILER_TREE) 2352 public Kind getKind() { 2353 return typetag.getKindLiteral(); 2354 } 2355 2356 @DefinedBy(Api.COMPILER_TREE) 2357 public Object getValue() { 2358 switch (typetag) { 2359 case BOOLEAN: 2360 int bi = (Integer) value; 2361 return (bi != 0); 2362 case CHAR: 2363 int ci = (Integer) value; 2364 char c = (char) ci; 2365 if (c != ci) 2366 throw new AssertionError("bad value for char literal"); 2367 return c; 2368 default: 2369 return value; 2370 } 2371 } 2372 @Override @DefinedBy(Api.COMPILER_TREE) 2373 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2374 return v.visitLiteral(this, d); 2375 } 2376 @Override 2377 public JCLiteral setType(Type type) { 2378 super.setType(type); 2379 return this; 2380 } 2381 @Override 2382 public Tag getTag() { 2383 return LITERAL; 2384 } 2385 } 2386 2387 /** 2388 * Identifies a basic type. 2389 * @see TypeTag 2390 */ 2391 public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree { 2392 /** the basic type id */ 2393 public TypeTag typetag; 2394 protected JCPrimitiveTypeTree(TypeTag typetag) { 2395 this.typetag = typetag; 2396 } 2397 @Override 2398 public void accept(Visitor v) { v.visitTypeIdent(this); } 2399 2400 @DefinedBy(Api.COMPILER_TREE) 2401 public Kind getKind() { return Kind.PRIMITIVE_TYPE; } 2402 @DefinedBy(Api.COMPILER_TREE) 2403 public TypeKind getPrimitiveTypeKind() { 2404 return typetag.getPrimitiveTypeKind(); 2405 } 2406 2407 @Override @DefinedBy(Api.COMPILER_TREE) 2408 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2409 return v.visitPrimitiveType(this, d); 2410 } 2411 @Override 2412 public Tag getTag() { 2413 return TYPEIDENT; 2414 } 2415 } 2416 2417 /** 2418 * An array type, A[] 2419 */ 2420 public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree { 2421 public JCExpression elemtype; 2422 protected JCArrayTypeTree(JCExpression elemtype) { 2423 this.elemtype = elemtype; 2424 } 2425 @Override 2426 public void accept(Visitor v) { v.visitTypeArray(this); } 2427 2428 @DefinedBy(Api.COMPILER_TREE) 2429 public Kind getKind() { return Kind.ARRAY_TYPE; } 2430 @DefinedBy(Api.COMPILER_TREE) 2431 public JCTree getType() { return elemtype; } 2432 @Override @DefinedBy(Api.COMPILER_TREE) 2433 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2434 return v.visitArrayType(this, d); 2435 } 2436 @Override 2437 public Tag getTag() { 2438 return TYPEARRAY; 2439 } 2440 } 2441 2442 /** 2443 * A parameterized type, {@literal T<...>} 2444 */ 2445 public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree { 2446 public JCExpression clazz; 2447 public List<JCExpression> arguments; 2448 protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) { 2449 this.clazz = clazz; 2450 this.arguments = arguments; 2451 } 2452 @Override 2453 public void accept(Visitor v) { v.visitTypeApply(this); } 2454 2455 @DefinedBy(Api.COMPILER_TREE) 2456 public Kind getKind() { return Kind.PARAMETERIZED_TYPE; } 2457 @DefinedBy(Api.COMPILER_TREE) 2458 public JCTree getType() { return clazz; } 2459 @DefinedBy(Api.COMPILER_TREE) 2460 public List<JCExpression> getTypeArguments() { 2461 return arguments; 2462 } 2463 @Override @DefinedBy(Api.COMPILER_TREE) 2464 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2465 return v.visitParameterizedType(this, d); 2466 } 2467 @Override 2468 public Tag getTag() { 2469 return TYPEAPPLY; 2470 } 2471 } 2472 2473 /** 2474 * A union type, T1 | T2 | ... Tn (used in multicatch statements) 2475 */ 2476 public static class JCTypeUnion extends JCExpression implements UnionTypeTree { 2477 2478 public List<JCExpression> alternatives; 2479 2480 protected JCTypeUnion(List<JCExpression> components) { 2481 this.alternatives = components; 2482 } 2483 @Override 2484 public void accept(Visitor v) { v.visitTypeUnion(this); } 2485 2486 @DefinedBy(Api.COMPILER_TREE) 2487 public Kind getKind() { return Kind.UNION_TYPE; } 2488 2489 @DefinedBy(Api.COMPILER_TREE) 2490 public List<JCExpression> getTypeAlternatives() { 2491 return alternatives; 2492 } 2493 @Override @DefinedBy(Api.COMPILER_TREE) 2494 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2495 return v.visitUnionType(this, d); 2496 } 2497 @Override 2498 public Tag getTag() { 2499 return TYPEUNION; 2500 } 2501 } 2502 2503 /** 2504 * An intersection type, {@code T1 & T2 & ... Tn} (used in cast expressions) 2505 */ 2506 public static class JCTypeIntersection extends JCExpression implements IntersectionTypeTree { 2507 2508 public List<JCExpression> bounds; 2509 2510 protected JCTypeIntersection(List<JCExpression> bounds) { 2511 this.bounds = bounds; 2512 } 2513 @Override 2514 public void accept(Visitor v) { v.visitTypeIntersection(this); } 2515 2516 @DefinedBy(Api.COMPILER_TREE) 2517 public Kind getKind() { return Kind.INTERSECTION_TYPE; } 2518 2519 @DefinedBy(Api.COMPILER_TREE) 2520 public List<JCExpression> getBounds() { 2521 return bounds; 2522 } 2523 @Override @DefinedBy(Api.COMPILER_TREE) 2524 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2525 return v.visitIntersectionType(this, d); 2526 } 2527 @Override 2528 public Tag getTag() { 2529 return TYPEINTERSECTION; 2530 } 2531 } 2532 2533 /** 2534 * A formal class parameter. 2535 */ 2536 public static class JCTypeParameter extends JCTree implements TypeParameterTree { 2537 /** name */ 2538 public Name name; 2539 /** bounds */ 2540 public List<JCExpression> bounds; 2541 /** type annotations on type parameter */ 2542 public List<JCAnnotation> annotations; 2543 protected JCTypeParameter(Name name, List<JCExpression> bounds, List<JCAnnotation> annotations) { 2544 this.name = name; 2545 this.bounds = bounds; 2546 this.annotations = annotations; 2547 } 2548 @Override 2549 public void accept(Visitor v) { v.visitTypeParameter(this); } 2550 2551 @DefinedBy(Api.COMPILER_TREE) 2552 public Kind getKind() { return Kind.TYPE_PARAMETER; } 2553 @DefinedBy(Api.COMPILER_TREE) 2554 public Name getName() { return name; } 2555 @DefinedBy(Api.COMPILER_TREE) 2556 public List<JCExpression> getBounds() { 2557 return bounds; 2558 } 2559 @DefinedBy(Api.COMPILER_TREE) 2560 public List<JCAnnotation> getAnnotations() { 2561 return annotations; 2562 } 2563 @Override @DefinedBy(Api.COMPILER_TREE) 2564 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2565 return v.visitTypeParameter(this, d); 2566 } 2567 @Override 2568 public Tag getTag() { 2569 return TYPEPARAMETER; 2570 } 2571 } 2572 2573 public static class JCWildcard extends JCExpression implements WildcardTree { 2574 public TypeBoundKind kind; 2575 public JCTree inner; 2576 protected JCWildcard(TypeBoundKind kind, JCTree inner) { 2577 this.kind = Assert.checkNonNull(kind); 2578 this.inner = inner; 2579 } 2580 @Override 2581 public void accept(Visitor v) { v.visitWildcard(this); } 2582 2583 @DefinedBy(Api.COMPILER_TREE) 2584 public Kind getKind() { 2585 switch (kind.kind) { 2586 case UNBOUND: 2587 return Kind.UNBOUNDED_WILDCARD; 2588 case EXTENDS: 2589 return Kind.EXTENDS_WILDCARD; 2590 case SUPER: 2591 return Kind.SUPER_WILDCARD; 2592 default: 2593 throw new AssertionError("Unknown wildcard bound " + kind); 2594 } 2595 } 2596 @DefinedBy(Api.COMPILER_TREE) 2597 public JCTree getBound() { return inner; } 2598 @Override @DefinedBy(Api.COMPILER_TREE) 2599 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2600 return v.visitWildcard(this, d); 2601 } 2602 @Override 2603 public Tag getTag() { 2604 return Tag.WILDCARD; 2605 } 2606 } 2607 2608 public static class TypeBoundKind extends JCTree { 2609 public BoundKind kind; 2610 protected TypeBoundKind(BoundKind kind) { 2611 this.kind = kind; 2612 } 2613 @Override 2614 public void accept(Visitor v) { v.visitTypeBoundKind(this); } 2615 2616 @DefinedBy(Api.COMPILER_TREE) 2617 public Kind getKind() { 2618 throw new AssertionError("TypeBoundKind is not part of a public API"); 2619 } 2620 @Override @DefinedBy(Api.COMPILER_TREE) 2621 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2622 throw new AssertionError("TypeBoundKind is not part of a public API"); 2623 } 2624 @Override 2625 public Tag getTag() { 2626 return TYPEBOUNDKIND; 2627 } 2628 } 2629 2630 public static class JCAnnotation extends JCExpression implements AnnotationTree { 2631 // Either Tag.ANNOTATION or Tag.TYPE_ANNOTATION 2632 private Tag tag; 2633 2634 public JCTree annotationType; 2635 public List<JCExpression> args; 2636 public Attribute.Compound attribute; 2637 2638 protected JCAnnotation(Tag tag, JCTree annotationType, List<JCExpression> args) { 2639 this.tag = tag; 2640 this.annotationType = annotationType; 2641 this.args = args; 2642 } 2643 2644 @Override 2645 public void accept(Visitor v) { v.visitAnnotation(this); } 2646 2647 @DefinedBy(Api.COMPILER_TREE) 2648 public Kind getKind() { return TreeInfo.tagToKind(getTag()); } 2649 2650 @DefinedBy(Api.COMPILER_TREE) 2651 public JCTree getAnnotationType() { return annotationType; } 2652 @DefinedBy(Api.COMPILER_TREE) 2653 public List<JCExpression> getArguments() { 2654 return args; 2655 } 2656 @Override @DefinedBy(Api.COMPILER_TREE) 2657 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2658 return v.visitAnnotation(this, d); 2659 } 2660 @Override 2661 public Tag getTag() { 2662 return tag; 2663 } 2664 } 2665 2666 public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree { 2667 public long flags; 2668 public List<JCAnnotation> annotations; 2669 protected JCModifiers(long flags, List<JCAnnotation> annotations) { 2670 this.flags = flags; 2671 this.annotations = annotations; 2672 } 2673 @Override 2674 public void accept(Visitor v) { v.visitModifiers(this); } 2675 2676 @DefinedBy(Api.COMPILER_TREE) 2677 public Kind getKind() { return Kind.MODIFIERS; } 2678 @DefinedBy(Api.COMPILER_TREE) 2679 public Set<Modifier> getFlags() { 2680 return Flags.asModifierSet(flags); 2681 } 2682 @DefinedBy(Api.COMPILER_TREE) 2683 public List<JCAnnotation> getAnnotations() { 2684 return annotations; 2685 } 2686 @Override @DefinedBy(Api.COMPILER_TREE) 2687 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2688 return v.visitModifiers(this, d); 2689 } 2690 @Override 2691 public Tag getTag() { 2692 return MODIFIERS; 2693 } 2694 } 2695 2696 public static class JCAnnotatedType extends JCExpression implements com.sun.source.tree.AnnotatedTypeTree { 2697 // type annotations 2698 public List<JCAnnotation> annotations; 2699 public JCExpression underlyingType; 2700 2701 protected JCAnnotatedType(List<JCAnnotation> annotations, JCExpression underlyingType) { 2702 Assert.check(annotations != null && annotations.nonEmpty()); 2703 this.annotations = annotations; 2704 this.underlyingType = underlyingType; 2705 } 2706 @Override 2707 public void accept(Visitor v) { v.visitAnnotatedType(this); } 2708 2709 @DefinedBy(Api.COMPILER_TREE) 2710 public Kind getKind() { return Kind.ANNOTATED_TYPE; } 2711 @DefinedBy(Api.COMPILER_TREE) 2712 public List<JCAnnotation> getAnnotations() { 2713 return annotations; 2714 } 2715 @DefinedBy(Api.COMPILER_TREE) 2716 public JCExpression getUnderlyingType() { 2717 return underlyingType; 2718 } 2719 @Override @DefinedBy(Api.COMPILER_TREE) 2720 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 2721 return v.visitAnnotatedType(this, d); 2722 } 2723 @Override 2724 public Tag getTag() { 2725 return ANNOTATED_TYPE; 2726 } 2727 } 2728 2729 public static abstract class JCDirective extends JCTree 2730 implements DirectiveTree { 2731 } 2732 2733 public static class JCModuleDecl extends JCTree implements ModuleTree { 2734 public JCModifiers mods; 2735 public ModuleType type; 2736 private final ModuleKind kind; 2737 public JCExpression qualId; 2738 public List<JCDirective> directives; 2739 public ModuleSymbol sym; 2740 2741 protected JCModuleDecl(JCModifiers mods, ModuleKind kind, 2742 JCExpression qualId, List<JCDirective> directives) { 2743 this.mods = mods; 2744 this.kind = kind; 2745 this.qualId = qualId; 2746 this.directives = directives; 2747 } 2748 2749 @Override 2750 public void accept(Visitor v) { v.visitModuleDef(this); } 2751 2752 @Override @DefinedBy(Api.COMPILER_TREE) 2753 public Kind getKind() { 2754 return Kind.MODULE; 2755 } 2756 2757 @Override @DefinedBy(Api.COMPILER_TREE) 2758 public List<? extends AnnotationTree> getAnnotations() { 2759 return mods.annotations; 2760 } 2761 2762 @Override @DefinedBy(Api.COMPILER_TREE) 2763 public ModuleKind getModuleType() { 2764 return kind; 2765 } 2766 2767 @Override @DefinedBy(Api.COMPILER_TREE) 2768 public JCExpression getName() { 2769 return qualId; 2770 } 2771 2772 @Override @DefinedBy(Api.COMPILER_TREE) 2773 public List<JCDirective> getDirectives() { 2774 return directives; 2775 } 2776 2777 @Override @DefinedBy(Api.COMPILER_TREE) 2778 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 2779 return v.visitModule(this, d); 2780 } 2781 2782 @Override 2783 public Tag getTag() { 2784 return MODULEDEF; 2785 } 2786 } 2787 2788 public static class JCExports extends JCDirective 2789 implements ExportsTree { 2790 public JCExpression qualid; 2791 public List<JCExpression> moduleNames; 2792 public ExportsDirective directive; 2793 2794 protected JCExports(JCExpression qualId, List<JCExpression> moduleNames) { 2795 this.qualid = qualId; 2796 this.moduleNames = moduleNames; 2797 } 2798 2799 @Override 2800 public void accept(Visitor v) { v.visitExports(this); } 2801 2802 @Override @DefinedBy(Api.COMPILER_TREE) 2803 public Kind getKind() { 2804 return Kind.EXPORTS; 2805 } 2806 2807 @Override @DefinedBy(Api.COMPILER_TREE) 2808 public JCExpression getPackageName() { 2809 return qualid; 2810 } 2811 2812 @Override @DefinedBy(Api.COMPILER_TREE) 2813 public List<JCExpression> getModuleNames() { 2814 return moduleNames; 2815 } 2816 2817 @Override @DefinedBy(Api.COMPILER_TREE) 2818 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 2819 return v.visitExports(this, d); 2820 } 2821 2822 @Override 2823 public Tag getTag() { 2824 return Tag.EXPORTS; 2825 } 2826 } 2827 2828 public static class JCOpens extends JCDirective 2829 implements OpensTree { 2830 public JCExpression qualid; 2831 public List<JCExpression> moduleNames; 2832 public OpensDirective directive; 2833 2834 protected JCOpens(JCExpression qualId, List<JCExpression> moduleNames) { 2835 this.qualid = qualId; 2836 this.moduleNames = moduleNames; 2837 } 2838 2839 @Override 2840 public void accept(Visitor v) { v.visitOpens(this); } 2841 2842 @Override @DefinedBy(Api.COMPILER_TREE) 2843 public Kind getKind() { 2844 return Kind.OPENS; 2845 } 2846 2847 @Override @DefinedBy(Api.COMPILER_TREE) 2848 public JCExpression getPackageName() { 2849 return qualid; 2850 } 2851 2852 @Override @DefinedBy(Api.COMPILER_TREE) 2853 public List<JCExpression> getModuleNames() { 2854 return moduleNames; 2855 } 2856 2857 @Override @DefinedBy(Api.COMPILER_TREE) 2858 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 2859 return v.visitOpens(this, d); 2860 } 2861 2862 @Override 2863 public Tag getTag() { 2864 return Tag.OPENS; 2865 } 2866 } 2867 2868 public static class JCProvides extends JCDirective 2869 implements ProvidesTree { 2870 public JCExpression serviceName; 2871 public List<JCExpression> implNames; 2872 2873 protected JCProvides(JCExpression serviceName, List<JCExpression> implNames) { 2874 this.serviceName = serviceName; 2875 this.implNames = implNames; 2876 } 2877 2878 @Override 2879 public void accept(Visitor v) { v.visitProvides(this); } 2880 2881 @Override @DefinedBy(Api.COMPILER_TREE) 2882 public Kind getKind() { 2883 return Kind.PROVIDES; 2884 } 2885 2886 @Override @DefinedBy(Api.COMPILER_TREE) 2887 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 2888 return v.visitProvides(this, d); 2889 } 2890 2891 @Override @DefinedBy(Api.COMPILER_TREE) 2892 public JCExpression getServiceName() { 2893 return serviceName; 2894 } 2895 2896 @Override @DefinedBy(Api.COMPILER_TREE) 2897 public List<JCExpression> getImplementationNames() { 2898 return implNames; 2899 } 2900 2901 @Override 2902 public Tag getTag() { 2903 return PROVIDES; 2904 } 2905 } 2906 2907 public static class JCRequires extends JCDirective 2908 implements RequiresTree { 2909 public boolean isTransitive; 2910 public boolean isStaticPhase; 2911 public JCExpression moduleName; 2912 public RequiresDirective directive; 2913 2914 protected JCRequires(boolean isTransitive, boolean isStaticPhase, JCExpression moduleName) { 2915 this.isTransitive = isTransitive; 2916 this.isStaticPhase = isStaticPhase; 2917 this.moduleName = moduleName; 2918 } 2919 2920 @Override 2921 public void accept(Visitor v) { v.visitRequires(this); } 2922 2923 @Override @DefinedBy(Api.COMPILER_TREE) 2924 public Kind getKind() { 2925 return Kind.REQUIRES; 2926 } 2927 2928 @Override @DefinedBy(Api.COMPILER_TREE) 2929 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 2930 return v.visitRequires(this, d); 2931 } 2932 2933 @Override @DefinedBy(Api.COMPILER_TREE) 2934 public boolean isTransitive() { 2935 return isTransitive; 2936 } 2937 2938 @Override @DefinedBy(Api.COMPILER_TREE) 2939 public boolean isStatic() { 2940 return isStaticPhase; 2941 } 2942 2943 @Override @DefinedBy(Api.COMPILER_TREE) 2944 public JCExpression getModuleName() { 2945 return moduleName; 2946 } 2947 2948 @Override 2949 public Tag getTag() { 2950 return REQUIRES; 2951 } 2952 } 2953 2954 public static class JCUses extends JCDirective 2955 implements UsesTree { 2956 public JCExpression qualid; 2957 2958 protected JCUses(JCExpression qualId) { 2959 this.qualid = qualId; 2960 } 2961 2962 @Override 2963 public void accept(Visitor v) { v.visitUses(this); } 2964 2965 @Override @DefinedBy(Api.COMPILER_TREE) 2966 public Kind getKind() { 2967 return Kind.USES; 2968 } 2969 2970 @Override @DefinedBy(Api.COMPILER_TREE) 2971 public JCExpression getServiceName() { 2972 return qualid; 2973 } 2974 2975 @Override @DefinedBy(Api.COMPILER_TREE) 2976 public <R, D> R accept(TreeVisitor<R, D> v, D d) { 2977 return v.visitUses(this, d); 2978 } 2979 2980 @Override 2981 public Tag getTag() { 2982 return USES; 2983 } 2984 } 2985 2986 public static class JCErroneous extends JCExpression 2987 implements ErroneousTree { 2988 public List<? extends JCTree> errs; 2989 protected JCErroneous(List<? extends JCTree> errs) { 2990 this.errs = errs; 2991 } 2992 @Override 2993 public void accept(Visitor v) { v.visitErroneous(this); } 2994 2995 @DefinedBy(Api.COMPILER_TREE) 2996 public Kind getKind() { return Kind.ERRONEOUS; } 2997 2998 @DefinedBy(Api.COMPILER_TREE) 2999 public List<? extends JCTree> getErrorTrees() { 3000 return errs; 3001 } 3002 3003 @Override @DefinedBy(Api.COMPILER_TREE) 3004 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 3005 return v.visitErroneous(this, d); 3006 } 3007 @Override 3008 public Tag getTag() { 3009 return ERRONEOUS; 3010 } 3011 } 3012 3013 /** (let int x = 3; in x+2) */ 3014 public static class LetExpr extends JCExpression { 3015 public List<JCStatement> defs; 3016 public JCExpression expr; 3017 protected LetExpr(List<JCStatement> defs, JCExpression expr) { 3018 this.defs = defs; 3019 this.expr = expr; 3020 } 3021 @Override 3022 public void accept(Visitor v) { v.visitLetExpr(this); } 3023 3024 @DefinedBy(Api.COMPILER_TREE) 3025 public Kind getKind() { 3026 throw new AssertionError("LetExpr is not part of a public API"); 3027 } 3028 @Override @DefinedBy(Api.COMPILER_TREE) 3029 public <R,D> R accept(TreeVisitor<R,D> v, D d) { 3030 throw new AssertionError("LetExpr is not part of a public API"); 3031 } 3032 @Override 3033 public Tag getTag() { 3034 return LETEXPR; 3035 } 3036 } 3037 3038 /** An interface for tree factories 3039 */ 3040 public interface Factory { 3041 JCCompilationUnit TopLevel(List<JCTree> defs); 3042 JCPackageDecl PackageDecl(List<JCAnnotation> annotations, 3043 JCExpression pid); 3044 JCImport Import(JCTree qualid, boolean staticImport); 3045 JCClassDecl ClassDef(JCModifiers mods, 3046 Name name, 3047 List<JCTypeParameter> typarams, 3048 JCExpression extending, 3049 List<JCExpression> implementing, 3050 List<JCTree> defs); 3051 JCMethodDecl MethodDef(JCModifiers mods, 3052 Name name, 3053 JCExpression restype, 3054 List<JCTypeParameter> typarams, 3055 JCVariableDecl recvparam, 3056 List<JCVariableDecl> params, 3057 List<JCExpression> thrown, 3058 JCBlock body, 3059 JCExpression defaultValue); 3060 JCVariableDecl VarDef(JCModifiers mods, 3061 Name name, 3062 JCExpression vartype, 3063 JCExpression init); 3064 JCSkip Skip(); 3065 JCBlock Block(long flags, List<JCStatement> stats); 3066 JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond); 3067 JCWhileLoop WhileLoop(JCExpression cond, JCStatement body); 3068 JCForLoop ForLoop(List<JCStatement> init, 3069 JCExpression cond, 3070 List<JCExpressionStatement> step, 3071 JCStatement body); 3072 JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body); 3073 JCLabeledStatement Labelled(Name label, JCStatement body); 3074 JCSwitch Switch(JCExpression selector, List<JCCase> cases); 3075 JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases); 3076 JCCase Case(@SuppressWarnings("removal") CaseKind caseKind, List<JCExpression> pat, 3077 List<JCStatement> stats, JCTree body); 3078 JCSynchronized Synchronized(JCExpression lock, JCBlock body); 3079 JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer); 3080 JCTry Try(List<JCTree> resources, 3081 JCBlock body, 3082 List<JCCatch> catchers, 3083 JCBlock finalizer); 3084 JCCatch Catch(JCVariableDecl param, JCBlock body); 3085 JCConditional Conditional(JCExpression cond, 3086 JCExpression thenpart, 3087 JCExpression elsepart); 3088 JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart); 3089 JCExpressionStatement Exec(JCExpression expr); 3090 JCBreak Break(JCExpression value); 3091 JCContinue Continue(Name label); 3092 JCReturn Return(JCExpression expr); 3093 JCThrow Throw(JCExpression expr); 3094 JCAssert Assert(JCExpression cond, JCExpression detail); 3095 JCMethodInvocation Apply(List<JCExpression> typeargs, 3096 JCExpression fn, 3097 List<JCExpression> args); 3098 JCNewClass NewClass(JCExpression encl, 3099 List<JCExpression> typeargs, 3100 JCExpression clazz, 3101 List<JCExpression> args, 3102 JCClassDecl def); 3103 JCNewArray NewArray(JCExpression elemtype, 3104 List<JCExpression> dims, 3105 List<JCExpression> elems); 3106 JCParens Parens(JCExpression expr); 3107 JCAssign Assign(JCExpression lhs, JCExpression rhs); 3108 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs); 3109 JCUnary Unary(Tag opcode, JCExpression arg); 3110 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs); 3111 JCTypeCast TypeCast(JCTree expr, JCExpression type); 3112 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); 3113 JCArrayAccess Indexed(JCExpression indexed, JCExpression index); 3114 JCFieldAccess Select(JCExpression selected, Name selector); 3115 JCIdent Ident(Name idname); 3116 JCLiteral Literal(TypeTag tag, Object value); 3117 JCPrimitiveTypeTree TypeIdent(TypeTag typetag); 3118 JCArrayTypeTree TypeArray(JCExpression elemtype); 3119 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments); 3120 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds); 3121 JCWildcard Wildcard(TypeBoundKind kind, JCTree type); 3122 TypeBoundKind TypeBoundKind(BoundKind kind); 3123 JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args); 3124 JCModifiers Modifiers(long flags, List<JCAnnotation> annotations); 3125 JCErroneous Erroneous(List<? extends JCTree> errs); 3126 JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives); 3127 JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames); 3128 JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames); 3129 JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames); 3130 JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId); 3131 JCUses Uses(JCExpression qualId); 3132 LetExpr LetExpr(List<JCStatement> defs, JCExpression expr); 3133 } 3134 3135 /** A generic visitor class for trees. 3136 */ 3137 public static abstract class Visitor { 3138 public void visitTopLevel(JCCompilationUnit that) { visitTree(that); } 3139 public void visitPackageDef(JCPackageDecl that) { visitTree(that); } 3140 public void visitImport(JCImport that) { visitTree(that); } 3141 public void visitClassDef(JCClassDecl that) { visitTree(that); } 3142 public void visitMethodDef(JCMethodDecl that) { visitTree(that); } 3143 public void visitVarDef(JCVariableDecl that) { visitTree(that); } 3144 public void visitSkip(JCSkip that) { visitTree(that); } 3145 public void visitBlock(JCBlock that) { visitTree(that); } 3146 public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); } 3147 public void visitWhileLoop(JCWhileLoop that) { visitTree(that); } 3148 public void visitForLoop(JCForLoop that) { visitTree(that); } 3149 public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); } 3150 public void visitLabelled(JCLabeledStatement that) { visitTree(that); } 3151 public void visitSwitch(JCSwitch that) { visitTree(that); } 3152 public void visitCase(JCCase that) { visitTree(that); } 3153 public void visitSwitchExpression(JCSwitchExpression that) { visitTree(that); } 3154 public void visitSynchronized(JCSynchronized that) { visitTree(that); } 3155 public void visitTry(JCTry that) { visitTree(that); } 3156 public void visitCatch(JCCatch that) { visitTree(that); } 3157 public void visitConditional(JCConditional that) { visitTree(that); } 3158 public void visitIf(JCIf that) { visitTree(that); } 3159 public void visitExec(JCExpressionStatement that) { visitTree(that); } 3160 public void visitBreak(JCBreak that) { visitTree(that); } 3161 public void visitContinue(JCContinue that) { visitTree(that); } 3162 public void visitReturn(JCReturn that) { visitTree(that); } 3163 public void visitThrow(JCThrow that) { visitTree(that); } 3164 public void visitAssert(JCAssert that) { visitTree(that); } 3165 public void visitApply(JCMethodInvocation that) { visitTree(that); } 3166 public void visitNewClass(JCNewClass that) { visitTree(that); } 3167 public void visitNewArray(JCNewArray that) { visitTree(that); } 3168 public void visitLambda(JCLambda that) { visitTree(that); } 3169 public void visitParens(JCParens that) { visitTree(that); } 3170 public void visitAssign(JCAssign that) { visitTree(that); } 3171 public void visitAssignop(JCAssignOp that) { visitTree(that); } 3172 public void visitUnary(JCUnary that) { visitTree(that); } 3173 public void visitBinary(JCBinary that) { visitTree(that); } 3174 public void visitTypeCast(JCTypeCast that) { visitTree(that); } 3175 public void visitTypeTest(JCInstanceOf that) { visitTree(that); } 3176 public void visitIndexed(JCArrayAccess that) { visitTree(that); } 3177 public void visitSelect(JCFieldAccess that) { visitTree(that); } 3178 public void visitReference(JCMemberReference that) { visitTree(that); } 3179 public void visitIdent(JCIdent that) { visitTree(that); } 3180 public void visitLiteral(JCLiteral that) { visitTree(that); } 3181 public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); } 3182 public void visitTypeArray(JCArrayTypeTree that) { visitTree(that); } 3183 public void visitTypeApply(JCTypeApply that) { visitTree(that); } 3184 public void visitTypeUnion(JCTypeUnion that) { visitTree(that); } 3185 public void visitTypeIntersection(JCTypeIntersection that) { visitTree(that); } 3186 public void visitTypeParameter(JCTypeParameter that) { visitTree(that); } 3187 public void visitWildcard(JCWildcard that) { visitTree(that); } 3188 public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); } 3189 public void visitAnnotation(JCAnnotation that) { visitTree(that); } 3190 public void visitModifiers(JCModifiers that) { visitTree(that); } 3191 public void visitAnnotatedType(JCAnnotatedType that) { visitTree(that); } 3192 public void visitErroneous(JCErroneous that) { visitTree(that); } 3193 public void visitModuleDef(JCModuleDecl that) { visitTree(that); } 3194 public void visitExports(JCExports that) { visitTree(that); } 3195 public void visitOpens(JCOpens that) { visitTree(that); } 3196 public void visitProvides(JCProvides that) { visitTree(that); } 3197 public void visitRequires(JCRequires that) { visitTree(that); } 3198 public void visitUses(JCUses that) { visitTree(that); } 3199 public void visitLetExpr(LetExpr that) { visitTree(that); } 3200 3201 public void visitTree(JCTree that) { Assert.error(); } 3202 } 3203 3204 }