| 1 | /* |
| 2 | * Copyright 1999-2006 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package com.sun.tools.javac.tree; |
| 27 | |
| 28 | import java.util.*; |
| 29 | |
| 30 | import java.io.File; |
| 31 | import java.io.IOException; |
| 32 | import java.io.PrintWriter; |
| 33 | import java.io.StringWriter; |
| 34 | import javax.lang.model.element.Modifier; |
| 35 | import javax.lang.model.type.TypeKind; |
| 36 | import javax.tools.JavaFileObject; |
| 37 | |
| 38 | import com.sun.tools.javac.util.*; |
| 39 | import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
| 40 | import com.sun.tools.javac.util.List; |
| 41 | import com.sun.tools.javac.code.*; |
| 42 | import com.sun.tools.javac.code.Scope; |
| 43 | import com.sun.tools.javac.code.Symbol.*; |
| 44 | import com.sun.source.tree.Tree; |
| 45 | import com.sun.source.tree.*; |
| 46 | |
| 47 | import static com.sun.tools.javac.code.BoundKind.*; |
| 48 | |
| 49 | /** |
| 50 | * Root class for abstract syntax tree nodes. It provides definitions |
| 51 | * for specific tree nodes as subclasses nested inside. |
| 52 | * |
| 53 | * <p>Each subclass is highly standardized. It generally contains |
| 54 | * only tree fields for the syntactic subcomponents of the node. Some |
| 55 | * classes that represent identifier uses or definitions also define a |
| 56 | * Symbol field that denotes the represented identifier. Classes for |
| 57 | * non-local jumps also carry the jump target as a field. The root |
| 58 | * class Tree itself defines fields for the tree's type and position. |
| 59 | * No other fields are kept in a tree node; instead parameters are |
| 60 | * passed to methods accessing the node. |
| 61 | * |
| 62 | * <p>Except for the methods defined by com.sun.source, the only |
| 63 | * method defined in subclasses is `visit' which applies a given |
| 64 | * visitor to the tree. The actual tree processing is done by visitor |
| 65 | * classes in other packages. The abstract class Visitor, as well as |
| 66 | * an Factory interface for trees, are defined as inner classes in |
| 67 | * Tree. |
| 68 | * |
| 69 | * <p>To avoid ambiguities with the Tree API in com.sun.source all sub |
| 70 | * classes should, by convention, start with JC (javac). |
| 71 | * |
| 72 | * <p><b>This is NOT part of any API supported by Sun Microsystems. |
| 73 | * If you write code that depends on this, you do so at your own risk. |
| 74 | * This code and its internal interfaces are subject to change or |
| 75 | * deletion without notice.</b> |
| 76 | * |
| 77 | * @see TreeMaker |
| 78 | * @see TreeInfo |
| 79 | * @see TreeTranslator |
| 80 | * @see Pretty |
| 81 | */ |
| 82 | public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition { |
| 83 | |
| 84 | /* Tree tag values, identifying kinds of trees */ |
| 85 | |
| 86 | /** Toplevel nodes, of type TopLevel, representing entire source files. |
| 87 | */ |
| 88 | public static final int TOPLEVEL = 1; |
| 89 | |
| 90 | /** Import clauses, of type Import. |
| 91 | */ |
| 92 | public static final int IMPORT = TOPLEVEL + 1; |
| 93 | |
| 94 | /** Class definitions, of type ClassDef. |
| 95 | */ |
| 96 | public static final int CLASSDEF = IMPORT + 1; |
| 97 | |
| 98 | /** Method definitions, of type MethodDef. |
| 99 | */ |
| 100 | public static final int METHODDEF = CLASSDEF + 1; |
| 101 | |
| 102 | /** Variable definitions, of type VarDef. |
| 103 | */ |
| 104 | public static final int VARDEF = METHODDEF + 1; |
| 105 | |
| 106 | /** The no-op statement ";", of type Skip |
| 107 | */ |
| 108 | public static final int SKIP = VARDEF + 1; |
| 109 | |
| 110 | /** Blocks, of type Block. |
| 111 | */ |
| 112 | public static final int BLOCK = SKIP + 1; |
| 113 | |
| 114 | /** Do-while loops, of type DoLoop. |
| 115 | */ |
| 116 | public static final int DOLOOP = BLOCK + 1; |
| 117 | |
| 118 | /** While-loops, of type WhileLoop. |
| 119 | */ |
| 120 | public static final int WHILELOOP = DOLOOP + 1; |
| 121 | |
| 122 | /** For-loops, of type ForLoop. |
| 123 | */ |
| 124 | public static final int FORLOOP = WHILELOOP + 1; |
| 125 | |
| 126 | /** Foreach-loops, of type ForeachLoop. |
| 127 | */ |
| 128 | public static final int FOREACHLOOP = FORLOOP + 1; |
| 129 | |
| 130 | /** Labelled statements, of type Labelled. |
| 131 | */ |
| 132 | public static final int LABELLED = FOREACHLOOP + 1; |
| 133 | |
| 134 | /** Switch statements, of type Switch. |
| 135 | */ |
| 136 | public static final int SWITCH = LABELLED + 1; |
| 137 | |
| 138 | /** Case parts in switch statements, of type Case. |
| 139 | */ |
| 140 | public static final int CASE = SWITCH + 1; |
| 141 | |
| 142 | /** Synchronized statements, of type Synchonized. |
| 143 | */ |
| 144 | public static final int SYNCHRONIZED = CASE + 1; |
| 145 | |
| 146 | /** Try statements, of type Try. |
| 147 | */ |
| 148 | public static final int TRY = SYNCHRONIZED + 1; |
| 149 | |
| 150 | /** Catch clauses in try statements, of type Catch. |
| 151 | */ |
| 152 | public static final int CATCH = TRY + 1; |
| 153 | |
| 154 | /** Conditional expressions, of type Conditional. |
| 155 | */ |
| 156 | public static final int CONDEXPR = CATCH + 1; |
| 157 | |
| 158 | /** Conditional statements, of type If. |
| 159 | */ |
| 160 | public static final int IF = CONDEXPR + 1; |
| 161 | |
| 162 | /** Expression statements, of type Exec. |
| 163 | */ |
| 164 | public static final int EXEC = IF + 1; |
| 165 | |
| 166 | /** Break statements, of type Break. |
| 167 | */ |
| 168 | public static final int BREAK = EXEC + 1; |
| 169 | |
| 170 | /** Continue statements, of type Continue. |
| 171 | */ |
| 172 | public static final int CONTINUE = BREAK + 1; |
| 173 | |
| 174 | /** Return statements, of type Return. |
| 175 | */ |
| 176 | public static final int RETURN = CONTINUE + 1; |
| 177 | |
| 178 | /** Throw statements, of type Throw. |
| 179 | */ |
| 180 | public static final int THROW = RETURN + 1; |
| 181 | |
| 182 | /** Assert statements, of type Assert. |
| 183 | */ |
| 184 | public static final int ASSERT = THROW + 1; |
| 185 | |
| 186 | /** Method invocation expressions, of type Apply. |
| 187 | */ |
| 188 | public static final int APPLY = ASSERT + 1; |
| 189 | |
| 190 | /** Class instance creation expressions, of type NewClass. |
| 191 | */ |
| 192 | public static final int NEWCLASS = APPLY + 1; |
| 193 | |
| 194 | /** Array creation expressions, of type NewArray. |
| 195 | */ |
| 196 | public static final int NEWARRAY = NEWCLASS + 1; |
| 197 | |
| 198 | /** Parenthesized subexpressions, of type Parens. |
| 199 | */ |
| 200 | public static final int PARENS = NEWARRAY + 1; |
| 201 | |
| 202 | /** Assignment expressions, of type Assign. |
| 203 | */ |
| 204 | public static final int ASSIGN = PARENS + 1; |
| 205 | |
| 206 | /** Type cast expressions, of type TypeCast. |
| 207 | */ |
| 208 | public static final int TYPECAST = ASSIGN + 1; |
| 209 | |
| 210 | /** Type test expressions, of type TypeTest. |
| 211 | */ |
| 212 | public static final int TYPETEST = TYPECAST + 1; |
| 213 | |
| 214 | /** Indexed array expressions, of type Indexed. |
| 215 | */ |
| 216 | public static final int INDEXED = TYPETEST + 1; |
| 217 | |
| 218 | /** Selections, of type Select. |
| 219 | */ |
| 220 | public static final int SELECT = INDEXED + 1; |
| 221 | |
| 222 | /** Simple identifiers, of type Ident. |
| 223 | */ |
| 224 | public static final int IDENT = SELECT + 1; |
| 225 | |
| 226 | /** Literals, of type Literal. |
| 227 | */ |
| 228 | public static final int LITERAL = IDENT + 1; |
| 229 | |
| 230 | /** Basic type identifiers, of type TypeIdent. |
| 231 | */ |
| 232 | public static final int TYPEIDENT = LITERAL + 1; |
| 233 | |
| 234 | /** Array types, of type TypeArray. |
| 235 | */ |
| 236 | public static final int TYPEARRAY = TYPEIDENT + 1; |
| 237 | |
| 238 | /** Parameterized types, of type TypeApply. |
| 239 | */ |
| 240 | public static final int TYPEAPPLY = TYPEARRAY + 1; |
| 241 | |
| 242 | /** Formal type parameters, of type TypeParameter. |
| 243 | */ |
| 244 | public static final int TYPEPARAMETER = TYPEAPPLY + 1; |
| 245 | |
| 246 | /** Type argument. |
| 247 | */ |
| 248 | public static final int WILDCARD = TYPEPARAMETER + 1; |
| 249 | |
| 250 | /** Bound kind: extends, super, exact, or unbound |
| 251 | */ |
| 252 | public static final int TYPEBOUNDKIND = WILDCARD + 1; |
| 253 | |
| 254 | /** metadata: Annotation. |
| 255 | */ |
| 256 | public static final int ANNOTATION = TYPEBOUNDKIND + 1; |
| 257 | |
| 258 | /** metadata: Modifiers |
| 259 | */ |
| 260 | public static final int MODIFIERS = ANNOTATION + 1; |
| 261 | |
| 262 | /** Error trees, of type Erroneous. |
| 263 | */ |
| 264 | public static final int ERRONEOUS = MODIFIERS + 1; |
| 265 | |
| 266 | /** Unary operators, of type Unary. |
| 267 | */ |
| 268 | public static final int POS = ERRONEOUS + 1; // + |
| 269 | public static final int NEG = POS + 1; // - |
| 270 | public static final int NOT = NEG + 1; // ! |
| 271 | public static final int COMPL = NOT + 1; // ~ |
| 272 | public static final int PREINC = COMPL + 1; // ++ _ |
| 273 | public static final int PREDEC = PREINC + 1; // -- _ |
| 274 | public static final int POSTINC = PREDEC + 1; // _ ++ |
| 275 | public static final int POSTDEC = POSTINC + 1; // _ -- |
| 276 | |
| 277 | /** unary operator for null reference checks, only used internally. |
| 278 | */ |
| 279 | public static final int NULLCHK = POSTDEC + 1; |
| 280 | |
| 281 | /** Binary operators, of type Binary. |
| 282 | */ |
| 283 | public static final int OR = NULLCHK + 1; // || |
| 284 | public static final int AND = OR + 1; // && |
| 285 | public static final int BITOR = AND + 1; // | |
| 286 | public static final int BITXOR = BITOR + 1; // ^ |
| 287 | public static final int BITAND = BITXOR + 1; // & |
| 288 | public static final int EQ = BITAND + 1; // == |
| 289 | public static final int NE = EQ + 1; // != |
| 290 | public static final int LT = NE + 1; // < |
| 291 | public static final int GT = LT + 1; // > |
| 292 | public static final int LE = GT + 1; // <= |
| 293 | public static final int GE = LE + 1; // >= |
| 294 | public static final int SL = GE + 1; // << |
| 295 | public static final int SR = SL + 1; // >> |
| 296 | public static final int USR = SR + 1; // >>> |
| 297 | public static final int PLUS = USR + 1; // + |
| 298 | public static final int MINUS = PLUS + 1; // - |
| 299 | public static final int MUL = MINUS + 1; // * |
| 300 | public static final int DIV = MUL + 1; // / |
| 301 | public static final int MOD = DIV + 1; // % |
| 302 | |
| 303 | /** Assignment operators, of type Assignop. |
| 304 | */ |
| 305 | public static final int BITOR_ASG = MOD + 1; // |= |
| 306 | public static final int BITXOR_ASG = BITOR_ASG + 1; // ^= |
| 307 | public static final int BITAND_ASG = BITXOR_ASG + 1; // &= |
| 308 | |
| 309 | public static final int SL_ASG = SL + BITOR_ASG - BITOR; // <<= |
| 310 | public static final int SR_ASG = SL_ASG + 1; // >>= |
| 311 | public static final int USR_ASG = SR_ASG + 1; // >>>= |
| 312 | public static final int PLUS_ASG = USR_ASG + 1; // += |
| 313 | public static final int MINUS_ASG = PLUS_ASG + 1; // -= |
| 314 | public static final int MUL_ASG = MINUS_ASG + 1; // *= |
| 315 | public static final int DIV_ASG = MUL_ASG + 1; // /= |
| 316 | public static final int MOD_ASG = DIV_ASG + 1; // %= |
| 317 | |
| 318 | /** A synthetic let expression, of type LetExpr. |
| 319 | */ |
| 320 | public static final int LETEXPR = MOD_ASG + 1; // ala scheme |
| 321 | |
| 322 | |
| 323 | /** The offset between assignment operators and normal operators. |
| 324 | */ |
| 325 | public static final int ASGOffset = BITOR_ASG - BITOR; |
| 326 | |
| 327 | /* The (encoded) position in the source file. @see util.Position. |
| 328 | */ |
| 329 | public int pos; |
| 330 | |
| 331 | /* The type of this node. |
| 332 | */ |
| 333 | public Type type; |
| 334 | |
| 335 | /* The tag of this node -- one of the constants declared above. |
| 336 | */ |
| 337 | public abstract int getTag(); |
| 338 | |
| 339 | /** Convert a tree to a pretty-printed string. */ |
| 340 | public String toString() { |
| 341 | StringWriter s = new StringWriter(); |
| 342 | try { |
| 343 | new Pretty(s, false).printExpr(this); |
| 344 | } |
| 345 | catch (IOException e) { |
| 346 | // should never happen, because StringWriter is defined |
| 347 | // never to throw any IOExceptions |
| 348 | throw new AssertionError(e); |
| 349 | } |
| 350 | return s.toString(); |
| 351 | } |
| 352 | |
| 353 | /** Set position field and return this tree. |
| 354 | */ |
| 355 | public JCTree setPos(int pos) { |
| 356 | this.pos = pos; |
| 357 | return this; |
| 358 | } |
| 359 | |
| 360 | /** Set type field and return this tree. |
| 361 | */ |
| 362 | public JCTree setType(Type type) { |
| 363 | this.type = type; |
| 364 | return this; |
| 365 | } |
| 366 | |
| 367 | /** Visit this tree with a given visitor. |
| 368 | */ |
| 369 | public abstract void accept(Visitor v); |
| 370 | |
| 371 | public abstract <R,D> R accept(TreeVisitor<R,D> v, D d); |
| 372 | |
| 373 | /** Return a shallow copy of this tree. |
| 374 | */ |
| 375 | public Object clone() { |
| 376 | try { |
| 377 | return super.clone(); |
| 378 | } catch(CloneNotSupportedException e) { |
| 379 | throw new RuntimeException(e); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | /** Get a default position for this tree node. |
| 384 | */ |
| 385 | public DiagnosticPosition pos() { |
| 386 | return this; |
| 387 | } |
| 388 | |
| 389 | // for default DiagnosticPosition |
| 390 | public JCTree getTree() { |
| 391 | return this; |
| 392 | } |
| 393 | |
| 394 | // for default DiagnosticPosition |
| 395 | public int getStartPosition() { |
| 396 | return TreeInfo.getStartPos(this); |
| 397 | } |
| 398 | |
| 399 | // for default DiagnosticPosition |
| 400 | public int getPreferredPosition() { |
| 401 | return pos; |
| 402 | } |
| 403 | |
| 404 | // for default DiagnosticPosition |
| 405 | public int getEndPosition(Map<JCTree, Integer> endPosTable) { |
| 406 | return TreeInfo.getEndPos(this, endPosTable); |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Everything in one source file is kept in a TopLevel structure. |
| 411 | * @param pid The tree representing the package clause. |
| 412 | * @param sourcefile The source file name. |
| 413 | * @param defs All definitions in this file (ClassDef, Import, and Skip) |
| 414 | * @param packge The package it belongs to. |
| 415 | * @param namedImportScope A scope for all named imports. |
| 416 | * @param starImportScope A scope for all import-on-demands. |
| 417 | * @param lineMap Line starting positions, defined only |
| 418 | * if option -g is set. |
| 419 | * @param docComments A hashtable that stores all documentation comments |
| 420 | * indexed by the tree nodes they refer to. |
| 421 | * defined only if option -s is set. |
| 422 | * @param endPositions A hashtable that stores ending positions of source |
| 423 | * ranges indexed by the tree nodes they belong to. |
| 424 | * Defined only if option -Xjcov is set. |
| 425 | */ |
| 426 | public static class JCCompilationUnit extends JCTree implements CompilationUnitTree { |
| 427 | public List<JCAnnotation> packageAnnotations; |
| 428 | public JCExpression pid; |
| 429 | public List<JCTree> defs; |
| 430 | public JavaFileObject sourcefile; |
| 431 | public PackageSymbol packge; |
| 432 | public Scope namedImportScope; |
| 433 | public Scope starImportScope; |
| 434 | public long flags; |
| 435 | public Position.LineMap lineMap = null; |
| 436 | public Map<JCTree, String> docComments = null; |
| 437 | public Map<JCTree, Integer> endPositions = null; |
| 438 | protected JCCompilationUnit(List<JCAnnotation> packageAnnotations, |
| 439 | JCExpression pid, |
| 440 | List<JCTree> defs, |
| 441 | JavaFileObject sourcefile, |
| 442 | PackageSymbol packge, |
| 443 | Scope namedImportScope, |
| 444 | Scope starImportScope) { |
| 445 | this.packageAnnotations = packageAnnotations; |
| 446 | this.pid = pid; |
| 447 | this.defs = defs; |
| 448 | this.sourcefile = sourcefile; |
| 449 | this.packge = packge; |
| 450 | this.namedImportScope = namedImportScope; |
| 451 | this.starImportScope = starImportScope; |
| 452 | } |
| 453 | @Override |
| 454 | public void accept(Visitor v) { v.visitTopLevel(this); } |
| 455 | |
| 456 | public Kind getKind() { return Kind.COMPILATION_UNIT; } |
| 457 | public List<JCAnnotation> getPackageAnnotations() { |
| 458 | return packageAnnotations; |
| 459 | } |
| 460 | public List<JCImport> getImports() { |
| 461 | ListBuffer<JCImport> imports = new ListBuffer<JCImport>(); |
| 462 | for (JCTree tree : defs) { |
| 463 | if (tree.getTag() == IMPORT) |
| 464 | imports.append((JCImport)tree); |
| 465 | else |
| 466 | break; |
| 467 | } |
| 468 | return imports.toList(); |
| 469 | } |
| 470 | public JCExpression getPackageName() { return pid; } |
| 471 | public JavaFileObject getSourceFile() { |
| 472 | return sourcefile; |
| 473 | } |
| 474 | public Position.LineMap getLineMap() { |
| 475 | return lineMap; |
| 476 | } |
| 477 | public List<JCTree> getTypeDecls() { |
| 478 | List<JCTree> typeDefs; |
| 479 | for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail) |
| 480 | if (typeDefs.head.getTag() != IMPORT) |
| 481 | break; |
| 482 | return typeDefs; |
| 483 | } |
| 484 | @Override |
| 485 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 486 | return v.visitCompilationUnit(this, d); |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public int getTag() { |
| 491 | return TOPLEVEL; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /** |
| 496 | * An import clause. |
| 497 | * @param qualid The imported class(es). |
| 498 | */ |
| 499 | public static class JCImport extends JCTree implements ImportTree { |
| 500 | public boolean staticImport; |
| 501 | public JCTree qualid; |
| 502 | protected JCImport(JCTree qualid, boolean importStatic) { |
| 503 | this.qualid = qualid; |
| 504 | this.staticImport = importStatic; |
| 505 | } |
| 506 | @Override |
| 507 | public void accept(Visitor v) { v.visitImport(this); } |
| 508 | |
| 509 | public boolean isStatic() { return staticImport; } |
| 510 | public JCTree getQualifiedIdentifier() { return qualid; } |
| 511 | |
| 512 | public Kind getKind() { return Kind.IMPORT; } |
| 513 | @Override |
| 514 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 515 | return v.visitImport(this, d); |
| 516 | } |
| 517 | |
| 518 | @Override |
| 519 | public int getTag() { |
| 520 | return IMPORT; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | public static abstract class JCStatement extends JCTree implements StatementTree { |
| 525 | @Override |
| 526 | public JCStatement setType(Type type) { |
| 527 | super.setType(type); |
| 528 | return this; |
| 529 | } |
| 530 | @Override |
| 531 | public JCStatement setPos(int pos) { |
| 532 | super.setPos(pos); |
| 533 | return this; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | public static abstract class JCExpression extends JCTree implements ExpressionTree { |
| 538 | @Override |
| 539 | public JCExpression setType(Type type) { |
| 540 | super.setType(type); |
| 541 | return this; |
| 542 | } |
| 543 | @Override |
| 544 | public JCExpression setPos(int pos) { |
| 545 | super.setPos(pos); |
| 546 | return this; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /** |
| 551 | * A class definition. |
| 552 | * @param modifiers the modifiers |
| 553 | * @param name the name of the class |
| 554 | * @param typarams formal class parameters |
| 555 | * @param extending the classes this class extends |
| 556 | * @param implementing the interfaces implemented by this class |
| 557 | * @param defs all variables and methods defined in this class |
| 558 | * @param sym the symbol |
| 559 | */ |
| 560 | public static class JCClassDecl extends JCStatement implements ClassTree { |
| 561 | public JCModifiers mods; |
| 562 | public Name name; |
| 563 | public List<JCTypeParameter> typarams; |
| 564 | public JCTree extending; |
| 565 | public List<JCExpression> implementing; |
| 566 | public List<JCTree> defs; |
| 567 | public ClassSymbol sym; |
| 568 | protected JCClassDecl(JCModifiers mods, |
| 569 | Name name, |
| 570 | List<JCTypeParameter> typarams, |
| 571 | JCTree extending, |
| 572 | List<JCExpression> implementing, |
| 573 | List<JCTree> defs, |
| 574 | ClassSymbol sym) |
| 575 | { |
| 576 | this.mods = mods; |
| 577 | this.name = name; |
| 578 | this.typarams = typarams; |
| 579 | this.extending = extending; |
| 580 | this.implementing = implementing; |
| 581 | this.defs = defs; |
| 582 | this.sym = sym; |
| 583 | } |
| 584 | @Override |
| 585 | public void accept(Visitor v) { v.visitClassDef(this); } |
| 586 | |
| 587 | public Kind getKind() { return Kind.CLASS; } |
| 588 | public JCModifiers getModifiers() { return mods; } |
| 589 | public Name getSimpleName() { return name; } |
| 590 | public List<JCTypeParameter> getTypeParameters() { |
| 591 | return typarams; |
| 592 | } |
| 593 | public JCTree getExtendsClause() { return extending; } |
| 594 | public List<JCExpression> getImplementsClause() { |
| 595 | return implementing; |
| 596 | } |
| 597 | public List<JCTree> getMembers() { |
| 598 | return defs; |
| 599 | } |
| 600 | @Override |
| 601 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 602 | return v.visitClass(this, d); |
| 603 | } |
| 604 | |
| 605 | @Override |
| 606 | public int getTag() { |
| 607 | return CLASSDEF; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * A method definition. |
| 613 | * @param modifiers method modifiers |
| 614 | * @param name method name |
| 615 | * @param restype type of method return value |
| 616 | * @param typarams type parameters |
| 617 | * @param params value parameters |
| 618 | * @param thrown exceptions thrown by this method |
| 619 | * @param stats statements in the method |
| 620 | * @param sym method symbol |
| 621 | */ |
| 622 | public static class JCMethodDecl extends JCTree implements MethodTree { |
| 623 | public JCModifiers mods; |
| 624 | public Name name; |
| 625 | public JCExpression restype; |
| 626 | public List<JCTypeParameter> typarams; |
| 627 | public List<JCVariableDecl> params; |
| 628 | public List<JCExpression> thrown; |
| 629 | public JCBlock body; |
| 630 | public JCExpression defaultValue; // for annotation types |
| 631 | public MethodSymbol sym; |
| 632 | protected JCMethodDecl(JCModifiers mods, |
| 633 | Name name, |
| 634 | JCExpression restype, |
| 635 | List<JCTypeParameter> typarams, |
| 636 | List<JCVariableDecl> params, |
| 637 | List<JCExpression> thrown, |
| 638 | JCBlock body, |
| 639 | JCExpression defaultValue, |
| 640 | MethodSymbol sym) |
| 641 | { |
| 642 | this.mods = mods; |
| 643 | this.name = name; |
| 644 | this.restype = restype; |
| 645 | this.typarams = typarams; |
| 646 | this.params = params; |
| 647 | this.thrown = thrown; |
| 648 | this.body = body; |
| 649 | this.defaultValue = defaultValue; |
| 650 | this.sym = sym; |
| 651 | } |
| 652 | @Override |
| 653 | public void accept(Visitor v) { v.visitMethodDef(this); } |
| 654 | |
| 655 | public Kind getKind() { return Kind.METHOD; } |
| 656 | public JCModifiers getModifiers() { return mods; } |
| 657 | public Name getName() { return name; } |
| 658 | public JCTree getReturnType() { return restype; } |
| 659 | public List<JCTypeParameter> getTypeParameters() { |
| 660 | return typarams; |
| 661 | } |
| 662 | public List<JCVariableDecl> getParameters() { |
| 663 | return params; |
| 664 | } |
| 665 | public List<JCExpression> getThrows() { |
| 666 | return thrown; |
| 667 | } |
| 668 | public JCBlock getBody() { return body; } |
| 669 | public JCTree getDefaultValue() { // for annotation types |
| 670 | return defaultValue; |
| 671 | } |
| 672 | @Override |
| 673 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 674 | return v.visitMethod(this, d); |
| 675 | } |
| 676 | |
| 677 | @Override |
| 678 | public int getTag() { |
| 679 | return METHODDEF; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | /** |
| 684 | * A variable definition. |
| 685 | * @param modifiers variable modifiers |
| 686 | * @param name variable name |
| 687 | * @param vartype type of the variable |
| 688 | * @param init variables initial value |
| 689 | * @param sym symbol |
| 690 | */ |
| 691 | public static class JCVariableDecl extends JCStatement implements VariableTree { |
| 692 | public JCModifiers mods; |
| 693 | public Name name; |
| 694 | public JCExpression vartype; |
| 695 | public JCExpression init; |
| 696 | public VarSymbol sym; |
| 697 | protected JCVariableDecl(JCModifiers mods, |
| 698 | Name name, |
| 699 | JCExpression vartype, |
| 700 | JCExpression init, |
| 701 | VarSymbol sym) { |
| 702 | this.mods = mods; |
| 703 | this.name = name; |
| 704 | this.vartype = vartype; |
| 705 | this.init = init; |
| 706 | this.sym = sym; |
| 707 | } |
| 708 | @Override |
| 709 | public void accept(Visitor v) { v.visitVarDef(this); } |
| 710 | |
| 711 | public Kind getKind() { return Kind.VARIABLE; } |
| 712 | public JCModifiers getModifiers() { return mods; } |
| 713 | public Name getName() { return name; } |
| 714 | public JCTree getType() { return vartype; } |
| 715 | public JCExpression getInitializer() { |
| 716 | return init; |
| 717 | } |
| 718 | @Override |
| 719 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 720 | return v.visitVariable(this, d); |
| 721 | } |
| 722 | |
| 723 | @Override |
| 724 | public int getTag() { |
| 725 | return VARDEF; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * A no-op statement ";". |
| 731 | */ |
| 732 | public static class JCSkip extends JCStatement implements EmptyStatementTree { |
| 733 | protected JCSkip() { |
| 734 | } |
| 735 | @Override |
| 736 | public void accept(Visitor v) { v.visitSkip(this); } |
| 737 | |
| 738 | public Kind getKind() { return Kind.EMPTY_STATEMENT; } |
| 739 | @Override |
| 740 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 741 | return v.visitEmptyStatement(this, d); |
| 742 | } |
| 743 | |
| 744 | @Override |
| 745 | public int getTag() { |
| 746 | return SKIP; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | /** |
| 751 | * A statement block. |
| 752 | * @param stats statements |
| 753 | * @param flags flags |
| 754 | */ |
| 755 | public static class JCBlock extends JCStatement implements BlockTree { |
| 756 | public long flags; |
| 757 | public List<JCStatement> stats; |
| 758 | /** Position of closing brace, optional. */ |
| 759 | public int endpos = Position.NOPOS; |
| 760 | protected JCBlock(long flags, List<JCStatement> stats) { |
| 761 | this.stats = stats; |
| 762 | this.flags = flags; |
| 763 | } |
| 764 | @Override |
| 765 | public void accept(Visitor v) { v.visitBlock(this); } |
| 766 | |
| 767 | public Kind getKind() { return Kind.BLOCK; } |
| 768 | public List<JCStatement> getStatements() { |
| 769 | return stats; |
| 770 | } |
| 771 | public boolean isStatic() { return (flags & Flags.STATIC) != 0; } |
| 772 | @Override |
| 773 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 774 | return v.visitBlock(this, d); |
| 775 | } |
| 776 | |
| 777 | @Override |
| 778 | public int getTag() { |
| 779 | return BLOCK; |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * A do loop |
| 785 | */ |
| 786 | public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree { |
| 787 | public JCStatement body; |
| 788 | public JCExpression cond; |
| 789 | protected JCDoWhileLoop(JCStatement body, JCExpression cond) { |
| 790 | this.body = body; |
| 791 | this.cond = cond; |
| 792 | } |
| 793 | @Override |
| 794 | public void accept(Visitor v) { v.visitDoLoop(this); } |
| 795 | |
| 796 | public Kind getKind() { return Kind.DO_WHILE_LOOP; } |
| 797 | public JCExpression getCondition() { return cond; } |
| 798 | public JCStatement getStatement() { return body; } |
| 799 | @Override |
| 800 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 801 | return v.visitDoWhileLoop(this, d); |
| 802 | } |
| 803 | |
| 804 | @Override |
| 805 | public int getTag() { |
| 806 | return DOLOOP; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * A while loop |
| 812 | */ |
| 813 | public static class JCWhileLoop extends JCStatement implements WhileLoopTree { |
| 814 | public JCExpression cond; |
| 815 | public JCStatement body; |
| 816 | protected JCWhileLoop(JCExpression cond, JCStatement body) { |
| 817 | this.cond = cond; |
| 818 | this.body = body; |
| 819 | } |
| 820 | @Override |
| 821 | public void accept(Visitor v) { v.visitWhileLoop(this); } |
| 822 | |
| 823 | public Kind getKind() { return Kind.WHILE_LOOP; } |
| 824 | public JCExpression getCondition() { return cond; } |
| 825 | public JCStatement getStatement() { return body; } |
| 826 | @Override |
| 827 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 828 | return v.visitWhileLoop(this, d); |
| 829 | } |
| 830 | |
| 831 | @Override |
| 832 | public int getTag() { |
| 833 | return WHILELOOP; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | /** |
| 838 | * A for loop. |
| 839 | */ |
| 840 | public static class JCForLoop extends JCStatement implements ForLoopTree { |
| 841 | public List<JCStatement> init; |
| 842 | public JCExpression cond; |
| 843 | public List<JCExpressionStatement> step; |
| 844 | public JCStatement body; |
| 845 | protected JCForLoop(List<JCStatement> init, |
| 846 | JCExpression cond, |
| 847 | List<JCExpressionStatement> update, |
| 848 | JCStatement body) |
| 849 | { |
| 850 | this.init = init; |
| 851 | this.cond = cond; |
| 852 | this.step = update; |
| 853 | this.body = body; |
| 854 | } |
| 855 | @Override |
| 856 | public void accept(Visitor v) { v.visitForLoop(this); } |
| 857 | |
| 858 | public Kind getKind() { return Kind.FOR_LOOP; } |
| 859 | public JCExpression getCondition() { return cond; } |
| 860 | public JCStatement getStatement() { return body; } |
| 861 | public List<JCStatement> getInitializer() { |
| 862 | return init; |
| 863 | } |
| 864 | public List<JCExpressionStatement> getUpdate() { |
| 865 | return step; |
| 866 | } |
| 867 | @Override |
| 868 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 869 | return v.visitForLoop(this, d); |
| 870 | } |
| 871 | |
| 872 | @Override |
| 873 | public int getTag() { |
| 874 | return FORLOOP; |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | /** |
| 879 | * The enhanced for loop. |
| 880 | */ |
| 881 | public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree { |
| 882 | public JCVariableDecl var; |
| 883 | public JCExpression expr; |
| 884 | public JCStatement body; |
| 885 | protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) { |
| 886 | this.var = var; |
| 887 | this.expr = expr; |
| 888 | this.body = body; |
| 889 | } |
| 890 | @Override |
| 891 | public void accept(Visitor v) { v.visitForeachLoop(this); } |
| 892 | |
| 893 | public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; } |
| 894 | public JCVariableDecl getVariable() { return var; } |
| 895 | public JCExpression getExpression() { return expr; } |
| 896 | public JCStatement getStatement() { return body; } |
| 897 | @Override |
| 898 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 899 | return v.visitEnhancedForLoop(this, d); |
| 900 | } |
| 901 | @Override |
| 902 | public int getTag() { |
| 903 | return FOREACHLOOP; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * A labelled expression or statement. |
| 909 | */ |
| 910 | public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree { |
| 911 | public Name label; |
| 912 | public JCStatement body; |
| 913 | protected JCLabeledStatement(Name label, JCStatement body) { |
| 914 | this.label = label; |
| 915 | this.body = body; |
| 916 | } |
| 917 | @Override |
| 918 | public void accept(Visitor v) { v.visitLabelled(this); } |
| 919 | public Kind getKind() { return Kind.LABELED_STATEMENT; } |
| 920 | public Name getLabel() { return label; } |
| 921 | public JCStatement getStatement() { return body; } |
| 922 | @Override |
| 923 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 924 | return v.visitLabeledStatement(this, d); |
| 925 | } |
| 926 | @Override |
| 927 | public int getTag() { |
| 928 | return LABELLED; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | /** |
| 933 | * A "switch ( ) { }" construction. |
| 934 | */ |
| 935 | public static class JCSwitch extends JCStatement implements SwitchTree { |
| 936 | public JCExpression selector; |
| 937 | public List<JCCase> cases; |
| 938 | protected JCSwitch(JCExpression selector, List<JCCase> cases) { |
| 939 | this.selector = selector; |
| 940 | this.cases = cases; |
| 941 | } |
| 942 | @Override |
| 943 | public void accept(Visitor v) { v.visitSwitch(this); } |
| 944 | |
| 945 | public Kind getKind() { return Kind.SWITCH; } |
| 946 | public JCExpression getExpression() { return selector; } |
| 947 | public List<JCCase> getCases() { return cases; } |
| 948 | @Override |
| 949 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 950 | return v.visitSwitch(this, d); |
| 951 | } |
| 952 | @Override |
| 953 | public int getTag() { |
| 954 | return SWITCH; |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | /** |
| 959 | * A "case :" of a switch. |
| 960 | */ |
| 961 | public static class JCCase extends JCStatement implements CaseTree { |
| 962 | public JCExpression pat; |
| 963 | public List<JCStatement> stats; |
| 964 | protected JCCase(JCExpression pat, List<JCStatement> stats) { |
| 965 | this.pat = pat; |
| 966 | this.stats = stats; |
| 967 | } |
| 968 | @Override |
| 969 | public void accept(Visitor v) { v.visitCase(this); } |
| 970 | |
| 971 | public Kind getKind() { return Kind.CASE; } |
| 972 | public JCExpression getExpression() { return pat; } |
| 973 | public List<JCStatement> getStatements() { return stats; } |
| 974 | @Override |
| 975 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 976 | return v.visitCase(this, d); |
| 977 | } |
| 978 | @Override |
| 979 | public int getTag() { |
| 980 | return CASE; |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | /** |
| 985 | * A synchronized block. |
| 986 | */ |
| 987 | public static class JCSynchronized extends JCStatement implements SynchronizedTree { |
| 988 | public JCExpression lock; |
| 989 | public JCBlock body; |
| 990 | protected JCSynchronized(JCExpression lock, JCBlock body) { |
| 991 | this.lock = lock; |
| 992 | this.body = body; |
| 993 | } |
| 994 | @Override |
| 995 | public void accept(Visitor v) { v.visitSynchronized(this); } |
| 996 | |
| 997 | public Kind getKind() { return Kind.SYNCHRONIZED; } |
| 998 | public JCExpression getExpression() { return lock; } |
| 999 | public JCBlock getBlock() { return body; } |
| 1000 | @Override |
| 1001 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1002 | return v.visitSynchronized(this, d); |
| 1003 | } |
| 1004 | @Override |
| 1005 | public int getTag() { |
| 1006 | return SYNCHRONIZED; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | /** |
| 1011 | * A "try { } catch ( ) { } finally { }" block. |
| 1012 | */ |
| 1013 | public static class JCTry extends JCStatement implements TryTree { |
| 1014 | public JCBlock body; |
| 1015 | public List<JCCatch> catchers; |
| 1016 | public JCBlock finalizer; |
| 1017 | protected JCTry(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) { |
| 1018 | this.body = body; |
| 1019 | this.catchers = catchers; |
| 1020 | this.finalizer = finalizer; |
| 1021 | } |
| 1022 | @Override |
| 1023 | public void accept(Visitor v) { v.visitTry(this); } |
| 1024 | |
| 1025 | public Kind getKind() { return Kind.TRY; } |
| 1026 | public JCBlock getBlock() { return body; } |
| 1027 | public List<JCCatch> getCatches() { |
| 1028 | return catchers; |
| 1029 | } |
| 1030 | public JCBlock getFinallyBlock() { return finalizer; } |
| 1031 | @Override |
| 1032 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1033 | return v.visitTry(this, d); |
| 1034 | } |
| 1035 | @Override |
| 1036 | public int getTag() { |
| 1037 | return TRY; |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | /** |
| 1042 | * A catch block. |
| 1043 | */ |
| 1044 | public static class JCCatch extends JCTree implements CatchTree { |
| 1045 | public JCVariableDecl param; |
| 1046 | public JCBlock body; |
| 1047 | protected JCCatch(JCVariableDecl param, JCBlock body) { |
| 1048 | this.param = param; |
| 1049 | this.body = body; |
| 1050 | } |
| 1051 | @Override |
| 1052 | public void accept(Visitor v) { v.visitCatch(this); } |
| 1053 | |
| 1054 | public Kind getKind() { return Kind.CATCH; } |
| 1055 | public JCVariableDecl getParameter() { return param; } |
| 1056 | public JCBlock getBlock() { return body; } |
| 1057 | @Override |
| 1058 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1059 | return v.visitCatch(this, d); |
| 1060 | } |
| 1061 | @Override |
| 1062 | public int getTag() { |
| 1063 | return CATCH; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | /** |
| 1068 | * A ( ) ? ( ) : ( ) conditional expression |
| 1069 | */ |
| 1070 | public static class JCConditional extends JCExpression implements ConditionalExpressionTree { |
| 1071 | public JCExpression cond; |
| 1072 | public JCExpression truepart; |
| 1073 | public JCExpression falsepart; |
| 1074 | protected JCConditional(JCExpression cond, |
| 1075 | JCExpression truepart, |
| 1076 | JCExpression falsepart) |
| 1077 | { |
| 1078 | this.cond = cond; |
| 1079 | this.truepart = truepart; |
| 1080 | this.falsepart = falsepart; |
| 1081 | } |
| 1082 | @Override |
| 1083 | public void accept(Visitor v) { v.visitConditional(this); } |
| 1084 | |
| 1085 | public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; } |
| 1086 | public JCExpression getCondition() { return cond; } |
| 1087 | public JCExpression getTrueExpression() { return truepart; } |
| 1088 | public JCExpression getFalseExpression() { return falsepart; } |
| 1089 | @Override |
| 1090 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1091 | return v.visitConditionalExpression(this, d); |
| 1092 | } |
| 1093 | @Override |
| 1094 | public int getTag() { |
| 1095 | return CONDEXPR; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * An "if ( ) { } else { }" block |
| 1101 | */ |
| 1102 | public static class JCIf extends JCStatement implements IfTree { |
| 1103 | public JCExpression cond; |
| 1104 | public JCStatement thenpart; |
| 1105 | public JCStatement elsepart; |
| 1106 | protected JCIf(JCExpression cond, |
| 1107 | JCStatement thenpart, |
| 1108 | JCStatement elsepart) |
| 1109 | { |
| 1110 | this.cond = cond; |
| 1111 | this.thenpart = thenpart; |
| 1112 | this.elsepart = elsepart; |
| 1113 | } |
| 1114 | @Override |
| 1115 | public void accept(Visitor v) { v.visitIf(this); } |
| 1116 | |
| 1117 | public Kind getKind() { return Kind.IF; } |
| 1118 | public JCExpression getCondition() { return cond; } |
| 1119 | public JCStatement getThenStatement() { return thenpart; } |
| 1120 | public JCStatement getElseStatement() { return elsepart; } |
| 1121 | @Override |
| 1122 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1123 | return v.visitIf(this, d); |
| 1124 | } |
| 1125 | @Override |
| 1126 | public int getTag() { |
| 1127 | return IF; |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | /** |
| 1132 | * an expression statement |
| 1133 | * @param expr expression structure |
| 1134 | */ |
| 1135 | public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree { |
| 1136 | public JCExpression expr; |
| 1137 | protected JCExpressionStatement(JCExpression expr) |
| 1138 | { |
| 1139 | this.expr = expr; |
| 1140 | } |
| 1141 | @Override |
| 1142 | public void accept(Visitor v) { v.visitExec(this); } |
| 1143 | |
| 1144 | public Kind getKind() { return Kind.EXPRESSION_STATEMENT; } |
| 1145 | public JCExpression getExpression() { return expr; } |
| 1146 | @Override |
| 1147 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1148 | return v.visitExpressionStatement(this, d); |
| 1149 | } |
| 1150 | @Override |
| 1151 | public int getTag() { |
| 1152 | return EXEC; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * A break from a loop or switch. |
| 1158 | */ |
| 1159 | public static class JCBreak extends JCStatement implements BreakTree { |
| 1160 | public Name label; |
| 1161 | public JCTree target; |
| 1162 | protected JCBreak(Name label, JCTree target) { |
| 1163 | this.label = label; |
| 1164 | this.target = target; |
| 1165 | } |
| 1166 | @Override |
| 1167 | public void accept(Visitor v) { v.visitBreak(this); } |
| 1168 | |
| 1169 | public Kind getKind() { return Kind.BREAK; } |
| 1170 | public Name getLabel() { return label; } |
| 1171 | @Override |
| 1172 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1173 | return v.visitBreak(this, d); |
| 1174 | } |
| 1175 | @Override |
| 1176 | public int getTag() { |
| 1177 | return BREAK; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | /** |
| 1182 | * A continue of a loop. |
| 1183 | */ |
| 1184 | public static class JCContinue extends JCStatement implements ContinueTree { |
| 1185 | public Name label; |
| 1186 | public JCTree target; |
| 1187 | protected JCContinue(Name label, JCTree target) { |
| 1188 | this.label = label; |
| 1189 | this.target = target; |
| 1190 | } |
| 1191 | @Override |
| 1192 | public void accept(Visitor v) { v.visitContinue(this); } |
| 1193 | |
| 1194 | public Kind getKind() { return Kind.CONTINUE; } |
| 1195 | public Name getLabel() { return label; } |
| 1196 | @Override |
| 1197 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1198 | return v.visitContinue(this, d); |
| 1199 | } |
| 1200 | @Override |
| 1201 | public int getTag() { |
| 1202 | return CONTINUE; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | /** |
| 1207 | * A return statement. |
| 1208 | */ |
| 1209 | public static class JCReturn extends JCStatement implements ReturnTree { |
| 1210 | public JCExpression expr; |
| 1211 | protected JCReturn(JCExpression expr) { |
| 1212 | this.expr = expr; |
| 1213 | } |
| 1214 | @Override |
| 1215 | public void accept(Visitor v) { v.visitReturn(this); } |
| 1216 | |
| 1217 | public Kind getKind() { return Kind.RETURN; } |
| 1218 | public JCExpression getExpression() { return expr; } |
| 1219 | @Override |
| 1220 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1221 | return v.visitReturn(this, d); |
| 1222 | } |
| 1223 | @Override |
| 1224 | public int getTag() { |
| 1225 | return RETURN; |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | /** |
| 1230 | * A throw statement. |
| 1231 | */ |
| 1232 | public static class JCThrow extends JCStatement implements ThrowTree { |
| 1233 | public JCExpression expr; |
| 1234 | protected JCThrow(JCTree expr) { |
| 1235 | this.expr = (JCExpression)expr; |
| 1236 | } |
| 1237 | @Override |
| 1238 | public void accept(Visitor v) { v.visitThrow(this); } |
| 1239 | |
| 1240 | public Kind getKind() { return Kind.THROW; } |
| 1241 | public JCExpression getExpression() { return expr; } |
| 1242 | @Override |
| 1243 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1244 | return v.visitThrow(this, d); |
| 1245 | } |
| 1246 | @Override |
| 1247 | public int getTag() { |
| 1248 | return THROW; |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | /** |
| 1253 | * An assert statement. |
| 1254 | */ |
| 1255 | public static class JCAssert extends JCStatement implements AssertTree { |
| 1256 | public JCExpression cond; |
| 1257 | public JCExpression detail; |
| 1258 | protected JCAssert(JCExpression cond, JCExpression detail) { |
| 1259 | this.cond = cond; |
| 1260 | this.detail = detail; |
| 1261 | } |
| 1262 | @Override |
| 1263 | public void accept(Visitor v) { v.visitAssert(this); } |
| 1264 | |
| 1265 | public Kind getKind() { return Kind.ASSERT; } |
| 1266 | public JCExpression getCondition() { return cond; } |
| 1267 | public JCExpression getDetail() { return detail; } |
| 1268 | @Override |
| 1269 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1270 | return v.visitAssert(this, d); |
| 1271 | } |
| 1272 | @Override |
| 1273 | public int getTag() { |
| 1274 | return ASSERT; |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | /** |
| 1279 | * A method invocation |
| 1280 | */ |
| 1281 | public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree { |
| 1282 | public List<JCExpression> typeargs; |
| 1283 | public JCExpression meth; |
| 1284 | public List<JCExpression> args; |
| 1285 | public Type varargsElement; |
| 1286 | protected JCMethodInvocation(List<JCExpression> typeargs, |
| 1287 | JCExpression meth, |
| 1288 | List<JCExpression> args) |
| 1289 | { |
| 1290 | this.typeargs = (typeargs == null) ? List.<JCExpression>nil() |
| 1291 | : typeargs; |
| 1292 | this.meth = meth; |
| 1293 | this.args = args; |
| 1294 | } |
| 1295 | @Override |
| 1296 | public void accept(Visitor v) { v.visitApply(this); } |
| 1297 | |
| 1298 | public Kind getKind() { return Kind.METHOD_INVOCATION; } |
| 1299 | public List<JCExpression> getTypeArguments() { |
| 1300 | return typeargs; |
| 1301 | } |
| 1302 | public JCExpression getMethodSelect() { return meth; } |
| 1303 | public List<JCExpression> getArguments() { |
| 1304 | return args; |
| 1305 | } |
| 1306 | @Override |
| 1307 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1308 | return v.visitMethodInvocation(this, d); |
| 1309 | } |
| 1310 | @Override |
| 1311 | public JCMethodInvocation setType(Type type) { |
| 1312 | super.setType(type); |
| 1313 | return this; |
| 1314 | } |
| 1315 | @Override |
| 1316 | public int getTag() { |
| 1317 | return(APPLY); |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * A new(...) operation. |
| 1323 | */ |
| 1324 | public static class JCNewClass extends JCExpression implements NewClassTree { |
| 1325 | public JCExpression encl; |
| 1326 | public List<JCExpression> typeargs; |
| 1327 | public JCExpression clazz; |
| 1328 | public List<JCExpression> args; |
| 1329 | public JCClassDecl def; |
| 1330 | public Symbol constructor; |
| 1331 | public Type varargsElement; |
| 1332 | protected JCNewClass(JCExpression encl, |
| 1333 | List<JCExpression> typeargs, |
| 1334 | JCExpression clazz, |
| 1335 | List<JCExpression> args, |
| 1336 | JCClassDecl def) |
| 1337 | { |
| 1338 | this.encl = encl; |
| 1339 | this.typeargs = (typeargs == null) ? List.<JCExpression>nil() |
| 1340 | : typeargs; |
| 1341 | this.clazz = clazz; |
| 1342 | this.args = args; |
| 1343 | this.def = def; |
| 1344 | } |
| 1345 | @Override |
| 1346 | public void accept(Visitor v) { v.visitNewClass(this); } |
| 1347 | |
| 1348 | public Kind getKind() { return Kind.NEW_CLASS; } |
| 1349 | public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... ) |
| 1350 | return encl; |
| 1351 | } |
| 1352 | public List<JCExpression> getTypeArguments() { |
| 1353 | return typeargs; |
| 1354 | } |
| 1355 | public JCExpression getIdentifier() { return clazz; } |
| 1356 | public List<JCExpression> getArguments() { |
| 1357 | return args; |
| 1358 | } |
| 1359 | public JCClassDecl getClassBody() { return def; } |
| 1360 | @Override |
| 1361 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1362 | return v.visitNewClass(this, d); |
| 1363 | } |
| 1364 | @Override |
| 1365 | public int getTag() { |
| 1366 | return NEWCLASS; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | /** |
| 1371 | * A new[...] operation. |
| 1372 | */ |
| 1373 | public static class JCNewArray extends JCExpression implements NewArrayTree { |
| 1374 | public JCExpression elemtype; |
| 1375 | public List<JCExpression> dims; |
| 1376 | public List<JCExpression> elems; |
| 1377 | protected JCNewArray(JCExpression elemtype, |
| 1378 | List<JCExpression> dims, |
| 1379 | List<JCExpression> elems) |
| 1380 | { |
| 1381 | this.elemtype = elemtype; |
| 1382 | this.dims = dims; |
| 1383 | this.elems = elems; |
| 1384 | } |
| 1385 | @Override |
| 1386 | public void accept(Visitor v) { v.visitNewArray(this); } |
| 1387 | |
| 1388 | public Kind getKind() { return Kind.NEW_ARRAY; } |
| 1389 | public JCExpression getType() { return elemtype; } |
| 1390 | public List<JCExpression> getDimensions() { |
| 1391 | return dims; |
| 1392 | } |
| 1393 | public List<JCExpression> getInitializers() { |
| 1394 | return elems; |
| 1395 | } |
| 1396 | @Override |
| 1397 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1398 | return v.visitNewArray(this, d); |
| 1399 | } |
| 1400 | @Override |
| 1401 | public int getTag() { |
| 1402 | return NEWARRAY; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * A parenthesized subexpression ( ... ) |
| 1408 | */ |
| 1409 | public static class JCParens extends JCExpression implements ParenthesizedTree { |
| 1410 | public JCExpression expr; |
| 1411 | protected JCParens(JCExpression expr) { |
| 1412 | this.expr = expr; |
| 1413 | } |
| 1414 | @Override |
| 1415 | public void accept(Visitor v) { v.visitParens(this); } |
| 1416 | |
| 1417 | public Kind getKind() { return Kind.PARENTHESIZED; } |
| 1418 | public JCExpression getExpression() { return expr; } |
| 1419 | @Override |
| 1420 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1421 | return v.visitParenthesized(this, d); |
| 1422 | } |
| 1423 | @Override |
| 1424 | public int getTag() { |
| 1425 | return PARENS; |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | /** |
| 1430 | * A assignment with "=". |
| 1431 | */ |
| 1432 | public static class JCAssign extends JCExpression implements AssignmentTree { |
| 1433 | public JCExpression lhs; |
| 1434 | public JCExpression rhs; |
| 1435 | protected JCAssign(JCExpression lhs, JCExpression rhs) { |
| 1436 | this.lhs = lhs; |
| 1437 | this.rhs = rhs; |
| 1438 | } |
| 1439 | @Override |
| 1440 | public void accept(Visitor v) { v.visitAssign(this); } |
| 1441 | |
| 1442 | public Kind getKind() { return Kind.ASSIGNMENT; } |
| 1443 | public JCExpression getVariable() { return lhs; } |
| 1444 | public JCExpression getExpression() { return rhs; } |
| 1445 | @Override |
| 1446 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1447 | return v.visitAssignment(this, d); |
| 1448 | } |
| 1449 | @Override |
| 1450 | public int getTag() { |
| 1451 | return ASSIGN; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | /** |
| 1456 | * An assignment with "+=", "|=" ... |
| 1457 | */ |
| 1458 | public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree { |
| 1459 | private int opcode; |
| 1460 | public JCExpression lhs; |
| 1461 | public JCExpression rhs; |
| 1462 | public Symbol operator; |
| 1463 | protected JCAssignOp(int opcode, JCTree lhs, JCTree rhs, Symbol operator) { |
| 1464 | this.opcode = opcode; |
| 1465 | this.lhs = (JCExpression)lhs; |
| 1466 | this.rhs = (JCExpression)rhs; |
| 1467 | this.operator = operator; |
| 1468 | } |
| 1469 | @Override |
| 1470 | public void accept(Visitor v) { v.visitAssignop(this); } |
| 1471 | |
| 1472 | public Kind getKind() { return TreeInfo.tagToKind(getTag()); } |
| 1473 | public JCExpression getVariable() { return lhs; } |
| 1474 | public JCExpression getExpression() { return rhs; } |
| 1475 | public Symbol getOperator() { |
| 1476 | return operator; |
| 1477 | } |
| 1478 | @Override |
| 1479 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1480 | return v.visitCompoundAssignment(this, d); |
| 1481 | } |
| 1482 | @Override |
| 1483 | public int getTag() { |
| 1484 | return opcode; |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | /** |
| 1489 | * A unary operation. |
| 1490 | */ |
| 1491 | public static class JCUnary extends JCExpression implements UnaryTree { |
| 1492 | private int opcode; |
| 1493 | public JCExpression arg; |
| 1494 | public Symbol operator; |
| 1495 | protected JCUnary(int opcode, JCExpression arg) { |
| 1496 | this.opcode = opcode; |
| 1497 | this.arg = arg; |
| 1498 | } |
| 1499 | @Override |
| 1500 | public void accept(Visitor v) { v.visitUnary(this); } |
| 1501 | |
| 1502 | public Kind getKind() { return TreeInfo.tagToKind(getTag()); } |
| 1503 | public JCExpression getExpression() { return arg; } |
| 1504 | public Symbol getOperator() { |
| 1505 | return operator; |
| 1506 | } |
| 1507 | @Override |
| 1508 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1509 | return v.visitUnary(this, d); |
| 1510 | } |
| 1511 | @Override |
| 1512 | public int getTag() { |
| 1513 | return opcode; |
| 1514 | } |
| 1515 | |
| 1516 | public void setTag(int tag) { |
| 1517 | opcode = tag; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * A binary operation. |
| 1523 | */ |
| 1524 | public static class JCBinary extends JCExpression implements BinaryTree { |
| 1525 | private int opcode; |
| 1526 | public JCExpression lhs; |
| 1527 | public JCExpression rhs; |
| 1528 | public Symbol operator; |
| 1529 | protected JCBinary(int opcode, |
| 1530 | JCExpression lhs, |
| 1531 | JCExpression rhs, |
| 1532 | Symbol operator) { |
| 1533 | this.opcode = opcode; |
| 1534 | this.lhs = lhs; |
| 1535 | this.rhs = rhs; |
| 1536 | this.operator = operator; |
| 1537 | } |
| 1538 | @Override |
| 1539 | public void accept(Visitor v) { v.visitBinary(this); } |
| 1540 | |
| 1541 | public Kind getKind() { return TreeInfo.tagToKind(getTag()); } |
| 1542 | public JCExpression getLeftOperand() { return lhs; } |
| 1543 | public JCExpression getRightOperand() { return rhs; } |
| 1544 | public Symbol getOperator() { |
| 1545 | return operator; |
| 1546 | } |
| 1547 | @Override |
| 1548 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1549 | return v.visitBinary(this, d); |
| 1550 | } |
| 1551 | @Override |
| 1552 | public int getTag() { |
| 1553 | return opcode; |
| 1554 | } |
| 1555 | } |
| 1556 | |
| 1557 | /** |
| 1558 | * A type cast. |
| 1559 | */ |
| 1560 | public static class JCTypeCast extends JCExpression implements TypeCastTree { |
| 1561 | public JCTree clazz; |
| 1562 | public JCExpression expr; |
| 1563 | protected JCTypeCast(JCTree clazz, JCExpression expr) { |
| 1564 | this.clazz = clazz; |
| 1565 | this.expr = expr; |
| 1566 | } |
| 1567 | @Override |
| 1568 | public void accept(Visitor v) { v.visitTypeCast(this); } |
| 1569 | |
| 1570 | public Kind getKind() { return Kind.TYPE_CAST; } |
| 1571 | public JCTree getType() { return clazz; } |
| 1572 | public JCExpression getExpression() { return expr; } |
| 1573 | @Override |
| 1574 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1575 | return v.visitTypeCast(this, d); |
| 1576 | } |
| 1577 | @Override |
| 1578 | public int getTag() { |
| 1579 | return TYPECAST; |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | /** |
| 1584 | * A type test. |
| 1585 | */ |
| 1586 | public static class JCInstanceOf extends JCExpression implements InstanceOfTree { |
| 1587 | public JCExpression expr; |
| 1588 | public JCTree clazz; |
| 1589 | protected JCInstanceOf(JCExpression expr, JCTree clazz) { |
| 1590 | this.expr = expr; |
| 1591 | this.clazz = clazz; |
| 1592 | } |
| 1593 | @Override |
| 1594 | public void accept(Visitor v) { v.visitTypeTest(this); } |
| 1595 | |
| 1596 | public Kind getKind() { return Kind.INSTANCE_OF; } |
| 1597 | public JCTree getType() { return clazz; } |
| 1598 | public JCExpression getExpression() { return expr; } |
| 1599 | @Override |
| 1600 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1601 | return v.visitInstanceOf(this, d); |
| 1602 | } |
| 1603 | @Override |
| 1604 | public int getTag() { |
| 1605 | return TYPETEST; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | /** |
| 1610 | * An array selection |
| 1611 | */ |
| 1612 | public static class JCArrayAccess extends JCExpression implements ArrayAccessTree { |
| 1613 | public JCExpression indexed; |
| 1614 | public JCExpression index; |
| 1615 | protected JCArrayAccess(JCExpression indexed, JCExpression index) { |
| 1616 | this.indexed = indexed; |
| 1617 | this.index = index; |
| 1618 | } |
| 1619 | @Override |
| 1620 | public void accept(Visitor v) { v.visitIndexed(this); } |
| 1621 | |
| 1622 | public Kind getKind() { return Kind.ARRAY_ACCESS; } |
| 1623 | public JCExpression getExpression() { return indexed; } |
| 1624 | public JCExpression getIndex() { return index; } |
| 1625 | @Override |
| 1626 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1627 | return v.visitArrayAccess(this, d); |
| 1628 | } |
| 1629 | @Override |
| 1630 | public int getTag() { |
| 1631 | return INDEXED; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | /** |
| 1636 | * Selects through packages and classes |
| 1637 | * @param selected selected Tree hierarchie |
| 1638 | * @param selector name of field to select thru |
| 1639 | * @param sym symbol of the selected class |
| 1640 | */ |
| 1641 | public static class JCFieldAccess extends JCExpression implements MemberSelectTree { |
| 1642 | public JCExpression selected; |
| 1643 | public Name name; |
| 1644 | public Symbol sym; |
| 1645 | protected JCFieldAccess(JCExpression selected, Name name, Symbol sym) { |
| 1646 | this.selected = selected; |
| 1647 | this.name = name; |
| 1648 | this.sym = sym; |
| 1649 | } |
| 1650 | @Override |
| 1651 | public void accept(Visitor v) { v.visitSelect(this); } |
| 1652 | |
| 1653 | public Kind getKind() { return Kind.MEMBER_SELECT; } |
| 1654 | public JCExpression getExpression() { return selected; } |
| 1655 | @Override |
| 1656 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1657 | return v.visitMemberSelect(this, d); |
| 1658 | } |
| 1659 | public Name getIdentifier() { return name; } |
| 1660 | @Override |
| 1661 | public int getTag() { |
| 1662 | return SELECT; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | /** |
| 1667 | * An identifier |
| 1668 | * @param idname the name |
| 1669 | * @param sym the symbol |
| 1670 | */ |
| 1671 | public static class JCIdent extends JCExpression implements IdentifierTree { |
| 1672 | public Name name; |
| 1673 | public Symbol sym; |
| 1674 | protected JCIdent(Name name, Symbol sym) { |
| 1675 | this.name = name; |
| 1676 | this.sym = sym; |
| 1677 | } |
| 1678 | @Override |
| 1679 | public void accept(Visitor v) { v.visitIdent(this); } |
| 1680 | |
| 1681 | public Kind getKind() { return Kind.IDENTIFIER; } |
| 1682 | public Name getName() { return name; } |
| 1683 | @Override |
| 1684 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1685 | return v.visitIdentifier(this, d); |
| 1686 | } |
| 1687 | public int getTag() { |
| 1688 | return IDENT; |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | /** |
| 1693 | * A constant value given literally. |
| 1694 | * @param value value representation |
| 1695 | */ |
| 1696 | public static class JCLiteral extends JCExpression implements LiteralTree { |
| 1697 | public int typetag; |
| 1698 | public Object value; |
| 1699 | protected JCLiteral(int typetag, Object value) { |
| 1700 | this.typetag = typetag; |
| 1701 | this.value = value; |
| 1702 | } |
| 1703 | @Override |
| 1704 | public void accept(Visitor v) { v.visitLiteral(this); } |
| 1705 | |
| 1706 | public Kind getKind() { |
| 1707 | switch (typetag) { |
| 1708 | case TypeTags.INT: |
| 1709 | return Kind.INT_LITERAL; |
| 1710 | case TypeTags.LONG: |
| 1711 | return Kind.LONG_LITERAL; |
| 1712 | case TypeTags.FLOAT: |
| 1713 | return Kind.FLOAT_LITERAL; |
| 1714 | case TypeTags.DOUBLE: |
| 1715 | return Kind.DOUBLE_LITERAL; |
| 1716 | case TypeTags.BOOLEAN: |
| 1717 | return Kind.BOOLEAN_LITERAL; |
| 1718 | case TypeTags.CHAR: |
| 1719 | return Kind.CHAR_LITERAL; |
| 1720 | case TypeTags.CLASS: |
| 1721 | return Kind.STRING_LITERAL; |
| 1722 | case TypeTags.BOT: |
| 1723 | return Kind.NULL_LITERAL; |
| 1724 | default: |
| 1725 | throw new AssertionError("unknown literal kind " + this); |
| 1726 | } |
| 1727 | } |
| 1728 | public Object getValue() { |
| 1729 | switch (typetag) { |
| 1730 | case TypeTags.BOOLEAN: |
| 1731 | int bi = (Integer) value; |
| 1732 | return (bi != 0); |
| 1733 | case TypeTags.CHAR: |
| 1734 | int ci = (Integer) value; |
| 1735 | char c = (char) ci; |
| 1736 | if (c != ci) |
| 1737 | throw new AssertionError("bad value for char literal"); |
| 1738 | return c; |
| 1739 | default: |
| 1740 | return value; |
| 1741 | } |
| 1742 | } |
| 1743 | @Override |
| 1744 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1745 | return v.visitLiteral(this, d); |
| 1746 | } |
| 1747 | @Override |
| 1748 | public JCLiteral setType(Type type) { |
| 1749 | super.setType(type); |
| 1750 | return this; |
| 1751 | } |
| 1752 | @Override |
| 1753 | public int getTag() { |
| 1754 | return LITERAL; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | /** |
| 1759 | * Identifies a basic type. |
| 1760 | * @param tag the basic type id |
| 1761 | * @see TypeTags |
| 1762 | */ |
| 1763 | public static class JCPrimitiveTypeTree extends JCExpression implements PrimitiveTypeTree { |
| 1764 | public int typetag; |
| 1765 | protected JCPrimitiveTypeTree(int typetag) { |
| 1766 | this.typetag = typetag; |
| 1767 | } |
| 1768 | @Override |
| 1769 | public void accept(Visitor v) { v.visitTypeIdent(this); } |
| 1770 | |
| 1771 | public Kind getKind() { return Kind.PRIMITIVE_TYPE; } |
| 1772 | public TypeKind getPrimitiveTypeKind() { |
| 1773 | switch (typetag) { |
| 1774 | case TypeTags.BOOLEAN: |
| 1775 | return TypeKind.BOOLEAN; |
| 1776 | case TypeTags.BYTE: |
| 1777 | return TypeKind.BYTE; |
| 1778 | case TypeTags.SHORT: |
| 1779 | return TypeKind.SHORT; |
| 1780 | case TypeTags.INT: |
| 1781 | return TypeKind.INT; |
| 1782 | case TypeTags.LONG: |
| 1783 | return TypeKind.LONG; |
| 1784 | case TypeTags.CHAR: |
| 1785 | return TypeKind.CHAR; |
| 1786 | case TypeTags.FLOAT: |
| 1787 | return TypeKind.FLOAT; |
| 1788 | case TypeTags.DOUBLE: |
| 1789 | return TypeKind.DOUBLE; |
| 1790 | case TypeTags.VOID: |
| 1791 | return TypeKind.VOID; |
| 1792 | default: |
| 1793 | throw new AssertionError("unknown primitive type " + this); |
| 1794 | } |
| 1795 | } |
| 1796 | @Override |
| 1797 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1798 | return v.visitPrimitiveType(this, d); |
| 1799 | } |
| 1800 | @Override |
| 1801 | public int getTag() { |
| 1802 | return TYPEIDENT; |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | /** |
| 1807 | * An array type, A[] |
| 1808 | */ |
| 1809 | public static class JCArrayTypeTree extends JCExpression implements ArrayTypeTree { |
| 1810 | public JCExpression elemtype; |
| 1811 | protected JCArrayTypeTree(JCExpression elemtype) { |
| 1812 | this.elemtype = elemtype; |
| 1813 | } |
| 1814 | @Override |
| 1815 | public void accept(Visitor v) { v.visitTypeArray(this); } |
| 1816 | |
| 1817 | public Kind getKind() { return Kind.ARRAY_TYPE; } |
| 1818 | public JCTree getType() { return elemtype; } |
| 1819 | @Override |
| 1820 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1821 | return v.visitArrayType(this, d); |
| 1822 | } |
| 1823 | @Override |
| 1824 | public int getTag() { |
| 1825 | return TYPEARRAY; |
| 1826 | } |
| 1827 | } |
| 1828 | |
| 1829 | /** |
| 1830 | * A parameterized type, T<...> |
| 1831 | */ |
| 1832 | public static class JCTypeApply extends JCExpression implements ParameterizedTypeTree { |
| 1833 | public JCExpression clazz; |
| 1834 | public List<JCExpression> arguments; |
| 1835 | protected JCTypeApply(JCExpression clazz, List<JCExpression> arguments) { |
| 1836 | this.clazz = clazz; |
| 1837 | this.arguments = arguments; |
| 1838 | } |
| 1839 | @Override |
| 1840 | public void accept(Visitor v) { v.visitTypeApply(this); } |
| 1841 | |
| 1842 | public Kind getKind() { return Kind.PARAMETERIZED_TYPE; } |
| 1843 | public JCTree getType() { return clazz; } |
| 1844 | public List<JCExpression> getTypeArguments() { |
| 1845 | return arguments; |
| 1846 | } |
| 1847 | @Override |
| 1848 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1849 | return v.visitParameterizedType(this, d); |
| 1850 | } |
| 1851 | @Override |
| 1852 | public int getTag() { |
| 1853 | return TYPEAPPLY; |
| 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | /** |
| 1858 | * A formal class parameter. |
| 1859 | * @param name name |
| 1860 | * @param bounds bounds |
| 1861 | */ |
| 1862 | public static class JCTypeParameter extends JCTree implements TypeParameterTree { |
| 1863 | public Name name; |
| 1864 | public List<JCExpression> bounds; |
| 1865 | protected JCTypeParameter(Name name, List<JCExpression> bounds) { |
| 1866 | this.name = name; |
| 1867 | this.bounds = bounds; |
| 1868 | } |
| 1869 | @Override |
| 1870 | public void accept(Visitor v) { v.visitTypeParameter(this); } |
| 1871 | |
| 1872 | public Kind getKind() { return Kind.TYPE_PARAMETER; } |
| 1873 | public Name getName() { return name; } |
| 1874 | public List<JCExpression> getBounds() { |
| 1875 | return bounds; |
| 1876 | } |
| 1877 | @Override |
| 1878 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1879 | return v.visitTypeParameter(this, d); |
| 1880 | } |
| 1881 | @Override |
| 1882 | public int getTag() { |
| 1883 | return TYPEPARAMETER; |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | public static class JCWildcard extends JCExpression implements WildcardTree { |
| 1888 | public TypeBoundKind kind; |
| 1889 | public JCTree inner; |
| 1890 | protected JCWildcard(TypeBoundKind kind, JCTree inner) { |
| 1891 | kind.getClass(); // null-check |
| 1892 | this.kind = kind; |
| 1893 | this.inner = inner; |
| 1894 | } |
| 1895 | @Override |
| 1896 | public void accept(Visitor v) { v.visitWildcard(this); } |
| 1897 | |
| 1898 | public Kind getKind() { |
| 1899 | switch (kind.kind) { |
| 1900 | case UNBOUND: |
| 1901 | return Kind.UNBOUNDED_WILDCARD; |
| 1902 | case EXTENDS: |
| 1903 | return Kind.EXTENDS_WILDCARD; |
| 1904 | case SUPER: |
| 1905 | return Kind.SUPER_WILDCARD; |
| 1906 | default: |
| 1907 | throw new AssertionError("Unknown wildcard bound " + kind); |
| 1908 | } |
| 1909 | } |
| 1910 | public JCTree getBound() { return inner; } |
| 1911 | @Override |
| 1912 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1913 | return v.visitWildcard(this, d); |
| 1914 | } |
| 1915 | @Override |
| 1916 | public int getTag() { |
| 1917 | return WILDCARD; |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | public static class TypeBoundKind extends JCTree { |
| 1922 | public BoundKind kind; |
| 1923 | protected TypeBoundKind(BoundKind kind) { |
| 1924 | this.kind = kind; |
| 1925 | } |
| 1926 | @Override |
| 1927 | public void accept(Visitor v) { v.visitTypeBoundKind(this); } |
| 1928 | |
| 1929 | public Kind getKind() { |
| 1930 | throw new AssertionError("TypeBoundKind is not part of a public API"); |
| 1931 | } |
| 1932 | @Override |
| 1933 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1934 | throw new AssertionError("TypeBoundKind is not part of a public API"); |
| 1935 | } |
| 1936 | @Override |
| 1937 | public int getTag() { |
| 1938 | return TYPEBOUNDKIND; |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | public static class JCAnnotation extends JCExpression implements AnnotationTree { |
| 1943 | public JCTree annotationType; |
| 1944 | public List<JCExpression> args; |
| 1945 | protected JCAnnotation(JCTree annotationType, List<JCExpression> args) { |
| 1946 | this.annotationType = annotationType; |
| 1947 | this.args = args; |
| 1948 | } |
| 1949 | @Override |
| 1950 | public void accept(Visitor v) { v.visitAnnotation(this); } |
| 1951 | |
| 1952 | public Kind getKind() { return Kind.ANNOTATION; } |
| 1953 | public JCTree getAnnotationType() { return annotationType; } |
| 1954 | public List<JCExpression> getArguments() { |
| 1955 | return args; |
| 1956 | } |
| 1957 | @Override |
| 1958 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1959 | return v.visitAnnotation(this, d); |
| 1960 | } |
| 1961 | @Override |
| 1962 | public int getTag() { |
| 1963 | return ANNOTATION; |
| 1964 | } |
| 1965 | } |
| 1966 | |
| 1967 | public static class JCModifiers extends JCTree implements com.sun.source.tree.ModifiersTree { |
| 1968 | public long flags; |
| 1969 | public List<JCAnnotation> annotations; |
| 1970 | protected JCModifiers(long flags, List<JCAnnotation> annotations) { |
| 1971 | this.flags = flags; |
| 1972 | this.annotations = annotations; |
| 1973 | } |
| 1974 | @Override |
| 1975 | public void accept(Visitor v) { v.visitModifiers(this); } |
| 1976 | |
| 1977 | public Kind getKind() { return Kind.MODIFIERS; } |
| 1978 | public Set<Modifier> getFlags() { |
| 1979 | return Flags.asModifierSet(flags); |
| 1980 | } |
| 1981 | public List<JCAnnotation> getAnnotations() { |
| 1982 | return annotations; |
| 1983 | } |
| 1984 | @Override |
| 1985 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 1986 | return v.visitModifiers(this, d); |
| 1987 | } |
| 1988 | @Override |
| 1989 | public int getTag() { |
| 1990 | return MODIFIERS; |
| 1991 | } |
| 1992 | } |
| 1993 | |
| 1994 | public static class JCErroneous extends JCExpression |
| 1995 | implements com.sun.source.tree.ErroneousTree { |
| 1996 | public List<? extends JCTree> errs; |
| 1997 | protected JCErroneous(List<? extends JCTree> errs) { |
| 1998 | this.errs = errs; |
| 1999 | } |
| 2000 | @Override |
| 2001 | public void accept(Visitor v) { v.visitErroneous(this); } |
| 2002 | |
| 2003 | public Kind getKind() { return Kind.ERRONEOUS; } |
| 2004 | |
| 2005 | public List<? extends JCTree> getErrorTrees() { |
| 2006 | return errs; |
| 2007 | } |
| 2008 | |
| 2009 | @Override |
| 2010 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 2011 | return v.visitErroneous(this, d); |
| 2012 | } |
| 2013 | @Override |
| 2014 | public int getTag() { |
| 2015 | return ERRONEOUS; |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | /** (let int x = 3; in x+2) */ |
| 2020 | public static class LetExpr extends JCExpression { |
| 2021 | public List<JCVariableDecl> defs; |
| 2022 | public JCTree expr; |
| 2023 | protected LetExpr(List<JCVariableDecl> defs, JCTree expr) { |
| 2024 | this.defs = defs; |
| 2025 | this.expr = expr; |
| 2026 | } |
| 2027 | @Override |
| 2028 | public void accept(Visitor v) { v.visitLetExpr(this); } |
| 2029 | |
| 2030 | public Kind getKind() { |
| 2031 | throw new AssertionError("LetExpr is not part of a public API"); |
| 2032 | } |
| 2033 | @Override |
| 2034 | public <R,D> R accept(TreeVisitor<R,D> v, D d) { |
| 2035 | throw new AssertionError("LetExpr is not part of a public API"); |
| 2036 | } |
| 2037 | @Override |
| 2038 | public int getTag() { |
| 2039 | return LETEXPR; |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | /** An interface for tree factories |
| 2044 | */ |
| 2045 | public interface Factory { |
| 2046 | JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, |
| 2047 | JCExpression pid, |
| 2048 | List<JCTree> defs); |
| 2049 | JCImport Import(JCTree qualid, boolean staticImport); |
| 2050 | JCClassDecl ClassDef(JCModifiers mods, |
| 2051 | Name name, |
| 2052 | List<JCTypeParameter> typarams, |
| 2053 | JCTree extending, |
| 2054 | List<JCExpression> implementing, |
| 2055 | List<JCTree> defs); |
| 2056 | JCMethodDecl MethodDef(JCModifiers mods, |
| 2057 | Name name, |
| 2058 | JCExpression restype, |
| 2059 | List<JCTypeParameter> typarams, |
| 2060 | List<JCVariableDecl> params, |
| 2061 | List<JCExpression> thrown, |
| 2062 | JCBlock body, |
| 2063 | JCExpression defaultValue); |
| 2064 | JCVariableDecl VarDef(JCModifiers mods, |
| 2065 | Name name, |
| 2066 | JCExpression vartype, |
| 2067 | JCExpression init); |
| 2068 | JCSkip Skip(); |
| 2069 | JCBlock Block(long flags, List<JCStatement> stats); |
| 2070 | JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond); |
| 2071 | JCWhileLoop WhileLoop(JCExpression cond, JCStatement body); |
| 2072 | JCForLoop ForLoop(List<JCStatement> init, |
| 2073 | JCExpression cond, |
| 2074 | List<JCExpressionStatement> step, |
| 2075 | JCStatement body); |
| 2076 | JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body); |
| 2077 | JCLabeledStatement Labelled(Name label, JCStatement body); |
| 2078 | JCSwitch Switch(JCExpression selector, List<JCCase> cases); |
| 2079 | JCCase Case(JCExpression pat, List<JCStatement> stats); |
| 2080 | JCSynchronized Synchronized(JCExpression lock, JCBlock body); |
| 2081 | JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer); |
| 2082 | JCCatch Catch(JCVariableDecl param, JCBlock body); |
| 2083 | JCConditional Conditional(JCExpression cond, |
| 2084 | JCExpression thenpart, |
| 2085 | JCExpression elsepart); |
| 2086 | JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart); |
| 2087 | JCExpressionStatement Exec(JCExpression expr); |
| 2088 | JCBreak Break(Name label); |
| 2089 | JCContinue Continue(Name label); |
| 2090 | JCReturn Return(JCExpression expr); |
| 2091 | JCThrow Throw(JCTree expr); |
| 2092 | JCAssert Assert(JCExpression cond, JCExpression detail); |
| 2093 | JCMethodInvocation Apply(List<JCExpression> typeargs, |
| 2094 | JCExpression fn, |
| 2095 | List<JCExpression> args); |
| 2096 | JCNewClass NewClass(JCExpression encl, |
| 2097 | List<JCExpression> typeargs, |
| 2098 | JCExpression clazz, |
| 2099 | List<JCExpression> args, |
| 2100 | JCClassDecl def); |
| 2101 | JCNewArray NewArray(JCExpression elemtype, |
| 2102 | List<JCExpression> dims, |
| 2103 | List<JCExpression> elems); |
| 2104 | JCParens Parens(JCExpression expr); |
| 2105 | JCAssign Assign(JCExpression lhs, JCExpression rhs); |
| 2106 | JCAssignOp Assignop(int opcode, JCTree lhs, JCTree rhs); |
| 2107 | JCUnary Unary(int opcode, JCExpression arg); |
| 2108 | JCBinary Binary(int opcode, JCExpression lhs, JCExpression rhs); |
| 2109 | JCTypeCast TypeCast(JCTree expr, JCExpression type); |
| 2110 | JCInstanceOf TypeTest(JCExpression expr, JCTree clazz); |
| 2111 | JCArrayAccess Indexed(JCExpression indexed, JCExpression index); |
| 2112 | JCFieldAccess Select(JCExpression selected, Name selector); |
| 2113 | JCIdent Ident(Name idname); |
| 2114 | JCLiteral Literal(int tag, Object value); |
| 2115 | JCPrimitiveTypeTree TypeIdent(int typetag); |
| 2116 | JCArrayTypeTree TypeArray(JCExpression elemtype); |
| 2117 | JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments); |
| 2118 | JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds); |
| 2119 | JCWildcard Wildcard(TypeBoundKind kind, JCTree type); |
| 2120 | TypeBoundKind TypeBoundKind(BoundKind kind); |
| 2121 | JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args); |
| 2122 | JCModifiers Modifiers(long flags, List<JCAnnotation> annotations); |
| 2123 | JCErroneous Erroneous(List<? extends JCTree> errs); |
| 2124 | LetExpr LetExpr(List<JCVariableDecl> defs, JCTree expr); |
| 2125 | } |
| 2126 | |
| 2127 | /** A generic visitor class for trees. |
| 2128 | */ |
| 2129 | public static abstract class Visitor { |
| 2130 | public void visitTopLevel(JCCompilationUnit that) { visitTree(that); } |
| 2131 | public void visitImport(JCImport that) { visitTree(that); } |
| 2132 | public void visitClassDef(JCClassDecl that) { visitTree(that); } |
| 2133 | public void visitMethodDef(JCMethodDecl that) { visitTree(that); } |
| 2134 | public void visitVarDef(JCVariableDecl that) { visitTree(that); } |
| 2135 | public void visitSkip(JCSkip that) { visitTree(that); } |
| 2136 | public void visitBlock(JCBlock that) { visitTree(that); } |
| 2137 | public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); } |
| 2138 | public void visitWhileLoop(JCWhileLoop that) { visitTree(that); } |
| 2139 | public void visitForLoop(JCForLoop that) { visitTree(that); } |
| 2140 | public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); } |
| 2141 | public void visitLabelled(JCLabeledStatement that) { visitTree(that); } |
| 2142 | public void visitSwitch(JCSwitch that) { visitTree(that); } |
| 2143 | public void visitCase(JCCase that) { visitTree(that); } |
| 2144 | public void visitSynchronized(JCSynchronized that) { visitTree(that); } |
| 2145 | public void visitTry(JCTry that) { visitTree(that); } |
| 2146 | public void visitCatch(JCCatch that) { visitTree(that); } |
| 2147 | public void visitConditional(JCConditional that) { visitTree(that); } |
| 2148 | public void visitIf(JCIf that) { visitTree(that); } |
| 2149 | public void visitExec(JCExpressionStatement that) { visitTree(that); } |
| 2150 | public void visitBreak(JCBreak that) { visitTree(that); } |
| 2151 | public void visitContinue(JCContinue that) { visitTree(that); } |
| 2152 | public void visitReturn(JCReturn that) { visitTree(that); } |
| 2153 | public void visitThrow(JCThrow that) { visitTree(that); } |
| 2154 | public void visitAssert(JCAssert that) { visitTree(that); } |
| 2155 | public void visitApply(JCMethodInvocation that) { visitTree(that); } |
| 2156 | public void visitNewClass(JCNewClass that) { visitTree(that); } |
| 2157 | public void visitNewArray(JCNewArray that) { visitTree(that); } |
| 2158 | public void visitParens(JCParens that) { visitTree(that); } |
| 2159 | public void visitAssign(JCAssign that) { visitTree(that); } |
| 2160 | public void visitAssignop(JCAssignOp that) { visitTree(that); } |
| 2161 | public void visitUnary(JCUnary that) { visitTree(that); } |
| 2162 | public void visitBinary(JCBinary that) { visitTree(that); } |
| 2163 | public void visitTypeCast(JCTypeCast that) { visitTree(that); } |
| 2164 | public void visitTypeTest(JCInstanceOf that) { visitTree(that); } |
| 2165 | public void visitIndexed(JCArrayAccess that) { visitTree(that); } |
| 2166 | public void visitSelect(JCFieldAccess that) { visitTree(that); } |
| 2167 | public void visitIdent(JCIdent that) { visitTree(that); } |
| 2168 | public void visitLiteral(JCLiteral that) { visitTree(that); } |
| 2169 | public void visitTypeIdent(JCPrimitiveTypeTree that) { visitTree(that); } |
| 2170 | public void visitTypeArray(JCArrayTypeTree that) { visitTree(that); } |
| 2171 | public void visitTypeApply(JCTypeApply that) { visitTree(that); } |
| 2172 | public void visitTypeParameter(JCTypeParameter that) { visitTree(that); } |
| 2173 | public void visitWildcard(JCWildcard that) { visitTree(that); } |
| 2174 | public void visitTypeBoundKind(TypeBoundKind that) { visitTree(that); } |
| 2175 | public void visitAnnotation(JCAnnotation that) { visitTree(that); } |
| 2176 | public void visitModifiers(JCModifiers that) { visitTree(that); } |
| 2177 | public void visitErroneous(JCErroneous that) { visitTree(that); } |
| 2178 | public void visitLetExpr(LetExpr that) { visitTree(that); } |
| 2179 | |
| 2180 | public void visitTree(JCTree that) { assert false; } |
| 2181 | } |
| 2182 | |
| 2183 | } |