OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 class Unparser implements Visitor { | 5 class Unparser implements Visitor { |
6 StringBuffer sb; | 6 StringBuffer sb; |
7 | 7 |
8 Unparser(); | 8 Unparser(); |
9 | 9 |
10 String unparse(Node node) { | 10 String unparse(Node node) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 visit(node.update); | 75 visit(node.update); |
76 sb.add(')'); | 76 sb.add(')'); |
77 visit(node.body); | 77 visit(node.body); |
78 } | 78 } |
79 | 79 |
80 visitFunctionDeclaration(FunctionDeclaration node) { | 80 visitFunctionDeclaration(FunctionDeclaration node) { |
81 visit(node.function); | 81 visit(node.function); |
82 } | 82 } |
83 | 83 |
84 visitFunctionExpression(FunctionExpression node) { | 84 visitFunctionExpression(FunctionExpression node) { |
85 // Check length to not print unnecessary whitespace. | |
86 if (node.modifiers !== null && node.modifiers.nodes.length() > 0) { | |
Anton Muhin
2012/07/13 07:07:21
are both cases possible, both null and empty list?
Roman
2012/07/13 08:14:57
I added null check after I got "noSuchMethod" erro
Anton Muhin
2012/07/13 08:15:47
Thanks a lot for explanations, Roma.
On 2012/07/1
| |
87 visit(node.modifiers); | |
88 sb.add(' '); | |
89 } | |
85 if (node.returnType !== null) { | 90 if (node.returnType !== null) { |
86 visit(node.returnType); | 91 visit(node.returnType); |
87 sb.add(' '); | 92 sb.add(' '); |
88 } | 93 } |
89 if (node.getOrSet !== null) { | 94 if (node.getOrSet !== null) { |
90 add(node.getOrSet.value); | 95 add(node.getOrSet.value); |
91 sb.add(' '); | 96 sb.add(' '); |
92 } | 97 } |
93 // TODO(antonm): that's a workaround as currently FunctionExpression | 98 // TODO(antonm): that's a workaround as currently FunctionExpression |
94 // names are modelled with Send and it emits operator[] as only | 99 // names are modelled with Send and it emits operator[] as only |
95 // operator, without [] which are expected to be emitted with | 100 // operator, without [] which are expected to be emitted with |
96 // arguments. | 101 // arguments. |
97 if (node.name is Send) { | 102 if (node.name is Send) { |
98 Send send = node.name; | 103 Send send = node.name; |
99 assert(send is !SendSet); | 104 assert(send is !SendSet); |
100 visit(send.receiver); | 105 visit(send.receiver); |
106 if (!send.isOperator) { | |
107 // Looks like a factory method. | |
108 sb.add('.'); | |
109 } | |
101 visit(send.selector); | 110 visit(send.selector); |
102 } else { | 111 } else { |
103 visit(node.name); | 112 visit(node.name); |
104 } | 113 } |
105 visit(node.parameters); | 114 visit(node.parameters); |
115 visit(node.initializers); | |
106 visit(node.body); | 116 visit(node.body); |
107 } | 117 } |
108 | 118 |
109 visitIdentifier(Identifier node) { | 119 visitIdentifier(Identifier node) { |
110 add(node.token.value); | 120 add(node.token.value); |
111 } | 121 } |
112 | 122 |
113 visitIf(If node) { | 123 visitIf(If node) { |
114 add(node.ifToken.value); | 124 add(node.ifToken.value); |
115 visit(node.condition); | 125 visit(node.condition); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 sb.add(' '); | 472 sb.add(' '); |
463 } | 473 } |
464 visit(node.name); | 474 visit(node.name); |
465 if (node.typeParameters !== null) { | 475 if (node.typeParameters !== null) { |
466 visit(node.typeParameters); | 476 visit(node.typeParameters); |
467 } | 477 } |
468 visit(node.formals); | 478 visit(node.formals); |
469 add(node.endToken.value); | 479 add(node.endToken.value); |
470 } | 480 } |
471 } | 481 } |
OLD | NEW |