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