| 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 LocalPlaceholder implements Hashable { | 5 class LocalPlaceholder implements Hashable { |
| 6 final String identifier; | 6 final String identifier; |
| 7 final Set<Node> nodes; | 7 final Set<Node> nodes; |
| 8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); | 8 LocalPlaceholder(this.identifier) : nodes = new Set<Node>(); |
| 9 int hashCode() => identifier.hashCode(); | 9 int hashCode() => identifier.hashCode(); |
| 10 String toString() => | 10 String toString() => |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 Element currentElement; | 98 Element currentElement; |
| 99 TreeElements treeElements; | 99 TreeElements treeElements; |
| 100 | 100 |
| 101 PlaceholderCollector(this.compiler) : | 101 PlaceholderCollector(this.compiler) : |
| 102 nullNodes = new Set<Node>(), | 102 nullNodes = new Set<Node>(), |
| 103 unresolvedNodes = new Set<Identifier>(), | 103 unresolvedNodes = new Set<Identifier>(), |
| 104 elementNodes = new Map<Element, Set<Node>>(), | 104 elementNodes = new Map<Element, Set<Node>>(), |
| 105 localPlaceholders = new Map<FunctionElement, Set<LocalPlaceholder>>(), | 105 localPlaceholders = new Map<FunctionElement, Set<LocalPlaceholder>>(), |
| 106 privateNodes = new Map<LibraryElement, Set<Identifier>>(); | 106 privateNodes = new Map<LibraryElement, Set<Identifier>>(); |
| 107 | 107 |
| 108 void tryMakeConstructorNamePlaceholder( |
| 109 FunctionExpression constructor, ClassElement element) { |
| 110 Node nameNode = constructor.name; |
| 111 if (nameNode is Send) nameNode = nameNode.receiver; |
| 112 if (nameNode.asIdentifier().token.slowToString() |
| 113 == element.name.slowToString()) { |
| 114 makeElementPlaceholder(nameNode, element); |
| 115 } |
| 116 } |
| 117 |
| 108 void collectFunctionDeclarationPlaceholders( | 118 void collectFunctionDeclarationPlaceholders( |
| 109 FunctionElement element, FunctionExpression node) { | 119 FunctionElement element, FunctionExpression node) { |
| 110 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { | 120 if (element.isGenerativeConstructor() || element.isFactoryConstructor()) { |
| 111 // Two complicated cases for class/interface renaming: | 121 // Two complicated cases for class/interface renaming: |
| 112 // 1) class which implements constructors of other interfaces, but not | 122 // 1) class which implements constructors of other interfaces, but not |
| 113 // implements interfaces themselves: | 123 // implements interfaces themselves: |
| 114 // 0.dart: class C { I(); } | 124 // 0.dart: class C { I(); } |
| 115 // 1.dart and 2.dart: interface I default C { I(); } | 125 // 1.dart and 2.dart: interface I default C { I(); } |
| 116 // now we have to duplicate our I() constructor in C class with | 126 // now we have to duplicate our I() constructor in C class with |
| 117 // proper names. | 127 // proper names. |
| 118 // 2) (even worse for us): | 128 // 2) (even worse for us): |
| 119 // 0.dart: class C { C(); } | 129 // 0.dart: class C { C(); } |
| 120 // 1.dart: interface C default p0.C { C(); } | 130 // 1.dart: interface C default p0.C { C(); } |
| 121 // the second case is just a bug now. | 131 // the second case is just a bug now. |
| 122 final enclosingClass = element.getEnclosingClass(); | 132 tryMakeConstructorNamePlaceholder(node, element.getEnclosingClass()); |
| 123 Node nameNode = node.name; | 133 |
| 124 if (nameNode is Send) nameNode = nameNode.receiver; | 134 // If we have interface constructor, make sure that we put placeholder |
| 125 // For cases like class C implements I { I(); } | 135 // for its default factory implementation. |
| 126 if (nameNode.asIdentifier().token.slowToString() | 136 // Example: |
| 127 == enclosingClass.name.slowToString()) { | 137 // interface I default C { I();} |
| 128 makeTypePlaceholder(nameNode, enclosingClass.type); | 138 // class C { factory I() {} } |
| 139 // 2 cases: |
| 140 // Plain interface name. Rename it unless it is the default |
| 141 // constructor for enclosing class. |
| 142 // Example: |
| 143 // interface I { I(); } |
| 144 // class C implements I { C(); } don't rename this case. |
| 145 // OR I.named() inside C, rename first part. |
| 146 if (element.defaultImplementation !== null |
| 147 && element.defaultImplementation !== element) { |
| 148 FunctionElement implementingFactory = element.defaultImplementation; |
| 149 tryMakeConstructorNamePlaceholder(implementingFactory.cachedNode, |
| 150 element.getEnclosingClass()); |
| 129 } | 151 } |
| 152 |
| 130 // Process Ctor(this._field) correctly. | 153 // Process Ctor(this._field) correctly. |
| 131 for (Node parameter in node.parameters) { | 154 for (Node parameter in node.parameters) { |
| 132 VariableDefinitions definitions = parameter.asVariableDefinitions(); | 155 VariableDefinitions definitions = parameter.asVariableDefinitions(); |
| 133 if (definitions !== null) { | 156 if (definitions !== null) { |
| 134 for (Node definition in definitions.definitions) { | 157 for (Node definition in definitions.definitions) { |
| 135 Send send = definition.asSend(); | 158 Send send = definition.asSend(); |
| 136 if (send !== null) { | 159 if (send !== null) { |
| 137 assert(send.receiver is Identifier); | 160 assert(send.receiver is Identifier); |
| 138 assert(send.receiver.asIdentifier().isThis()); | 161 assert(send.receiver.asIdentifier().isThis()); |
| 139 if (send.selector is Identifier) { | 162 if (send.selector is Identifier) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 visit(node.defaultClause.typeArguments); | 446 visit(node.defaultClause.typeArguments); |
| 424 } | 447 } |
| 425 } | 448 } |
| 426 | 449 |
| 427 visitTypedef(Typedef node) { | 450 visitTypedef(Typedef node) { |
| 428 assert(currentElement is TypedefElement); | 451 assert(currentElement is TypedefElement); |
| 429 makeElementPlaceholder(node.name, currentElement); | 452 makeElementPlaceholder(node.name, currentElement); |
| 430 node.visitChildren(this); | 453 node.visitChildren(this); |
| 431 } | 454 } |
| 432 } | 455 } |
| OLD | NEW |