120 * @param defs a list of ClassDef, Import, and Skip |
120 * @param defs a list of ClassDef, Import, and Skip |
121 */ |
121 */ |
122 public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, |
122 public JCCompilationUnit TopLevel(List<JCAnnotation> packageAnnotations, |
123 JCExpression pid, |
123 JCExpression pid, |
124 List<JCTree> defs) { |
124 List<JCTree> defs) { |
125 assert packageAnnotations != null; |
125 Assert.checkNonNull(packageAnnotations); |
126 for (JCTree node : defs) |
126 for (JCTree node : defs) |
127 assert node instanceof JCClassDecl |
127 Assert.check(node instanceof JCClassDecl |
128 || node instanceof JCImport |
128 || node instanceof JCImport |
129 || node instanceof JCSkip |
129 || node instanceof JCSkip |
130 || node instanceof JCErroneous |
130 || node instanceof JCErroneous |
131 || (node instanceof JCExpressionStatement |
131 || (node instanceof JCExpressionStatement |
132 && ((JCExpressionStatement)node).expr instanceof JCErroneous) |
132 && ((JCExpressionStatement)node).expr instanceof JCErroneous), |
133 : node.getClass().getSimpleName(); |
133 node.getClass().getSimpleName()); |
134 JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs, |
134 JCCompilationUnit tree = new JCCompilationUnit(packageAnnotations, pid, defs, |
135 null, null, null, null); |
135 null, null, null, null); |
136 tree.pos = pos; |
136 tree.pos = pos; |
137 return tree; |
137 return tree; |
138 } |
138 } |
645 default: |
645 default: |
646 throw new AssertionError("unexpected type: " + t); |
646 throw new AssertionError("unexpected type: " + t); |
647 } |
647 } |
648 return tp.setType(t); |
648 return tp.setType(t); |
649 } |
649 } |
650 //where |
|
651 private JCExpression Selectors(JCExpression base, Symbol sym, Symbol limit) { |
|
652 if (sym == limit) return base; |
|
653 else return Select(Selectors(base, sym.owner, limit), sym); |
|
654 } |
|
655 |
650 |
656 /** Create a list of trees representing given list of types. |
651 /** Create a list of trees representing given list of types. |
657 */ |
652 */ |
658 public List<JCExpression> Types(List<Type> ts) { |
653 public List<JCExpression> Types(List<Type> ts) { |
659 ListBuffer<JCExpression> types = new ListBuffer<JCExpression>(); |
654 ListBuffer<JCExpression> lb = new ListBuffer<JCExpression>(); |
660 for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
655 for (List<Type> l = ts; l.nonEmpty(); l = l.tail) |
661 types.append(Type(l.head)); |
656 lb.append(Type(l.head)); |
662 return types.toList(); |
657 return lb.toList(); |
663 } |
658 } |
664 |
659 |
665 /** Create a variable definition from a variable symbol and an initializer |
660 /** Create a variable definition from a variable symbol and an initializer |
666 * expression. |
661 * expression. |
667 */ |
662 */ |