OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
7 */ | 7 */ |
8 class Namer { | 8 class Namer { |
9 final Compiler compiler; | 9 final Compiler compiler; |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 LibraryElement lib = element.getLibrary(); | 113 LibraryElement lib = element.getLibrary(); |
114 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 114 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
115 ConstructorBodyElement bodyElement = element; | 115 ConstructorBodyElement bodyElement = element; |
116 name = bodyElement.constructor.name; | 116 name = bodyElement.constructor.name; |
117 } | 117 } |
118 FunctionSignature signature = element.computeSignature(compiler); | 118 FunctionSignature signature = element.computeSignature(compiler); |
119 String methodName = | 119 String methodName = |
120 '${privateName(lib, name)}\$${signature.parameterCount}'; | 120 '${privateName(lib, name)}\$${signature.parameterCount}'; |
121 if (!signature.optionalParametersAreNamed) { | 121 if (!signature.optionalParametersAreNamed) { |
122 return methodName; | 122 return methodName; |
123 } else if (!signature.optionalParameters.isEmpty()) { | 123 } else if (!signature.optionalParameters.isEmpty) { |
124 StringBuffer buffer = new StringBuffer(); | 124 StringBuffer buffer = new StringBuffer(); |
125 signature.orderedOptionalParameters.forEach((Element element) { | 125 signature.orderedOptionalParameters.forEach((Element element) { |
126 buffer.add('\$${JsNames.getValid(element.name.slowToString())}'); | 126 buffer.add('\$${JsNames.getValid(element.name.slowToString())}'); |
127 }); | 127 }); |
128 return '$methodName$buffer'; | 128 return '$methodName$buffer'; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 String publicInstanceMethodNameByArity(SourceString name, int arity) { | 132 String publicInstanceMethodNameByArity(SourceString name, int arity) { |
133 assert(!name.isPrivate()); | 133 assert(!name.isPrivate()); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 } | 322 } |
323 | 323 |
324 String safeName(String name) { | 324 String safeName(String name) { |
325 if (jsReserved.contains(name) || name.startsWith('\$')) { | 325 if (jsReserved.contains(name) || name.startsWith('\$')) { |
326 name = "\$$name"; | 326 name = "\$$name"; |
327 assert(!jsReserved.contains(name)); | 327 assert(!jsReserved.contains(name)); |
328 } | 328 } |
329 return name; | 329 return name; |
330 } | 330 } |
331 } | 331 } |
OLD | NEW |