30 import java.util.*;
31
32 import javax.lang.model.element.Modifier;
33 import javax.lang.model.type.TypeKind;
34 import javax.tools.JavaFileObject;
35
36 import com.sun.source.tree.*;
37 import com.sun.tools.javac.code.*;
38 import com.sun.tools.javac.code.Directive.RequiresDirective;
39 import com.sun.tools.javac.code.Scope.*;
40 import com.sun.tools.javac.code.Symbol.*;
41 import com.sun.tools.javac.util.*;
42 import com.sun.tools.javac.util.DefinedBy.Api;
43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
44 import com.sun.tools.javac.util.List;
45
46 import static com.sun.tools.javac.tree.JCTree.Tag.*;
47
48 import javax.tools.JavaFileManager.Location;
49
50 import com.sun.source.tree.ModuleTree.ModuleKind;
51 import com.sun.tools.javac.code.Directive.ExportsDirective;
52 import com.sun.tools.javac.code.Directive.OpensDirective;
53 import com.sun.tools.javac.code.Type.ModuleType;
54
55 /**
56 * Root class for abstract syntax tree nodes. It provides definitions
57 * for specific tree nodes as subclasses nested inside.
58 *
59 * <p>Each subclass is highly standardized. It generally contains
60 * only tree fields for the syntactic subcomponents of the node. Some
61 * classes that represent identifier uses or definitions also define a
62 * Symbol field that denotes the represented identifier. Classes for
63 * non-local jumps also carry the jump target as a field. The root
64 * class Tree itself defines fields for the tree's type and position.
65 * No other fields are kept in a tree node; instead parameters are
66 * passed to methods accessing the node.
67 *
68 * <p>Except for the methods defined by com.sun.source, the only
69 * method defined in subclasses is `visit' which applies a given
70 * visitor to the tree. The actual tree processing is done by visitor
71 * classes in other packages. The abstract class Visitor, as well as
72 * an Factory interface for trees, are defined as inner classes in
73 * Tree.
132 /** While-loops, of type WhileLoop.
133 */
134 WHILELOOP,
135
136 /** For-loops, of type ForLoop.
137 */
138 FORLOOP,
139
140 /** Foreach-loops, of type ForeachLoop.
141 */
142 FOREACHLOOP,
143
144 /** Labelled statements, of type Labelled.
145 */
146 LABELLED,
147
148 /** Switch statements, of type Switch.
149 */
150 SWITCH,
151
152 /** Case parts in switch statements, of type Case.
153 */
154 CASE,
155
156 /** Synchronized statements, of type Synchonized.
157 */
158 SYNCHRONIZED,
159
160 /** Try statements, of type Try.
161 */
162 TRY,
163
164 /** Catch clauses in try statements, of type Catch.
165 */
166 CATCH,
167
168 /** Conditional expressions, of type Conditional.
169 */
170 CONDEXPR,
171
172 /** Conditional statements, of type If.
173 */
174 IF,
175
1221 @DefinedBy(Api.COMPILER_TREE)
1222 public Kind getKind() { return Kind.SWITCH; }
1223 @DefinedBy(Api.COMPILER_TREE)
1224 public JCExpression getExpression() { return selector; }
1225 @DefinedBy(Api.COMPILER_TREE)
1226 public List<JCCase> getCases() { return cases; }
1227 @Override @DefinedBy(Api.COMPILER_TREE)
1228 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1229 return v.visitSwitch(this, d);
1230 }
1231 @Override
1232 public Tag getTag() {
1233 return SWITCH;
1234 }
1235 }
1236
1237 /**
1238 * A "case :" of a switch.
1239 */
1240 public static class JCCase extends JCStatement implements CaseTree {
1241 public JCExpression pat;
1242 public List<JCStatement> stats;
1243 protected JCCase(JCExpression pat, List<JCStatement> stats) {
1244 this.pat = pat;
1245 this.stats = stats;
1246 }
1247 @Override
1248 public void accept(Visitor v) { v.visitCase(this); }
1249
1250 @DefinedBy(Api.COMPILER_TREE)
1251 public Kind getKind() { return Kind.CASE; }
1252 @DefinedBy(Api.COMPILER_TREE)
1253 public JCExpression getExpression() { return pat; }
1254 @DefinedBy(Api.COMPILER_TREE)
1255 public List<JCStatement> getStatements() { return stats; }
1256 @Override @DefinedBy(Api.COMPILER_TREE)
1257 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1258 return v.visitCase(this, d);
1259 }
1260 @Override
1261 public Tag getTag() {
1262 return CASE;
1263 }
1264 }
1265
1266 /**
1267 * A synchronized block.
1268 */
1269 public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1270 public JCExpression lock;
1271 public JCBlock body;
1272 protected JCSynchronized(JCExpression lock, JCBlock body) {
1273 this.lock = lock;
1274 this.body = body;
1275 }
1276 @Override
1277 public void accept(Visitor v) { v.visitSynchronized(this); }
1278
1279 @DefinedBy(Api.COMPILER_TREE)
1280 public Kind getKind() { return Kind.SYNCHRONIZED; }
1281 @DefinedBy(Api.COMPILER_TREE)
1282 public JCExpression getExpression() { return lock; }
1283 @DefinedBy(Api.COMPILER_TREE)
1284 public JCBlock getBlock() { return body; }
1285 @Override @DefinedBy(Api.COMPILER_TREE)
1286 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1467 /** Convert a expression-statement tree to a pretty-printed string. */
1468 @Override
1469 public String toString() {
1470 StringWriter s = new StringWriter();
1471 try {
1472 new Pretty(s, false).printStat(this);
1473 }
1474 catch (IOException e) {
1475 // should never happen, because StringWriter is defined
1476 // never to throw any IOExceptions
1477 throw new AssertionError(e);
1478 }
1479 return s.toString();
1480 }
1481 }
1482
1483 /**
1484 * A break from a loop or switch.
1485 */
1486 public static class JCBreak extends JCStatement implements BreakTree {
1487 public Name label;
1488 public JCTree target;
1489 protected JCBreak(Name label, JCTree target) {
1490 this.label = label;
1491 this.target = target;
1492 }
1493 @Override
1494 public void accept(Visitor v) { v.visitBreak(this); }
1495
1496 @DefinedBy(Api.COMPILER_TREE)
1497 public Kind getKind() { return Kind.BREAK; }
1498 @DefinedBy(Api.COMPILER_TREE)
1499 public Name getLabel() { return label; }
1500 @Override @DefinedBy(Api.COMPILER_TREE)
1501 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1502 return v.visitBreak(this, d);
1503 }
1504 @Override
1505 public Tag getTag() {
1506 return BREAK;
1507 }
1508 }
1509
1510 /**
1511 * A continue of a loop.
1512 */
1513 public static class JCContinue extends JCStatement implements ContinueTree {
1514 public Name label;
1515 public JCTree target;
1516 protected JCContinue(Name label, JCTree target) {
1517 this.label = label;
1518 this.target = target;
1519 }
2917 @DefinedBy(Api.COMPILER_TREE)
2918 public Kind getKind() { return Kind.ERRONEOUS; }
2919
2920 @DefinedBy(Api.COMPILER_TREE)
2921 public List<? extends JCTree> getErrorTrees() {
2922 return errs;
2923 }
2924
2925 @Override @DefinedBy(Api.COMPILER_TREE)
2926 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2927 return v.visitErroneous(this, d);
2928 }
2929 @Override
2930 public Tag getTag() {
2931 return ERRONEOUS;
2932 }
2933 }
2934
2935 /** (let int x = 3; in x+2) */
2936 public static class LetExpr extends JCExpression {
2937 public List<JCVariableDecl> defs;
2938 public JCExpression expr;
2939 protected LetExpr(List<JCVariableDecl> defs, JCExpression expr) {
2940 this.defs = defs;
2941 this.expr = expr;
2942 }
2943 @Override
2944 public void accept(Visitor v) { v.visitLetExpr(this); }
2945
2946 @DefinedBy(Api.COMPILER_TREE)
2947 public Kind getKind() {
2948 throw new AssertionError("LetExpr is not part of a public API");
2949 }
2950 @Override @DefinedBy(Api.COMPILER_TREE)
2951 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2952 throw new AssertionError("LetExpr is not part of a public API");
2953 }
2954 @Override
2955 public Tag getTag() {
2956 return LETEXPR;
2957 }
2958 }
2959
2977 JCVariableDecl recvparam,
2978 List<JCVariableDecl> params,
2979 List<JCExpression> thrown,
2980 JCBlock body,
2981 JCExpression defaultValue);
2982 JCVariableDecl VarDef(JCModifiers mods,
2983 Name name,
2984 JCExpression vartype,
2985 JCExpression init);
2986 JCSkip Skip();
2987 JCBlock Block(long flags, List<JCStatement> stats);
2988 JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
2989 JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
2990 JCForLoop ForLoop(List<JCStatement> init,
2991 JCExpression cond,
2992 List<JCExpressionStatement> step,
2993 JCStatement body);
2994 JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
2995 JCLabeledStatement Labelled(Name label, JCStatement body);
2996 JCSwitch Switch(JCExpression selector, List<JCCase> cases);
2997 JCCase Case(JCExpression pat, List<JCStatement> stats);
2998 JCSynchronized Synchronized(JCExpression lock, JCBlock body);
2999 JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
3000 JCTry Try(List<JCTree> resources,
3001 JCBlock body,
3002 List<JCCatch> catchers,
3003 JCBlock finalizer);
3004 JCCatch Catch(JCVariableDecl param, JCBlock body);
3005 JCConditional Conditional(JCExpression cond,
3006 JCExpression thenpart,
3007 JCExpression elsepart);
3008 JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
3009 JCExpressionStatement Exec(JCExpression expr);
3010 JCBreak Break(Name label);
3011 JCContinue Continue(Name label);
3012 JCReturn Return(JCExpression expr);
3013 JCThrow Throw(JCExpression expr);
3014 JCAssert Assert(JCExpression cond, JCExpression detail);
3015 JCMethodInvocation Apply(List<JCExpression> typeargs,
3016 JCExpression fn,
3017 List<JCExpression> args);
3018 JCNewClass NewClass(JCExpression encl,
3019 List<JCExpression> typeargs,
3020 JCExpression clazz,
3021 List<JCExpression> args,
3022 JCClassDecl def);
3023 JCNewArray NewArray(JCExpression elemtype,
3024 List<JCExpression> dims,
3025 List<JCExpression> elems);
3026 JCParens Parens(JCExpression expr);
3027 JCAssign Assign(JCExpression lhs, JCExpression rhs);
3028 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3029 JCUnary Unary(Tag opcode, JCExpression arg);
3030 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3032 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3033 JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3034 JCFieldAccess Select(JCExpression selected, Name selector);
3035 JCIdent Ident(Name idname);
3036 JCLiteral Literal(TypeTag tag, Object value);
3037 JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3038 JCArrayTypeTree TypeArray(JCExpression elemtype);
3039 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3040 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3041 JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3042 TypeBoundKind TypeBoundKind(BoundKind kind);
3043 JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3044 JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3045 JCErroneous Erroneous(List<? extends JCTree> errs);
3046 JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3047 JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3048 JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3049 JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3050 JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3051 JCUses Uses(JCExpression qualId);
3052 LetExpr LetExpr(List<JCVariableDecl> defs, JCExpression expr);
3053 }
3054
3055 /** A generic visitor class for trees.
3056 */
3057 public static abstract class Visitor {
3058 public void visitTopLevel(JCCompilationUnit that) { visitTree(that); }
3059 public void visitPackageDef(JCPackageDecl that) { visitTree(that); }
3060 public void visitImport(JCImport that) { visitTree(that); }
3061 public void visitClassDef(JCClassDecl that) { visitTree(that); }
3062 public void visitMethodDef(JCMethodDecl that) { visitTree(that); }
3063 public void visitVarDef(JCVariableDecl that) { visitTree(that); }
3064 public void visitSkip(JCSkip that) { visitTree(that); }
3065 public void visitBlock(JCBlock that) { visitTree(that); }
3066 public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); }
3067 public void visitWhileLoop(JCWhileLoop that) { visitTree(that); }
3068 public void visitForLoop(JCForLoop that) { visitTree(that); }
3069 public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3070 public void visitLabelled(JCLabeledStatement that) { visitTree(that); }
3071 public void visitSwitch(JCSwitch that) { visitTree(that); }
3072 public void visitCase(JCCase that) { visitTree(that); }
3073 public void visitSynchronized(JCSynchronized that) { visitTree(that); }
3074 public void visitTry(JCTry that) { visitTree(that); }
3075 public void visitCatch(JCCatch that) { visitTree(that); }
3076 public void visitConditional(JCConditional that) { visitTree(that); }
3077 public void visitIf(JCIf that) { visitTree(that); }
3078 public void visitExec(JCExpressionStatement that) { visitTree(that); }
3079 public void visitBreak(JCBreak that) { visitTree(that); }
3080 public void visitContinue(JCContinue that) { visitTree(that); }
3081 public void visitReturn(JCReturn that) { visitTree(that); }
3082 public void visitThrow(JCThrow that) { visitTree(that); }
3083 public void visitAssert(JCAssert that) { visitTree(that); }
3084 public void visitApply(JCMethodInvocation that) { visitTree(that); }
3085 public void visitNewClass(JCNewClass that) { visitTree(that); }
3086 public void visitNewArray(JCNewArray that) { visitTree(that); }
3087 public void visitLambda(JCLambda that) { visitTree(that); }
3088 public void visitParens(JCParens that) { visitTree(that); }
3089 public void visitAssign(JCAssign that) { visitTree(that); }
3090 public void visitAssignop(JCAssignOp that) { visitTree(that); }
3091 public void visitUnary(JCUnary that) { visitTree(that); }
3092 public void visitBinary(JCBinary that) { visitTree(that); }
|
30 import java.util.*;
31
32 import javax.lang.model.element.Modifier;
33 import javax.lang.model.type.TypeKind;
34 import javax.tools.JavaFileObject;
35
36 import com.sun.source.tree.*;
37 import com.sun.tools.javac.code.*;
38 import com.sun.tools.javac.code.Directive.RequiresDirective;
39 import com.sun.tools.javac.code.Scope.*;
40 import com.sun.tools.javac.code.Symbol.*;
41 import com.sun.tools.javac.util.*;
42 import com.sun.tools.javac.util.DefinedBy.Api;
43 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
44 import com.sun.tools.javac.util.List;
45
46 import static com.sun.tools.javac.tree.JCTree.Tag.*;
47
48 import javax.tools.JavaFileManager.Location;
49
50 import com.sun.source.tree.CaseTree.CaseKind;
51 import com.sun.source.tree.ModuleTree.ModuleKind;
52 import com.sun.tools.javac.code.Directive.ExportsDirective;
53 import com.sun.tools.javac.code.Directive.OpensDirective;
54 import com.sun.tools.javac.code.Type.ModuleType;
55 import com.sun.tools.javac.tree.JCTree.JCPolyExpression.PolyKind;
56
57 /**
58 * Root class for abstract syntax tree nodes. It provides definitions
59 * for specific tree nodes as subclasses nested inside.
60 *
61 * <p>Each subclass is highly standardized. It generally contains
62 * only tree fields for the syntactic subcomponents of the node. Some
63 * classes that represent identifier uses or definitions also define a
64 * Symbol field that denotes the represented identifier. Classes for
65 * non-local jumps also carry the jump target as a field. The root
66 * class Tree itself defines fields for the tree's type and position.
67 * No other fields are kept in a tree node; instead parameters are
68 * passed to methods accessing the node.
69 *
70 * <p>Except for the methods defined by com.sun.source, the only
71 * method defined in subclasses is `visit' which applies a given
72 * visitor to the tree. The actual tree processing is done by visitor
73 * classes in other packages. The abstract class Visitor, as well as
74 * an Factory interface for trees, are defined as inner classes in
75 * Tree.
134 /** While-loops, of type WhileLoop.
135 */
136 WHILELOOP,
137
138 /** For-loops, of type ForLoop.
139 */
140 FORLOOP,
141
142 /** Foreach-loops, of type ForeachLoop.
143 */
144 FOREACHLOOP,
145
146 /** Labelled statements, of type Labelled.
147 */
148 LABELLED,
149
150 /** Switch statements, of type Switch.
151 */
152 SWITCH,
153
154 /** Case parts in switch statements/expressions, of type Case.
155 */
156 CASE,
157
158 /** Switch expression statements, of type Switch.
159 */
160 SWITCH_EXPRESSION,
161
162 /** Synchronized statements, of type Synchonized.
163 */
164 SYNCHRONIZED,
165
166 /** Try statements, of type Try.
167 */
168 TRY,
169
170 /** Catch clauses in try statements, of type Catch.
171 */
172 CATCH,
173
174 /** Conditional expressions, of type Conditional.
175 */
176 CONDEXPR,
177
178 /** Conditional statements, of type If.
179 */
180 IF,
181
1227 @DefinedBy(Api.COMPILER_TREE)
1228 public Kind getKind() { return Kind.SWITCH; }
1229 @DefinedBy(Api.COMPILER_TREE)
1230 public JCExpression getExpression() { return selector; }
1231 @DefinedBy(Api.COMPILER_TREE)
1232 public List<JCCase> getCases() { return cases; }
1233 @Override @DefinedBy(Api.COMPILER_TREE)
1234 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1235 return v.visitSwitch(this, d);
1236 }
1237 @Override
1238 public Tag getTag() {
1239 return SWITCH;
1240 }
1241 }
1242
1243 /**
1244 * A "case :" of a switch.
1245 */
1246 public static class JCCase extends JCStatement implements CaseTree {
1247 //as CaseKind is deprecated for removal (as it is part of a preview feature),
1248 //using indirection through these fields to avoid unnecessary @SuppressWarnings:
1249 @SuppressWarnings("removal")
1250 public static final CaseKind STATEMENT = CaseKind.STATEMENT;
1251 @SuppressWarnings("removal")
1252 public static final CaseKind RULE = CaseKind.RULE;
1253 @SuppressWarnings("removal")
1254 public final CaseKind caseKind;
1255 public List<JCExpression> pats;
1256 public List<JCStatement> stats;
1257 public JCTree body;
1258 public boolean completesNormally;
1259 protected JCCase(@SuppressWarnings("removal") CaseKind caseKind, List<JCExpression> pats,
1260 List<JCStatement> stats, JCTree body) {
1261 Assert.checkNonNull(pats);
1262 Assert.check(pats.isEmpty() || pats.head != null);
1263 this.caseKind = caseKind;
1264 this.pats = pats;
1265 this.stats = stats;
1266 this.body = body;
1267 }
1268 @Override
1269 public void accept(Visitor v) { v.visitCase(this); }
1270
1271 @Override @DefinedBy(Api.COMPILER_TREE)
1272 public Kind getKind() { return Kind.CASE; }
1273 @Override @Deprecated @DefinedBy(Api.COMPILER_TREE)
1274 public JCExpression getExpression() { return pats.head; }
1275 @Override @DefinedBy(Api.COMPILER_TREE)
1276 @SuppressWarnings("removal")
1277 public List<JCExpression> getExpressions() { return pats; }
1278 @DefinedBy(Api.COMPILER_TREE)
1279 public List<JCStatement> getStatements() { return stats; }
1280 @DefinedBy(Api.COMPILER_TREE)
1281 @SuppressWarnings("removal")
1282 public JCTree getBody() { return body; }
1283 @Override
1284 @SuppressWarnings("removal")
1285 public CaseKind getCaseKind() {
1286 return caseKind;
1287 }
1288 @Override @DefinedBy(Api.COMPILER_TREE)
1289 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1290 return v.visitCase(this, d);
1291 }
1292 @Override
1293 public Tag getTag() {
1294 return CASE;
1295 }
1296 }
1297
1298 /**
1299 * A "switch ( ) { }" construction.
1300 */
1301 @SuppressWarnings("removal")
1302 public static class JCSwitchExpression extends JCPolyExpression implements SwitchExpressionTree {
1303 public JCExpression selector;
1304 public List<JCCase> cases;
1305 protected JCSwitchExpression(JCExpression selector, List<JCCase> cases) {
1306 this.selector = selector;
1307 this.cases = cases;
1308 }
1309 @Override
1310 public void accept(Visitor v) { v.visitSwitchExpression(this); }
1311
1312 @DefinedBy(Api.COMPILER_TREE)
1313 public Kind getKind() { return Kind.SWITCH_EXPRESSION; }
1314 @DefinedBy(Api.COMPILER_TREE)
1315 public JCExpression getExpression() { return selector; }
1316 @DefinedBy(Api.COMPILER_TREE)
1317 public List<JCCase> getCases() { return cases; }
1318 @Override @DefinedBy(Api.COMPILER_TREE)
1319 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1320 return v.visitSwitchExpression(this, d);
1321 }
1322 @Override
1323 public Tag getTag() {
1324 return SWITCH_EXPRESSION;
1325 }
1326 }
1327
1328 /**
1329 * A synchronized block.
1330 */
1331 public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1332 public JCExpression lock;
1333 public JCBlock body;
1334 protected JCSynchronized(JCExpression lock, JCBlock body) {
1335 this.lock = lock;
1336 this.body = body;
1337 }
1338 @Override
1339 public void accept(Visitor v) { v.visitSynchronized(this); }
1340
1341 @DefinedBy(Api.COMPILER_TREE)
1342 public Kind getKind() { return Kind.SYNCHRONIZED; }
1343 @DefinedBy(Api.COMPILER_TREE)
1344 public JCExpression getExpression() { return lock; }
1345 @DefinedBy(Api.COMPILER_TREE)
1346 public JCBlock getBlock() { return body; }
1347 @Override @DefinedBy(Api.COMPILER_TREE)
1348 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1529 /** Convert a expression-statement tree to a pretty-printed string. */
1530 @Override
1531 public String toString() {
1532 StringWriter s = new StringWriter();
1533 try {
1534 new Pretty(s, false).printStat(this);
1535 }
1536 catch (IOException e) {
1537 // should never happen, because StringWriter is defined
1538 // never to throw any IOExceptions
1539 throw new AssertionError(e);
1540 }
1541 return s.toString();
1542 }
1543 }
1544
1545 /**
1546 * A break from a loop or switch.
1547 */
1548 public static class JCBreak extends JCStatement implements BreakTree {
1549 public JCExpression value;
1550 public JCTree target;
1551 protected JCBreak(JCExpression value, JCTree target) {
1552 this.value = value;
1553 this.target = target;
1554 }
1555 @Override
1556 public void accept(Visitor v) { v.visitBreak(this); }
1557 public boolean isValueBreak() {
1558 return target != null && target.hasTag(SWITCH_EXPRESSION);
1559 }
1560
1561 @DefinedBy(Api.COMPILER_TREE)
1562 public Kind getKind() { return Kind.BREAK; }
1563 @DefinedBy(Api.COMPILER_TREE)
1564 public Name getLabel() {
1565 return value != null && value.getKind() == Kind.IDENTIFIER ? ((JCIdent) value).getName() : null;
1566 }
1567 @DefinedBy(Api.COMPILER_TREE)
1568 @SuppressWarnings("removal")
1569 public JCExpression getValue() { return value; }
1570 @Override @DefinedBy(Api.COMPILER_TREE)
1571 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1572 return v.visitBreak(this, d);
1573 }
1574 @Override
1575 public Tag getTag() {
1576 return BREAK;
1577 }
1578 }
1579
1580 /**
1581 * A continue of a loop.
1582 */
1583 public static class JCContinue extends JCStatement implements ContinueTree {
1584 public Name label;
1585 public JCTree target;
1586 protected JCContinue(Name label, JCTree target) {
1587 this.label = label;
1588 this.target = target;
1589 }
2987 @DefinedBy(Api.COMPILER_TREE)
2988 public Kind getKind() { return Kind.ERRONEOUS; }
2989
2990 @DefinedBy(Api.COMPILER_TREE)
2991 public List<? extends JCTree> getErrorTrees() {
2992 return errs;
2993 }
2994
2995 @Override @DefinedBy(Api.COMPILER_TREE)
2996 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
2997 return v.visitErroneous(this, d);
2998 }
2999 @Override
3000 public Tag getTag() {
3001 return ERRONEOUS;
3002 }
3003 }
3004
3005 /** (let int x = 3; in x+2) */
3006 public static class LetExpr extends JCExpression {
3007 public List<JCStatement> defs;
3008 public JCExpression expr;
3009 protected LetExpr(List<JCStatement> defs, JCExpression expr) {
3010 this.defs = defs;
3011 this.expr = expr;
3012 }
3013 @Override
3014 public void accept(Visitor v) { v.visitLetExpr(this); }
3015
3016 @DefinedBy(Api.COMPILER_TREE)
3017 public Kind getKind() {
3018 throw new AssertionError("LetExpr is not part of a public API");
3019 }
3020 @Override @DefinedBy(Api.COMPILER_TREE)
3021 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3022 throw new AssertionError("LetExpr is not part of a public API");
3023 }
3024 @Override
3025 public Tag getTag() {
3026 return LETEXPR;
3027 }
3028 }
3029
3047 JCVariableDecl recvparam,
3048 List<JCVariableDecl> params,
3049 List<JCExpression> thrown,
3050 JCBlock body,
3051 JCExpression defaultValue);
3052 JCVariableDecl VarDef(JCModifiers mods,
3053 Name name,
3054 JCExpression vartype,
3055 JCExpression init);
3056 JCSkip Skip();
3057 JCBlock Block(long flags, List<JCStatement> stats);
3058 JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
3059 JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
3060 JCForLoop ForLoop(List<JCStatement> init,
3061 JCExpression cond,
3062 List<JCExpressionStatement> step,
3063 JCStatement body);
3064 JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
3065 JCLabeledStatement Labelled(Name label, JCStatement body);
3066 JCSwitch Switch(JCExpression selector, List<JCCase> cases);
3067 JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases);
3068 JCCase Case(@SuppressWarnings("removal") CaseKind caseKind, List<JCExpression> pat,
3069 List<JCStatement> stats, JCTree body);
3070 JCSynchronized Synchronized(JCExpression lock, JCBlock body);
3071 JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
3072 JCTry Try(List<JCTree> resources,
3073 JCBlock body,
3074 List<JCCatch> catchers,
3075 JCBlock finalizer);
3076 JCCatch Catch(JCVariableDecl param, JCBlock body);
3077 JCConditional Conditional(JCExpression cond,
3078 JCExpression thenpart,
3079 JCExpression elsepart);
3080 JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
3081 JCExpressionStatement Exec(JCExpression expr);
3082 JCBreak Break(JCExpression value);
3083 JCContinue Continue(Name label);
3084 JCReturn Return(JCExpression expr);
3085 JCThrow Throw(JCExpression expr);
3086 JCAssert Assert(JCExpression cond, JCExpression detail);
3087 JCMethodInvocation Apply(List<JCExpression> typeargs,
3088 JCExpression fn,
3089 List<JCExpression> args);
3090 JCNewClass NewClass(JCExpression encl,
3091 List<JCExpression> typeargs,
3092 JCExpression clazz,
3093 List<JCExpression> args,
3094 JCClassDecl def);
3095 JCNewArray NewArray(JCExpression elemtype,
3096 List<JCExpression> dims,
3097 List<JCExpression> elems);
3098 JCParens Parens(JCExpression expr);
3099 JCAssign Assign(JCExpression lhs, JCExpression rhs);
3100 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3101 JCUnary Unary(Tag opcode, JCExpression arg);
3102 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3104 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3105 JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3106 JCFieldAccess Select(JCExpression selected, Name selector);
3107 JCIdent Ident(Name idname);
3108 JCLiteral Literal(TypeTag tag, Object value);
3109 JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3110 JCArrayTypeTree TypeArray(JCExpression elemtype);
3111 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3112 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3113 JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3114 TypeBoundKind TypeBoundKind(BoundKind kind);
3115 JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3116 JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3117 JCErroneous Erroneous(List<? extends JCTree> errs);
3118 JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3119 JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3120 JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3121 JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3122 JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3123 JCUses Uses(JCExpression qualId);
3124 LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);
3125 }
3126
3127 /** A generic visitor class for trees.
3128 */
3129 public static abstract class Visitor {
3130 public void visitTopLevel(JCCompilationUnit that) { visitTree(that); }
3131 public void visitPackageDef(JCPackageDecl that) { visitTree(that); }
3132 public void visitImport(JCImport that) { visitTree(that); }
3133 public void visitClassDef(JCClassDecl that) { visitTree(that); }
3134 public void visitMethodDef(JCMethodDecl that) { visitTree(that); }
3135 public void visitVarDef(JCVariableDecl that) { visitTree(that); }
3136 public void visitSkip(JCSkip that) { visitTree(that); }
3137 public void visitBlock(JCBlock that) { visitTree(that); }
3138 public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); }
3139 public void visitWhileLoop(JCWhileLoop that) { visitTree(that); }
3140 public void visitForLoop(JCForLoop that) { visitTree(that); }
3141 public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3142 public void visitLabelled(JCLabeledStatement that) { visitTree(that); }
3143 public void visitSwitch(JCSwitch that) { visitTree(that); }
3144 public void visitCase(JCCase that) { visitTree(that); }
3145 public void visitSwitchExpression(JCSwitchExpression that) { visitTree(that); }
3146 public void visitSynchronized(JCSynchronized that) { visitTree(that); }
3147 public void visitTry(JCTry that) { visitTree(that); }
3148 public void visitCatch(JCCatch that) { visitTree(that); }
3149 public void visitConditional(JCConditional that) { visitTree(that); }
3150 public void visitIf(JCIf that) { visitTree(that); }
3151 public void visitExec(JCExpressionStatement that) { visitTree(that); }
3152 public void visitBreak(JCBreak that) { visitTree(that); }
3153 public void visitContinue(JCContinue that) { visitTree(that); }
3154 public void visitReturn(JCReturn that) { visitTree(that); }
3155 public void visitThrow(JCThrow that) { visitTree(that); }
3156 public void visitAssert(JCAssert that) { visitTree(that); }
3157 public void visitApply(JCMethodInvocation that) { visitTree(that); }
3158 public void visitNewClass(JCNewClass that) { visitTree(that); }
3159 public void visitNewArray(JCNewArray that) { visitTree(that); }
3160 public void visitLambda(JCLambda that) { visitTree(that); }
3161 public void visitParens(JCParens that) { visitTree(that); }
3162 public void visitAssign(JCAssign that) { visitTree(that); }
3163 public void visitAssignop(JCAssignOp that) { visitTree(that); }
3164 public void visitUnary(JCUnary that) { visitTree(that); }
3165 public void visitBinary(JCBinary that) { visitTree(that); }
|