249 }
250
251 public JCBlock Block(long flags, List<JCStatement> stats) {
252 JCBlock tree = new JCBlock(flags, stats);
253 tree.pos = pos;
254 return tree;
255 }
256
257 public JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond) {
258 JCDoWhileLoop tree = new JCDoWhileLoop(body, cond);
259 tree.pos = pos;
260 return tree;
261 }
262
263 public JCWhileLoop WhileLoop(JCExpression cond, JCStatement body) {
264 JCWhileLoop tree = new JCWhileLoop(cond, body);
265 tree.pos = pos;
266 return tree;
267 }
268
269 public JCForLoop ForLoop(List<JCStatement> init,
270 JCExpression cond,
271 List<JCExpressionStatement> step,
272 JCStatement body)
273 {
274 JCForLoop tree = new JCForLoop(init, cond, step, body);
275 tree.pos = pos;
276 return tree;
277 }
278
279 public JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
280 JCEnhancedForLoop tree = new JCEnhancedForLoop(var, expr, body);
281 tree.pos = pos;
282 return tree;
283 }
284
285 public JCLabeledStatement Labelled(Name label, JCStatement body) {
286 JCLabeledStatement tree = new JCLabeledStatement(label, body);
287 tree.pos = pos;
288 return tree;
289 }
290
291 public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
292 JCSwitch tree = new JCSwitch(selector, cases);
293 tree.pos = pos;
294 return tree;
295 }
296
297 public JCCase Case(CaseTree.CaseKind caseKind, List<JCCaseLabel> labels,
298 JCExpression guard, List<JCStatement> stats, JCTree body) {
299 JCCase tree = new JCCase(caseKind, labels, guard, stats, body);
300 tree.pos = pos;
301 return tree;
302 }
303
304 public JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases) {
305 JCSwitchExpression tree = new JCSwitchExpression(selector, cases);
306 tree.pos = pos;
307 return tree;
308 }
309
310 public JCSynchronized Synchronized(JCExpression lock, JCBlock body) {
311 JCSynchronized tree = new JCSynchronized(lock, body);
312 tree.pos = pos;
313 return tree;
314 }
315
316 public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
317 return Try(List.nil(), body, catchers, finalizer);
318 }
319
320 public JCTry Try(List<JCTree> resources,
321 JCBlock body,
322 List<JCCatch> catchers,
323 JCBlock finalizer) {
845 switch (t.getKind()) {
846 case UNION: {
847 UnionClassType tu = (UnionClassType)t;
848 ListBuffer<JCExpression> la = new ListBuffer<>();
849 for (Type ta : tu.getAlternativeTypes()) {
850 la.add(Type(ta));
851 }
852 tp = TypeUnion(la.toList());
853 break;
854 }
855 case INTERSECTION: {
856 IntersectionClassType it = (IntersectionClassType)t;
857 ListBuffer<JCExpression> la = new ListBuffer<>();
858 for (Type ta : it.getExplicitComponents()) {
859 la.add(Type(ta));
860 }
861 tp = TypeIntersection(la.toList());
862 break;
863 }
864 default: {
865 Type outer = t.getEnclosingType();
866 JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP
867 ? Select(Type(outer), t.tsym)
868 : QualIdent(t.tsym);
869 tp = t.getTypeArguments().isEmpty()
870 ? clazz
871 : TypeApply(clazz, Types(t.getTypeArguments()));
872 break;
873 }
874 }
875 break;
876 case ARRAY:
877 tp = TypeArray(Type(types.elemtype(t)));
878 break;
879 case ERROR:
880 tp = TypeIdent(ERROR);
881 break;
882 default:
883 throw new AssertionError("unexpected type: " + t);
884 }
885 return tp.setType(t);
886 }
887
888 /** Create a list of trees representing given list of types.
889 */
890 public List<JCExpression> Types(List<Type> ts) {
891 ListBuffer<JCExpression> lb = new ListBuffer<>();
|
249 }
250
251 public JCBlock Block(long flags, List<JCStatement> stats) {
252 JCBlock tree = new JCBlock(flags, stats);
253 tree.pos = pos;
254 return tree;
255 }
256
257 public JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond) {
258 JCDoWhileLoop tree = new JCDoWhileLoop(body, cond);
259 tree.pos = pos;
260 return tree;
261 }
262
263 public JCWhileLoop WhileLoop(JCExpression cond, JCStatement body) {
264 JCWhileLoop tree = new JCWhileLoop(cond, body);
265 tree.pos = pos;
266 return tree;
267 }
268
269 public JCWithField WithField(JCExpression field, JCExpression value) {
270 JCWithField tree = new JCWithField(field, value);
271 tree.pos = pos;
272 return tree;
273 }
274
275 public JCForLoop ForLoop(List<JCStatement> init,
276 JCExpression cond,
277 List<JCExpressionStatement> step,
278 JCStatement body)
279 {
280 JCForLoop tree = new JCForLoop(init, cond, step, body);
281 tree.pos = pos;
282 return tree;
283 }
284
285 public JCEnhancedForLoop ForeachLoop(JCVariableDecl var, JCExpression expr, JCStatement body) {
286 JCEnhancedForLoop tree = new JCEnhancedForLoop(var, expr, body);
287 tree.pos = pos;
288 return tree;
289 }
290
291 public JCLabeledStatement Labelled(Name label, JCStatement body) {
292 JCLabeledStatement tree = new JCLabeledStatement(label, body);
293 tree.pos = pos;
294 return tree;
295 }
296
297 public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
298 JCSwitch tree = new JCSwitch(selector, cases);
299 tree.pos = pos;
300 return tree;
301 }
302
303 public JCCase Case(CaseTree.CaseKind caseKind, List<JCCaseLabel> labels,
304 JCExpression guard, List<JCStatement> stats, JCTree body) {
305 JCCase tree = new JCCase(caseKind, labels, guard, stats, body);
306 tree.pos = pos;
307 return tree;
308 }
309
310 public JCDefaultValue DefaultValue(JCExpression type) {
311 JCDefaultValue tree = new JCDefaultValue(type);
312 tree.pos = pos;
313 return tree;
314 }
315
316 public JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases) {
317 JCSwitchExpression tree = new JCSwitchExpression(selector, cases);
318 tree.pos = pos;
319 return tree;
320 }
321
322 public JCSynchronized Synchronized(JCExpression lock, JCBlock body) {
323 JCSynchronized tree = new JCSynchronized(lock, body);
324 tree.pos = pos;
325 return tree;
326 }
327
328 public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
329 return Try(List.nil(), body, catchers, finalizer);
330 }
331
332 public JCTry Try(List<JCTree> resources,
333 JCBlock body,
334 List<JCCatch> catchers,
335 JCBlock finalizer) {
857 switch (t.getKind()) {
858 case UNION: {
859 UnionClassType tu = (UnionClassType)t;
860 ListBuffer<JCExpression> la = new ListBuffer<>();
861 for (Type ta : tu.getAlternativeTypes()) {
862 la.add(Type(ta));
863 }
864 tp = TypeUnion(la.toList());
865 break;
866 }
867 case INTERSECTION: {
868 IntersectionClassType it = (IntersectionClassType)t;
869 ListBuffer<JCExpression> la = new ListBuffer<>();
870 for (Type ta : it.getExplicitComponents()) {
871 la.add(Type(ta));
872 }
873 tp = TypeIntersection(la.toList());
874 break;
875 }
876 default: {
877 if (t.isReferenceProjection()) {
878 // For parameterized types, we want V.ref<A1 ... An> not V<A1 ... An>.ref
879 JCExpression vp = Type(t.valueProjection());
880 if (vp.hasTag(Tag.TYPEAPPLY)) {
881 // vp now is V<A1 ... An>, build V.ref<A1 ... An>
882 JCFieldAccess f = Select(((JCTypeApply) vp).clazz, t.tsym);
883 f.name = names.ref;
884 tp = TypeApply(f, ((JCTypeApply) vp).arguments);
885 } else {
886 JCFieldAccess f = Select(vp, t.tsym);
887 f.name = names.ref;
888 tp = f;
889 }
890 } else {
891 Type outer = t.getEnclosingType();
892 JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP
893 ? Select(Type(outer), t.tsym)
894 : QualIdent(t.tsym);
895 tp = t.getTypeArguments().isEmpty()
896 ? clazz
897 : TypeApply(clazz, Types(t.getTypeArguments()));
898 }
899 break;
900 }
901 }
902 break;
903 case ARRAY:
904 tp = TypeArray(Type(types.elemtype(t)));
905 break;
906 case ERROR:
907 tp = TypeIdent(ERROR);
908 break;
909 default:
910 throw new AssertionError("unexpected type: " + t);
911 }
912 return tp.setType(t);
913 }
914
915 /** Create a list of trees representing given list of types.
916 */
917 public List<JCExpression> Types(List<Type> ts) {
918 ListBuffer<JCExpression> lb = new ListBuffer<>();
|