PageRenderTime 61ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/sun/tools/javac/tree/JCTree.java

https://bitbucket.org/showoowohs/termide
Java | 2183 lines | 1626 code | 191 blank | 366 comment | 16 complexity | 5759babc2fea348bd1cbe02815e7a360 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 1999, 2006, 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. package com.sun.tools.javac.tree;
  26. import java.util.*;
  27. import java.io.File;
  28. import java.io.IOException;
  29. import java.io.PrintWriter;
  30. import java.io.StringWriter;
  31. import javax.lang.model.element.Modifier;
  32. import javax.lang.model.type.TypeKind;
  33. import javax.tools.JavaFileObject;
  34. import com.sun.tools.javac.util.*;
  35. import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  36. import com.sun.tools.javac.util.List;
  37. import com.sun.tools.javac.code.*;
  38. import com.sun.tools.javac.code.Scope;
  39. import com.sun.tools.javac.code.Symbol.*;
  40. import com.sun.source.tree.Tree;
  41. import com.sun.source.tree.*;
  42. import static com.sun.tools.javac.code.BoundKind.*;
  43. /**
  44. * Root class for abstract syntax tree nodes. It provides definitions
  45. * for specific tree nodes as subclasses nested inside.
  46. *
  47. * <p>Each subclass is highly standardized. It generally contains
  48. * only tree fields for the syntactic subcomponents of the node. Some
  49. * classes that represent identifier uses or definitions also define a
  50. * Symbol field that denotes the represented identifier. Classes for
  51. * non-local jumps also carry the jump target as a field. The root
  52. * class Tree itself defines fields for the tree's type and position.
  53. * No other fields are kept in a tree node; instead parameters are
  54. * passed to methods accessing the node.
  55. *
  56. * <p>Except for the methods defined by com.sun.source, the only
  57. * method defined in subclasses is `visit' which applies a given
  58. * visitor to the tree. The actual tree processing is done by visitor
  59. * classes in other packages. The abstract class Visitor, as well as
  60. * an Factory interface for trees, are defined as inner classes in
  61. * Tree.
  62. *
  63. * <p>To avoid ambiguities with the Tree API in com.sun.source all sub
  64. * classes should, by convention, start with JC (javac).
  65. *
  66. * <p><b>This is NOT part of any supported API.
  67. * If you write code that depends on this, you do so at your own risk.
  68. * This code and its internal interfaces are subject to change or
  69. * deletion without notice.</b>
  70. *
  71. * @see TreeMaker
  72. * @see TreeInfo
  73. * @see TreeTranslator
  74. * @see Pretty
  75. */
  76. public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {
  77. /* Tree tag values, identifying kinds of trees */
  78. /** Toplevel nodes, of type TopLevel, representing entire source files.
  79. */
  80. public static final int TOPLEVEL = 1;
  81. /** Import clauses, of type Import.
  82. */
  83. public static final int IMPORT = TOPLEVEL + 1;
  84. /** Class definitions, of type ClassDef.
  85. */
  86. public static final int CLASSDEF = IMPORT + 1;
  87. /** Method definitions, of type MethodDef.
  88. */
  89. public static final int METHODDEF = CLASSDEF + 1;
  90. /** Variable definitions, of type VarDef.
  91. */
  92. public static final int VARDEF = METHODDEF + 1;
  93. /** The no-op statement ";", of type Skip
  94. */
  95. public static final int SKIP = VARDEF + 1;
  96. /** Blocks, of type Block.
  97. */
  98. public static final int BLOCK = SKIP + 1;
  99. /** Do-while loops, of type DoLoop.
  100. */
  101. public static final int DOLOOP = BLOCK + 1;
  102. /** While-loops, of type WhileLoop.
  103. */
  104. public static final int WHILELOOP = DOLOOP + 1;
  105. /** For-loops, of type ForLoop.
  106. */
  107. public static final int FORLOOP = WHILELOOP + 1;
  108. /** Foreach-loops, of type ForeachLoop.
  109. */
  110. public static final int FOREACHLOOP = FORLOOP + 1;
  111. /** Labelled statements, of type Labelled.
  112. */
  113. public static final int LABELLED = FOREACHLOOP + 1;
  114. /** Switch statements, of type Switch.
  115. */
  116. public static final int SWITCH = LABELLED + 1;
  117. /** Case parts in switch statements, of type Case.
  118. */
  119. public static final int CASE = SWITCH + 1;
  120. /** Synchronized statements, of type Synchonized.
  121. */
  122. public static final int SYNCHRONIZED = CASE + 1;
  123. /** Try statements, of type Try.
  124. */
  125. public static final int TRY = SYNCHRONIZED + 1;
  126. /** Catch clauses in try statements, of type Catch.
  127. */
  128. public static final int CATCH = TRY + 1;
  129. /** Conditional expressions, of type Conditional.
  130. */
  131. public static final int CONDEXPR = CATCH + 1;
  132. /** Conditional statements, of type If.
  133. */
  134. public static final int IF = CONDEXPR + 1;
  135. /** Expression statements, of type Exec.
  136. */
  137. public static final int EXEC = IF + 1;
  138. /** Break statements, of type Break.
  139. */
  140. public static final int BREAK = EXEC + 1;
  141. /** Continue statements, of type Continue.
  142. */
  143. public static final int CONTINUE = BREAK + 1;
  144. /** Return statements, of type Return.
  145. */
  146. public static final int RETURN = CONTINUE + 1;
  147. /** Throw statements, of type Throw.
  148. */
  149. public static final int THROW = RETURN + 1;
  150. /** Assert statements, of type Assert.
  151. */
  152. public static final int ASSERT = THROW + 1;
  153. /** Method invocation expressions, of type Apply.
  154. */
  155. public static final int APPLY = ASSERT + 1;
  156. /** Class instance creation expressions, of type NewClass.
  157. */
  158. public static final int NEWCLASS = APPLY + 1;
  159. /** Array creation expressions, of type NewArray.
  160. */
  161. public static final int NEWARRAY = NEWCLASS + 1;
  162. /** Parenthesized subexpressions, of type Parens.
  163. */
  164. public static final int PARENS = NEWARRAY + 1;
  165. /** Assignment expressions, of type Assign.
  166. */
  167. public static final int ASSIGN = PARENS + 1;
  168. /** Type cast expressions, of type TypeCast.
  169. */
  170. public static final int TYPECAST = ASSIGN + 1;
  171. /** Type test expressions, of type TypeTest.
  172. */
  173. public static final int TYPETEST = TYPECAST + 1;
  174. /** Indexed array expressions, of type Indexed.
  175. */
  176. public static final int INDEXED = TYPETEST + 1;
  177. /** Selections, of type Select.
  178. */
  179. public static final int SELECT = INDEXED + 1;
  180. /** Simple identifiers, of type Ident.
  181. */
  182. public static final int IDENT = SELECT + 1;
  183. /** Literals, of type Literal.
  184. */
  185. public static final int LITERAL = IDENT + 1;
  186. /** Basic type identifiers, of type TypeIdent.
  187. */
  188. public static final int TYPEIDENT = LITERAL + 1;
  189. /** Array types, of type TypeArray.
  190. */
  191. public static final int TYPEARRAY = TYPEIDENT + 1;
  192. /** Parameterized types, of type TypeApply.
  193. */
  194. public static final int TYPEAPPLY = TYPEARRAY + 1;
  195. /** Formal type parameters, of type TypeParameter.
  196. */
  197. public static final int TYPEPARAMETER = TYPEAPPLY + 1;
  198. /** Type argument.
  199. */
  200. public static final int WILDCARD = TYPEPARAMETER + 1;
  201. /** Bound kind: extends, super, exact, or unbound
  202. */
  203. public static final int TYPEBOUNDKIND = WILDCARD + 1;
  204. /** metadata: Annotation.
  205. */
  206. public static final int ANNOTATION = TYPEBOUNDKIND + 1;
  207. /** metadata: Modifiers
  208. */
  209. public static final int MODIFIERS = ANNOTATION + 1;
  210. /** Error trees, of type Erroneous.
  211. */
  212. public static final int ERRONEOUS = MODIFIERS + 1;
  213. /** Unary operators, of type Unary.
  214. */
  215. public static final int POS = ERRONEOUS + 1; // +
  216. public static final int NEG = POS + 1; // -
  217. public static final int NOT = NEG + 1; // !
  218. public static final int COMPL = NOT + 1; // ~
  219. public static final int PREINC = COMPL + 1; // ++ _
  220. public static final int PREDEC = PREINC + 1; // -- _
  221. public static final int POSTINC = PREDEC + 1; // _ ++
  222. public static final int POSTDEC = POSTINC + 1; // _ --
  223. /** unary operator for null reference checks, only used internally.
  224. */
  225. public static final int NULLCHK = POSTDEC + 1;
  226. /** Binary operators, of type Binary.
  227. */
  228. public static final int OR = NULLCHK + 1; // ||
  229. public static final int AND = OR + 1; // &&
  230. public static final int BITOR = AND + 1; // |
  231. public static final int BITXOR = BITOR + 1; // ^
  232. public static final int BITAND = BITXOR + 1; // &
  233. public static final int EQ = BITAND + 1; // ==
  234. public static final int NE = EQ + 1; // !=
  235. public static final int LT = NE + 1; // <
  236. public static final int GT = LT + 1; // >
  237. public static final int LE = GT + 1; // <=
  238. public static final int GE = LE + 1; // >=
  239. public static final int SL = GE + 1; // <<
  240. public static final int SR = SL + 1; // >>
  241. public static final int USR = SR + 1; // >>>
  242. public static final int PLUS = USR + 1; // +
  243. public static final int MINUS = PLUS + 1; // -
  244. public static final int MUL = MINUS + 1; // *
  245. public static final int DIV = MUL + 1; // /
  246. public static final int MOD = DIV + 1; // %
  247. /** Assignment operators, of type Assignop.
  248. */
  249. public static final int BITOR_ASG = MOD + 1; // |=
  250. public static final int BITXOR_ASG = BITOR_ASG + 1; // ^=
  251. public static final int BITAND_ASG = BITXOR_ASG + 1; // &=
  252. public static final int SL_ASG = SL + BITOR_ASG - BITOR; // <<=
  253. public static final int SR_ASG = SL_ASG + 1; // >>=
  254. public static final int USR_ASG = SR_ASG + 1; // >>>=
  255. public static final int PLUS_ASG = USR_ASG + 1; // +=
  256. public static final int MINUS_ASG = PLUS_ASG + 1; // -=
  257. public static final int MUL_ASG = MINUS_ASG + 1; // *=
  258. public static final int DIV_ASG = MUL_ASG + 1; // /=
  259. public static final int MOD_ASG = DIV_ASG + 1; // %=
  260. /** A synthetic let expression, of type LetExpr.
  261. */
  262. public static final int LETEXPR = MOD_ASG + 1; // ala scheme
  263. /** The offset between assignment operators and normal operators.
  264. */
  265. public static final int ASGOffset = BITOR_ASG - BITOR;
  266. /* The (encoded) position in the source file. @see util.Position.
  267. */
  268. public int pos;
  269. /* The type of this node.
  270. */
  271. public Type type;
  272. /* The tag of this node -- one of the constants declared above.
  273. */
  274. public abstract int getTag();
  275. /** Convert a tree to a pretty-printed string. */
  276. public String toString() {
  277. StringWriter s = new StringWriter();
  278. try {
  279. new Pretty(s, false).printExpr(this);
  280. }
  281. catch (IOException e) {
  282. // should never happen, because StringWriter is defined
  283. // never to throw any IOExceptions
  284. throw new AssertionError(e);
  285. }
  286. return s.toString();
  287. }
  288. /** Set position field and return this tree.
  289. */
  290. public JCTree setPos(int pos) {
  291. this.pos = pos;
  292. return this;
  293. }
  294. /** Set type field and return this tree.
  295. */
  296. public JCTree setType(Type type) {
  297. this.type = type;
  298. return this;
  299. }
  300. /** Visit this tree with a given visitor.
  301. */
  302. public abstract void accept(Visitor v);
  303. public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);
  304. /** Return a shallow copy of this tree.
  305. */
  306. public Object clone() {
  307. try {
  308. return super.clone();
  309. } catch(CloneNotSupportedException e) {
  310. throw new RuntimeException(e);
  311. }
  312. }
  313. /** Get a default position for this tree node.
  314. */
  315. public DiagnosticPosition pos() {
  316. return this;
  317. }
  318. // for default DiagnosticPosition
  319. public JCTree getTree() {
  320. return this;
  321. }
  322. // for default DiagnosticPosition
  323. public int getStartPosition() {
  324. return TreeInfo.getStartPos(this);
  325. }
  326. // for default DiagnosticPosition
  327. public int getPreferredPosition() {
  328. return pos;
  329. }
  330. // for default DiagnosticPosition
  331. public int getEndPosition(Map<JCTree, Integer> endPosTable) {
  332. return TreeInfo.getEndPos(this, endPosTable);
  333. }
  334. /**
  335. * Everything in one source file is kept in a TopLevel structure.
  336. * @param pid The tree representing the package clause.
  337. * @param sourcefile The source file name.
  338. * @param defs All definitions in this file (ClassDef, Import, and Skip)
  339. * @param packge The package it belongs to.
  340. * @param namedImportScope A scope for all named imports.
  341. * @param starImportScope A scope for all import-on-demands.
  342. * @param lineMap Line starting positions, defined only
  343. * if option -g is set.
  344. * @param docComments A hashtable that stores all documentation comments
  345. * indexed by the tree nodes they refer to.
  346. * defined only if option -s is set.
  347. * @param endPositions A hashtable that stores ending positions of source
  348. * ranges indexed by the tree nodes they belong to.
  349. * Defined only if option -Xjcov is set.
  350. */
  351. public static class JCCompilationUnit extends JCTree implements CompilationUnitTree {
  352. public List<JCAnnotation> packageAnnotations;
  353. public JCExpression pid;
  354. public List<JCTree> defs;
  355. public JavaFileObject sourcefile;
  356. public PackageSymbol packge;
  357. public Scope namedImportScope;
  358. public Scope starImportScope;
  359. public long flags;
  360. public Position.LineMap lineMap = null;
  361. public Map<JCTree, String> docComments = null;
  362. public Map<JCTree, Integer> endPositions = null;
  363. protected JCCompilationUnit(List<JCAnnotation> packageAnnotations,
  364. JCExpression pid,
  365. List<JCTree> defs,
  366. JavaFileObject sourcefile,
  367. PackageSymbol packge,
  368. Scope namedImportScope,
  369. Scope starImportScope) {
  370. this.packageAnnotations = packageAnnotations;
  371. this.pid = pid;
  372. this.defs = defs;
  373. this.sourcefile = sourcefile;
  374. this.packge = packge;
  375. this.namedImportScope = namedImportScope;
  376. this.starImportScope = starImportScope;
  377. }
  378. @Override
  379. public void accept(Visitor v) { v.visitTopLevel(this); }
  380. public Kind getKind() { return Kind.COMPILATION_UNIT; }
  381. public List<JCAnnotation> getPackageAnnotations() {
  382. return packageAnnotations;
  383. }
  384. public List<JCImport> getImports() {
  385. ListBuffer<JCImport> imports = new ListBuffer<JCImport>();
  386. for (JCTree tree : defs) {
  387. if (tree.getTag() == IMPORT)
  388. imports.append((JCImport)tree);
  389. else
  390. break;
  391. }
  392. return imports.toList();
  393. }
  394. public JCExpression getPackageName() { return pid; }
  395. public JavaFileObject getSourceFile() {
  396. return sourcefile;
  397. }
  398. public Position.LineMap getLineMap() {
  399. return lineMap;
  400. }
  401. public List<JCTree> getTypeDecls() {
  402. List<JCTree> typeDefs;
  403. for (typeDefs = defs; !typeDefs.isEmpty(); typeDefs = typeDefs.tail)
  404. if (typeDefs.head.getTag() != IMPORT)
  405. break;
  406. return typeDefs;
  407. }
  408. @Override
  409. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  410. return v.visitCompilationUnit(this, d);
  411. }
  412. @Override
  413. public int getTag() {
  414. return TOPLEVEL;
  415. }
  416. }
  417. /**
  418. * An import clause.
  419. * @param qualid The imported class(es).
  420. */
  421. public static class JCImport extends JCTree implements ImportTree {
  422. public boolean staticImport;
  423. public JCTree qualid;
  424. protected JCImport(JCTree qualid, boolean importStatic) {
  425. this.qualid = qualid;
  426. this.staticImport = importStatic;
  427. }
  428. @Override
  429. public void accept(Visitor v) { v.visitImport(this); }
  430. public boolean isStatic() { return staticImport; }
  431. public JCTree getQualifiedIdentifier() { return qualid; }
  432. public Kind getKind() { return Kind.IMPORT; }
  433. @Override
  434. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  435. return v.visitImport(this, d);
  436. }
  437. @Override
  438. public int getTag() {
  439. return IMPORT;
  440. }
  441. }
  442. public static abstract class JCStatement extends JCTree implements StatementTree {
  443. @Override
  444. public JCStatement setType(Type type) {
  445. super.setType(type);
  446. return this;
  447. }
  448. @Override
  449. public JCStatement setPos(int pos) {
  450. super.setPos(pos);
  451. return this;
  452. }
  453. }
  454. public static abstract class JCExpression extends JCTree implements ExpressionTree {
  455. @Override
  456. public JCExpression setType(Type type) {
  457. super.setType(type);
  458. return this;
  459. }
  460. @Override
  461. public JCExpression setPos(int pos) {
  462. super.setPos(pos);
  463. return this;
  464. }
  465. }
  466. /**
  467. * A class definition.
  468. * @param modifiers the modifiers
  469. * @param name the name of the class
  470. * @param typarams formal class parameters
  471. * @param extending the classes this class extends
  472. * @param implementing the interfaces implemented by this class
  473. * @param defs all variables and methods defined in this class
  474. * @param sym the symbol
  475. */
  476. public static class JCClassDecl extends JCStatement implements ClassTree {
  477. public JCModifiers mods;
  478. public Name name;
  479. public List<JCTypeParameter> typarams;
  480. public JCTree extending;
  481. public List<JCExpression> implementing;
  482. public List<JCTree> defs;
  483. public ClassSymbol sym;
  484. protected JCClassDecl(JCModifiers mods,
  485. Name name,
  486. List<JCTypeParameter> typarams,
  487. JCTree extending,
  488. List<JCExpression> implementing,
  489. List<JCTree> defs,
  490. ClassSymbol sym)
  491. {
  492. this.mods = mods;
  493. this.name = name;
  494. this.typarams = typarams;
  495. this.extending = extending;
  496. this.implementing = implementing;
  497. this.defs = defs;
  498. this.sym = sym;
  499. }
  500. @Override
  501. public void accept(Visitor v) { v.visitClassDef(this); }
  502. public Kind getKind() { return Kind.CLASS; }
  503. public JCModifiers getModifiers() { return mods; }
  504. public Name getSimpleName() { return name; }
  505. public List<JCTypeParameter> getTypeParameters() {
  506. return typarams;
  507. }
  508. public JCTree getExtendsClause() { return extending; }
  509. public List<JCExpression> getImplementsClause() {
  510. return implementing;
  511. }
  512. public List<JCTree> getMembers() {
  513. return defs;
  514. }
  515. @Override
  516. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  517. return v.visitClass(this, d);
  518. }
  519. @Override
  520. public int getTag() {
  521. return CLASSDEF;
  522. }
  523. }
  524. /**
  525. * A method definition.
  526. * @param modifiers method modifiers
  527. * @param name method name
  528. * @param restype type of method return value
  529. * @param typarams type parameters
  530. * @param params value parameters
  531. * @param thrown exceptions thrown by this method
  532. * @param stats statements in the method
  533. * @param sym method symbol
  534. */
  535. public static class JCMethodDecl extends JCTree implements MethodTree {
  536. public JCModifiers mods;
  537. public Name name;
  538. public JCExpression restype;
  539. public List<JCTypeParameter> typarams;
  540. public List<JCVariableDecl> params;
  541. public List<JCExpression> thrown;
  542. public JCBlock body;
  543. public JCExpression defaultValue; // for annotation types
  544. public MethodSymbol sym;
  545. protected JCMethodDecl(JCModifiers mods,
  546. Name name,
  547. JCExpression restype,
  548. List<JCTypeParameter> typarams,
  549. List<JCVariableDecl> params,
  550. List<JCExpression> thrown,
  551. JCBlock body,
  552. JCExpression defaultValue,
  553. MethodSymbol sym)
  554. {
  555. this.mods = mods;
  556. this.name = name;
  557. this.restype = restype;
  558. this.typarams = typarams;
  559. this.params = params;
  560. this.thrown = thrown;
  561. this.body = body;
  562. this.defaultValue = defaultValue;
  563. this.sym = sym;
  564. }
  565. @Override
  566. public void accept(Visitor v) { v.visitMethodDef(this); }
  567. public Kind getKind() { return Kind.METHOD; }
  568. public JCModifiers getModifiers() { return mods; }
  569. public Name getName() { return name; }
  570. public JCTree getReturnType() { return restype; }
  571. public List<JCTypeParameter> getTypeParameters() {
  572. return typarams;
  573. }
  574. public List<JCVariableDecl> getParameters() {
  575. return params;
  576. }
  577. public List<JCExpression> getThrows() {
  578. return thrown;
  579. }
  580. public JCBlock getBody() { return body; }
  581. public JCTree getDefaultValue() { // for annotation types
  582. return defaultValue;
  583. }
  584. @Override
  585. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  586. return v.visitMethod(this, d);
  587. }
  588. @Override
  589. public int getTag() {
  590. return METHODDEF;
  591. }
  592. }
  593. /**
  594. * A variable definition.
  595. * @param modifiers variable modifiers
  596. * @param name variable name
  597. * @param vartype type of the variable
  598. * @param init variables initial value
  599. * @param sym symbol
  600. */
  601. public static class JCVariableDecl extends JCStatement implements VariableTree {
  602. public JCModifiers mods;
  603. public Name name;
  604. public JCExpression vartype;
  605. public JCExpression init;
  606. public VarSymbol sym;
  607. protected JCVariableDecl(JCModifiers mods,
  608. Name name,
  609. JCExpression vartype,
  610. JCExpression init,
  611. VarSymbol sym) {
  612. this.mods = mods;
  613. this.name = name;
  614. this.vartype = vartype;
  615. this.init = init;
  616. this.sym = sym;
  617. }
  618. @Override
  619. public void accept(Visitor v) { v.visitVarDef(this); }
  620. public Kind getKind() { return Kind.VARIABLE; }
  621. public JCModifiers getModifiers() { return mods; }
  622. public Name getName() { return name; }
  623. public JCTree getType() { return vartype; }
  624. public JCExpression getInitializer() {
  625. return init;
  626. }
  627. @Override
  628. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  629. return v.visitVariable(this, d);
  630. }
  631. @Override
  632. public int getTag() {
  633. return VARDEF;
  634. }
  635. }
  636. /**
  637. * A no-op statement ";".
  638. */
  639. public static class JCSkip extends JCStatement implements EmptyStatementTree {
  640. protected JCSkip() {
  641. }
  642. @Override
  643. public void accept(Visitor v) { v.visitSkip(this); }
  644. public Kind getKind() { return Kind.EMPTY_STATEMENT; }
  645. @Override
  646. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  647. return v.visitEmptyStatement(this, d);
  648. }
  649. @Override
  650. public int getTag() {
  651. return SKIP;
  652. }
  653. }
  654. /**
  655. * A statement block.
  656. * @param stats statements
  657. * @param flags flags
  658. */
  659. public static class JCBlock extends JCStatement implements BlockTree {
  660. public long flags;
  661. public List<JCStatement> stats;
  662. /** Position of closing brace, optional. */
  663. public int endpos = Position.NOPOS;
  664. protected JCBlock(long flags, List<JCStatement> stats) {
  665. this.stats = stats;
  666. this.flags = flags;
  667. }
  668. @Override
  669. public void accept(Visitor v) { v.visitBlock(this); }
  670. public Kind getKind() { return Kind.BLOCK; }
  671. public List<JCStatement> getStatements() {
  672. return stats;
  673. }
  674. public boolean isStatic() { return (flags & Flags.STATIC) != 0; }
  675. @Override
  676. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  677. return v.visitBlock(this, d);
  678. }
  679. @Override
  680. public int getTag() {
  681. return BLOCK;
  682. }
  683. }
  684. /**
  685. * A do loop
  686. */
  687. public static class JCDoWhileLoop extends JCStatement implements DoWhileLoopTree {
  688. public JCStatement body;
  689. public JCExpression cond;
  690. protected JCDoWhileLoop(JCStatement body, JCExpression cond) {
  691. this.body = body;
  692. this.cond = cond;
  693. }
  694. @Override
  695. public void accept(Visitor v) { v.visitDoLoop(this); }
  696. public Kind getKind() { return Kind.DO_WHILE_LOOP; }
  697. public JCExpression getCondition() { return cond; }
  698. public JCStatement getStatement() { return body; }
  699. @Override
  700. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  701. return v.visitDoWhileLoop(this, d);
  702. }
  703. @Override
  704. public int getTag() {
  705. return DOLOOP;
  706. }
  707. }
  708. /**
  709. * A while loop
  710. */
  711. public static class JCWhileLoop extends JCStatement implements WhileLoopTree {
  712. public JCExpression cond;
  713. public JCStatement body;
  714. protected JCWhileLoop(JCExpression cond, JCStatement body) {
  715. this.cond = cond;
  716. this.body = body;
  717. }
  718. @Override
  719. public void accept(Visitor v) { v.visitWhileLoop(this); }
  720. public Kind getKind() { return Kind.WHILE_LOOP; }
  721. public JCExpression getCondition() { return cond; }
  722. public JCStatement getStatement() { return body; }
  723. @Override
  724. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  725. return v.visitWhileLoop(this, d);
  726. }
  727. @Override
  728. public int getTag() {
  729. return WHILELOOP;
  730. }
  731. }
  732. /**
  733. * A for loop.
  734. */
  735. public static class JCForLoop extends JCStatement implements ForLoopTree {
  736. public List<JCStatement> init;
  737. public JCExpression cond;
  738. public List<JCExpressionStatement> step;
  739. public JCStatement body;
  740. protected JCForLoop(List<JCStatement> init,
  741. JCExpression cond,
  742. List<JCExpressionStatement> update,
  743. JCStatement body)
  744. {
  745. this.init = init;
  746. this.cond = cond;
  747. this.step = update;
  748. this.body = body;
  749. }
  750. @Override
  751. public void accept(Visitor v) { v.visitForLoop(this); }
  752. public Kind getKind() { return Kind.FOR_LOOP; }
  753. public JCExpression getCondition() { return cond; }
  754. public JCStatement getStatement() { return body; }
  755. public List<JCStatement> getInitializer() {
  756. return init;
  757. }
  758. public List<JCExpressionStatement> getUpdate() {
  759. return step;
  760. }
  761. @Override
  762. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  763. return v.visitForLoop(this, d);
  764. }
  765. @Override
  766. public int getTag() {
  767. return FORLOOP;
  768. }
  769. }
  770. /**
  771. * The enhanced for loop.
  772. */
  773. public static class JCEnhancedForLoop extends JCStatement implements EnhancedForLoopTree {
  774. public JCVariableDecl var;
  775. public JCExpression expr;
  776. public JCStatement body;
  777. protected JCEnhancedForLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
  778. this.var = var;
  779. this.expr = expr;
  780. this.body = body;
  781. }
  782. @Override
  783. public void accept(Visitor v) { v.visitForeachLoop(this); }
  784. public Kind getKind() { return Kind.ENHANCED_FOR_LOOP; }
  785. public JCVariableDecl getVariable() { return var; }
  786. public JCExpression getExpression() { return expr; }
  787. public JCStatement getStatement() { return body; }
  788. @Override
  789. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  790. return v.visitEnhancedForLoop(this, d);
  791. }
  792. @Override
  793. public int getTag() {
  794. return FOREACHLOOP;
  795. }
  796. }
  797. /**
  798. * A labelled expression or statement.
  799. */
  800. public static class JCLabeledStatement extends JCStatement implements LabeledStatementTree {
  801. public Name label;
  802. public JCStatement body;
  803. protected JCLabeledStatement(Name label, JCStatement body) {
  804. this.label = label;
  805. this.body = body;
  806. }
  807. @Override
  808. public void accept(Visitor v) { v.visitLabelled(this); }
  809. public Kind getKind() { return Kind.LABELED_STATEMENT; }
  810. public Name getLabel() { return label; }
  811. public JCStatement getStatement() { return body; }
  812. @Override
  813. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  814. return v.visitLabeledStatement(this, d);
  815. }
  816. @Override
  817. public int getTag() {
  818. return LABELLED;
  819. }
  820. }
  821. /**
  822. * A "switch ( ) { }" construction.
  823. */
  824. public static class JCSwitch extends JCStatement implements SwitchTree {
  825. public JCExpression selector;
  826. public List<JCCase> cases;
  827. protected JCSwitch(JCExpression selector, List<JCCase> cases) {
  828. this.selector = selector;
  829. this.cases = cases;
  830. }
  831. @Override
  832. public void accept(Visitor v) { v.visitSwitch(this); }
  833. public Kind getKind() { return Kind.SWITCH; }
  834. public JCExpression getExpression() { return selector; }
  835. public List<JCCase> getCases() { return cases; }
  836. @Override
  837. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  838. return v.visitSwitch(this, d);
  839. }
  840. @Override
  841. public int getTag() {
  842. return SWITCH;
  843. }
  844. }
  845. /**
  846. * A "case :" of a switch.
  847. */
  848. public static class JCCase extends JCStatement implements CaseTree {
  849. public JCExpression pat;
  850. public List<JCStatement> stats;
  851. protected JCCase(JCExpression pat, List<JCStatement> stats) {
  852. this.pat = pat;
  853. this.stats = stats;
  854. }
  855. @Override
  856. public void accept(Visitor v) { v.visitCase(this); }
  857. public Kind getKind() { return Kind.CASE; }
  858. public JCExpression getExpression() { return pat; }
  859. public List<JCStatement> getStatements() { return stats; }
  860. @Override
  861. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  862. return v.visitCase(this, d);
  863. }
  864. @Override
  865. public int getTag() {
  866. return CASE;
  867. }
  868. }
  869. /**
  870. * A synchronized block.
  871. */
  872. public static class JCSynchronized extends JCStatement implements SynchronizedTree {
  873. public JCExpression lock;
  874. public JCBlock body;
  875. protected JCSynchronized(JCExpression lock, JCBlock body) {
  876. this.lock = lock;
  877. this.body = body;
  878. }
  879. @Override
  880. public void accept(Visitor v) { v.visitSynchronized(this); }
  881. public Kind getKind() { return Kind.SYNCHRONIZED; }
  882. public JCExpression getExpression() { return lock; }
  883. public JCBlock getBlock() { return body; }
  884. @Override
  885. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  886. return v.visitSynchronized(this, d);
  887. }
  888. @Override
  889. public int getTag() {
  890. return SYNCHRONIZED;
  891. }
  892. }
  893. /**
  894. * A "try { } catch ( ) { } finally { }" block.
  895. */
  896. public static class JCTry extends JCStatement implements TryTree {
  897. public JCBlock body;
  898. public List<JCCatch> catchers;
  899. public JCBlock finalizer;
  900. protected JCTry(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
  901. this.body = body;
  902. this.catchers = catchers;
  903. this.finalizer = finalizer;
  904. }
  905. @Override
  906. public void accept(Visitor v) { v.visitTry(this); }
  907. public Kind getKind() { return Kind.TRY; }
  908. public JCBlock getBlock() { return body; }
  909. public List<JCCatch> getCatches() {
  910. return catchers;
  911. }
  912. public JCBlock getFinallyBlock() { return finalizer; }
  913. @Override
  914. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  915. return v.visitTry(this, d);
  916. }
  917. @Override
  918. public int getTag() {
  919. return TRY;
  920. }
  921. }
  922. /**
  923. * A catch block.
  924. */
  925. public static class JCCatch extends JCTree implements CatchTree {
  926. public JCVariableDecl param;
  927. public JCBlock body;
  928. protected JCCatch(JCVariableDecl param, JCBlock body) {
  929. this.param = param;
  930. this.body = body;
  931. }
  932. @Override
  933. public void accept(Visitor v) { v.visitCatch(this); }
  934. public Kind getKind() { return Kind.CATCH; }
  935. public JCVariableDecl getParameter() { return param; }
  936. public JCBlock getBlock() { return body; }
  937. @Override
  938. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  939. return v.visitCatch(this, d);
  940. }
  941. @Override
  942. public int getTag() {
  943. return CATCH;
  944. }
  945. }
  946. /**
  947. * A ( ) ? ( ) : ( ) conditional expression
  948. */
  949. public static class JCConditional extends JCExpression implements ConditionalExpressionTree {
  950. public JCExpression cond;
  951. public JCExpression truepart;
  952. public JCExpression falsepart;
  953. protected JCConditional(JCExpression cond,
  954. JCExpression truepart,
  955. JCExpression falsepart)
  956. {
  957. this.cond = cond;
  958. this.truepart = truepart;
  959. this.falsepart = falsepart;
  960. }
  961. @Override
  962. public void accept(Visitor v) { v.visitConditional(this); }
  963. public Kind getKind() { return Kind.CONDITIONAL_EXPRESSION; }
  964. public JCExpression getCondition() { return cond; }
  965. public JCExpression getTrueExpression() { return truepart; }
  966. public JCExpression getFalseExpression() { return falsepart; }
  967. @Override
  968. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  969. return v.visitConditionalExpression(this, d);
  970. }
  971. @Override
  972. public int getTag() {
  973. return CONDEXPR;
  974. }
  975. }
  976. /**
  977. * An "if ( ) { } else { }" block
  978. */
  979. public static class JCIf extends JCStatement implements IfTree {
  980. public JCExpression cond;
  981. public JCStatement thenpart;
  982. public JCStatement elsepart;
  983. protected JCIf(JCExpression cond,
  984. JCStatement thenpart,
  985. JCStatement elsepart)
  986. {
  987. this.cond = cond;
  988. this.thenpart = thenpart;
  989. this.elsepart = elsepart;
  990. }
  991. @Override
  992. public void accept(Visitor v) { v.visitIf(this); }
  993. public Kind getKind() { return Kind.IF; }
  994. public JCExpression getCondition() { return cond; }
  995. public JCStatement getThenStatement() { return thenpart; }
  996. public JCStatement getElseStatement() { return elsepart; }
  997. @Override
  998. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  999. return v.visitIf(this, d);
  1000. }
  1001. @Override
  1002. public int getTag() {
  1003. return IF;
  1004. }
  1005. }
  1006. /**
  1007. * an expression statement
  1008. * @param expr expression structure
  1009. */
  1010. public static class JCExpressionStatement extends JCStatement implements ExpressionStatementTree {
  1011. public JCExpression expr;
  1012. protected JCExpressionStatement(JCExpression expr)
  1013. {
  1014. this.expr = expr;
  1015. }
  1016. @Override
  1017. public void accept(Visitor v) { v.visitExec(this); }
  1018. public Kind getKind() { return Kind.EXPRESSION_STATEMENT; }
  1019. public JCExpression getExpression() { return expr; }
  1020. @Override
  1021. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1022. return v.visitExpressionStatement(this, d);
  1023. }
  1024. @Override
  1025. public int getTag() {
  1026. return EXEC;
  1027. }
  1028. }
  1029. /**
  1030. * A break from a loop or switch.
  1031. */
  1032. public static class JCBreak extends JCStatement implements BreakTree {
  1033. public Name label;
  1034. public JCTree target;
  1035. protected JCBreak(Name label, JCTree target) {
  1036. this.label = label;
  1037. this.target = target;
  1038. }
  1039. @Override
  1040. public void accept(Visitor v) { v.visitBreak(this); }
  1041. public Kind getKind() { return Kind.BREAK; }
  1042. public Name getLabel() { return label; }
  1043. @Override
  1044. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1045. return v.visitBreak(this, d);
  1046. }
  1047. @Override
  1048. public int getTag() {
  1049. return BREAK;
  1050. }
  1051. }
  1052. /**
  1053. * A continue of a loop.
  1054. */
  1055. public static class JCContinue extends JCStatement implements ContinueTree {
  1056. public Name label;
  1057. public JCTree target;
  1058. protected JCContinue(Name label, JCTree target) {
  1059. this.label = label;
  1060. this.target = target;
  1061. }
  1062. @Override
  1063. public void accept(Visitor v) { v.visitContinue(this); }
  1064. public Kind getKind() { return Kind.CONTINUE; }
  1065. public Name getLabel() { return label; }
  1066. @Override
  1067. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1068. return v.visitContinue(this, d);
  1069. }
  1070. @Override
  1071. public int getTag() {
  1072. return CONTINUE;
  1073. }
  1074. }
  1075. /**
  1076. * A return statement.
  1077. */
  1078. public static class JCReturn extends JCStatement implements ReturnTree {
  1079. public JCExpression expr;
  1080. protected JCReturn(JCExpression expr) {
  1081. this.expr = expr;
  1082. }
  1083. @Override
  1084. public void accept(Visitor v) { v.visitReturn(this); }
  1085. public Kind getKind() { return Kind.RETURN; }
  1086. public JCExpression getExpression() { return expr; }
  1087. @Override
  1088. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1089. return v.visitReturn(this, d);
  1090. }
  1091. @Override
  1092. public int getTag() {
  1093. return RETURN;
  1094. }
  1095. }
  1096. /**
  1097. * A throw statement.
  1098. */
  1099. public static class JCThrow extends JCStatement implements ThrowTree {
  1100. public JCExpression expr;
  1101. protected JCThrow(JCTree expr) {
  1102. this.expr = (JCExpression)expr;
  1103. }
  1104. @Override
  1105. public void accept(Visitor v) { v.visitThrow(this); }
  1106. public Kind getKind() { return Kind.THROW; }
  1107. public JCExpression getExpression() { return expr; }
  1108. @Override
  1109. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1110. return v.visitThrow(this, d);
  1111. }
  1112. @Override
  1113. public int getTag() {
  1114. return THROW;
  1115. }
  1116. }
  1117. /**
  1118. * An assert statement.
  1119. */
  1120. public static class JCAssert extends JCStatement implements AssertTree {
  1121. public JCExpression cond;
  1122. public JCExpression detail;
  1123. protected JCAssert(JCExpression cond, JCExpression detail) {
  1124. this.cond = cond;
  1125. this.detail = detail;
  1126. }
  1127. @Override
  1128. public void accept(Visitor v) { v.visitAssert(this); }
  1129. public Kind getKind() { return Kind.ASSERT; }
  1130. public JCExpression getCondition() { return cond; }
  1131. public JCExpression getDetail() { return detail; }
  1132. @Override
  1133. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1134. return v.visitAssert(this, d);
  1135. }
  1136. @Override
  1137. public int getTag() {
  1138. return ASSERT;
  1139. }
  1140. }
  1141. /**
  1142. * A method invocation
  1143. */
  1144. public static class JCMethodInvocation extends JCExpression implements MethodInvocationTree {
  1145. public List<JCExpression> typeargs;
  1146. public JCExpression meth;
  1147. public List<JCExpression> args;
  1148. public Type varargsElement;
  1149. protected JCMethodInvocation(List<JCExpression> typeargs,
  1150. JCExpression meth,
  1151. List<JCExpression> args)
  1152. {
  1153. this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
  1154. : typeargs;
  1155. this.meth = meth;
  1156. this.args = args;
  1157. }
  1158. @Override
  1159. public void accept(Visitor v) { v.visitApply(this); }
  1160. public Kind getKind() { return Kind.METHOD_INVOCATION; }
  1161. public List<JCExpression> getTypeArguments() {
  1162. return typeargs;
  1163. }
  1164. public JCExpression getMethodSelect() { return meth; }
  1165. public List<JCExpression> getArguments() {
  1166. return args;
  1167. }
  1168. @Override
  1169. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1170. return v.visitMethodInvocation(this, d);
  1171. }
  1172. @Override
  1173. public JCMethodInvocation setType(Type type) {
  1174. super.setType(type);
  1175. return this;
  1176. }
  1177. @Override
  1178. public int getTag() {
  1179. return(APPLY);
  1180. }
  1181. }
  1182. /**
  1183. * A new(...) operation.
  1184. */
  1185. public static class JCNewClass extends JCExpression implements NewClassTree {
  1186. public JCExpression encl;
  1187. public List<JCExpression> typeargs;
  1188. public JCExpression clazz;
  1189. public List<JCExpression> args;
  1190. public JCClassDecl def;
  1191. public Symbol constructor;
  1192. public Type varargsElement;
  1193. protected JCNewClass(JCExpression encl,
  1194. List<JCExpression> typeargs,
  1195. JCExpression clazz,
  1196. List<JCExpression> args,
  1197. JCClassDecl def)
  1198. {
  1199. this.encl = encl;
  1200. this.typeargs = (typeargs == null) ? List.<JCExpression>nil()
  1201. : typeargs;
  1202. this.clazz = clazz;
  1203. this.args = args;
  1204. this.def = def;
  1205. }
  1206. @Override
  1207. public void accept(Visitor v) { v.visitNewClass(this); }
  1208. public Kind getKind() { return Kind.NEW_CLASS; }
  1209. public JCExpression getEnclosingExpression() { // expr.new C< ... > ( ... )
  1210. return encl;
  1211. }
  1212. public List<JCExpression> getTypeArguments() {
  1213. return typeargs;
  1214. }
  1215. public JCExpression getIdentifier() { return clazz; }
  1216. public List<JCExpression> getArguments() {
  1217. return args;
  1218. }
  1219. public JCClassDecl getClassBody() { return def; }
  1220. @Override
  1221. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1222. return v.visitNewClass(this, d);
  1223. }
  1224. @Override
  1225. public int getTag() {
  1226. return NEWCLASS;
  1227. }
  1228. }
  1229. /**
  1230. * A new[...] operation.
  1231. */
  1232. public static class JCNewArray extends JCExpression implements NewArrayTree {
  1233. public JCExpression elemtype;
  1234. public List<JCExpression> dims;
  1235. public List<JCExpression> elems;
  1236. protected JCNewArray(JCExpression elemtype,
  1237. List<JCExpression> dims,
  1238. List<JCExpression> elems)
  1239. {
  1240. this.elemtype = elemtype;
  1241. this.dims = dims;
  1242. this.elems = elems;
  1243. }
  1244. @Override
  1245. public void accept(Visitor v) { v.visitNewArray(this); }
  1246. public Kind getKind() { return Kind.NEW_ARRAY; }
  1247. public JCExpression getType() { return elemtype; }
  1248. public List<JCExpression> getDimensions() {
  1249. return dims;
  1250. }
  1251. public List<JCExpression> getInitializers() {
  1252. return elems;
  1253. }
  1254. @Override
  1255. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1256. return v.visitNewArray(this, d);
  1257. }
  1258. @Override
  1259. public int getTag() {
  1260. return NEWARRAY;
  1261. }
  1262. }
  1263. /**
  1264. * A parenthesized subexpression ( ... )
  1265. */
  1266. public static class JCParens extends JCExpression implements ParenthesizedTree {
  1267. public JCExpression expr;
  1268. protected JCParens(JCExpression expr) {
  1269. this.expr = expr;
  1270. }
  1271. @Override
  1272. public void accept(Visitor v) { v.visitParens(this); }
  1273. public Kind getKind() { return Kind.PARENTHESIZED; }
  1274. public JCExpression getExpression() { return expr; }
  1275. @Override
  1276. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1277. return v.visitParenthesized(this, d);
  1278. }
  1279. @Override
  1280. public int getTag() {
  1281. return PARENS;
  1282. }
  1283. }
  1284. /**
  1285. * A assignment with "=".
  1286. */
  1287. public static class JCAssign extends JCExpression implements AssignmentTree {
  1288. public JCExpression lhs;
  1289. public JCExpression rhs;
  1290. protected JCAssign(JCExpression lhs, JCExpression rhs) {
  1291. this.lhs = lhs;
  1292. this.rhs = rhs;
  1293. }
  1294. @Override
  1295. public void accept(Visitor v) { v.visitAssign(this); }
  1296. public Kind getKind() { return Kind.ASSIGNMENT; }
  1297. public JCExpression getVariable() { return lhs; }
  1298. public JCExpression getExpression() { return rhs; }
  1299. @Override
  1300. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1301. return v.visitAssignment(this, d);
  1302. }
  1303. @Override
  1304. public int getTag() {
  1305. return ASSIGN;
  1306. }
  1307. }
  1308. /**
  1309. * An assignment with "+=", "|=" ...
  1310. */
  1311. public static class JCAssignOp extends JCExpression implements CompoundAssignmentTree {
  1312. private int opcode;
  1313. public JCExpression lhs;
  1314. public JCExpression rhs;
  1315. public Symbol operator;
  1316. protected JCAssignOp(int opcode, JCTree lhs, JCTree rhs, Symbol operator) {
  1317. this.opcode = opcode;
  1318. this.lhs = (JCExpression)lhs;
  1319. this.rhs = (JCExpression)rhs;
  1320. this.operator = operator;
  1321. }
  1322. @Override
  1323. public void accept(Visitor v) { v.visitAssignop(this); }
  1324. public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1325. public JCExpression getVariable() { return lhs; }
  1326. public JCExpression getExpression() { return rhs; }
  1327. public Symbol getOperator() {
  1328. return operator;
  1329. }
  1330. @Override
  1331. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1332. return v.visitCompoundAssignment(this, d);
  1333. }
  1334. @Override
  1335. public int getTag() {
  1336. return opcode;
  1337. }
  1338. }
  1339. /**
  1340. * A unary operation.
  1341. */
  1342. public static class JCUnary extends JCExpression implements UnaryTree {
  1343. private int opcode;
  1344. public JCExpression arg;
  1345. public Symbol operator;
  1346. protected JCUnary(int opcode, JCExpression arg) {
  1347. this.opcode = opcode;
  1348. this.arg = arg;
  1349. }
  1350. @Override
  1351. public void accept(Visitor v) { v.visitUnary(this); }
  1352. public Kind getKind() { return TreeInfo.tagToKind(getTag()); }
  1353. public JCExpression getExpression() { return arg; }
  1354. public Symbol getOperator() {
  1355. return operator;
  1356. }
  1357. @Override
  1358. public <R,D> R accept(TreeVisitor<R,D> v, D d) {
  1359. return v.visitUnary(this, d);
  1360. }
  1361. @Override
  1362. public int getTag() {
  1363. return opcode;
  1364. }
  1365. public void setTag(int tag) {
  1366. opcode = tag;
  1367. }
  1368. }
  1369. /**
  1370. * A binary operation.
  1371. */
  1372. public static class JCBinary extends JCExpression implements BinaryTree {
  1373. private int opcode;
  1374. public JCExpression lhs;
  1375. public JCExpression rhs;
  1376. public Symbol operator;
  1377. protected JCBinary(int opcode,
  1378. JCExpression lhs,
  1379. JCExpression rhs,
  1380. Symbol operator) {
  1381. this.opcode = opcode;
  1382. this.lhs = lhs;
  1383. this.rhs = rhs;

Large files files are truncated, but you can click here to view the full file