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 ElementAst { | 5 class ElementAst { |
6 final Node ast; | 6 final Node ast; |
7 final TreeElements treeElements; | 7 final TreeElements treeElements; |
8 | 8 |
9 ElementAst(this.ast, this.treeElements); | 9 ElementAst(this.ast, this.treeElements); |
10 | 10 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 return true; | 78 return true; |
79 } | 79 } |
80 } | 80 } |
81 } | 81 } |
82 return false; | 82 return false; |
83 } | 83 } |
84 | 84 |
85 rewiteStatement(Statement statement) { | 85 rewiteStatement(Statement statement) { |
86 if (statement is Block) { | 86 if (statement is Block) { |
87 Link statements = statement.statements.nodes; | 87 Link statements = statement.statements.nodes; |
88 if (!statements.isEmpty() && statements.tail.isEmpty()) { | 88 if (!statements.isEmpty && statements.tail.isEmpty) { |
89 Statement single = statements.head; | 89 Statement single = statements.head; |
90 bool isDeclaration = | 90 bool isDeclaration = |
91 single is VariableDefinitions || single is FunctionDeclaration; | 91 single is VariableDefinitions || single is FunctionDeclaration; |
92 if (!isDeclaration) return single; | 92 if (!isDeclaration) return single; |
93 } | 93 } |
94 } | 94 } |
95 return statement; | 95 return statement; |
96 } | 96 } |
97 | 97 |
98 NodeList statements = block.statements; | 98 NodeList statements = block.statements; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 147 } |
148 if (typeArgument == null) continue; | 148 if (typeArgument == null) continue; |
149 assert(typeArgument is TypeAnnotation); | 149 assert(typeArgument is TypeAnnotation); |
150 DartType argumentType = | 150 DartType argumentType = |
151 compiler.resolveTypeAnnotation(classElement, typeArgument); | 151 compiler.resolveTypeAnnotation(classElement, typeArgument); |
152 assert(argumentType != null); | 152 assert(argumentType != null); |
153 workQueue.add(argumentType); | 153 workQueue.add(argumentType); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 while (!workQueue.isEmpty()) { | 157 while (!workQueue.isEmpty) { |
158 DartType type = workQueue.removeLast(); | 158 DartType type = workQueue.removeLast(); |
159 if (processedTypes.contains(type)) continue; | 159 if (processedTypes.contains(type)) continue; |
160 processedTypes.add(type); | 160 processedTypes.add(type); |
161 if (type is TypedefType) return false; | 161 if (type is TypedefType) return false; |
162 if (type is InterfaceType) { | 162 if (type is InterfaceType) { |
163 ClassElement element = type.element; | 163 ClassElement element = type.element; |
164 ClassNode node = element.parseNode(compiler); | 164 ClassNode node = element.parseNode(compiler); |
165 // Check class type args. | 165 // Check class type args. |
166 processTypeArguments(element, node.typeParameters); | 166 processTypeArguments(element, node.typeParameters); |
167 // Check superclass type args. | 167 // Check superclass type args. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // but which originally had any constructor. That should prevent | 336 // but which originally had any constructor. That should prevent |
337 // those classes from being instantiable with default constructor. | 337 // those classes from being instantiable with default constructor. |
338 Identifier synthesizedIdentifier = | 338 Identifier synthesizedIdentifier = |
339 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); | 339 new Identifier(new StringToken(IDENTIFIER_INFO, '', -1)); |
340 | 340 |
341 NextClassElement: | 341 NextClassElement: |
342 for (ClassElement classElement in classMembers.getKeys()) { | 342 for (ClassElement classElement in classMembers.getKeys()) { |
343 for (Element member in classMembers[classElement]) { | 343 for (Element member in classMembers[classElement]) { |
344 if (member.isConstructor()) continue NextClassElement; | 344 if (member.isConstructor()) continue NextClassElement; |
345 } | 345 } |
346 if (classElement.constructors.isEmpty()) continue NextClassElement; | 346 if (classElement.constructors.isEmpty) continue NextClassElement; |
347 | 347 |
348 // TODO(antonm): check with AAR team if there is better approach. | 348 // TODO(antonm): check with AAR team if there is better approach. |
349 // As an idea: provide template as a Dart code---class C { C.name(); }--- | 349 // As an idea: provide template as a Dart code---class C { C.name(); }--- |
350 // and then overwrite necessary parts. | 350 // and then overwrite necessary parts. |
351 SynthesizedConstructorElement constructor = | 351 SynthesizedConstructorElement constructor = |
352 new SynthesizedConstructorElement(classElement); | 352 new SynthesizedConstructorElement(classElement); |
353 constructor.type = new FunctionType( | 353 constructor.type = new FunctionType( |
354 compiler.types.voidType, const Link<DartType>(), | 354 compiler.types.voidType, const Link<DartType>(), |
355 constructor); | 355 constructor); |
356 constructor.cachedNode = new FunctionExpression( | 356 constructor.cachedNode = new FunctionExpression( |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 } | 536 } |
537 | 537 |
538 compareElements(e0, e1) { | 538 compareElements(e0, e1) { |
539 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); | 539 int result = compareBy((e) => e.getLibrary().uri.toString())(e0, e1); |
540 if (result != 0) return result; | 540 if (result != 0) return result; |
541 return compareBy((e) => e.position().charOffset)(e0, e1); | 541 return compareBy((e) => e.position().charOffset)(e0, e1); |
542 } | 542 } |
543 | 543 |
544 List<Element> sortElements(Collection<Element> elements) => | 544 List<Element> sortElements(Collection<Element> elements) => |
545 sorted(elements, compareElements); | 545 sorted(elements, compareElements); |
OLD | NEW |