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 // VM-specific implementation of the dart:mirrors library. | 5 // VM-specific implementation of the dart:mirrors library. |
| 6 | 6 |
| 7 // These values are allowed to be passed directly over the wire. | 7 // These values are allowed to be passed directly over the wire. |
| 8 bool _isSimpleValue(var value) { | 8 bool _isSimpleValue(var value) { |
| 9 return (value == null || value is num || value is String || value is bool); | 9 return (value == null || value is num || value is String || value is bool); |
| 10 } | 10 } |
| 11 | 11 |
| 12 Map _filterMap(Map old_map, bool filter(key, value)) { | 12 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { |
| 13 Map new_map = new Map(); | 13 Map new_map = new Map<Symbol, dynamic>(); |
| 14 old_map.forEach((key, value) { | 14 old_map.forEach((key, value) { |
| 15 if (filter(key, value)) { | 15 if (filter(key, value)) { |
| 16 new_map[key] = value; | 16 new_map[key] = value; |
| 17 } | 17 } |
| 18 }); | 18 }); |
| 19 return new_map; | 19 return new_map; |
| 20 } | 20 } |
| 21 | 21 |
| 22 String _n(Symbol symbol) => _collection_dev.Symbol.getName(symbol); | |
| 23 | |
| 24 Symbol _s(String name) { | |
| 25 if (name == null) return null; | |
| 26 return new _collection_dev.Symbol.unvalidated(name); | |
| 27 } | |
| 28 | |
| 29 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { | |
| 30 if (owner == null) return simpleName; | |
| 31 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); | |
| 32 } | |
| 33 | |
| 34 Map<Symbol, dynamic> _convertStringToSymbolMap(Map<String, dynamic> map) { | |
| 35 if (map == null) return null; | |
| 36 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); | |
| 37 map.forEach((name, value) => result[_s(name)] = value); | |
| 38 return result; | |
| 39 } | |
| 40 | |
| 22 String _makeSignatureString(TypeMirror returnType, | 41 String _makeSignatureString(TypeMirror returnType, |
| 23 List<ParameterMirror> parameters) { | 42 List<ParameterMirror> parameters) { |
| 24 StringBuffer buf = new StringBuffer(); | 43 StringBuffer buf = new StringBuffer(); |
| 25 buf.write(returnType.qualifiedName); | 44 buf.write(_n(returnType.qualifiedName)); |
| 26 buf.write(' ('); | 45 buf.write(' ('); |
| 27 bool found_optional_param = false; | 46 bool found_optional_param = false; |
| 28 for (int i = 0; i < parameters.length; i++) { | 47 for (int i = 0; i < parameters.length; i++) { |
| 29 var param = parameters[i]; | 48 var param = parameters[i]; |
| 30 if (param.isOptional && !found_optional_param) { | 49 if (param.isOptional && !found_optional_param) { |
| 31 buf.write('['); | 50 buf.write('['); |
| 32 found_optional_param = true; | 51 found_optional_param = true; |
| 33 } | 52 } |
| 34 buf.write(param.type.qualifiedName); | 53 buf.write(_n(param.type.qualifiedName)); |
| 35 if (i < (parameters.length - 1)) { | 54 if (i < (parameters.length - 1)) { |
| 36 buf.write(', '); | 55 buf.write(', '); |
| 37 } | 56 } |
| 38 } | 57 } |
| 39 if (found_optional_param) { | 58 if (found_optional_param) { |
| 40 buf.write(']'); | 59 buf.write(']'); |
| 41 } | 60 } |
| 42 buf.write(')'); | 61 buf.write(')'); |
| 43 return buf.toString(); | 62 return buf.toString(); |
| 44 } | 63 } |
| 45 | 64 |
| 46 class _LocalMirrorSystemImpl implements MirrorSystem { | 65 class _LocalMirrorSystemImpl implements MirrorSystem { |
| 47 _LocalMirrorSystemImpl(this.libraries, this.isolate) | 66 // TODO(ahe): [libraries] should be Map<Uri, LibraryMirror>. |
| 48 : _functionTypes = new Map<String, FunctionTypeMirror>() {} | 67 // Change parameter back to "this.libraries" when native code is changed. |
| 68 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate) | |
|
Søren Gjesse
2013/04/15 14:08:31
Four space indent - more below.
ahe
2013/04/15 14:29:55
Done.
| |
| 69 : _functionTypes = new Map<String, FunctionTypeMirror>(), | |
| 70 this.libraries = _convertStringToSymbolMap(libraries); | |
| 49 | 71 |
| 50 final Map<String, LibraryMirror> libraries; | 72 final Map<Symbol, LibraryMirror> libraries; |
| 51 final IsolateMirror isolate; | 73 final IsolateMirror isolate; |
| 52 | 74 |
| 53 TypeMirror _dynamicType = null; | 75 TypeMirror _dynamicType = null; |
| 54 | 76 |
| 55 TypeMirror get dynamicType { | 77 TypeMirror get dynamicType { |
| 56 if (_dynamicType == null) { | 78 if (_dynamicType == null) { |
| 57 _dynamicType = | 79 _dynamicType = |
| 58 new _LocalClassMirrorImpl( | 80 new _LocalClassMirrorImpl( |
| 59 null, 'dynamic', false, null, null, [], null, | 81 null, 'dynamic', false, null, null, [], null, |
| 60 const {}, const {}, const {}); | 82 const {}, const {}, const {}); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 // For now, all VMObjects hold a VMReference. We could consider | 154 // For now, all VMObjects hold a VMReference. We could consider |
| 133 // storing the Object reference itself here if the object is a Dart | 155 // storing the Object reference itself here if the object is a Dart |
| 134 // language objects (except for objects of type VMReference, of | 156 // language objects (except for objects of type VMReference, of |
| 135 // course). | 157 // course). |
| 136 VMReference _reference; | 158 VMReference _reference; |
| 137 } | 159 } |
| 138 | 160 |
| 139 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl | 161 abstract class _LocalObjectMirrorImpl extends _LocalVMObjectMirrorImpl |
| 140 implements ObjectMirror { | 162 implements ObjectMirror { |
| 141 _LocalObjectMirrorImpl(ref) : super(ref) {} | 163 _LocalObjectMirrorImpl(ref) : super(ref) {} |
| 142 | 164 |
| 143 Future<InstanceMirror> invokeAsync(String memberName, | 165 Future<InstanceMirror> invokeAsync(Symbol memberName, |
| 144 List positionalArguments, | 166 List positionalArguments, |
| 145 [Map<String,dynamic> namedArguments]) { | 167 [Map<Symbol, dynamic> namedArguments]) { |
| 146 if (namedArguments != null) { | 168 if (namedArguments != null) { |
| 147 throw new UnimplementedError( | 169 throw new UnimplementedError( |
| 148 'named argument support is not implemented'); | 170 'named argument support is not implemented'); |
| 149 } | 171 } |
| 150 // Walk the arguments and make sure they are legal. | 172 // Walk the arguments and make sure they are legal. |
| 151 for (int i = 0; i < positionalArguments.length; i++) { | 173 for (int i = 0; i < positionalArguments.length; i++) { |
| 152 var arg = positionalArguments[i]; | 174 var arg = positionalArguments[i]; |
| 153 _validateArgument(i, arg); | 175 _validateArgument(i, arg); |
| 154 } | 176 } |
| 155 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 177 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 156 try { | 178 try { |
| 157 completer.complete( | 179 completer.complete( |
| 158 _invoke(this, memberName, positionalArguments)); | 180 _invoke(this, _n(memberName), positionalArguments)); |
| 159 } catch (exception, s) { | 181 } catch (exception, s) { |
| 160 completer.completeError(exception, s); | 182 completer.completeError(exception, s); |
| 161 } | 183 } |
| 162 return completer.future; | 184 return completer.future; |
| 163 } | 185 } |
| 164 | 186 |
| 165 Future<InstanceMirror> getFieldAsync(String fieldName) { | 187 Future<InstanceMirror> getFieldAsync(Symbol fieldName) { |
| 166 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 188 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 167 try { | 189 try { |
| 168 completer.complete(_getField(this, fieldName)); | 190 completer.complete(_getField(this, _n(fieldName))); |
| 169 } catch (exception, s) { | 191 } catch (exception, s) { |
| 170 completer.completeError(exception, s); | 192 completer.completeError(exception, s); |
| 171 } | 193 } |
| 172 return completer.future; | 194 return completer.future; |
| 173 } | 195 } |
| 174 | 196 |
| 175 Future<InstanceMirror> setFieldAsync(String fieldName, Object arg) { | 197 Future<InstanceMirror> setFieldAsync(Symbol fieldName, Object arg) { |
| 176 _validateArgument(0, arg); | 198 _validateArgument(0, arg); |
| 177 | 199 |
| 178 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 200 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 179 try { | 201 try { |
| 180 completer.complete(_setField(this, fieldName, arg)); | 202 completer.complete(_setField(this, _n(fieldName), arg)); |
| 181 } catch (exception, s) { | 203 } catch (exception, s) { |
| 182 completer.completeError(exception, s); | 204 completer.completeError(exception, s); |
| 183 } | 205 } |
| 184 return completer.future; | 206 return completer.future; |
| 185 } | 207 } |
| 186 | 208 |
| 187 static _validateArgument(int i, Object arg) | 209 static _validateArgument(int i, Object arg) |
| 188 { | 210 { |
| 189 if (arg is Mirror) { | 211 if (arg is Mirror) { |
| 190 if (arg is! InstanceMirror) { | 212 if (arg is! InstanceMirror) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 this.function) : super(ref, type, reflectee) {} | 319 this.function) : super(ref, type, reflectee) {} |
| 298 | 320 |
| 299 final MethodMirror function; | 321 final MethodMirror function; |
| 300 | 322 |
| 301 String get source { | 323 String get source { |
| 302 throw new UnimplementedError( | 324 throw new UnimplementedError( |
| 303 'ClosureMirror.source is not implemented'); | 325 'ClosureMirror.source is not implemented'); |
| 304 } | 326 } |
| 305 | 327 |
| 306 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, | 328 Future<InstanceMirror> applyAsync(List<Object> positionalArguments, |
| 307 [Map<String,Object> namedArguments]) { | 329 [Map<Symbol, Object> namedArguments]) { |
| 308 if (namedArguments != null) { | 330 if (namedArguments != null) { |
| 309 throw new UnimplementedError( | 331 throw new UnimplementedError( |
| 310 'named argument support is not implemented'); | 332 'named argument support is not implemented'); |
| 311 } | 333 } |
| 312 // Walk the arguments and make sure they are legal. | 334 // Walk the arguments and make sure they are legal. |
| 313 for (int i = 0; i < positionalArguments.length; i++) { | 335 for (int i = 0; i < positionalArguments.length; i++) { |
| 314 var arg = positionalArguments[i]; | 336 var arg = positionalArguments[i]; |
| 315 _LocalObjectMirrorImpl._validateArgument(i, arg); | 337 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 316 } | 338 } |
| 317 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 339 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 318 try { | 340 try { |
| 319 completer.complete( | 341 completer.complete( |
| 320 _apply(this, positionalArguments)); | 342 _apply(this, positionalArguments)); |
| 321 } catch (exception) { | 343 } catch (exception) { |
| 322 completer.completeError(exception); | 344 completer.completeError(exception); |
| 323 } | 345 } |
| 324 return completer.future; | 346 return completer.future; |
| 325 } | 347 } |
| 326 | 348 |
| 327 Future<InstanceMirror> findInContext(String name) { | 349 Future<InstanceMirror> findInContext(Symbol name) { |
| 328 throw new UnimplementedError( | 350 throw new UnimplementedError( |
| 329 'ClosureMirror.findInContext() is not implemented'); | 351 'ClosureMirror.findInContext() is not implemented'); |
| 330 } | 352 } |
| 331 | 353 |
| 332 static _apply(ref, positionalArguments) | 354 static _apply(ref, positionalArguments) |
| 333 native 'LocalClosureMirrorImpl_apply'; | 355 native 'LocalClosureMirrorImpl_apply'; |
| 334 } | 356 } |
| 335 | 357 |
| 336 class _LazyTypeMirror { | 358 class _LazyTypeMirror { |
| 337 _LazyTypeMirror(this.libraryName, this.typeName) {} | 359 _LazyTypeMirror(String libraryName, String typeName) |
| 360 : this.libraryName = _s(libraryName), | |
| 361 this.typeName = _s(typeName); | |
| 338 | 362 |
| 339 TypeMirror resolve(MirrorSystem mirrors) { | 363 TypeMirror resolve(MirrorSystem mirrors) { |
| 340 if (libraryName == null) { | 364 if (libraryName == null) { |
| 341 if (typeName == 'dynamic') { | 365 if (typeName == const Symbol('dynamic')) { |
| 342 return mirrors.dynamicType; | 366 return mirrors.dynamicType; |
| 343 } else if (typeName == 'void') { | 367 } else if (typeName == const Symbol('void')) { |
| 344 return mirrors.voidType; | 368 return mirrors.voidType; |
| 345 } else { | 369 } else { |
| 346 throw new UnimplementedError( | 370 throw new UnimplementedError( |
| 347 "Mirror for type '$typeName' is not implemented"); | 371 "Mirror for type '$typeName' is not implemented"); |
| 348 } | 372 } |
| 349 } | 373 } |
| 350 var resolved = mirrors.libraries[libraryName].members[typeName]; | 374 var resolved = mirrors.libraries[libraryName].members[typeName]; |
| 351 if (resolved == null) { | 375 if (resolved == null) { |
| 352 throw new UnimplementedError( | 376 throw new UnimplementedError( |
| 353 "Mirror for type '$typeName' is not implemented"); | 377 "Mirror for type '$typeName' is not implemented"); |
| 354 } | 378 } |
| 355 return resolved; | 379 return resolved; |
| 356 } | 380 } |
| 357 | 381 |
| 358 final String libraryName; | 382 final Symbol libraryName; |
| 359 final String typeName; | 383 final Symbol typeName; |
| 360 } | 384 } |
| 361 | 385 |
| 362 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 386 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
| 363 implements ClassMirror { | 387 implements ClassMirror { |
| 364 _LocalClassMirrorImpl(ref, | 388 _LocalClassMirrorImpl(ref, |
| 365 this.simpleName, | 389 String simpleName, |
| 366 this.isClass, | 390 this.isClass, |
| 367 this._owner, | 391 this._owner, |
| 368 this._superclass, | 392 this._superclass, |
| 369 this._superinterfaces, | 393 this._superinterfaces, |
| 370 this._defaultFactory, | 394 this._defaultFactory, |
| 371 this.members, | 395 Map<String, Mirror> members, |
| 372 this.constructors, | 396 Map<String, Mirror> constructors, |
| 373 this.typeVariables) : super(ref) {} | 397 Map<String, Mirror> typeVariables) |
| 398 : this.simpleName = _s(simpleName), | |
| 399 this.members = _convertStringToSymbolMap(members), | |
| 400 this.constructors = _convertStringToSymbolMap(constructors), | |
| 401 this.typeVariables = _convertStringToSymbolMap(typeVariables), | |
| 402 super(ref); | |
| 374 | 403 |
| 375 final String simpleName; | 404 final Symbol simpleName; |
| 376 | 405 |
| 377 String _qualifiedName = null; | 406 Symbol _qualifiedName = null; |
| 378 String get qualifiedName { | 407 Symbol get qualifiedName { |
| 379 if (_owner != null) { | 408 if (_qualifiedName == null) { |
| 380 if (_qualifiedName == null) { | 409 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 381 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | |
| 382 } | |
| 383 } else { | |
| 384 // The owner of a ClassMirror is null in certain odd cases, like | |
| 385 // 'void', 'dynamic' and function type mirrors. | |
| 386 _qualifiedName = simpleName; | |
| 387 } | 410 } |
| 388 return _qualifiedName; | 411 return _qualifiedName; |
| 389 } | 412 } |
| 390 | 413 |
| 391 var _owner; | 414 var _owner; |
| 392 DeclarationMirror get owner { | 415 DeclarationMirror get owner { |
| 393 if (_owner != null && _owner is! Mirror) { | 416 if (_owner != null && _owner is! Mirror) { |
| 394 _owner = _owner.resolve(mirrors); | 417 _owner = _owner.resolve(mirrors); |
| 395 } | 418 } |
| 396 return _owner; | 419 return _owner; |
| 397 } | 420 } |
| 398 | 421 |
| 399 bool get isPrivate => simpleName.startsWith('_'); | 422 bool get isPrivate => _n(simpleName).startsWith('_'); |
| 400 | 423 |
| 401 final bool isTopLevel = true; | 424 final bool isTopLevel = true; |
| 402 | 425 |
| 403 SourceLocation get location { | 426 SourceLocation get location { |
| 404 throw new UnimplementedError( | 427 throw new UnimplementedError( |
| 405 'ClassMirror.location is not implemented'); | 428 'ClassMirror.location is not implemented'); |
| 406 } | 429 } |
| 407 | 430 |
| 408 final bool isClass; | 431 final bool isClass; |
| 409 | 432 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 429 } | 452 } |
| 430 | 453 |
| 431 var _defaultFactory; | 454 var _defaultFactory; |
| 432 ClassMirror get defaultFactory { | 455 ClassMirror get defaultFactory { |
| 433 if (_defaultFactory != null && _defaultFactory is! Mirror) { | 456 if (_defaultFactory != null && _defaultFactory is! Mirror) { |
| 434 _defaultFactory = _defaultFactory.resolve(mirrors); | 457 _defaultFactory = _defaultFactory.resolve(mirrors); |
| 435 } | 458 } |
| 436 return _defaultFactory; | 459 return _defaultFactory; |
| 437 } | 460 } |
| 438 | 461 |
| 439 final Map<String, Mirror> members; | 462 final Map<Symbol, Mirror> members; |
| 440 | 463 |
| 441 Map<String, MethodMirror> _methods = null; | 464 Map<Symbol, MethodMirror> _methods = null; |
| 442 Map<String, MethodMirror> _getters = null; | 465 Map<Symbol, MethodMirror> _getters = null; |
| 443 Map<String, MethodMirror> _setters = null; | 466 Map<Symbol, MethodMirror> _setters = null; |
| 444 Map<String, VariableMirror> _variables = null; | 467 Map<Symbol, VariableMirror> _variables = null; |
| 445 | 468 |
| 446 Map<String, MethodMirror> get methods { | 469 Map<Symbol, MethodMirror> get methods { |
| 447 if (_methods == null) { | 470 if (_methods == null) { |
| 448 _methods = _filterMap( | 471 _methods = _filterMap( |
| 449 members, | 472 members, |
| 450 (key, value) => (value is MethodMirror && value.isRegularMethod)); | 473 (key, value) => (value is MethodMirror && value.isRegularMethod)); |
| 451 } | 474 } |
| 452 return _methods; | 475 return _methods; |
| 453 } | 476 } |
| 454 | 477 |
| 455 Map<String, MethodMirror> get getters { | 478 Map<Symbol, MethodMirror> get getters { |
| 456 if (_getters == null) { | 479 if (_getters == null) { |
| 457 _getters = _filterMap( | 480 _getters = _filterMap( |
| 458 members, | 481 members, |
| 459 (key, value) => (value is MethodMirror && value.isGetter)); | 482 (key, value) => (value is MethodMirror && value.isGetter)); |
| 460 } | 483 } |
| 461 return _getters; | 484 return _getters; |
| 462 } | 485 } |
| 463 | 486 |
| 464 Map<String, MethodMirror> get setters { | 487 Map<Symbol, MethodMirror> get setters { |
| 465 if (_setters == null) { | 488 if (_setters == null) { |
| 466 _setters = _filterMap( | 489 _setters = _filterMap( |
| 467 members, | 490 members, |
| 468 (key, value) => (value is MethodMirror && value.isSetter)); | 491 (key, value) => (value is MethodMirror && value.isSetter)); |
| 469 } | 492 } |
| 470 return _setters; | 493 return _setters; |
| 471 } | 494 } |
| 472 | 495 |
| 473 Map<String, VariableMirror> get variables { | 496 Map<Symbol, VariableMirror> get variables { |
| 474 if (_variables == null) { | 497 if (_variables == null) { |
| 475 _variables = _filterMap( | 498 _variables = _filterMap( |
| 476 members, | 499 members, |
| 477 (key, value) => (value is VariableMirror)); | 500 (key, value) => (value is VariableMirror)); |
| 478 } | 501 } |
| 479 return _variables; | 502 return _variables; |
| 480 } | 503 } |
| 481 | 504 |
| 482 Map<String, MethodMirror> constructors; | 505 Map<Symbol, MethodMirror> constructors; |
| 483 Map<String, TypeVariableMirror> typeVariables; | 506 Map<Symbol, TypeVariableMirror> typeVariables; |
| 484 | 507 |
| 485 Map<String, TypeMirror> get typeArguments { | 508 Map<Symbol, TypeMirror> get typeArguments { |
| 486 throw new UnimplementedError( | 509 throw new UnimplementedError( |
| 487 'ClassMirror.typeArguments is not implemented'); | 510 'ClassMirror.typeArguments is not implemented'); |
| 488 } | 511 } |
| 489 | 512 |
| 490 bool get isOriginalDeclaration { | 513 bool get isOriginalDeclaration { |
| 491 throw new UnimplementedError( | 514 throw new UnimplementedError( |
| 492 'ClassMirror.isOriginalDeclaration is not implemented'); | 515 'ClassMirror.isOriginalDeclaration is not implemented'); |
| 493 } | 516 } |
| 494 | 517 |
| 495 ClassMirror get genericDeclaration { | 518 ClassMirror get genericDeclaration { |
| 496 throw new UnimplementedError( | 519 throw new UnimplementedError( |
| 497 'ClassMirror.originalDeclaration is not implemented'); | 520 'ClassMirror.originalDeclaration is not implemented'); |
| 498 } | 521 } |
| 499 | 522 |
| 500 String toString() => "ClassMirror on '$simpleName'"; | 523 String toString() => "ClassMirror on '$simpleName'"; |
| 501 | 524 |
| 502 Future<InstanceMirror> newInstanceAsync(String constructorName, | 525 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, |
| 503 List positionalArguments, | 526 List positionalArguments, |
| 504 [Map<String,dynamic> namedArguments]) { | 527 [Map<Symbol, dynamic> namedArguments]) { |
| 505 if (namedArguments != null) { | 528 if (namedArguments != null) { |
| 506 throw new UnimplementedError( | 529 throw new UnimplementedError( |
| 507 'named argument support is not implemented'); | 530 'named argument support is not implemented'); |
| 508 } | 531 } |
| 509 // Walk the arguments and make sure they are legal. | 532 // Walk the arguments and make sure they are legal. |
| 510 for (int i = 0; i < positionalArguments.length; i++) { | 533 for (int i = 0; i < positionalArguments.length; i++) { |
| 511 var arg = positionalArguments[i]; | 534 var arg = positionalArguments[i]; |
| 512 _LocalObjectMirrorImpl._validateArgument(i, arg); | 535 _LocalObjectMirrorImpl._validateArgument(i, arg); |
| 513 } | 536 } |
| 514 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); | 537 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); |
| 515 try { | 538 try { |
| 516 completer.complete( | 539 completer.complete( |
| 517 _invokeConstructor(this, constructorName, positionalArguments)); | 540 _invokeConstructor(this, _n(constructorName), positionalArguments)); |
| 518 } catch (exception) { | 541 } catch (exception) { |
| 519 completer.completeError(exception); | 542 completer.completeError(exception); |
| 520 } | 543 } |
| 521 return completer.future; | 544 return completer.future; |
| 522 } | 545 } |
| 523 | 546 |
| 524 static _invokeConstructor(ref, constructorName, positionalArguments) | 547 static _invokeConstructor(ref, constructorName, positionalArguments) |
| 525 native 'LocalClassMirrorImpl_invokeConstructor'; | 548 native 'LocalClassMirrorImpl_invokeConstructor'; |
| 526 } | 549 } |
| 527 | 550 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 return _returnType; | 585 return _returnType; |
| 563 } | 586 } |
| 564 | 587 |
| 565 final List<ParameterMirror> parameters; | 588 final List<ParameterMirror> parameters; |
| 566 | 589 |
| 567 String toString() => "FunctionTypeMirror on '$simpleName'"; | 590 String toString() => "FunctionTypeMirror on '$simpleName'"; |
| 568 } | 591 } |
| 569 | 592 |
| 570 | 593 |
| 571 class _LazyTypeVariableMirror { | 594 class _LazyTypeVariableMirror { |
| 572 _LazyTypeVariableMirror(this._variableName, this._owner) {} | 595 _LazyTypeVariableMirror(String variableName, this._owner) |
| 596 : this._variableName = _s(variableName); | |
| 573 | 597 |
| 574 TypeVariableMirror resolve(MirrorSystem mirrors) { | 598 TypeVariableMirror resolve(MirrorSystem mirrors) { |
| 575 ClassMirror owner = _owner.resolve(mirrors); | 599 ClassMirror owner = _owner.resolve(mirrors); |
| 576 return owner.typeVariables[_variableName]; | 600 return owner.typeVariables[_variableName]; |
| 577 } | 601 } |
| 578 | 602 |
| 579 final String _variableName; | 603 final Symbol _variableName; |
| 580 final _LazyTypeMirror _owner; | 604 final _LazyTypeMirror _owner; |
| 581 } | 605 } |
| 582 | 606 |
| 583 class _LocalTypeVariableMirrorImpl extends _LocalMirrorImpl | 607 class _LocalTypeVariableMirrorImpl extends _LocalMirrorImpl |
| 584 implements TypeVariableMirror { | 608 implements TypeVariableMirror { |
| 585 _LocalTypeVariableMirrorImpl(this.simpleName, | 609 _LocalTypeVariableMirrorImpl(String simpleName, |
| 586 this._owner, | 610 this._owner, |
| 587 this._upperBound) {} | 611 this._upperBound) |
| 588 final String simpleName; | 612 : this.simpleName = _s(simpleName); |
| 589 | 613 |
| 590 String _qualifiedName = null; | 614 final Symbol simpleName; |
| 591 String get qualifiedName { | 615 |
| 616 Symbol _qualifiedName = null; | |
| 617 Symbol get qualifiedName { | |
| 592 if (_qualifiedName == null) { | 618 if (_qualifiedName == null) { |
| 593 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 619 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 594 } | 620 } |
| 595 return _qualifiedName; | 621 return _qualifiedName; |
| 596 } | 622 } |
| 597 | 623 |
| 598 var _owner; | 624 var _owner; |
| 599 DeclarationMirror get owner { | 625 DeclarationMirror get owner { |
| 600 if (_owner is! Mirror) { | 626 if (_owner is! Mirror) { |
| 601 _owner = _owner.resolve(mirrors); | 627 _owner = _owner.resolve(mirrors); |
| 602 } | 628 } |
| 603 return _owner; | 629 return _owner; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 619 } | 645 } |
| 620 return _upperBound; | 646 return _upperBound; |
| 621 } | 647 } |
| 622 | 648 |
| 623 String toString() => "TypeVariableMirror on '$simpleName'"; | 649 String toString() => "TypeVariableMirror on '$simpleName'"; |
| 624 } | 650 } |
| 625 | 651 |
| 626 | 652 |
| 627 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl | 653 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl |
| 628 implements TypedefMirror { | 654 implements TypedefMirror { |
| 629 _LocalTypedefMirrorImpl(this.simpleName, | 655 _LocalTypedefMirrorImpl(String simpleName, |
| 630 this._owner, | 656 this._owner, |
| 631 this._referent) {} | 657 this._referent) |
| 632 final String simpleName; | 658 : this.simpleName = _s(simpleName); |
| 633 | 659 |
| 634 String _qualifiedName = null; | 660 final Symbol simpleName; |
| 635 String get qualifiedName { | 661 |
| 662 Symbol _qualifiedName = null; | |
| 663 Symbol get qualifiedName { | |
| 636 if (_qualifiedName == null) { | 664 if (_qualifiedName == null) { |
| 637 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 665 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 638 } | 666 } |
| 639 return _qualifiedName; | 667 return _qualifiedName; |
| 640 } | 668 } |
| 641 | 669 |
| 642 var _owner; | 670 var _owner; |
| 643 DeclarationMirror get owner { | 671 DeclarationMirror get owner { |
| 644 if (_owner is! Mirror) { | 672 if (_owner is! Mirror) { |
| 645 _owner = _owner.resolve(mirrors); | 673 _owner = _owner.resolve(mirrors); |
| 646 } | 674 } |
| 647 return _owner; | 675 return _owner; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 662 _referent = _referent.resolve(mirrors); | 690 _referent = _referent.resolve(mirrors); |
| 663 } | 691 } |
| 664 return _referent; | 692 return _referent; |
| 665 } | 693 } |
| 666 | 694 |
| 667 String toString() => "TypedefMirror on '$simpleName'"; | 695 String toString() => "TypedefMirror on '$simpleName'"; |
| 668 } | 696 } |
| 669 | 697 |
| 670 | 698 |
| 671 class _LazyLibraryMirror { | 699 class _LazyLibraryMirror { |
| 672 _LazyLibraryMirror(this.libraryName) {} | 700 _LazyLibraryMirror(String libraryName) |
| 701 : this.libraryName = _s(libraryName); | |
| 673 | 702 |
| 674 LibraryMirror resolve(MirrorSystem mirrors) { | 703 LibraryMirror resolve(MirrorSystem mirrors) { |
| 675 return mirrors.libraries[libraryName]; | 704 return mirrors.libraries[libraryName]; |
| 676 } | 705 } |
| 677 | 706 |
| 678 final String libraryName; | 707 final Symbol libraryName; |
| 679 } | 708 } |
| 680 | 709 |
| 681 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl | 710 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl |
| 682 implements LibraryMirror { | 711 implements LibraryMirror { |
| 683 _LocalLibraryMirrorImpl(ref, | 712 _LocalLibraryMirrorImpl(ref, |
| 684 this.simpleName, | 713 String simpleName, |
| 685 this.url, | 714 this.url, |
| 686 this.members) : super(ref) {} | 715 Map<String, Mirror> members) |
| 716 : this.simpleName = _s(simpleName), | |
| 717 this.members = _convertStringToSymbolMap(members), | |
| 718 super(ref); | |
| 687 | 719 |
| 688 final String simpleName; | 720 final Symbol simpleName; |
| 689 | 721 |
| 690 // The simple name and the qualified name are the same for a library. | 722 // The simple name and the qualified name are the same for a library. |
| 691 String get qualifiedName => simpleName; | 723 Symbol get qualifiedName => simpleName; |
| 692 | 724 |
| 693 // Always null for libraries. | 725 // Always null for libraries. |
| 694 final DeclarationMirror owner = null; | 726 final DeclarationMirror owner = null; |
| 695 | 727 |
| 696 // Always false for libraries. | 728 // Always false for libraries. |
| 697 final bool isPrivate = false; | 729 final bool isPrivate = false; |
| 698 | 730 |
| 699 // Always false for libraries. | 731 // Always false for libraries. |
| 700 final bool isTopLevel = false; | 732 final bool isTopLevel = false; |
| 701 | 733 |
| 702 SourceLocation get location { | 734 SourceLocation get location { |
| 703 throw new UnimplementedError( | 735 throw new UnimplementedError( |
| 704 'LibraryMirror.location is not implemented'); | 736 'LibraryMirror.location is not implemented'); |
| 705 } | 737 } |
| 706 | 738 |
| 707 final String url; | 739 final String url; |
| 708 final Map<String, Mirror> members; | 740 final Map<Symbol, Mirror> members; |
| 709 | 741 |
| 710 Map<String, ClassMirror> _classes = null; | 742 Map<Symbol, ClassMirror> _classes = null; |
| 711 Map<String, MethodMirror> _functions = null; | 743 Map<Symbol, MethodMirror> _functions = null; |
| 712 Map<String, MethodMirror> _getters = null; | 744 Map<Symbol, MethodMirror> _getters = null; |
| 713 Map<String, MethodMirror> _setters = null; | 745 Map<Symbol, MethodMirror> _setters = null; |
| 714 Map<String, VariableMirror> _variables = null; | 746 Map<Symbol, VariableMirror> _variables = null; |
| 715 | 747 |
| 716 Map<String, ClassMirror> get classes { | 748 Map<Symbol, ClassMirror> get classes { |
| 717 if (_classes == null) { | 749 if (_classes == null) { |
| 718 _classes = _filterMap(members, | 750 _classes = _filterMap(members, |
| 719 (key, value) => (value is ClassMirror)); | 751 (key, value) => (value is ClassMirror)); |
| 720 } | 752 } |
| 721 return _classes; | 753 return _classes; |
| 722 } | 754 } |
| 723 | 755 |
| 724 Map<String, MethodMirror> get functions { | 756 Map<Symbol, MethodMirror> get functions { |
| 725 if (_functions == null) { | 757 if (_functions == null) { |
| 726 _functions = _filterMap(members, | 758 _functions = _filterMap(members, |
| 727 (key, value) => (value is MethodMirror)); | 759 (key, value) => (value is MethodMirror)); |
| 728 } | 760 } |
| 729 return _functions; | 761 return _functions; |
| 730 } | 762 } |
| 731 | 763 |
| 732 Map<String, MethodMirror> get getters { | 764 Map<Symbol, MethodMirror> get getters { |
| 733 if (_getters == null) { | 765 if (_getters == null) { |
| 734 _getters = _filterMap(functions, | 766 _getters = _filterMap(functions, |
| 735 (key, value) => (value.isGetter)); | 767 (key, value) => (value.isGetter)); |
| 736 } | 768 } |
| 737 return _getters; | 769 return _getters; |
| 738 } | 770 } |
| 739 | 771 |
| 740 Map<String, MethodMirror> get setters { | 772 Map<Symbol, MethodMirror> get setters { |
| 741 if (_setters == null) { | 773 if (_setters == null) { |
| 742 _setters = _filterMap(functions, | 774 _setters = _filterMap(functions, |
| 743 (key, value) => (value.isSetter)); | 775 (key, value) => (value.isSetter)); |
| 744 } | 776 } |
| 745 return _setters; | 777 return _setters; |
| 746 } | 778 } |
| 747 | 779 |
| 748 Map<String, VariableMirror> get variables { | 780 Map<Symbol, VariableMirror> get variables { |
| 749 if (_variables == null) { | 781 if (_variables == null) { |
| 750 _variables = _filterMap(members, | 782 _variables = _filterMap(members, |
| 751 (key, value) => (value is VariableMirror)); | 783 (key, value) => (value is VariableMirror)); |
| 752 } | 784 } |
| 753 return _variables; | 785 return _variables; |
| 754 } | 786 } |
| 755 | 787 |
| 756 String toString() => "LibraryMirror on '$simpleName'"; | 788 String toString() => "LibraryMirror on '$simpleName'"; |
| 757 } | 789 } |
| 758 | 790 |
| 759 class _LocalMethodMirrorImpl extends _LocalMirrorImpl | 791 class _LocalMethodMirrorImpl extends _LocalMirrorImpl |
| 760 implements MethodMirror { | 792 implements MethodMirror { |
| 761 _LocalMethodMirrorImpl(this.simpleName, | 793 _LocalMethodMirrorImpl(String simpleName, |
| 762 this._owner, | 794 this._owner, |
| 763 this.parameters, | 795 this.parameters, |
| 764 this._returnType, | 796 this._returnType, |
| 765 this.isStatic, | 797 this.isStatic, |
| 766 this.isAbstract, | 798 this.isAbstract, |
| 767 this.isGetter, | 799 this.isGetter, |
| 768 this.isSetter, | 800 this.isSetter, |
| 769 this.isConstructor, | 801 this.isConstructor, |
| 770 this.isConstConstructor, | 802 this.isConstConstructor, |
| 771 this.isGenerativeConstructor, | 803 this.isGenerativeConstructor, |
| 772 this.isRedirectingConstructor, | 804 this.isRedirectingConstructor, |
| 773 this.isFactoryConstructor) {} | 805 this.isFactoryConstructor) |
| 806 : this.simpleName = _s(simpleName); | |
| 774 | 807 |
| 775 final String simpleName; | 808 final Symbol simpleName; |
| 776 | 809 |
| 777 String _qualifiedName = null; | 810 Symbol _qualifiedName = null; |
| 778 String get qualifiedName { | 811 Symbol get qualifiedName { |
| 779 if (_qualifiedName == null) { | 812 if (_qualifiedName == null) { |
| 780 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 813 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 781 } | 814 } |
| 782 return _qualifiedName; | 815 return _qualifiedName; |
| 783 } | 816 } |
| 784 | 817 |
| 785 var _owner; | 818 var _owner; |
| 786 DeclarationMirror get owner { | 819 DeclarationMirror get owner { |
| 787 if (_owner is! Mirror) { | 820 if (_owner is! Mirror) { |
| 788 _owner = _owner.resolve(mirrors); | 821 _owner = _owner.resolve(mirrors); |
| 789 } | 822 } |
| 790 return _owner; | 823 return _owner; |
| 791 } | 824 } |
| 792 | 825 |
| 793 bool get isPrivate { | 826 bool get isPrivate { |
| 794 return simpleName.startsWith('_') || constructorName.startsWith('_'); | 827 return _n(simpleName).startsWith('_') || |
| 828 _n(constructorName).startsWith('_'); | |
| 795 } | 829 } |
| 796 | 830 |
| 797 bool get isTopLevel => owner is LibraryMirror; | 831 bool get isTopLevel => owner is LibraryMirror; |
| 798 | 832 |
| 799 SourceLocation get location { | 833 SourceLocation get location { |
| 800 throw new UnimplementedError( | 834 throw new UnimplementedError( |
| 801 'MethodMirror.location is not implemented'); | 835 'MethodMirror.location is not implemented'); |
| 802 } | 836 } |
| 803 | 837 |
| 804 var _returnType; | 838 var _returnType; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 818 | 852 |
| 819 TypeMirror get isOperator { | 853 TypeMirror get isOperator { |
| 820 throw new UnimplementedError( | 854 throw new UnimplementedError( |
| 821 'MethodMirror.isOperator is not implemented'); | 855 'MethodMirror.isOperator is not implemented'); |
| 822 } | 856 } |
| 823 | 857 |
| 824 final bool isGetter; | 858 final bool isGetter; |
| 825 final bool isSetter; | 859 final bool isSetter; |
| 826 final bool isConstructor; | 860 final bool isConstructor; |
| 827 | 861 |
| 828 var _constructorName = null; | 862 Symbol _constructorName = null; |
| 829 String get constructorName { | 863 Symbol get constructorName { |
| 830 if (_constructorName == null) { | 864 if (_constructorName == null) { |
| 831 if (!isConstructor) { | 865 if (!isConstructor) { |
| 832 _constructorName = ''; | 866 _constructorName = _s(''); |
| 833 } else { | 867 } else { |
| 834 var parts = simpleName.split('.'); | 868 var parts = _n(simpleName).split('.'); |
| 835 if (parts.length > 2) { | 869 if (parts.length > 2) { |
| 836 throw new MirrorException( | 870 throw new MirrorException( |
| 837 'Internal error in MethodMirror.constructorName: ' | 871 'Internal error in MethodMirror.constructorName: ' |
| 838 'malformed name <$simpleName>'); | 872 'malformed name <$simpleName>'); |
| 839 } else if (parts.length == 2) { | 873 } else if (parts.length == 2) { |
| 840 _constructorName = parts[1]; | 874 _constructorName = _s(parts[1]); |
| 841 } else { | 875 } else { |
| 842 _constructorName = ''; | 876 _constructorName = _s(''); |
| 843 } | 877 } |
| 844 } | 878 } |
| 845 } | 879 } |
| 846 return _constructorName; | 880 return _constructorName; |
| 847 } | 881 } |
| 848 | 882 |
| 849 final bool isConstConstructor; | 883 final bool isConstConstructor; |
| 850 final bool isGenerativeConstructor; | 884 final bool isGenerativeConstructor; |
| 851 final bool isRedirectingConstructor; | 885 final bool isRedirectingConstructor; |
| 852 final bool isFactoryConstructor; | 886 final bool isFactoryConstructor; |
| 853 | 887 |
| 854 String toString() => "MethodMirror on '$simpleName'"; | 888 String toString() => "MethodMirror on '$simpleName'"; |
| 855 } | 889 } |
| 856 | 890 |
| 857 class _LocalVariableMirrorImpl extends _LocalMirrorImpl | 891 class _LocalVariableMirrorImpl extends _LocalMirrorImpl |
| 858 implements VariableMirror { | 892 implements VariableMirror { |
| 859 _LocalVariableMirrorImpl(this.simpleName, | 893 _LocalVariableMirrorImpl(String simpleName, |
| 860 this._owner, | 894 this._owner, |
| 861 this._type, | 895 this._type, |
| 862 this.isStatic, | 896 this.isStatic, |
| 863 this.isFinal) {} | 897 this.isFinal) |
| 898 : this.simpleName = _s(simpleName); | |
| 864 | 899 |
| 865 final String simpleName; | 900 final Symbol simpleName; |
| 866 | 901 |
| 867 String _qualifiedName = null; | 902 Symbol _qualifiedName = null; |
| 868 String get qualifiedName { | 903 Symbol get qualifiedName { |
| 869 if (_qualifiedName == null) { | 904 if (_qualifiedName == null) { |
| 870 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; | 905 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 871 } | 906 } |
| 872 return _qualifiedName; | 907 return _qualifiedName; |
| 873 } | 908 } |
| 874 | 909 |
| 875 var _owner; | 910 var _owner; |
| 876 DeclarationMirror get owner { | 911 DeclarationMirror get owner { |
| 877 if (_owner is! Mirror) { | 912 if (_owner is! Mirror) { |
| 878 _owner = _owner.resolve(mirrors); | 913 _owner = _owner.resolve(mirrors); |
| 879 } | 914 } |
| 880 return _owner; | 915 return _owner; |
| 881 } | 916 } |
| 882 | 917 |
| 883 bool get isPrivate { | 918 bool get isPrivate { |
| 884 return simpleName.startsWith('_'); | 919 return _n(simpleName).startsWith('_'); |
| 885 } | 920 } |
| 886 | 921 |
| 887 bool get isTopLevel { | 922 bool get isTopLevel { |
| 888 return owner is LibraryMirror; | 923 return owner is LibraryMirror; |
| 889 } | 924 } |
| 890 | 925 |
| 891 SourceLocation get location { | 926 SourceLocation get location { |
| 892 throw new UnimplementedError( | 927 throw new UnimplementedError( |
| 893 'VariableMirror.location is not implemented'); | 928 'VariableMirror.location is not implemented'); |
| 894 } | 929 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 966 | 1001 |
| 967 // Creates a new local mirror for some Object. | 1002 // Creates a new local mirror for some Object. |
| 968 static InstanceMirror reflect(Object reflectee) { | 1003 static InstanceMirror reflect(Object reflectee) { |
| 969 return makeLocalInstanceMirror(reflectee); | 1004 return makeLocalInstanceMirror(reflectee); |
| 970 } | 1005 } |
| 971 | 1006 |
| 972 static ClassMirror reflectClass(Type reflectee) { | 1007 static ClassMirror reflectClass(Type reflectee) { |
| 973 throw new UnimplementedError('reflectClass is not implemented'); | 1008 throw new UnimplementedError('reflectClass is not implemented'); |
| 974 } | 1009 } |
| 975 } | 1010 } |
| OLD | NEW |