< 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) {

 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<>();

 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) {

 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 = (JCFieldAccess) Select(((JCTypeApply) vp).clazz, t.tsym);
 873                         f.name = names.ref;
 874                         tp = TypeApply(f, ((JCTypeApply) vp).arguments);
 875                     } else {
 876                         JCFieldAccess f = (JCFieldAccess) 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 >