| 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 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 class _LocalMirrorSystemImpl extends MirrorSystem { | 77 class _LocalMirrorSystemImpl extends MirrorSystem { |
| 78 // Change parameter back to "this.libraries" when native code is changed. | 78 // Change parameter back to "this.libraries" when native code is changed. |
| 79 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate) | 79 _LocalMirrorSystemImpl(Map<String, LibraryMirror> libraries, this.isolate) |
| 80 : this.libraries = _createLibrariesMap(libraries), | 80 : this.libraries = _createLibrariesMap(libraries), |
| 81 _functionTypes = new Map<String, FunctionTypeMirror>(); | 81 _functionTypes = new Map<String, FunctionTypeMirror>(); |
| 82 | 82 |
| 83 final Map<Uri, LibraryMirror> libraries; | 83 final Map<Uri, LibraryMirror> libraries; |
| 84 final IsolateMirror isolate; | 84 final IsolateMirror isolate; |
| 85 | 85 |
| 86 // TODO(11743): dynamicType and voidType should not respond to the |
| 87 // ClassMirror protocol, so they should not inherit from the ClassMirror |
| 88 // implementation. |
| 89 |
| 86 TypeMirror _dynamicType = null; | 90 TypeMirror _dynamicType = null; |
| 87 | 91 |
| 88 TypeMirror get dynamicType { | 92 TypeMirror get dynamicType { |
| 89 if (_dynamicType == null) { | 93 if (_dynamicType == null) { |
| 90 _dynamicType = | 94 _dynamicType = |
| 91 new _LocalClassMirrorImpl( | 95 new _LocalClassMirrorImpl( |
| 92 null, 'dynamic', false, null, null, [], null, | 96 null, null, 'dynamic', false, null, null, [], null, |
| 93 const {}, const {}, const {}); | 97 const {}, const {}, const {}); |
| 94 } | 98 } |
| 95 return _dynamicType; | 99 return _dynamicType; |
| 96 } | 100 } |
| 97 | 101 |
| 98 TypeMirror _voidType = null; | 102 TypeMirror _voidType = null; |
| 99 | 103 |
| 100 TypeMirror get voidType { | 104 TypeMirror get voidType { |
| 101 if (_voidType == null) { | 105 if (_voidType == null) { |
| 102 _voidType = | 106 _voidType = |
| 103 new _LocalClassMirrorImpl( | 107 new _LocalClassMirrorImpl( |
| 104 null, 'void', false, null, null, [], null, | 108 null, null, 'void', false, null, null, [], null, |
| 105 const {}, const {}, const {}); | 109 const {}, const {}, const {}); |
| 106 } | 110 } |
| 107 return _voidType; | 111 return _voidType; |
| 108 } | 112 } |
| 109 | 113 |
| 110 final Map<String, FunctionTypeMirror> _functionTypes; | 114 final Map<String, FunctionTypeMirror> _functionTypes; |
| 111 FunctionTypeMirror _lookupFunctionTypeMirror( | 115 FunctionTypeMirror _lookupFunctionTypeMirror( |
| 112 TypeMirror returnType, | 116 TypeMirror returnType, |
| 113 List<ParameterMirror> parameters) { | 117 List<ParameterMirror> parameters) { |
| 114 var sigString = _makeSignatureString(returnType, parameters); | 118 var sigString = _makeSignatureString(returnType, parameters); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 } | 373 } |
| 370 return resolved; | 374 return resolved; |
| 371 } | 375 } |
| 372 | 376 |
| 373 final String libraryUrl; | 377 final String libraryUrl; |
| 374 final Symbol typeName; | 378 final Symbol typeName; |
| 375 } | 379 } |
| 376 | 380 |
| 377 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 381 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl |
| 378 implements ClassMirror { | 382 implements ClassMirror { |
| 379 _LocalClassMirrorImpl(ref, | 383 _LocalClassMirrorImpl(this._reflectee, |
| 384 ref, |
| 380 String simpleName, | 385 String simpleName, |
| 381 this.isClass, | 386 this.isClass, |
| 382 this._owner, | 387 this._owner, |
| 383 this._superclass, | 388 this._superclass, |
| 384 this._superinterfaces, | 389 this._superinterfaces, |
| 385 this._defaultFactory, | 390 this._defaultFactory, |
| 386 Map<String, Mirror> members, | 391 Map<String, Mirror> members, |
| 387 Map<String, Mirror> constructors, | 392 Map<String, Mirror> constructors, |
| 388 Map<String, Mirror> typeVariables) | 393 Map<String, Mirror> typeVariables) |
| 389 : this.simpleName = _s(simpleName), | 394 : this._simpleName = _s(simpleName), |
| 390 this.members = _convertStringToSymbolMap(members), | 395 this.members = _convertStringToSymbolMap(members), |
| 391 this.constructors = _convertStringToSymbolMap(constructors), | 396 this.constructors = _convertStringToSymbolMap(constructors), |
| 392 this.typeVariables = _convertStringToSymbolMap(typeVariables), | 397 this.typeVariables = _convertStringToSymbolMap(typeVariables), |
| 393 super(ref); | 398 super(ref); |
| 394 | 399 |
| 395 final Symbol simpleName; | 400 final _MirrorReference _reflectee; |
| 401 |
| 402 Symbol _simpleName; |
| 403 Symbol get simpleName { |
| 404 // dynamic, void and the function types have their names set eagerly in the |
| 405 // constructor. |
| 406 if(_simpleName == null) { |
| 407 _simpleName = _s(_ClassMirror_name(_reflectee)); |
| 408 } |
| 409 return _simpleName; |
| 410 } |
| 396 | 411 |
| 397 Symbol _qualifiedName = null; | 412 Symbol _qualifiedName = null; |
| 398 Symbol get qualifiedName { | 413 Symbol get qualifiedName { |
| 399 if (_qualifiedName == null) { | 414 if (_qualifiedName == null) { |
| 400 _qualifiedName = _computeQualifiedName(owner, simpleName); | 415 _qualifiedName = _computeQualifiedName(owner, simpleName); |
| 401 } | 416 } |
| 402 return _qualifiedName; | 417 return _qualifiedName; |
| 403 } | 418 } |
| 404 | 419 |
| 405 var _owner; | 420 var _owner; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 return new Future<InstanceMirror>.error(exception); | 566 return new Future<InstanceMirror>.error(exception); |
| 552 } | 567 } |
| 553 } | 568 } |
| 554 | 569 |
| 555 // get the metadata objects, convert them into InstanceMirrors using | 570 // get the metadata objects, convert them into InstanceMirrors using |
| 556 // reflect() and then make them into a Dart list | 571 // reflect() and then make them into a Dart list |
| 557 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList(); | 572 List<InstanceMirror> get metadata => _metadata(this).map(reflect).toList(); |
| 558 | 573 |
| 559 static _invokeConstructor(ref, constructorName, positionalArguments, async) | 574 static _invokeConstructor(ref, constructorName, positionalArguments, async) |
| 560 native 'LocalClassMirrorImpl_invokeConstructor'; | 575 native 'LocalClassMirrorImpl_invokeConstructor'; |
| 576 |
| 577 static String _ClassMirror_name(reflectee) |
| 578 native "ClassMirror_name"; |
| 561 } | 579 } |
| 562 | 580 |
| 563 class _LazyFunctionTypeMirror { | 581 class _LazyFunctionTypeMirror { |
| 564 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} | 582 _LazyFunctionTypeMirror(this.returnType, this.parameters) {} |
| 565 | 583 |
| 566 ClassMirror resolve(MirrorSystem mirrors) { | 584 ClassMirror resolve(MirrorSystem mirrors) { |
| 567 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), | 585 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors), |
| 568 parameters); | 586 parameters); |
| 569 } | 587 } |
| 570 | 588 |
| 571 final returnType; | 589 final returnType; |
| 572 final List<ParameterMirror> parameters; | 590 final List<ParameterMirror> parameters; |
| 573 } | 591 } |
| 574 | 592 |
| 575 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl | 593 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl |
| 576 implements FunctionTypeMirror { | 594 implements FunctionTypeMirror { |
| 577 _LocalFunctionTypeMirrorImpl(ref, | 595 _LocalFunctionTypeMirrorImpl(ref, |
| 578 simpleName, | 596 simpleName, |
| 579 this._returnType, | 597 this._returnType, |
| 580 this.parameters) | 598 this.parameters) |
| 581 : super(ref, | 599 : super(null, |
| 600 ref, |
| 582 simpleName, | 601 simpleName, |
| 583 true, | 602 true, |
| 584 null, | 603 null, |
| 585 new _LazyTypeMirror('dart:core', 'Object'), | 604 new _LazyTypeMirror('dart:core', 'Object'), |
| 586 [ new _LazyTypeMirror('dart:core', 'Function') ], | 605 [ new _LazyTypeMirror('dart:core', 'Function') ], |
| 587 null, | 606 null, |
| 588 const {}, | 607 const {}, |
| 589 const {}, | 608 const {}, |
| 590 const {}); | 609 const {}); |
| 591 | 610 |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1037 } | 1056 } |
| 1038 | 1057 |
| 1039 // Creates a new local ClassMirror. | 1058 // Creates a new local ClassMirror. |
| 1040 static ClassMirror makeLocalClassMirror(Type key) | 1059 static ClassMirror makeLocalClassMirror(Type key) |
| 1041 native "Mirrors_makeLocalClassMirror"; | 1060 native "Mirrors_makeLocalClassMirror"; |
| 1042 | 1061 |
| 1043 static ClassMirror reflectClass(Type key) { | 1062 static ClassMirror reflectClass(Type key) { |
| 1044 return makeLocalClassMirror(key); | 1063 return makeLocalClassMirror(key); |
| 1045 } | 1064 } |
| 1046 } | 1065 } |
| OLD | NEW |