mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
Fix factory constructors unparse:
class A{ A.fromFoo(); } => class A{ AfromFoo(); } and also print out initializers. Review URL: https://chromiumcodereview.appspot.com//10692186 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9623 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
e9b7aaeba3
commit
6cb768b4a2
3 changed files with 21 additions and 1 deletions
|
@ -18,7 +18,8 @@ class Emitter {
|
|||
void outputClass(ClassElement classElement, Set<Element> innerElements) {
|
||||
// TODO(smok): Very soon properly print out correct class declaration with
|
||||
// extends, implements, etc.
|
||||
sb.add('class ');
|
||||
sb.add(classElement.beginToken.slowToString()); // 'class' or 'interface'.
|
||||
sb.add(' ');
|
||||
sb.add(classElement.name.slowToString());
|
||||
sb.add('{');
|
||||
innerElements.forEach((element) {
|
||||
|
|
|
@ -82,6 +82,11 @@ class Unparser implements Visitor {
|
|||
}
|
||||
|
||||
visitFunctionExpression(FunctionExpression node) {
|
||||
// Check length to not print unnecessary whitespace.
|
||||
if (node.modifiers !== null && node.modifiers.nodes.length() > 0) {
|
||||
visit(node.modifiers);
|
||||
sb.add(' ');
|
||||
}
|
||||
if (node.returnType !== null) {
|
||||
visit(node.returnType);
|
||||
sb.add(' ');
|
||||
|
@ -98,11 +103,16 @@ class Unparser implements Visitor {
|
|||
Send send = node.name;
|
||||
assert(send is !SendSet);
|
||||
visit(send.receiver);
|
||||
if (!send.isOperator) {
|
||||
// Looks like a factory method.
|
||||
sb.add('.');
|
||||
}
|
||||
visit(send.selector);
|
||||
} else {
|
||||
visit(node.name);
|
||||
}
|
||||
visit(node.parameters);
|
||||
visit(node.initializers);
|
||||
visit(node.body);
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ testClosure() {
|
|||
|
||||
testIndexedOperatorDecl() {
|
||||
testUnparseMember('operator[](int i)=> null;');
|
||||
testUnparseMember('operator[]=(int i, int j)=> null;');
|
||||
}
|
||||
|
||||
testNativeMethods() {
|
||||
|
@ -161,6 +162,13 @@ testGetSet() {
|
|||
testDart2Dart('String get foo(){return "a";}main(){foo;}');
|
||||
}
|
||||
|
||||
testFactoryConstructor() {
|
||||
testDart2Dart('main(){new A.fromFoo();}class A{A.fromFoo();}');
|
||||
// Now more complicated, with normal constructor and factory parameters.
|
||||
testDart2Dart('main(){new A.fromFoo(5);}'
|
||||
'class A{A(this.f);A.fromFoo(foo):this("f");final String f;}');
|
||||
}
|
||||
|
||||
main() {
|
||||
testGenericTypes();
|
||||
testForLoop();
|
||||
|
@ -177,5 +185,6 @@ main() {
|
|||
testClassWithMethod();
|
||||
testVariableDefinitions();
|
||||
testGetSet();
|
||||
testFactoryConstructor();
|
||||
testTopLevelField();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue