< prev index next >

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

Print this page

 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.asValueType());
 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 if (t.isValueProjection()) {
 868                     // For parameterized types, we want V.val<A1 ... An> not V<A1 ... An>.val
 869                     JCExpression vp = Type(t.referenceProjection());
 870                     if (vp.hasTag(Tag.TYPEAPPLY)) {
 871                         // vp now is V<A1 ... An>, build V.val<A1 ... An>
 872                         JCFieldAccess f = (JCFieldAccess) Select(((JCTypeApply) vp).clazz, t.tsym);
 873                         f.name = names.val;
 874                         tp = TypeApply(f, ((JCTypeApply) vp).arguments);
 875                     } else {
 876                         JCFieldAccess f = (JCFieldAccess) Select(vp, t.tsym);
 877                         f.name = names.val;
 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 >