| 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 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; | 7 import "dart:collection" show UnmodifiableListView, UnmodifiableMapView; |
| 8 | 8 |
| 9 final emptyList = new UnmodifiableListView([]); | 9 final emptyList = new UnmodifiableListView([]); |
| 10 final emptyMap = new UnmodifiableMapView({}); | 10 final emptyMap = new UnmodifiableMapView({}); |
| 11 | 11 |
| 12 class _InternalMirrorError { | 12 class _InternalMirrorError { |
| 13 final String _msg; | 13 final String _msg; |
| 14 const _InternalMirrorError(String this._msg); | 14 const _InternalMirrorError(String this._msg); |
| 15 String toString() => _msg; | 15 String toString() => _msg; |
| 16 } | 16 } |
| 17 | 17 |
| 18 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { | |
| 19 Map new_map = new Map<Symbol, dynamic>(); | |
| 20 old_map.forEach((key, value) { | |
| 21 if (filter(key, value)) { | |
| 22 new_map[key] = value; | |
| 23 } | |
| 24 }); | |
| 25 return new UnmodifiableMapView(new_map); | |
| 26 } | |
| 27 | |
| 28 Map _makeMemberMap(List mirrors) { | 18 Map _makeMemberMap(List mirrors) { |
| 29 return new UnmodifiableMapView<Symbol, DeclarationMirror>( | 19 return new UnmodifiableMapView<Symbol, DeclarationMirror>( |
| 30 new Map<Symbol, DeclarationMirror>.fromIterable( | 20 new Map<Symbol, DeclarationMirror>.fromIterable( |
| 31 mirrors, key: (e) => e.simpleName)); | 21 mirrors, key: (e) => e.simpleName)); |
| 32 } | 22 } |
| 33 | 23 |
| 34 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 24 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
| 35 | 25 |
| 36 Symbol _s(String name) { | 26 Symbol _s(String name) { |
| 37 if (name == null) return null; | 27 if (name == null) return null; |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 Map<Symbol, Mirror> _cachedMembers; | 768 Map<Symbol, Mirror> _cachedMembers; |
| 779 Map<Symbol, Mirror> get _members { | 769 Map<Symbol, Mirror> get _members { |
| 780 if (_cachedMembers == null) { | 770 if (_cachedMembers == null) { |
| 781 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; | 771 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; |
| 782 _cachedMembers = _makeMemberMap(mixin._computeMembers( | 772 _cachedMembers = _makeMemberMap(mixin._computeMembers( |
| 783 _instantiator, whoseMembers.mixin._reflectee)); | 773 _instantiator, whoseMembers.mixin._reflectee)); |
| 784 } | 774 } |
| 785 return _cachedMembers; | 775 return _cachedMembers; |
| 786 } | 776 } |
| 787 | 777 |
| 788 Map<Symbol, MethodMirror> _cachedMethods; | |
| 789 Map<Symbol, MethodMirror> get _methods { | |
| 790 if (_cachedMethods == null) { | |
| 791 _cachedMethods = _filterMap( | |
| 792 _members, | |
| 793 (key, value) => (value is MethodMirror && value.isRegularMethod)); | |
| 794 } | |
| 795 return _cachedMethods; | |
| 796 } | |
| 797 | |
| 798 Map<Symbol, MethodMirror> _cachedConstructors; | 778 Map<Symbol, MethodMirror> _cachedConstructors; |
| 799 Map<Symbol, MethodMirror> get _constructors { | 779 Map<Symbol, MethodMirror> get _constructors { |
| 800 if (_cachedConstructors == null) { | 780 if (_cachedConstructors == null) { |
| 801 var constructorsList = _computeConstructors(_instantiator, _reflectee); | 781 var constructorsList = _computeConstructors(_instantiator, _reflectee); |
| 802 var stringName = _n(simpleName); | 782 var stringName = _n(simpleName); |
| 803 constructorsList.forEach((c) => c._patchConstructorName(stringName)); | 783 constructorsList.forEach((c) => c._patchConstructorName(stringName)); |
| 804 _cachedConstructors = | 784 _cachedConstructors = |
| 805 new Map.fromIterable(constructorsList, key: (e) => e.simpleName); | 785 new Map.fromIterable(constructorsList, key: (e) => e.simpleName); |
| 806 } | 786 } |
| 807 return _cachedConstructors; | 787 return _cachedConstructors; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 _parameters = new UnmodifiableListView(_parameters); | 990 _parameters = new UnmodifiableListView(_parameters); |
| 1011 } | 991 } |
| 1012 return _parameters; | 992 return _parameters; |
| 1013 } | 993 } |
| 1014 | 994 |
| 1015 bool get isOriginalDeclaration => true; | 995 bool get isOriginalDeclaration => true; |
| 1016 get originalDeclaration => this; | 996 get originalDeclaration => this; |
| 1017 get typeVariables => emptyList; | 997 get typeVariables => emptyList; |
| 1018 get typeArguments => emptyList; | 998 get typeArguments => emptyList; |
| 1019 get metadata => emptyList; | 999 get metadata => emptyList; |
| 1020 Map<Symbol, Mirror> get members => emptyMap; | |
| 1021 Map<Symbol, MethodMirror> get constructors => emptyMap; | |
| 1022 | 1000 |
| 1023 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; | 1001 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; |
| 1024 | 1002 |
| 1025 MethodMirror _FunctionTypeMirror_call_method(reflectee) | 1003 MethodMirror _FunctionTypeMirror_call_method(reflectee) |
| 1026 native "FunctionTypeMirror_call_method"; | 1004 native "FunctionTypeMirror_call_method"; |
| 1027 | 1005 |
| 1028 static Type _FunctionTypeMirror_return_type(reflectee, instantiator) | 1006 static Type _FunctionTypeMirror_return_type(reflectee, instantiator) |
| 1029 native "FunctionTypeMirror_return_type"; | 1007 native "FunctionTypeMirror_return_type"; |
| 1030 | 1008 |
| 1031 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) | 1009 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1684 if (typeMirror == null) { | 1662 if (typeMirror == null) { |
| 1685 typeMirror = makeLocalTypeMirror(key); | 1663 typeMirror = makeLocalTypeMirror(key); |
| 1686 _instanitationCache[key] = typeMirror; | 1664 _instanitationCache[key] = typeMirror; |
| 1687 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1665 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1688 _declarationCache[key] = typeMirror; | 1666 _declarationCache[key] = typeMirror; |
| 1689 } | 1667 } |
| 1690 } | 1668 } |
| 1691 return typeMirror; | 1669 return typeMirror; |
| 1692 } | 1670 } |
| 1693 } | 1671 } |
| OLD | NEW |