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"; | 7 import "dart:collection"; |
8 | 8 |
9 final emptyList = new UnmodifiableListView([]); | |
10 final emptyMap = new _UnmodifiableMapView({}); | |
11 | |
12 // Copied from js_mirrors, Copied from package "unmodifiable_collection". | |
ahe
2013/10/22 18:18:10
Awesome, a copy of a copy :-)
Second "Copied" sho
| |
13 // TODO(ahe): Lobby to get it added to dart:collection. | |
ahe
2013/10/22 18:18:10
Please don't copy my TODO into your code ;-)
| |
14 class _UnmodifiableMapView<K, V> implements Map<K, V> { | |
15 Map<K, V> _source; | |
16 _UnmodifiableMapView(Map<K, V> source) : _source = source; | |
17 | |
18 static void _throw() { | |
19 throw new UnsupportedError("Cannot modify an unmodifiable Map"); | |
20 } | |
21 | |
22 int get length => _source.length; | |
23 | |
24 bool get isEmpty => _source.isEmpty; | |
25 | |
26 bool get isNotEmpty => _source.isNotEmpty; | |
27 | |
28 V operator [](K key) => _source[key]; | |
29 | |
30 bool containsKey(K key) => _source.containsKey(key); | |
31 | |
32 bool containsValue(V value) => _source.containsValue(value); | |
33 | |
34 void forEach(void f(K key, V value)) => _source.forEach(f); | |
35 | |
36 Iterable<K> get keys => _source.keys; | |
37 | |
38 Iterable<V> get values => _source.values; | |
39 | |
40 void operator []=(K key, V value) => _throw(); | |
41 | |
42 V putIfAbsent(K key, V ifAbsent()) { _throw(); } | |
43 | |
44 void addAll(Map<K, V> other) => _throw(); | |
45 | |
46 V remove(K key) { _throw(); } | |
47 | |
48 void clear() => _throw(); | |
49 } | |
50 | |
9 // These values are allowed to be passed directly over the wire. | 51 // These values are allowed to be passed directly over the wire. |
10 bool _isSimpleValue(var value) { | 52 bool _isSimpleValue(var value) { |
11 return (value == null || value is num || value is String || value is bool); | 53 return (value == null || value is num || value is String || value is bool); |
12 } | 54 } |
13 | 55 |
14 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { | 56 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { |
15 Map new_map = new Map<Symbol, dynamic>(); | 57 Map new_map = new Map<Symbol, dynamic>(); |
16 old_map.forEach((key, value) { | 58 old_map.forEach((key, value) { |
17 if (filter(key, value)) { | 59 if (filter(key, value)) { |
18 new_map[key] = value; | 60 new_map[key] = value; |
19 } | 61 } |
20 }); | 62 }); |
21 return new_map; | 63 return new _UnmodifiableMapView(new_map); |
22 } | 64 } |
23 | 65 |
24 Map _makeMemberMap(List mirrors) => new Map<Symbol, dynamic>.fromIterable( | 66 Map _makeMemberMap(List mirrors) { |
25 mirrors, key: (e) => e.simpleName); | 67 return new _UnmodifiableMapView( |
68 new Map<Symbol, dynamic>.fromIterable(mirrors, key: (e) => e.simpleName)); | |
69 } | |
26 | 70 |
27 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); | 71 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); |
28 | 72 |
29 Symbol _s(String name) { | 73 Symbol _s(String name) { |
30 if (name == null) return null; | 74 if (name == null) return null; |
31 return new _symbol_dev.Symbol.unvalidated(name); | 75 return new _symbol_dev.Symbol.unvalidated(name); |
32 } | 76 } |
33 | 77 |
34 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { | 78 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { |
35 if (owner == null) return simpleName; | 79 if (owner == null) return simpleName; |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 ClassMirror get superclass { | 547 ClassMirror get superclass { |
504 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; | 548 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass; |
505 } | 549 } |
506 | 550 |
507 var _superinterfaces; | 551 var _superinterfaces; |
508 List<ClassMirror> get superinterfaces { | 552 List<ClassMirror> get superinterfaces { |
509 if (_superinterfaces == null) { | 553 if (_superinterfaces == null) { |
510 _superinterfaces = isOriginalDeclaration | 554 _superinterfaces = isOriginalDeclaration |
511 ? _nativeInterfaces(_reflectedType) | 555 ? _nativeInterfaces(_reflectedType) |
512 : _nativeInterfacesInstantiated(_reflectedType); | 556 : _nativeInterfacesInstantiated(_reflectedType); |
513 _superinterfaces = _superinterfaces | 557 _superinterfaces = |
514 .map((i) => reflectType(i)).toList(growable:false); | 558 new UnmodifiableListView(_superinterfaces.map(reflectType)); |
515 } | 559 } |
516 return _superinterfaces; | 560 return _superinterfaces; |
517 } | 561 } |
518 | 562 |
519 get _mixinApplicationName { | 563 get _mixinApplicationName { |
520 var mixins = new List<ClassMirror>(); | 564 var mixins = new List<ClassMirror>(); |
521 var klass = this; | 565 var klass = this; |
522 while (_nativeMixin(klass._reflectedType) != null) { | 566 while (_nativeMixin(klass._reflectedType) != null) { |
523 mixins.add(klass.mixin); | 567 mixins.add(klass.mixin); |
524 klass = klass.superclass; | 568 klass = klass.superclass; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 | 658 |
615 bool get _isAnonymousMixinApplication { | 659 bool get _isAnonymousMixinApplication { |
616 if (_isMixinTypedef) return false; // Named mixin application. | 660 if (_isMixinTypedef) return false; // Named mixin application. |
617 if (mixin == this) return false; // Not a mixin application. | 661 if (mixin == this) return false; // Not a mixin application. |
618 return true; | 662 return true; |
619 } | 663 } |
620 | 664 |
621 List<TypeVariableMirror> _typeVariables = null; | 665 List<TypeVariableMirror> _typeVariables = null; |
622 List<TypeVariableMirror> get typeVariables { | 666 List<TypeVariableMirror> get typeVariables { |
623 if (_typeVariables == null) { | 667 if (_typeVariables == null) { |
668 if (_isAnonymousMixinApplication) return _typeVariables = emptyList; | |
624 _typeVariables = new List<TypeVariableMirror>(); | 669 _typeVariables = new List<TypeVariableMirror>(); |
625 if (_isAnonymousMixinApplication) return _typeVariables; | |
626 | 670 |
627 List params = _ClassMirror_type_variables(_reflectee); | 671 List params = _ClassMirror_type_variables(_reflectee); |
628 var mirror; | 672 var mirror; |
629 for (var i = 0; i < params.length; i += 2) { | 673 for (var i = 0; i < params.length; i += 2) { |
630 mirror = new _LocalTypeVariableMirrorImpl( | 674 mirror = new _LocalTypeVariableMirrorImpl( |
631 params[i + 1], params[i], this); | 675 params[i + 1], params[i], this); |
632 _typeVariables.add(mirror); | 676 _typeVariables.add(mirror); |
633 } | 677 } |
678 _typeVariables = new UnmodifiableListView(_typeVariables); | |
634 } | 679 } |
635 return _typeVariables; | 680 return _typeVariables; |
636 } | 681 } |
637 | 682 |
638 List<TypeMirror> _typeArguments = null; | 683 List<TypeMirror> _typeArguments = null; |
639 List<TypeMirror> get typeArguments { | 684 List<TypeMirror> get typeArguments { |
640 if(_typeArguments == null) { | 685 if(_typeArguments == null) { |
641 if(_isGenericDeclaration || _isAnonymousMixinApplication) { | 686 if(_isGenericDeclaration || _isAnonymousMixinApplication) { |
642 _typeArguments = new List<TypeMirror>(); | 687 _typeArguments = emptyList; |
643 } else { | 688 } else { |
644 _typeArguments = | 689 _typeArguments = |
645 new List<TypeMirror>.from(_computeTypeArguments(_reflectedType)); | 690 new UnmodifiableListView(_computeTypeArguments(_reflectedType)); |
646 } | 691 } |
647 } | 692 } |
648 return _typeArguments; | 693 return _typeArguments; |
649 } | 694 } |
650 | 695 |
651 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; | 696 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; |
652 | 697 |
653 ClassMirror get originalDeclaration { | 698 ClassMirror get originalDeclaration { |
654 if (isOriginalDeclaration) { | 699 if (isOriginalDeclaration) { |
655 return this; | 700 return this; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
693 return new Future(() { | 738 return new Future(() { |
694 return this.newInstance(constructorName, | 739 return this.newInstance(constructorName, |
695 _unwrapAsyncPositionals(positionalArguments), | 740 _unwrapAsyncPositionals(positionalArguments), |
696 _unwrapAsyncNamed(namedArguments)); | 741 _unwrapAsyncNamed(namedArguments)); |
697 }); | 742 }); |
698 } | 743 } |
699 | 744 |
700 List<InstanceMirror> get metadata { | 745 List<InstanceMirror> get metadata { |
701 // Get the metadata objects, convert them into InstanceMirrors using | 746 // Get the metadata objects, convert them into InstanceMirrors using |
702 // reflect() and then make them into a Dart list. | 747 // reflect() and then make them into a Dart list. |
703 return _metadata(_reflectee).map(reflect).toList(growable:false); | 748 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
704 } | 749 } |
705 | 750 |
706 bool operator ==(other) { | 751 bool operator ==(other) { |
707 return this.runtimeType == other.runtimeType && | 752 return this.runtimeType == other.runtimeType && |
708 this._reflectee == other._reflectee && | 753 this._reflectee == other._reflectee && |
709 this._reflectedType == other._reflectedType && | 754 this._reflectedType == other._reflectedType && |
710 this._isGenericDeclaration == other._isGenericDeclaration; | 755 this._isGenericDeclaration == other._isGenericDeclaration; |
711 } | 756 } |
712 | 757 |
713 int get hashCode => simpleName.hashCode; | 758 int get hashCode => simpleName.hashCode; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 return _returnType; | 836 return _returnType; |
792 } | 837 } |
793 | 838 |
794 List<ParameterMirror> _parameters = null; | 839 List<ParameterMirror> _parameters = null; |
795 List<ParameterMirror> get parameters { | 840 List<ParameterMirror> get parameters { |
796 if (_parameters == null) { | 841 if (_parameters == null) { |
797 _parameters = _FunctionTypeMirror_parameters(_reflectee); | 842 _parameters = _FunctionTypeMirror_parameters(_reflectee); |
798 _parameters.forEach((p) { | 843 _parameters.forEach((p) { |
799 p._type = p.type._instantiateInContextOf(reflectType(_instantiator)); | 844 p._type = p.type._instantiateInContextOf(reflectType(_instantiator)); |
800 }); | 845 }); |
846 _parameters = new UnmodifiableListView(_parameters); | |
801 } | 847 } |
802 return _parameters; | 848 return _parameters; |
803 } | 849 } |
804 | 850 |
805 bool get isOriginalDeclaration => true; | 851 bool get isOriginalDeclaration => true; |
806 get originalDeclaration => this; | 852 get originalDeclaration => this; |
807 get typeVariables => []; | 853 get typeVariables => emptyList; |
808 get typeArguments => []; | 854 get typeArguments => emptyList; |
809 get metadata => []; | 855 get metadata => emptyList; |
810 | 856 Map<Symbol, Mirror> get members => emptyMap; |
811 Map<Symbol, Mirror> get members => new Map<Symbol,Mirror>(); | 857 Map<Symbol, MethodMirror> get constructors => emptyMap; |
812 Map<Symbol, MethodMirror> get constructors => new Map<Symbol,MethodMirror>(); | |
813 | 858 |
814 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; | 859 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; |
815 | 860 |
816 MethodMirror _FunctionTypeMirror_call_method(reflectee) | 861 MethodMirror _FunctionTypeMirror_call_method(reflectee) |
817 native "FunctionTypeMirror_call_method"; | 862 native "FunctionTypeMirror_call_method"; |
818 | 863 |
819 static Type _FunctionTypeMirror_return_type(reflectee) | 864 static Type _FunctionTypeMirror_return_type(reflectee) |
820 native "FunctionTypeMirror_return_type"; | 865 native "FunctionTypeMirror_return_type"; |
821 | 866 |
822 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) | 867 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) |
(...skipping 13 matching lines...) Expand all Loading... | |
836 Symbol get qualifiedName { | 881 Symbol get qualifiedName { |
837 if (_qualifiedName == null) { | 882 if (_qualifiedName == null) { |
838 _qualifiedName = _computeQualifiedName(owner, simpleName); | 883 _qualifiedName = _computeQualifiedName(owner, simpleName); |
839 } | 884 } |
840 return _qualifiedName; | 885 return _qualifiedName; |
841 } | 886 } |
842 | 887 |
843 List<InstanceMirror> get metadata { | 888 List<InstanceMirror> get metadata { |
844 // Get the metadata objects, convert them into InstanceMirrors using | 889 // Get the metadata objects, convert them into InstanceMirrors using |
845 // reflect() and then make them into a Dart list. | 890 // reflect() and then make them into a Dart list. |
846 return _metadata(_reflectee).map(reflect).toList(growable:false); | 891 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
847 } | 892 } |
848 | 893 |
849 bool operator ==(other) { | 894 bool operator ==(other) { |
850 return this.runtimeType == other.runtimeType && | 895 return this.runtimeType == other.runtimeType && |
851 this._reflectee == other._reflectee; | 896 this._reflectee == other._reflectee; |
852 } | 897 } |
853 | 898 |
854 int get hashCode => simpleName.hashCode; | 899 int get hashCode => simpleName.hashCode; |
855 } | 900 } |
856 | 901 |
(...skipping 25 matching lines...) Expand all Loading... | |
882 TypeMirror get upperBound { | 927 TypeMirror get upperBound { |
883 if (_upperBound == null) { | 928 if (_upperBound == null) { |
884 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); | 929 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); |
885 } | 930 } |
886 return _upperBound; | 931 return _upperBound; |
887 } | 932 } |
888 | 933 |
889 bool get hasReflectedType => false; | 934 bool get hasReflectedType => false; |
890 Type get reflectedType => throw new UnsupportedError() ; | 935 Type get reflectedType => throw new UnsupportedError() ; |
891 | 936 |
892 List<TypeVariableMirror> get typeVariables => new UnmodifiableListView<TypeVar iableMirror>(); | 937 List<TypeVariableMirror> get typeVariables => emptyList; |
893 List<TypeMirror> get typeArguments => new UnmodifiableListView<TypeMirror>(); | 938 List<TypeMirror> get typeArguments => emptyList; |
894 | 939 |
895 bool get isOriginalDeclaration => true; | 940 bool get isOriginalDeclaration => true; |
896 TypeMirror get originalDeclaration => this; | 941 TypeMirror get originalDeclaration => this; |
897 | 942 |
898 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 943 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
899 | 944 |
900 operator ==(other) { | 945 operator ==(other) { |
901 return other is TypeVariableMirror | 946 return other is TypeVariableMirror |
902 && simpleName == other.simpleName | 947 && simpleName == other.simpleName |
903 && owner == other.owner; | 948 && owner == other.owner; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
988 _typeVariables.add(mirror); | 1033 _typeVariables.add(mirror); |
989 } | 1034 } |
990 } | 1035 } |
991 return _typeVariables; | 1036 return _typeVariables; |
992 } | 1037 } |
993 | 1038 |
994 List<TypeMirror> _typeArguments = null; | 1039 List<TypeMirror> _typeArguments = null; |
995 List<TypeMirror> get typeArguments { | 1040 List<TypeMirror> get typeArguments { |
996 if(_typeArguments == null) { | 1041 if(_typeArguments == null) { |
997 if(_isGenericDeclaration) { | 1042 if(_isGenericDeclaration) { |
998 _typeArguments = new List<TypeMirror>(); | 1043 _typeArguments = emptyList; |
999 } else { | 1044 } else { |
1000 _typeArguments = | 1045 _typeArguments = new UnmodifiableListView( |
1001 new List<TypeMirror>.from(_LocalClassMirrorImpl._computeTypeArgument s(_reflectedType)); | 1046 _LocalClassMirrorImpl._computeTypeArguments(_reflectedType)); |
1002 } | 1047 } |
1003 } | 1048 } |
1004 return _typeArguments; | 1049 return _typeArguments; |
1005 } | 1050 } |
1006 | 1051 |
1007 TypeMirror _instantiateInContextOf(declaration) { | 1052 TypeMirror _instantiateInContextOf(declaration) { |
1008 var instantiator = declaration; | 1053 var instantiator = declaration; |
1009 while (instantiator is MethodMirror) instantiator = instantiator.owner; | 1054 while (instantiator is MethodMirror) instantiator = instantiator.owner; |
1010 if (instantiator is LibraryMirror) return this; | 1055 if (instantiator is LibraryMirror) return this; |
1011 if (!(instantiator is ClassMirror || instantiator is TypedefMirror)) | 1056 if (!(instantiator is ClassMirror || instantiator is TypedefMirror)) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1068 Map<Symbol, TypeMirror> get types { | 1113 Map<Symbol, TypeMirror> get types { |
1069 if (_types == null) { | 1114 if (_types == null) { |
1070 _types = _filterMap(members, (key, value) => (value is TypeMirror)); | 1115 _types = _filterMap(members, (key, value) => (value is TypeMirror)); |
1071 } | 1116 } |
1072 return _types; | 1117 return _types; |
1073 } | 1118 } |
1074 | 1119 |
1075 Map<Symbol, ClassMirror> _classes; | 1120 Map<Symbol, ClassMirror> _classes; |
1076 Map<Symbol, ClassMirror> get classes { | 1121 Map<Symbol, ClassMirror> get classes { |
1077 if (_classes == null) { | 1122 if (_classes == null) { |
1078 _classes = _filterMap(members, | 1123 _classes = _filterMap(members, (key, value) => (value is ClassMirror)); |
1079 (key, value) => (value is ClassMirror)); | |
1080 } | 1124 } |
1081 return _classes; | 1125 return _classes; |
1082 } | 1126 } |
1083 | 1127 |
1084 Map<Symbol, MethodMirror> _functions; | 1128 Map<Symbol, MethodMirror> _functions; |
1085 Map<Symbol, MethodMirror> get functions { | 1129 Map<Symbol, MethodMirror> get functions { |
1086 if (_functions == null) { | 1130 if (_functions == null) { |
1087 _functions = _filterMap(members, (key, value) => (value is MethodMirror)); | 1131 _functions = _filterMap(members, (key, value) => (value is MethodMirror)); |
1088 } | 1132 } |
1089 return _functions; | 1133 return _functions; |
(...skipping 20 matching lines...) Expand all Loading... | |
1110 if (_variables == null) { | 1154 if (_variables == null) { |
1111 _variables = _filterMap(members, | 1155 _variables = _filterMap(members, |
1112 (key, value) => (value is VariableMirror)); | 1156 (key, value) => (value is VariableMirror)); |
1113 } | 1157 } |
1114 return _variables; | 1158 return _variables; |
1115 } | 1159 } |
1116 | 1160 |
1117 List<InstanceMirror> get metadata { | 1161 List<InstanceMirror> get metadata { |
1118 // Get the metadata objects, convert them into InstanceMirrors using | 1162 // Get the metadata objects, convert them into InstanceMirrors using |
1119 // reflect() and then make them into a Dart list. | 1163 // reflect() and then make them into a Dart list. |
1120 return _metadata(_reflectee).map(reflect).toList(growable:false); | 1164 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
1121 } | 1165 } |
1122 | 1166 |
1123 bool operator ==(other) { | 1167 bool operator ==(other) { |
1124 return this.runtimeType == other.runtimeType && | 1168 return this.runtimeType == other.runtimeType && |
1125 this._reflectee == other._reflectee; | 1169 this._reflectee == other._reflectee; |
1126 } | 1170 } |
1127 | 1171 |
1128 int get hashCode => simpleName.hashCode; | 1172 int get hashCode => simpleName.hashCode; |
1129 | 1173 |
1130 String toString() => "LibraryMirror on '${_n(simpleName)}'"; | 1174 String toString() => "LibraryMirror on '${_n(simpleName)}'"; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1202 } | 1246 } |
1203 _returnType = _returnType._instantiateInContextOf(owner); | 1247 _returnType = _returnType._instantiateInContextOf(owner); |
1204 } | 1248 } |
1205 return _returnType; | 1249 return _returnType; |
1206 } | 1250 } |
1207 | 1251 |
1208 List<ParameterMirror> _parameters = null; | 1252 List<ParameterMirror> _parameters = null; |
1209 List<ParameterMirror> get parameters { | 1253 List<ParameterMirror> get parameters { |
1210 if (_parameters == null) { | 1254 if (_parameters == null) { |
1211 _parameters = _MethodMirror_parameters(_reflectee); | 1255 _parameters = _MethodMirror_parameters(_reflectee); |
1256 _parameters = new UnmodifiableListView(_parameters); | |
1212 } | 1257 } |
1213 return _parameters; | 1258 return _parameters; |
1214 } | 1259 } |
1215 | 1260 |
1216 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; | 1261 bool get isRegularMethod => !isGetter && !isSetter && !isConstructor; |
1217 | 1262 |
1218 Symbol _constructorName = null; | 1263 Symbol _constructorName = null; |
1219 Symbol get constructorName { | 1264 Symbol get constructorName { |
1220 if (_constructorName == null) { | 1265 if (_constructorName == null) { |
1221 if (!isConstructor) { | 1266 if (!isConstructor) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1337 } | 1382 } |
1338 if (_defaultValue == null) { | 1383 if (_defaultValue == null) { |
1339 _defaultValue = reflect(_defaultValueReflectee); | 1384 _defaultValue = reflect(_defaultValueReflectee); |
1340 } | 1385 } |
1341 return _defaultValue; | 1386 return _defaultValue; |
1342 } | 1387 } |
1343 | 1388 |
1344 bool get hasDefaultValue => _defaultValueReflectee != null; | 1389 bool get hasDefaultValue => _defaultValueReflectee != null; |
1345 | 1390 |
1346 List<InstanceMirror> get metadata { | 1391 List<InstanceMirror> get metadata { |
1347 if ( _unmirroredMetadata == null) return const []; | 1392 if ( _unmirroredMetadata == null) return emptyList; |
1348 return _unmirroredMetadata.map(reflect).toList(growable:false); | 1393 return new UnmodifiableListView(_unmirroredMetadata.map(reflect)); |
1349 } | 1394 } |
1350 | 1395 |
1351 TypeMirror _type = null; | 1396 TypeMirror _type = null; |
1352 TypeMirror get type { | 1397 TypeMirror get type { |
1353 if (_type == null) { | 1398 if (_type == null) { |
1354 _type = reflectType(_ParameterMirror_type(_reflectee, _position)); | 1399 _type = reflectType(_ParameterMirror_type(_reflectee, _position)); |
1355 _type = _type._instantiateInContextOf(owner); | 1400 _type = _type._instantiateInContextOf(owner); |
1356 } | 1401 } |
1357 return _type; | 1402 return _type; |
1358 } | 1403 } |
1359 | 1404 |
1360 String toString() => "ParameterMirror on '${_n(simpleName)}'"; | 1405 String toString() => "ParameterMirror on '${_n(simpleName)}'"; |
1361 | 1406 |
1362 static Type _ParameterMirror_type(_reflectee, _position) | 1407 static Type _ParameterMirror_type(_reflectee, _position) |
1363 native "ParameterMirror_type"; | 1408 native "ParameterMirror_type"; |
1364 } | 1409 } |
1365 | 1410 |
1366 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1411 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl |
1367 implements TypeMirror, DeclarationMirror { | 1412 implements TypeMirror, DeclarationMirror { |
1368 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); | 1413 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); |
1369 | 1414 |
1370 final bool isPrivate = false; | 1415 final bool isPrivate = false; |
1371 final DeclarationMirror owner = null; | 1416 final DeclarationMirror owner = null; |
1372 final Symbol simpleName; | 1417 final Symbol simpleName; |
1373 final bool isTopLevel = true; | 1418 final bool isTopLevel = true; |
1374 // Fixed length 0, therefore immutable. | 1419 // Fixed length 0, therefore immutable. |
1375 final List<InstanceMirror> metadata = new List(0); | 1420 final List<InstanceMirror> metadata = emptyList; |
1376 | 1421 |
1377 SourceLocation get location { | 1422 SourceLocation get location { |
1378 throw new UnimplementedError('TypeMirror.location is not implemented'); | 1423 throw new UnimplementedError('TypeMirror.location is not implemented'); |
1379 } | 1424 } |
1380 | 1425 |
1381 Symbol get qualifiedName => simpleName; | 1426 Symbol get qualifiedName => simpleName; |
1382 | 1427 |
1383 // TODO(11955): Remove once dynamicType and voidType are canonical objects in | 1428 // TODO(11955): Remove once dynamicType and voidType are canonical objects in |
1384 // the object store. | 1429 // the object store. |
1385 bool operator ==(other) { | 1430 bool operator ==(other) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1461 if (typeMirror == null) { | 1506 if (typeMirror == null) { |
1462 typeMirror = makeLocalTypeMirror(key); | 1507 typeMirror = makeLocalTypeMirror(key); |
1463 _instanitationCache[key] = typeMirror; | 1508 _instanitationCache[key] = typeMirror; |
1464 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1509 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1465 _declarationCache[key] = typeMirror; | 1510 _declarationCache[key] = typeMirror; |
1466 } | 1511 } |
1467 } | 1512 } |
1468 return typeMirror; | 1513 return typeMirror; |
1469 } | 1514 } |
1470 } | 1515 } |
OLD | NEW |