Chromium Code Reviews| 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 /** | 5 /** |
| 6 * Renames only top-level elements that would let to ambiguity if not renamed. | 6 * Renames only top-level elements that would let to ambiguity if not renamed. |
| 7 * TODO(smok): Make sure that top-level fields are correctly renamed. | 7 * TODO(smok): Make sure that top-level fields are correctly renamed. |
| 8 */ | 8 */ |
| 9 class ConflictingRenamer extends Renamer { | 9 class ConflictingRenamer extends Renamer { |
| 10 final Compiler compiler; | 10 final Compiler compiler; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 imports = new Map<LibraryElement, String>(); | 23 imports = new Map<LibraryElement, String>(); |
| 24 | 24 |
| 25 void setContext(Element element) { | 25 void setContext(Element element) { |
| 26 this.context = element; | 26 this.context = element; |
| 27 contextElements = resolvedElements[element]; | 27 contextElements = resolvedElements[element]; |
| 28 } | 28 } |
| 29 | 29 |
| 30 String getFactoryName(FunctionExpression node) => | 30 String getFactoryName(FunctionExpression node) => |
| 31 node.name.asSend().selector.asIdentifier().source.slowToString(); | 31 node.name.asSend().selector.asIdentifier().source.slowToString(); |
| 32 | 32 |
| 33 bool isNamedConstructor(Element element) => | |
| 34 element.isGenerativeConstructor() | |
| 35 && element.asFunctionElement().cachedNode.name is Send; | |
| 36 | |
| 37 String renameSendMethod(Send send) { | 33 String renameSendMethod(Send send) { |
| 38 if (contextElements[send] === null) return null; | 34 if (contextElements[send] === null) return null; |
| 39 Element element = contextElements[send]; | 35 Element element = contextElements[send]; |
| 40 if (element.isTopLevel()) { | 36 if (element.isTopLevel()) { |
| 41 return renameElement(element); | 37 return renameElement(element); |
| 42 } else if (isNamedConstructor(element) | 38 } else if ((element.isGenerativeConstructor() || element.isFactoryConstructo r()) |
|
Roman
2012/07/31 14:28:39
>80 chars
Anton Muhin
2012/07/31 15:05:04
Done.
| |
| 39 && element.asFunctionElement().cachedNode.name is Send | |
| 43 // Don't want to rename redirects to :this(args). | 40 // Don't want to rename redirects to :this(args). |
| 44 && !Initializers.isConstructorRedirect(send) | 41 && !Initializers.isConstructorRedirect(send) |
| 45 // Don't want to rename super calls. | 42 // Don't want to rename super calls. |
| 46 && !Initializers.isSuperConstructorCall(send)) { | 43 && !Initializers.isSuperConstructorCall(send)) { |
| 47 FunctionExpression constructor = element.asFunctionElement().cachedNode; | 44 FunctionExpression constructor = element.asFunctionElement().cachedNode; |
| 48 return '${renameType(element.getEnclosingClass().type)}' | 45 return '${renameType(element.getEnclosingClass().type)}' |
| 49 '.${getFactoryName(constructor)}'; | 46 '.${getFactoryName(constructor)}'; |
| 50 } else { | 47 } else { |
| 51 return null; | 48 return null; |
| 52 } | 49 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 final library = element.getLibrary(); | 99 final library = element.getLibrary(); |
| 103 if (library === compiler.coreLibrary) return originalName; | 100 if (library === compiler.coreLibrary) return originalName; |
| 104 if (isDartCoreLib(compiler, library)) { | 101 if (isDartCoreLib(compiler, library)) { |
| 105 final prefix = | 102 final prefix = |
| 106 imports.putIfAbsent(library, () => generateUniqueName('p')); | 103 imports.putIfAbsent(library, () => generateUniqueName('p')); |
| 107 return '$prefix.$originalName'; | 104 return '$prefix.$originalName'; |
| 108 } | 105 } |
| 109 return renamed[element] = generateUniqueName(originalName); | 106 return renamed[element] = generateUniqueName(originalName); |
| 110 } | 107 } |
| 111 } | 108 } |
| OLD | NEW |