| 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 25 matching lines...) Expand all Loading... |
| 36 if (element.isTopLevel()) { | 36 if (element.isTopLevel()) { |
| 37 return renameElement(element); | 37 return renameElement(element); |
| 38 } else if ( | 38 } else if ( |
| 39 (element.isGenerativeConstructor() || element.isFactoryConstructor()) | 39 (element.isGenerativeConstructor() || element.isFactoryConstructor()) |
| 40 && element.asFunctionElement().cachedNode.name is Send | 40 && element.asFunctionElement().cachedNode.name is Send |
| 41 // Don't want to rename redirects to :this(args). | 41 // Don't want to rename redirects to :this(args). |
| 42 && !Initializers.isConstructorRedirect(send) | 42 && !Initializers.isConstructorRedirect(send) |
| 43 // Don't want to rename super calls. | 43 // Don't want to rename super calls. |
| 44 && !Initializers.isSuperConstructorCall(send)) { | 44 && !Initializers.isSuperConstructorCall(send)) { |
| 45 FunctionExpression constructor = element.asFunctionElement().cachedNode; | 45 FunctionExpression constructor = element.asFunctionElement().cachedNode; |
| 46 return '${renameType(element.getEnclosingClass().type)}' | 46 TypeAnnotation typeAnnotation; |
| 47 '.${getFactoryName(constructor)}'; | 47 if (send.selector is TypeAnnotation) { |
| 48 // <simple class name>.<name> case. |
| 49 typeAnnotation = send.selector; |
| 50 } else if (send.selector.receiver is TypeAnnotation) { |
| 51 // <complex generic type>.<name> case. |
| 52 typeAnnotation = send.selector.receiver; |
| 53 compiler.cancel( |
| 54 reason: "Don't know how to deduce type ${send.toDebugString()}", |
| 55 element: element, |
| 56 node: send); |
| 57 } else { |
| 58 compiler.cancel( |
| 59 reason: "Don't know how to deduce type", |
| 60 element: element, |
| 61 node: send); |
| 62 } |
| 63 final type = new Unparser(this).unparse(typeAnnotation); |
| 64 return '$type.${getFactoryName(constructor)}'; |
| 48 } else { | 65 } else { |
| 49 return null; | 66 return null; |
| 50 } | 67 } |
| 51 } | 68 } |
| 52 | 69 |
| 53 String renameTypeName(TypeAnnotation typeAnnotation) { | 70 String renameTypeName(TypeAnnotation typeAnnotation) { |
| 54 Type type; | 71 Type type; |
| 55 if (context.isClass()) { | 72 if (context.isClass()) { |
| 56 // This only happens if we're unparsing class declaration. | 73 // This only happens if we're unparsing class declaration. |
| 57 type = new TypeResolver(compiler) | 74 type = new TypeResolver(compiler) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 final library = element.getLibrary(); | 117 final library = element.getLibrary(); |
| 101 if (library === compiler.coreLibrary) return originalName; | 118 if (library === compiler.coreLibrary) return originalName; |
| 102 if (isDartCoreLib(compiler, library)) { | 119 if (isDartCoreLib(compiler, library)) { |
| 103 final prefix = | 120 final prefix = |
| 104 imports.putIfAbsent(library, () => generateUniqueName('p')); | 121 imports.putIfAbsent(library, () => generateUniqueName('p')); |
| 105 return '$prefix.$originalName'; | 122 return '$prefix.$originalName'; |
| 106 } | 123 } |
| 107 return renamed[element] = generateUniqueName(originalName); | 124 return renamed[element] = generateUniqueName(originalName); |
| 108 } | 125 } |
| 109 } | 126 } |
| OLD | NEW |