| 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 library mirrors_dart2js; | 5 library mirrors_dart2js; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection' show LinkedHashMap; | 8 import 'dart:collection' show LinkedHashMap; |
| 9 | 9 |
| 10 import '../../compiler.dart' as api; | 10 import '../../compiler.dart' as api; |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 } | 1300 } |
| 1301 | 1301 |
| 1302 //------------------------------------------------------------------------------ | 1302 //------------------------------------------------------------------------------ |
| 1303 // Member mirrors implementation. | 1303 // Member mirrors implementation. |
| 1304 //------------------------------------------------------------------------------ | 1304 //------------------------------------------------------------------------------ |
| 1305 | 1305 |
| 1306 class Dart2JsMethodMirror extends Dart2JsMemberMirror | 1306 class Dart2JsMethodMirror extends Dart2JsMemberMirror |
| 1307 implements MethodMirror { | 1307 implements MethodMirror { |
| 1308 final Dart2JsContainerMirror _objectMirror; | 1308 final Dart2JsContainerMirror _objectMirror; |
| 1309 final String simpleName; | 1309 final String simpleName; |
| 1310 final String constructorName; | |
| 1311 final Dart2JsMethodKind _kind; | 1310 final Dart2JsMethodKind _kind; |
| 1312 | 1311 |
| 1313 Dart2JsMethodMirror._internal(Dart2JsContainerMirror objectMirror, | 1312 Dart2JsMethodMirror._internal(Dart2JsContainerMirror objectMirror, |
| 1314 FunctionElement function, | 1313 FunctionElement function, |
| 1315 String this.simpleName, | 1314 String this.simpleName, |
| 1316 String this.constructorName, | |
| 1317 Dart2JsMethodKind this._kind) | 1315 Dart2JsMethodKind this._kind) |
| 1318 : this._objectMirror = objectMirror, | 1316 : this._objectMirror = objectMirror, |
| 1319 super(objectMirror.mirrors, function); | 1317 super(objectMirror.mirrors, function); |
| 1320 | 1318 |
| 1321 factory Dart2JsMethodMirror(Dart2JsContainerMirror objectMirror, | 1319 factory Dart2JsMethodMirror(Dart2JsContainerMirror objectMirror, |
| 1322 FunctionElement function) { | 1320 FunctionElement function) { |
| 1323 String realName = function.name.slowToString(); | 1321 String realName = function.name.slowToString(); |
| 1324 // TODO(ahe): This method should not be calling | 1322 // TODO(ahe): This method should not be calling |
| 1325 // Elements.operatorNameToIdentifier. | 1323 // Elements.operatorNameToIdentifier. |
| 1326 String simpleName = | 1324 String simpleName = |
| 1327 Elements.operatorNameToIdentifier(function.name).slowToString(); | 1325 Elements.operatorNameToIdentifier(function.name).slowToString(); |
| 1328 String constructorName = null; | |
| 1329 Dart2JsMethodKind kind; | 1326 Dart2JsMethodKind kind; |
| 1330 if (function.kind == ElementKind.GETTER) { | 1327 if (function.kind == ElementKind.GETTER) { |
| 1331 kind = Dart2JsMethodKind.GETTER; | 1328 kind = Dart2JsMethodKind.GETTER; |
| 1332 } else if (function.kind == ElementKind.SETTER) { | 1329 } else if (function.kind == ElementKind.SETTER) { |
| 1333 kind = Dart2JsMethodKind.SETTER; | 1330 kind = Dart2JsMethodKind.SETTER; |
| 1334 simpleName = '$simpleName='; | 1331 simpleName = '$simpleName='; |
| 1335 } else if (function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { | 1332 } else if (function.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 1336 // TODO(johnniwinther): Support detection of redirecting constructors. | 1333 // TODO(johnniwinther): Support detection of redirecting constructors. |
| 1337 constructorName = ''; | |
| 1338 int dollarPos = simpleName.indexOf('\$'); | |
| 1339 if (dollarPos != -1) { | |
| 1340 constructorName = simpleName.substring(dollarPos + 1); | |
| 1341 simpleName = simpleName.substring(0, dollarPos); | |
| 1342 // Simple name is TypeName.constructorName. | |
| 1343 simpleName = '$simpleName.$constructorName'; | |
| 1344 } else { | |
| 1345 // Simple name is TypeName. | |
| 1346 } | |
| 1347 if (function.modifiers.isConst()) { | 1334 if (function.modifiers.isConst()) { |
| 1348 kind = Dart2JsMethodKind.CONST; | 1335 kind = Dart2JsMethodKind.CONST; |
| 1349 } else { | 1336 } else { |
| 1350 kind = Dart2JsMethodKind.GENERATIVE; | 1337 kind = Dart2JsMethodKind.GENERATIVE; |
| 1351 } | 1338 } |
| 1352 } else if (function.modifiers.isFactory()) { | 1339 } else if (function.modifiers.isFactory()) { |
| 1353 kind = Dart2JsMethodKind.FACTORY; | 1340 kind = Dart2JsMethodKind.FACTORY; |
| 1354 constructorName = ''; | |
| 1355 int dollarPos = simpleName.indexOf('\$'); | |
| 1356 if (dollarPos != -1) { | |
| 1357 constructorName = simpleName.substring(dollarPos+1); | |
| 1358 simpleName = simpleName.substring(0, dollarPos); | |
| 1359 simpleName = '$simpleName.$constructorName'; | |
| 1360 } | |
| 1361 } else if (realName == 'unary-') { | 1341 } else if (realName == 'unary-') { |
| 1362 kind = Dart2JsMethodKind.OPERATOR; | 1342 kind = Dart2JsMethodKind.OPERATOR; |
| 1363 // Simple name is 'unary-'. | 1343 // Simple name is 'unary-'. |
| 1364 simpleName = Mirror.UNARY_MINUS; | 1344 simpleName = Mirror.UNARY_MINUS; |
| 1365 } else if (simpleName.startsWith('operator\$')) { | 1345 } else if (simpleName.startsWith('operator\$')) { |
| 1366 String str = simpleName.substring(9); | 1346 String str = simpleName.substring(9); |
| 1367 simpleName = 'operator'; | 1347 simpleName = 'operator'; |
| 1368 kind = Dart2JsMethodKind.OPERATOR; | 1348 kind = Dart2JsMethodKind.OPERATOR; |
| 1369 simpleName = _getOperatorFromOperatorName(str); | 1349 simpleName = _getOperatorFromOperatorName(str); |
| 1370 } else { | 1350 } else { |
| 1371 kind = Dart2JsMethodKind.REGULAR; | 1351 kind = Dart2JsMethodKind.REGULAR; |
| 1372 } | 1352 } |
| 1373 return new Dart2JsMethodMirror._internal(objectMirror, function, | 1353 return new Dart2JsMethodMirror._internal(objectMirror, function, |
| 1374 simpleName, constructorName, kind); | 1354 simpleName, kind); |
| 1375 } | 1355 } |
| 1376 | 1356 |
| 1377 FunctionElement get _function => _element; | 1357 FunctionElement get _function => _element; |
| 1378 | 1358 |
| 1379 String get qualifiedName | 1359 String get qualifiedName |
| 1380 => '${owner.qualifiedName}.$simpleName'; | 1360 => '${owner.qualifiedName}.$simpleName'; |
| 1381 | 1361 |
| 1382 DeclarationMirror get owner => _objectMirror; | 1362 DeclarationMirror get owner => _objectMirror; |
| 1383 | 1363 |
| 1384 bool get isTopLevel => _objectMirror is LibraryMirror; | 1364 bool get isTopLevel => _objectMirror is LibraryMirror; |
| 1385 | 1365 |
| 1386 bool get isConstructor | 1366 bool get isConstructor |
| 1387 => isGenerativeConstructor || isConstConstructor || | 1367 => isGenerativeConstructor || isConstConstructor || |
| 1388 isFactoryConstructor || isRedirectingConstructor; | 1368 isFactoryConstructor || isRedirectingConstructor; |
| 1389 | 1369 |
| 1390 bool get isMethod => !isConstructor; | 1370 bool get isMethod => !isConstructor; |
| 1391 | 1371 |
| 1392 bool get isPrivate => | |
| 1393 isConstructor ? _isPrivate(constructorName) : _isPrivate(simpleName); | |
| 1394 | |
| 1395 bool get isStatic => _function.modifiers.isStatic(); | 1372 bool get isStatic => _function.modifiers.isStatic(); |
| 1396 | 1373 |
| 1397 List<ParameterMirror> get parameters { | 1374 List<ParameterMirror> get parameters { |
| 1398 return _parametersFromFunctionSignature(mirrors, this, | 1375 return _parametersFromFunctionSignature(mirrors, this, |
| 1399 _function.computeSignature(mirrors.compiler)); | 1376 _function.computeSignature(mirrors.compiler)); |
| 1400 } | 1377 } |
| 1401 | 1378 |
| 1402 TypeMirror get returnType => _convertTypeToTypeMirror( | 1379 TypeMirror get returnType => _convertTypeToTypeMirror( |
| 1403 mirrors, _function.computeSignature(mirrors.compiler).returnType, | 1380 mirrors, _function.computeSignature(mirrors.compiler).returnType, |
| 1404 mirrors.compiler.types.dynamicType); | 1381 mirrors.compiler.types.dynamicType); |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1771 * | 1748 * |
| 1772 * All API in this class is experimental. | 1749 * All API in this class is experimental. |
| 1773 */ | 1750 */ |
| 1774 class BackDoor { | 1751 class BackDoor { |
| 1775 /// Return the compilation units comprising [library]. | 1752 /// Return the compilation units comprising [library]. |
| 1776 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { | 1753 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { |
| 1777 return library._library.compilationUnits.toList().map( | 1754 return library._library.compilationUnits.toList().map( |
| 1778 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); | 1755 (cu) => new Dart2JsCompilationUnitMirror(cu, library)).toList(); |
| 1779 } | 1756 } |
| 1780 } | 1757 } |
| OLD | NEW |