< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java

Print this page

 247     }
 248 
 249     public JCBlock Block(long flags, List<JCStatement> stats) {
 250         JCBlock tree = new JCBlock(flags, stats);
 251         tree.pos = pos;
 252         return tree;
 253     }
 254 
 255     public JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond) {
 256         JCDoWhileLoop tree = new JCDoWhileLoop(body, cond);
 257         tree.pos = pos;
 258         return tree;
 259     }
 260 
 261     public JCWhileLoop WhileLoop(JCExpression cond, JCStatement body) {
 262         JCWhileLoop tree = new JCWhileLoop(cond, body);
 263         tree.pos = pos;
 264         return tree;
 265     }
 266 






 267     public JCForLoop ForLoop(List<JCStatement> init,
 268                            JCExpression cond,
 269                            List<JCExpressionStatement> step,
 270                            JCStatement body)
 271     {
 272         JCForLoop tree = new JCForLoop(init, cond, step, body);
 273         tree.pos = pos;
 274         return tree;
 275     }
 276 
 277     public JCEnhancedForLoop ForeachLoop(JCTree varOrRecordPattern, JCExpression expr, JCStatement body) {
 278         JCEnhancedForLoop tree = new JCEnhancedForLoop(varOrRecordPattern, expr, body);
 279         tree.pos = pos;
 280         return tree;
 281     }
 282 
 283     public JCLabeledStatement Labelled(Name label, JCStatement body) {
 284         JCLabeledStatement tree = new JCLabeledStatement(label, body);
 285         tree.pos = pos;
 286         return tree;
 287     }
 288 
 289     public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
 290         JCSwitch tree = new JCSwitch(selector, cases);
 291         tree.pos = pos;
 292         return tree;
 293     }
 294 
 295     public JCCase Case(CaseTree.CaseKind caseKind, List<JCCaseLabel> labels,
 296                        List<JCStatement> stats, JCTree body) {
 297         JCCase tree = new JCCase(caseKind, labels, stats, body);
 298         tree.pos = pos;
 299         return tree;
 300     }
 301 






 302     public JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases) {
 303         JCSwitchExpression tree = new JCSwitchExpression(selector, cases);
 304         tree.pos = pos;
 305         return tree;
 306     }
 307 
 308     public JCSynchronized Synchronized(JCExpression lock, JCBlock body) {
 309         JCSynchronized tree = new JCSynchronized(lock, body);
 310         tree.pos = pos;
 311         return tree;
 312     }
 313 
 314     public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
 315         return Try(List.nil(), body, catchers, finalizer);
 316     }
 317 
 318     public JCTry Try(List<JCTree> resources,
 319                      JCBlock body,
 320                      List<JCCatch> catchers,
 321                      JCBlock finalizer) {

 835             switch (t.getKind()) {
 836             case UNION: {
 837                 UnionClassType tu = (UnionClassType)t;
 838                 ListBuffer<JCExpression> la = new ListBuffer<>();
 839                 for (Type ta : tu.getAlternativeTypes()) {
 840                     la.add(Type(ta));
 841                 }
 842                 tp = TypeUnion(la.toList());
 843                 break;
 844             }
 845             case INTERSECTION: {
 846                 IntersectionClassType it = (IntersectionClassType)t;
 847                 ListBuffer<JCExpression> la = new ListBuffer<>();
 848                 for (Type ta : it.getExplicitComponents()) {
 849                     la.add(Type(ta));
 850                 }
 851                 tp = TypeIntersection(la.toList());
 852                 break;
 853             }
 854             default: {
 855                 Type outer = t.getEnclosingType();
 856                 JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP
 857                         ? Select(Type(outer), t.tsym)
 858                         : QualIdent(t.tsym);
 859                 tp = t.getTypeArguments().isEmpty()
 860                         ? clazz
 861                         : TypeApply(clazz, Types(t.getTypeArguments()));















 862                 break;
 863             }
 864             }
 865             break;
 866         case ARRAY:
 867             tp = TypeArray(Type(types.elemtype(t)));
 868             break;
 869         case ERROR:
 870             tp = TypeIdent(ERROR);
 871             break;
 872         default:
 873             throw new AssertionError("unexpected type: " + t);
 874         }
 875         return tp.setType(t);
 876     }
 877 
 878     /** Create a list of trees representing given list of types.
 879      */
 880     public List<JCExpression> Types(List<Type> ts) {
 881         ListBuffer<JCExpression> lb = new ListBuffer<>();

 247     }
 248 
 249     public JCBlock Block(long flags, List<JCStatement> stats) {
 250         JCBlock tree = new JCBlock(flags, stats);
 251         tree.pos = pos;
 252         return tree;
 253     }
 254 
 255     public JCDoWhileLoop DoLoop(JCStatement body, JCExpression cond) {
 256         JCDoWhileLoop tree = new JCDoWhileLoop(body, cond);
 257         tree.pos = pos;
 258         return tree;
 259     }
 260 
 261     public JCWhileLoop WhileLoop(JCExpression cond, JCStatement body) {
 262         JCWhileLoop tree = new JCWhileLoop(cond, body);
 263         tree.pos = pos;
 264         return tree;
 265     }
 266 
 267     public JCWithField WithField(JCExpression field, JCExpression value) {
 268         JCWithField tree = new JCWithField(field, value);
 269         tree.pos = pos;
 270         return tree;
 271     }
 272 
 273     public JCForLoop ForLoop(List<JCStatement> init,
 274                            JCExpression cond,
 275                            List<JCExpressionStatement> step,
 276                            JCStatement body)
 277     {
 278         JCForLoop tree = new JCForLoop(init, cond, step, body);
 279         tree.pos = pos;
 280         return tree;
 281     }
 282 
 283     public JCEnhancedForLoop ForeachLoop(JCTree varOrRecordPattern, JCExpression expr, JCStatement body) {
 284         JCEnhancedForLoop tree = new JCEnhancedForLoop(varOrRecordPattern, expr, body);
 285         tree.pos = pos;
 286         return tree;
 287     }
 288 
 289     public JCLabeledStatement Labelled(Name label, JCStatement body) {
 290         JCLabeledStatement tree = new JCLabeledStatement(label, body);
 291         tree.pos = pos;
 292         return tree;
 293     }
 294 
 295     public JCSwitch Switch(JCExpression selector, List<JCCase> cases) {
 296         JCSwitch tree = new JCSwitch(selector, cases);
 297         tree.pos = pos;
 298         return tree;
 299     }
 300 
 301     public JCCase Case(CaseTree.CaseKind caseKind, List<JCCaseLabel> labels,
 302                        List<JCStatement> stats, JCTree body) {
 303         JCCase tree = new JCCase(caseKind, labels, stats, body);
 304         tree.pos = pos;
 305         return tree;
 306     }
 307 
 308     public JCDefaultValue DefaultValue(JCExpression type) {
 309         JCDefaultValue tree = new JCDefaultValue(type);
 310         tree.pos = pos;
 311         return tree;
 312     }
 313 
 314     public JCSwitchExpression SwitchExpression(JCExpression selector, List<JCCase> cases) {
 315         JCSwitchExpression tree = new JCSwitchExpression(selector, cases);
 316         tree.pos = pos;
 317         return tree;
 318     }
 319 
 320     public JCSynchronized Synchronized(JCExpression lock, JCBlock body) {
 321         JCSynchronized tree = new JCSynchronized(lock, body);
 322         tree.pos = pos;
 323         return tree;
 324     }
 325 
 326     public JCTry Try(JCBlock body, List<JCCatch> catchers, JCBlock finalizer) {
 327         return Try(List.nil(), body, catchers, finalizer);
 328     }
 329 
 330     public JCTry Try(List<JCTree> resources,
 331                      JCBlock body,
 332                      List<JCCatch> catchers,
 333                      JCBlock finalizer) {

 847             switch (t.getKind()) {
 848             case UNION: {
 849                 UnionClassType tu = (UnionClassType)t;
 850                 ListBuffer<JCExpression> la = new ListBuffer<>();
 851                 for (Type ta : tu.getAlternativeTypes()) {
 852                     la.add(Type(ta));
 853                 }
 854                 tp = TypeUnion(la.toList());
 855                 break;
 856             }
 857             case INTERSECTION: {
 858                 IntersectionClassType it = (IntersectionClassType)t;
 859                 ListBuffer<JCExpression> la = new ListBuffer<>();
 860                 for (Type ta : it.getExplicitComponents()) {
 861                     la.add(Type(ta));
 862                 }
 863                 tp = TypeIntersection(la.toList());
 864                 break;
 865             }
 866             default: {
 867                 if (t.isReferenceProjection()) {
 868                     // For parameterized types, we want V.ref<A1 ... An> not V<A1 ... An>.ref
 869                     JCExpression vp = Type(t.valueProjection());
 870                     if (vp.hasTag(Tag.TYPEAPPLY)) {
 871                         // vp now is V<A1 ... An>, build V.ref<A1 ... An>
 872                         JCFieldAccess f = Select(((JCTypeApply) vp).clazz, t.tsym);
 873                         f.name = names.ref;
 874                         tp = TypeApply(f, ((JCTypeApply) vp).arguments);
 875                     } else {
 876                         JCFieldAccess f = Select(vp, t.tsym);
 877                         f.name = names.ref;
 878                         tp = f;
 879                     }
 880                 } else {
 881                     Type outer = t.getEnclosingType();
 882                     JCExpression clazz = outer.hasTag(CLASS) && t.tsym.owner.kind == TYP
 883                             ? Select(Type(outer), t.tsym)
 884                             : QualIdent(t.tsym);
 885                     tp = t.getTypeArguments().isEmpty()
 886                             ? clazz
 887                             : TypeApply(clazz, Types(t.getTypeArguments()));
 888                 }
 889                 break;
 890             }
 891             }
 892             break;
 893         case ARRAY:
 894             tp = TypeArray(Type(types.elemtype(t)));
 895             break;
 896         case ERROR:
 897             tp = TypeIdent(ERROR);
 898             break;
 899         default:
 900             throw new AssertionError("unexpected type: " + t);
 901         }
 902         return tp.setType(t);
 903     }
 904 
 905     /** Create a list of trees representing given list of types.
 906      */
 907     public List<JCExpression> Types(List<Type> ts) {
 908         ListBuffer<JCExpression> lb = new ListBuffer<>();
< prev index next >