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