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 @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 @Override @DefinedBy(Api.COMPILER_TREE)
1279 @SuppressWarnings("removal")
1280 public List<JCStatement> getStatements() {
1281 return caseKind == CaseKind.STATEMENT ? stats : null;
1282 }
1283 @Override @DefinedBy(Api.COMPILER_TREE)
1284 @SuppressWarnings("removal")
1285 public JCTree getBody() { return body; }
1286 @Override @DefinedBy(Api.COMPILER_TREE)
1287 @SuppressWarnings("removal")
1288 public CaseKind getCaseKind() {
1289 return caseKind;
1290 }
1291 @Override @DefinedBy(Api.COMPILER_TREE)
1292 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1293 return v.visitCase(this, d);
1294 }
1295 @Override
1296 public Tag getTag() {
1297 return CASE;
1298 }
1299 }
1300
1301 /**
1302 * A "switch ( ) { }" construction.
1303 */
1304 @SuppressWarnings("removal")
1305 public static class JCSwitchExpression extends JCPolyExpression implements SwitchExpressionTree {
1306 public JCExpression selector;
1307 public List<JCCase> cases;
1308 protected JCSwitchExpression(JCExpression selector, List<JCCase> cases) {
1309 this.selector = selector;
1310 this.cases = cases;
1311 }
1312 @Override
1313 public void accept(Visitor v) { v.visitSwitchExpression(this); }
1314
1315 @DefinedBy(Api.COMPILER_TREE)
1316 public Kind getKind() { return Kind.SWITCH_EXPRESSION; }
1317 @DefinedBy(Api.COMPILER_TREE)
1318 public JCExpression getExpression() { return selector; }
1319 @DefinedBy(Api.COMPILER_TREE)
1320 public List<JCCase> getCases() { return cases; }
1321 @Override @DefinedBy(Api.COMPILER_TREE)
1322 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1323 return v.visitSwitchExpression(this, d);
1324 }
1325 @Override
1326 public Tag getTag() {
1327 return SWITCH_EXPRESSION;
1328 }
1329 }
1330
1331 /**
1332 * A synchronized block.
1333 */
1334 public static class JCSynchronized extends JCStatement implements SynchronizedTree {
1335 public JCExpression lock;
1336 public JCBlock body;
1337 protected JCSynchronized(JCExpression lock, JCBlock body) {
1338 this.lock = lock;
1339 this.body = body;
1340 }
1341 @Override
1342 public void accept(Visitor v) { v.visitSynchronized(this); }
1343
1344 @DefinedBy(Api.COMPILER_TREE)
1345 public Kind getKind() { return Kind.SYNCHRONIZED; }
1346 @DefinedBy(Api.COMPILER_TREE)
1347 public JCExpression getExpression() { return lock; }
1348 @DefinedBy(Api.COMPILER_TREE)
1349 public JCBlock getBlock() { return body; }
1350 @Override @DefinedBy(Api.COMPILER_TREE)
1351 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1532 /** Convert a expression-statement tree to a pretty-printed string. */
1533 @Override
1534 public String toString() {
1535 StringWriter s = new StringWriter();
1536 try {
1537 new Pretty(s, false).printStat(this);
1538 }
1539 catch (IOException e) {
1540 // should never happen, because StringWriter is defined
1541 // never to throw any IOExceptions
1542 throw new AssertionError(e);
1543 }
1544 return s.toString();
1545 }
1546 }
1547
1548 /**
1549 * A break from a loop or switch.
1550 */
1551 public static class JCBreak extends JCStatement implements BreakTree {
1552 public JCExpression value;
1553 public JCTree target;
1554 protected JCBreak(JCExpression value, JCTree target) {
1555 this.value = value;
1556 this.target = target;
1557 }
1558 @Override
1559 public void accept(Visitor v) { v.visitBreak(this); }
1560 public boolean isValueBreak() {
1561 return target != null && target.hasTag(SWITCH_EXPRESSION);
1562 }
1563
1564 @DefinedBy(Api.COMPILER_TREE)
1565 public Kind getKind() { return Kind.BREAK; }
1566 @DefinedBy(Api.COMPILER_TREE)
1567 public Name getLabel() {
1568 return value != null && value.getKind() == Kind.IDENTIFIER ? ((JCIdent) value).getName() : null;
1569 }
1570 @DefinedBy(Api.COMPILER_TREE)
1571 @SuppressWarnings("removal")
1572 public JCExpression getValue() { return value; }
1573 @Override @DefinedBy(Api.COMPILER_TREE)
1574 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
1575 return v.visitBreak(this, d);
1576 }
1577 @Override
1578 public Tag getTag() {
1579 return BREAK;
1580 }
1581 }
1582
1583 /**
1584 * A continue of a loop.
1585 */
1586 public static class JCContinue extends JCStatement implements ContinueTree {
1587 public Name label;
1588 public JCTree target;
1589 protected JCContinue(Name label, JCTree target) {
1590 this.label = label;
1591 this.target = target;
1592 }
2990 @DefinedBy(Api.COMPILER_TREE)
2991 public Kind getKind() { return Kind.ERRONEOUS; }
2992
2993 @DefinedBy(Api.COMPILER_TREE)
2994 public List<? extends JCTree> getErrorTrees() {
2995 return errs;
2996 }
2997
2998 @Override @DefinedBy(Api.COMPILER_TREE)
2999 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3000 return v.visitErroneous(this, d);
3001 }
3002 @Override
3003 public Tag getTag() {
3004 return ERRONEOUS;
3005 }
3006 }
3007
3008 /** (let int x = 3; in x+2) */
3009 public static class LetExpr extends JCExpression {
3010 public List<JCStatement> defs;
3011 public JCExpression expr;
3012 protected LetExpr(List<JCStatement> defs, JCExpression expr) {
3013 this.defs = defs;
3014 this.expr = expr;
3015 }
3016 @Override
3017 public void accept(Visitor v) { v.visitLetExpr(this); }
3018
3019 @DefinedBy(Api.COMPILER_TREE)
3020 public Kind getKind() {
3021 throw new AssertionError("LetExpr is not part of a public API");
3022 }
3023 @Override @DefinedBy(Api.COMPILER_TREE)
3024 public <R,D> R accept(TreeVisitor<R,D> v, D d) {
3025 throw new AssertionError("LetExpr is not part of a public API");
3026 }
3027 @Override
3028 public Tag getTag() {
3029 return LETEXPR;
3030 }
3031 }
3032
3050 JCVariableDecl recvparam,
3051 List<JCVariableDecl> params,
3052 List<JCExpression> thrown,
3053 JCBlock body,
3054 JCExpression defaultValue);
3055 JCVariableDecl VarDef(JCModifiers mods,
3056 Name name,
3057 JCExpression vartype,
3058 JCExpression init);
3059 JCSkip Skip();
3060 JCBlock Block(long flags, List<JCStatement> stats);
3061 JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond);
3062 JCWhileLoop WhileLoop(JCExpression cond, JCStatement body);
3063 JCForLoop ForLoop(List<JCStatement> init,
3064 JCExpression cond,
3065 List<JCExpressionStatement> step,
3066 JCStatement body);
3067 JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body);
3068 JCLabeledStatement Labelled(Name label, JCStatement body);
3069 JCSwitch Switch(JCExpression selector, List<JCCase> cases);
3070 JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases);
3071 JCCase Case(@SuppressWarnings("removal") CaseKind caseKind, List<JCExpression> pat,
3072 List<JCStatement> stats, JCTree body);
3073 JCSynchronized Synchronized(JCExpression lock, JCBlock body);
3074 JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer);
3075 JCTry Try(List<JCTree> resources,
3076 JCBlock body,
3077 List<JCCatch> catchers,
3078 JCBlock finalizer);
3079 JCCatch Catch(JCVariableDecl param, JCBlock body);
3080 JCConditional Conditional(JCExpression cond,
3081 JCExpression thenpart,
3082 JCExpression elsepart);
3083 JCIf If(JCExpression cond, JCStatement thenpart, JCStatement elsepart);
3084 JCExpressionStatement Exec(JCExpression expr);
3085 JCBreak Break(JCExpression value);
3086 JCContinue Continue(Name label);
3087 JCReturn Return(JCExpression expr);
3088 JCThrow Throw(JCExpression expr);
3089 JCAssert Assert(JCExpression cond, JCExpression detail);
3090 JCMethodInvocation Apply(List<JCExpression> typeargs,
3091 JCExpression fn,
3092 List<JCExpression> args);
3093 JCNewClass NewClass(JCExpression encl,
3094 List<JCExpression> typeargs,
3095 JCExpression clazz,
3096 List<JCExpression> args,
3097 JCClassDecl def);
3098 JCNewArray NewArray(JCExpression elemtype,
3099 List<JCExpression> dims,
3100 List<JCExpression> elems);
3101 JCParens Parens(JCExpression expr);
3102 JCAssign Assign(JCExpression lhs, JCExpression rhs);
3103 JCAssignOp Assignop(Tag opcode, JCTree lhs, JCTree rhs);
3104 JCUnary Unary(Tag opcode, JCExpression arg);
3105 JCBinary Binary(Tag opcode, JCExpression lhs, JCExpression rhs);
3107 JCInstanceOf TypeTest(JCExpression expr, JCTree clazz);
3108 JCArrayAccess Indexed(JCExpression indexed, JCExpression index);
3109 JCFieldAccess Select(JCExpression selected, Name selector);
3110 JCIdent Ident(Name idname);
3111 JCLiteral Literal(TypeTag tag, Object value);
3112 JCPrimitiveTypeTree TypeIdent(TypeTag typetag);
3113 JCArrayTypeTree TypeArray(JCExpression elemtype);
3114 JCTypeApply TypeApply(JCExpression clazz, List<JCExpression> arguments);
3115 JCTypeParameter TypeParameter(Name name, List<JCExpression> bounds);
3116 JCWildcard Wildcard(TypeBoundKind kind, JCTree type);
3117 TypeBoundKind TypeBoundKind(BoundKind kind);
3118 JCAnnotation Annotation(JCTree annotationType, List<JCExpression> args);
3119 JCModifiers Modifiers(long flags, List<JCAnnotation> annotations);
3120 JCErroneous Erroneous(List<? extends JCTree> errs);
3121 JCModuleDecl ModuleDef(JCModifiers mods, ModuleKind kind, JCExpression qualId, List<JCDirective> directives);
3122 JCExports Exports(JCExpression qualId, List<JCExpression> moduleNames);
3123 JCOpens Opens(JCExpression qualId, List<JCExpression> moduleNames);
3124 JCProvides Provides(JCExpression serviceName, List<JCExpression> implNames);
3125 JCRequires Requires(boolean isTransitive, boolean isStaticPhase, JCExpression qualId);
3126 JCUses Uses(JCExpression qualId);
3127 LetExpr LetExpr(List<JCStatement> defs, JCExpression expr);
3128 }
3129
3130 /** A generic visitor class for trees.
3131 */
3132 public static abstract class Visitor {
3133 public void visitTopLevel(JCCompilationUnit that) { visitTree(that); }
3134 public void visitPackageDef(JCPackageDecl that) { visitTree(that); }
3135 public void visitImport(JCImport that) { visitTree(that); }
3136 public void visitClassDef(JCClassDecl that) { visitTree(that); }
3137 public void visitMethodDef(JCMethodDecl that) { visitTree(that); }
3138 public void visitVarDef(JCVariableDecl that) { visitTree(that); }
3139 public void visitSkip(JCSkip that) { visitTree(that); }
3140 public void visitBlock(JCBlock that) { visitTree(that); }
3141 public void visitDoLoop(JCDoWhileLoop that) { visitTree(that); }
3142 public void visitWhileLoop(JCWhileLoop that) { visitTree(that); }
3143 public void visitForLoop(JCForLoop that) { visitTree(that); }
3144 public void visitForeachLoop(JCEnhancedForLoop that) { visitTree(that); }
3145 public void visitLabelled(JCLabeledStatement that) { visitTree(that); }
3146 public void visitSwitch(JCSwitch that) { visitTree(that); }
3147 public void visitCase(JCCase that) { visitTree(that); }
3148 public void visitSwitchExpression(JCSwitchExpression that) { visitTree(that); }
3149 public void visitSynchronized(JCSynchronized that) { visitTree(that); }
3150 public void visitTry(JCTry that) { visitTree(that); }
3151 public void visitCatch(JCCatch that) { visitTree(that); }
3152 public void visitConditional(JCConditional that) { visitTree(that); }
3153 public void visitIf(JCIf that) { visitTree(that); }
3154 public void visitExec(JCExpressionStatement that) { visitTree(that); }
3155 public void visitBreak(JCBreak that) { visitTree(that); }
3156 public void visitContinue(JCContinue that) { visitTree(that); }
3157 public void visitReturn(JCReturn that) { visitTree(that); }
3158 public void visitThrow(JCThrow that) { visitTree(that); }
3159 public void visitAssert(JCAssert that) { visitTree(that); }
3160 public void visitApply(JCMethodInvocation that) { visitTree(that); }
3161 public void visitNewClass(JCNewClass that) { visitTree(that); }
3162 public void visitNewArray(JCNewArray that) { visitTree(that); }
3163 public void visitLambda(JCLambda that) { visitTree(that); }
3164 public void visitParens(JCParens that) { visitTree(that); }
3165 public void visitAssign(JCAssign that) { visitTree(that); }
3166 public void visitAssignop(JCAssignOp that) { visitTree(that); }
3167 public void visitUnary(JCUnary that) { visitTree(that); }
3168 public void visitBinary(JCBinary that) { visitTree(that); }
|