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