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([]); | 9 final emptyList = new UnmodifiableListView([]); |
10 final emptyMap = new _UnmodifiableMapView({}); | 10 final emptyMap = new _UnmodifiableMapView({}); |
11 | 11 |
12 // Copied from js_mirrors, in turn copied from the package | |
13 // "unmodifiable_collection". | |
14 // TODO(14314): Move to dart:collection. | 12 // TODO(14314): Move to dart:collection. |
15 class _UnmodifiableMapView<K, V> implements Map<K, V> { | 13 class _UnmodifiableMapView<K, V> implements Map<K, V> { |
16 Map<K, V> _source; | 14 Map<K, V> _source; |
| 15 |
17 _UnmodifiableMapView(Map<K, V> source) : _source = source; | 16 _UnmodifiableMapView(Map<K, V> source) : _source = source; |
18 | 17 |
19 static void _throw() { | 18 static void _throw() { |
20 throw new UnsupportedError("Cannot modify an unmodifiable Map"); | 19 throw new UnsupportedError("Cannot modify an unmodifiable Map"); |
21 } | 20 } |
22 | 21 |
23 int get length => _source.length; | 22 int get length => _source.length; |
24 | |
25 bool get isEmpty => _source.isEmpty; | 23 bool get isEmpty => _source.isEmpty; |
26 | |
27 bool get isNotEmpty => _source.isNotEmpty; | 24 bool get isNotEmpty => _source.isNotEmpty; |
28 | |
29 V operator [](K key) => _source[key]; | 25 V operator [](K key) => _source[key]; |
30 | |
31 bool containsKey(K key) => _source.containsKey(key); | 26 bool containsKey(K key) => _source.containsKey(key); |
32 | |
33 bool containsValue(V value) => _source.containsValue(value); | 27 bool containsValue(V value) => _source.containsValue(value); |
34 | |
35 void forEach(void f(K key, V value)) => _source.forEach(f); | 28 void forEach(void f(K key, V value)) => _source.forEach(f); |
36 | |
37 Iterable<K> get keys => _source.keys; | 29 Iterable<K> get keys => _source.keys; |
38 | |
39 Iterable<V> get values => _source.values; | 30 Iterable<V> get values => _source.values; |
40 | |
41 void operator []=(K key, V value) => _throw(); | 31 void operator []=(K key, V value) => _throw(); |
42 | |
43 V putIfAbsent(K key, V ifAbsent()) { _throw(); } | 32 V putIfAbsent(K key, V ifAbsent()) { _throw(); } |
44 | |
45 void addAll(Map<K, V> other) => _throw(); | 33 void addAll(Map<K, V> other) => _throw(); |
46 | |
47 V remove(K key) { _throw(); } | 34 V remove(K key) { _throw(); } |
48 | |
49 void clear() => _throw(); | 35 void clear() => _throw(); |
50 } | 36 } |
51 | 37 |
52 class _InternalMirrorError { | 38 class _InternalMirrorError { |
| 39 final String _msg; |
53 const _InternalMirrorError(String this._msg); | 40 const _InternalMirrorError(String this._msg); |
54 String toString() => _msg; | 41 String toString() => _msg; |
55 final String _msg; | |
56 } | 42 } |
57 | 43 |
58 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { | 44 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { |
59 Map new_map = new Map<Symbol, dynamic>(); | 45 Map new_map = new Map<Symbol, dynamic>(); |
60 old_map.forEach((key, value) { | 46 old_map.forEach((key, value) { |
61 if (filter(key, value)) { | 47 if (filter(key, value)) { |
62 new_map[key] = value; | 48 new_map[key] = value; |
63 } | 49 } |
64 }); | 50 }); |
65 return new _UnmodifiableMapView(new_map); | 51 return new _UnmodifiableMapView(new_map); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 99 } |
114 if (found_optional_positional) { | 100 if (found_optional_positional) { |
115 buf.write(']'); | 101 buf.write(']'); |
116 } | 102 } |
117 buf.write(') -> '); | 103 buf.write(') -> '); |
118 buf.write(_n(returnType.qualifiedName)); | 104 buf.write(_n(returnType.qualifiedName)); |
119 return buf.toString(); | 105 return buf.toString(); |
120 } | 106 } |
121 | 107 |
122 List _metadata(reflectee) | 108 List _metadata(reflectee) |
123 native 'DeclarationMirror_metadata'; | 109 native 'DeclarationMirror_metadata'; |
124 | 110 |
125 class _LocalMirrorSystem extends MirrorSystem { | 111 class _LocalMirrorSystem extends MirrorSystem { |
126 // Change parameter back to "this.libraries" when native code is changed. | 112 final Map<Uri, LibraryMirror> libraries; |
| 113 final IsolateMirror isolate; |
| 114 |
127 _LocalMirrorSystem(List<LibraryMirror> libraries, this.isolate) | 115 _LocalMirrorSystem(List<LibraryMirror> libraries, this.isolate) |
128 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable( | 116 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable( |
129 libraries, key: (e) => e.uri); | 117 libraries, key: (e) => e.uri); |
130 | 118 |
131 final Map<Uri, LibraryMirror> libraries; | |
132 final IsolateMirror isolate; | |
133 | |
134 TypeMirror _dynamicType = null; | 119 TypeMirror _dynamicType = null; |
135 TypeMirror get dynamicType { | 120 TypeMirror get dynamicType { |
136 if (_dynamicType == null) { | 121 if (_dynamicType == null) { |
137 _dynamicType = new _SpecialTypeMirror('dynamic'); | 122 _dynamicType = new _SpecialTypeMirror('dynamic'); |
138 } | 123 } |
139 return _dynamicType; | 124 return _dynamicType; |
140 } | 125 } |
141 | 126 |
142 TypeMirror _voidType = null; | 127 TypeMirror _voidType = null; |
143 TypeMirror get voidType { | 128 TypeMirror get voidType { |
144 if (_voidType == null) { | 129 if (_voidType == null) { |
145 _voidType = new _SpecialTypeMirror('void'); | 130 _voidType = new _SpecialTypeMirror('void'); |
146 } | 131 } |
147 return _voidType; | 132 return _voidType; |
148 } | 133 } |
149 | 134 |
150 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; | 135 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; |
151 } | 136 } |
152 | 137 |
153 abstract class _LocalMirror implements Mirror {} | 138 abstract class _LocalMirror implements Mirror {} |
154 | 139 |
155 class _LocalIsolateMirror extends _LocalMirror implements IsolateMirror { | 140 class _LocalIsolateMirror extends _LocalMirror implements IsolateMirror { |
156 _LocalIsolateMirror (this.debugName, this.rootLibrary); | 141 final String debugName; |
| 142 final LibraryMirror rootLibrary; |
157 | 143 |
158 final String debugName; | 144 _LocalIsolateMirror(this.debugName, this.rootLibrary); |
159 final bool isCurrent = true; | 145 |
160 final LibraryMirror rootLibrary; | 146 bool get isCurrent => true; |
161 | 147 |
162 String toString() => "IsolateMirror on '$debugName'"; | 148 String toString() => "IsolateMirror on '$debugName'"; |
163 } | 149 } |
164 | 150 |
165 class _InvocationTrampoline implements Function { | 151 class _InvocationTrampoline implements Function { |
166 ObjectMirror _receiver; | 152 final ObjectMirror _receiver; |
167 Symbol _selector; | 153 final Symbol _selector; |
168 _InvocationTrampoline(this._receiver, this._selector); | 154 _InvocationTrampoline(this._receiver, this._selector); |
169 noSuchMethod(Invocation msg) { | 155 noSuchMethod(Invocation msg) { |
170 if (msg.memberName != #call) return super.noSuchMethod(msg); | 156 if (msg.memberName != #call) return super.noSuchMethod(msg); |
171 return _receiver.invoke(_selector, | 157 return _receiver.invoke(_selector, |
172 msg.positionalArguments, | 158 msg.positionalArguments, |
173 msg.namedArguments); | 159 msg.namedArguments); |
174 } | 160 } |
175 } | 161 } |
176 | 162 |
177 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { | 163 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { |
| 164 final _reflectee; // May be a MirrorReference or an ordinary object. |
| 165 |
178 _LocalObjectMirror(this._reflectee); | 166 _LocalObjectMirror(this._reflectee); |
179 | 167 |
180 final _reflectee; // May be a MirrorReference or an ordinary object. | |
181 | |
182 InstanceMirror invoke(Symbol memberName, | 168 InstanceMirror invoke(Symbol memberName, |
183 List positionalArguments, | 169 List positionalArguments, |
184 [Map<Symbol, dynamic> namedArguments]) { | 170 [Map<Symbol, dynamic> namedArguments]) { |
185 | |
186 int numPositionalArguments = positionalArguments.length; | 171 int numPositionalArguments = positionalArguments.length; |
187 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 172 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
188 int numArguments = numPositionalArguments + numNamedArguments; | 173 int numArguments = numPositionalArguments + numNamedArguments; |
189 List arguments = new List(numArguments); | 174 List arguments = new List(numArguments); |
190 arguments.setRange(0, numPositionalArguments, positionalArguments); | 175 arguments.setRange(0, numPositionalArguments, positionalArguments); |
191 List names = new List(numNamedArguments); | 176 List names = new List(numNamedArguments); |
192 int argumentIndex = numPositionalArguments; | 177 int argumentIndex = numPositionalArguments; |
193 int nameIndex = 0; | 178 int nameIndex = 0; |
194 if (numNamedArguments > 0) { | 179 if (numNamedArguments > 0) { |
195 namedArguments.forEach((name, value) { | 180 namedArguments.forEach((name, value) { |
196 arguments[argumentIndex++] = value; | 181 arguments[argumentIndex++] = value; |
197 names[nameIndex++] = _n(name); | 182 names[nameIndex++] = _n(name); |
198 }); | 183 }); |
199 } | 184 } |
200 | 185 |
201 return reflect(this._invoke(_reflectee, | 186 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); |
202 _n(memberName), | |
203 arguments, | |
204 names)); | |
205 } | 187 } |
206 | 188 |
207 InstanceMirror getField(Symbol memberName) { | 189 InstanceMirror getField(Symbol memberName) { |
208 return reflect(this._invokeGetter(_reflectee, | 190 return reflect(this._invokeGetter(_reflectee, _n(memberName))); |
209 _n(memberName))); | |
210 } | 191 } |
211 | 192 |
212 InstanceMirror setField(Symbol memberName, Object value) { | 193 InstanceMirror setField(Symbol memberName, Object value) { |
213 this._invokeSetter(_reflectee, | 194 this._invokeSetter(_reflectee, _n(memberName), value); |
214 _n(memberName), | |
215 value); | |
216 return reflect(value); | 195 return reflect(value); |
217 } | 196 } |
218 } | 197 } |
219 | 198 |
220 class _LocalInstanceMirror extends _LocalObjectMirror | 199 class _LocalInstanceMirror extends _LocalObjectMirror |
221 implements InstanceMirror { | 200 implements InstanceMirror { |
222 // TODO(ahe): This is a hack, see delegate below. | 201 // TODO(ahe): This is a hack, see delegate below. |
223 static Function _invokeOnClosure; | 202 static Function _invokeOnClosure; |
224 | 203 |
225 _LocalInstanceMirror(reflectee) : super(reflectee); | 204 _LocalInstanceMirror(reflectee) : super(reflectee); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 List names = new List(numNamedArguments); | 275 List names = new List(numNamedArguments); |
297 int argumentIndex = numPositionalArguments; | 276 int argumentIndex = numPositionalArguments; |
298 int nameIndex = 0; | 277 int nameIndex = 0; |
299 if (numNamedArguments > 0) { | 278 if (numNamedArguments > 0) { |
300 namedArguments.forEach((name, value) { | 279 namedArguments.forEach((name, value) { |
301 arguments[argumentIndex++] = value; | 280 arguments[argumentIndex++] = value; |
302 names[nameIndex++] = _n(name); | 281 names[nameIndex++] = _n(name); |
303 }); | 282 }); |
304 } | 283 } |
305 | 284 |
306 return reflect(this._invoke(_reflectee, | 285 return reflect(this._invoke(_reflectee, _n(memberName), arguments, names)); |
307 _n(memberName), | |
308 arguments, | |
309 names)); | |
310 } | 286 } |
311 | 287 |
312 _invoke(reflectee, functionName, arguments, argumentNames) | 288 _invoke(reflectee, functionName, arguments, argumentNames) |
313 native 'InstanceMirror_invoke'; | 289 native 'InstanceMirror_invoke'; |
314 | 290 |
315 _invokeGetter(reflectee, getterName) | 291 _invokeGetter(reflectee, getterName) |
316 native 'InstanceMirror_invokeGetter'; | 292 native 'InstanceMirror_invokeGetter'; |
317 | 293 |
318 _invokeSetter(reflectee, setterName, value) | 294 _invokeSetter(reflectee, setterName, value) |
319 native 'InstanceMirror_invokeSetter'; | 295 native 'InstanceMirror_invokeSetter'; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 | 368 |
393 static _computeFunction(reflectee) | 369 static _computeFunction(reflectee) |
394 native 'ClosureMirror_function'; | 370 native 'ClosureMirror_function'; |
395 | 371 |
396 static _computeFindInContext(reflectee, name) | 372 static _computeFindInContext(reflectee, name) |
397 native 'ClosureMirror_find_in_context'; | 373 native 'ClosureMirror_find_in_context'; |
398 } | 374 } |
399 | 375 |
400 class _LocalClassMirror extends _LocalObjectMirror | 376 class _LocalClassMirror extends _LocalObjectMirror |
401 implements ClassMirror { | 377 implements ClassMirror { |
| 378 final Type _reflectedType; |
| 379 Symbol _simpleName; |
| 380 DeclarationMirror _owner; |
| 381 final bool _isGeneric; |
| 382 final bool _isMixinAlias; |
| 383 final bool _isGenericDeclaration; |
| 384 Type _instantiator; |
| 385 |
402 _LocalClassMirror(reflectee, | 386 _LocalClassMirror(reflectee, |
403 reflectedType, | 387 reflectedType, |
404 String simpleName, | 388 String simpleName, |
405 this._owner, | 389 this._owner, |
406 this._isGeneric, | 390 this._isGeneric, |
407 this._isMixinAlias, | 391 this._isMixinAlias, |
408 this._isGenericDeclaration) | 392 this._isGenericDeclaration) |
409 : this._simpleName = _s(simpleName), | 393 : this._simpleName = _s(simpleName), |
410 this._reflectedType = reflectedType, | 394 this._reflectedType = reflectedType, |
411 this._instantiator = reflectedType, | 395 this._instantiator = reflectedType, |
412 super(reflectee); | 396 super(reflectee); |
413 | 397 |
414 final Type _reflectedType; | |
415 final bool _isGeneric; | |
416 final bool _isMixinAlias; | |
417 final bool _isGenericDeclaration; | |
418 Type _instantiator; | |
419 | 398 |
420 bool get hasReflectedType => !_isGenericDeclaration; | 399 bool get hasReflectedType => !_isGenericDeclaration; |
421 Type get reflectedType { | 400 Type get reflectedType { |
422 if (!hasReflectedType) { | 401 if (!hasReflectedType) { |
423 throw new UnsupportedError( | 402 throw new UnsupportedError( |
424 "Declarations of generics have no reflected type"); | 403 "Declarations of generics have no reflected type"); |
425 } | 404 } |
426 return _reflectedType; | 405 return _reflectedType; |
427 } | 406 } |
428 | 407 |
429 Symbol _simpleName; | |
430 Symbol get simpleName { | 408 Symbol get simpleName { |
431 // All but anonymous mixin applications have their name set at construction. | 409 // All but anonymous mixin applications have their name set at construction. |
432 if(_simpleName == null) { | 410 if(_simpleName == null) { |
433 _simpleName = this._mixinApplicationName; | 411 _simpleName = this._mixinApplicationName; |
434 } | 412 } |
435 return _simpleName; | 413 return _simpleName; |
436 } | 414 } |
437 | 415 |
438 Symbol _qualifiedName = null; | 416 Symbol _qualifiedName = null; |
439 Symbol get qualifiedName { | 417 Symbol get qualifiedName { |
440 if (_qualifiedName == null) { | 418 if (_qualifiedName == null) { |
441 _qualifiedName = _computeQualifiedName(owner, simpleName); | 419 _qualifiedName = _computeQualifiedName(owner, simpleName); |
442 } | 420 } |
443 return _qualifiedName; | 421 return _qualifiedName; |
444 } | 422 } |
445 | 423 |
446 var _owner; | |
447 DeclarationMirror get owner { | 424 DeclarationMirror get owner { |
448 if (_owner == null) { | 425 if (_owner == null) { |
449 _owner = _library(_reflectee); | 426 _owner = _library(_reflectee); |
450 } | 427 } |
451 return _owner; | 428 return _owner; |
452 } | 429 } |
453 | 430 |
454 bool get isPrivate => _n(simpleName).startsWith('_'); | 431 bool get isPrivate => _n(simpleName).startsWith('_'); |
455 | 432 |
456 final bool isTopLevel = true; | 433 final bool isTopLevel = true; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 | 786 |
810 static Type _FunctionTypeMirror_return_type(reflectee, instantiator) | 787 static Type _FunctionTypeMirror_return_type(reflectee, instantiator) |
811 native "FunctionTypeMirror_return_type"; | 788 native "FunctionTypeMirror_return_type"; |
812 | 789 |
813 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) | 790 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) |
814 native "FunctionTypeMirror_parameters"; | 791 native "FunctionTypeMirror_parameters"; |
815 } | 792 } |
816 | 793 |
817 abstract class _LocalDeclarationMirror extends _LocalMirror | 794 abstract class _LocalDeclarationMirror extends _LocalMirror |
818 implements DeclarationMirror { | 795 implements DeclarationMirror { |
| 796 final _reflectee; |
| 797 Symbol _simpleName; |
| 798 |
819 _LocalDeclarationMirror(this._reflectee, this._simpleName); | 799 _LocalDeclarationMirror(this._reflectee, this._simpleName); |
820 | 800 |
821 final _reflectee; | |
822 | |
823 Symbol _simpleName; | |
824 Symbol get simpleName => _simpleName; | 801 Symbol get simpleName => _simpleName; |
825 | 802 |
826 Symbol _qualifiedName = null; | 803 Symbol _qualifiedName = null; |
827 Symbol get qualifiedName { | 804 Symbol get qualifiedName { |
828 if (_qualifiedName == null) { | 805 if (_qualifiedName == null) { |
829 _qualifiedName = _computeQualifiedName(owner, simpleName); | 806 _qualifiedName = _computeQualifiedName(owner, simpleName); |
830 } | 807 } |
831 return _qualifiedName; | 808 return _qualifiedName; |
832 } | 809 } |
833 | 810 |
(...skipping 21 matching lines...) Expand all Loading... |
855 DeclarationMirror _owner; | 832 DeclarationMirror _owner; |
856 DeclarationMirror get owner { | 833 DeclarationMirror get owner { |
857 if (_owner == null) { | 834 if (_owner == null) { |
858 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; | 835 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; |
859 } | 836 } |
860 return _owner; | 837 return _owner; |
861 } | 838 } |
862 | 839 |
863 bool get isPrivate => false; | 840 bool get isPrivate => false; |
864 bool get isStatic => false; | 841 bool get isStatic => false; |
865 | 842 bool get isTopLevel => false; |
866 final bool isTopLevel = false; | |
867 | 843 |
868 SourceLocation get location { | 844 SourceLocation get location { |
869 throw new UnimplementedError( | 845 throw new UnimplementedError( |
870 'TypeVariableMirror.location is not implemented'); | 846 'TypeVariableMirror.location is not implemented'); |
871 } | 847 } |
872 | 848 |
873 TypeMirror _upperBound = null; | 849 TypeMirror _upperBound = null; |
874 TypeMirror get upperBound { | 850 TypeMirror get upperBound { |
875 if (_upperBound == null) { | 851 if (_upperBound == null) { |
876 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); | 852 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); |
(...skipping 22 matching lines...) Expand all Loading... |
899 static DeclarationMirror _TypeVariableMirror_owner(reflectee) | 875 static DeclarationMirror _TypeVariableMirror_owner(reflectee) |
900 native "TypeVariableMirror_owner"; | 876 native "TypeVariableMirror_owner"; |
901 | 877 |
902 static Type _TypeVariableMirror_upper_bound(reflectee) | 878 static Type _TypeVariableMirror_upper_bound(reflectee) |
903 native "TypeVariableMirror_upper_bound"; | 879 native "TypeVariableMirror_upper_bound"; |
904 } | 880 } |
905 | 881 |
906 | 882 |
907 class _LocalTypedefMirror extends _LocalDeclarationMirror | 883 class _LocalTypedefMirror extends _LocalDeclarationMirror |
908 implements TypedefMirror { | 884 implements TypedefMirror { |
| 885 final Type _reflectedType; |
| 886 final bool _isGeneric; |
| 887 final bool _isGenericDeclaration; |
| 888 |
909 _LocalTypedefMirror(reflectee, | 889 _LocalTypedefMirror(reflectee, |
910 this._reflectedType, | 890 this._reflectedType, |
911 String simpleName, | 891 String simpleName, |
912 this._isGeneric, | 892 this._isGeneric, |
913 this._isGenericDeclaration, | 893 this._isGenericDeclaration, |
914 this._owner) | 894 this._owner) |
915 : super(reflectee, _s(simpleName)); | 895 : super(reflectee, _s(simpleName)); |
916 | 896 |
917 final Type _reflectedType; | |
918 final bool _isGeneric; | |
919 final bool _isGenericDeclaration; | |
920 | |
921 bool get isTopLevel => true; | 897 bool get isTopLevel => true; |
922 bool get isPrivate => false; | 898 bool get isPrivate => false; |
923 | 899 |
924 DeclarationMirror _owner; | 900 DeclarationMirror _owner; |
925 DeclarationMirror get owner { | 901 DeclarationMirror get owner { |
926 if (_owner == null) { | 902 if (_owner == null) { |
927 _owner = _LocalClassMirror._library(_reflectee); | 903 _owner = _LocalClassMirror._library(_reflectee); |
928 } | 904 } |
929 return _owner; | 905 return _owner; |
930 } | 906 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 | 961 |
986 static _nativeReferent(reflectedType) | 962 static _nativeReferent(reflectedType) |
987 native "TypedefMirror_referent"; | 963 native "TypedefMirror_referent"; |
988 | 964 |
989 static _nativeDeclaration(reflectedType) | 965 static _nativeDeclaration(reflectedType) |
990 native "TypedefMirror_declaration"; | 966 native "TypedefMirror_declaration"; |
991 } | 967 } |
992 | 968 |
993 class _LocalLibraryMirror extends _LocalObjectMirror | 969 class _LocalLibraryMirror extends _LocalObjectMirror |
994 implements LibraryMirror { | 970 implements LibraryMirror { |
| 971 final Symbol simpleName; |
| 972 final Uri uri; |
| 973 |
995 _LocalLibraryMirror(reflectee, | 974 _LocalLibraryMirror(reflectee, |
996 String simpleName, | 975 String simpleName, |
997 String url) | 976 String url) |
998 : this.simpleName = _s(simpleName), | 977 : this.simpleName = _s(simpleName), |
999 this.uri = Uri.parse(url), | 978 this.uri = Uri.parse(url), |
1000 super(reflectee); | 979 super(reflectee); |
1001 | 980 |
1002 final Symbol simpleName; | |
1003 | |
1004 // The simple name and the qualified name are the same for a library. | 981 // The simple name and the qualified name are the same for a library. |
1005 Symbol get qualifiedName => simpleName; | 982 Symbol get qualifiedName => simpleName; |
1006 | 983 |
1007 // Always null for libraries. | 984 DeclarationMirror get owner => null; |
1008 final DeclarationMirror owner = null; | |
1009 | 985 |
1010 // Always false for libraries. | 986 bool get isPrivate => false; |
1011 final bool isPrivate = false; | 987 bool get isTopLevel => false; |
1012 | |
1013 // Always false for libraries. | |
1014 final bool isTopLevel = false; | |
1015 | 988 |
1016 Type get _instantiator => null; | 989 Type get _instantiator => null; |
1017 | 990 |
1018 SourceLocation get location { | 991 SourceLocation get location { |
1019 throw new UnimplementedError('LibraryMirror.location is not implemented'); | 992 throw new UnimplementedError('LibraryMirror.location is not implemented'); |
1020 } | 993 } |
1021 | 994 |
1022 final Uri uri; | |
1023 | |
1024 Map<Symbol, DeclarationMirror> _declarations; | 995 Map<Symbol, DeclarationMirror> _declarations; |
1025 Map<Symbol, DeclarationMirror> get declarations { | 996 Map<Symbol, DeclarationMirror> get declarations { |
1026 if (_declarations != null) return _declarations; | 997 if (_declarations != null) return _declarations; |
1027 return _declarations = | 998 return _declarations = |
1028 new _UnmodifiableMapView<Symbol, DeclarationMirror>(members); | 999 new _UnmodifiableMapView<Symbol, DeclarationMirror>(members); |
1029 } | 1000 } |
1030 | 1001 |
1031 Map<Symbol, Mirror> _members; | 1002 Map<Symbol, Mirror> _members; |
1032 Map<Symbol, Mirror> get members { | 1003 Map<Symbol, Mirror> get members { |
1033 if (_members == null) { | 1004 if (_members == null) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 | 1089 |
1119 _invokeSetter(reflectee, setterName, value) | 1090 _invokeSetter(reflectee, setterName, value) |
1120 native 'LibraryMirror_invokeSetter'; | 1091 native 'LibraryMirror_invokeSetter'; |
1121 | 1092 |
1122 _computeMembers(reflectee) | 1093 _computeMembers(reflectee) |
1123 native "LibraryMirror_members"; | 1094 native "LibraryMirror_members"; |
1124 } | 1095 } |
1125 | 1096 |
1126 class _LocalMethodMirror extends _LocalDeclarationMirror | 1097 class _LocalMethodMirror extends _LocalDeclarationMirror |
1127 implements MethodMirror { | 1098 implements MethodMirror { |
| 1099 final bool isStatic; |
| 1100 final bool isAbstract; |
| 1101 final bool isGetter; |
| 1102 final bool isSetter; |
| 1103 final bool isConstructor; |
| 1104 final bool isConstConstructor; |
| 1105 final bool isGenerativeConstructor; |
| 1106 final bool isRedirectingConstructor; |
| 1107 final bool isFactoryConstructor; |
| 1108 final bool isOperator; |
| 1109 |
| 1110 static const _operators = const ["%", "&", "*", "+", "-", "/", "<", "<<", |
| 1111 "<=", "==", ">", ">=", ">>", "[]", "[]=", "^", "|", "~", "unary-", "~/"]; |
| 1112 |
1128 _LocalMethodMirror(reflectee, | 1113 _LocalMethodMirror(reflectee, |
1129 String simpleName, | 1114 String simpleName, |
1130 this._owner, | 1115 this._owner, |
1131 this.isStatic, | 1116 this.isStatic, |
1132 this.isAbstract, | 1117 this.isAbstract, |
1133 this.isGetter, | 1118 this.isGetter, |
1134 this.isSetter, | 1119 this.isSetter, |
1135 this.isConstructor, | 1120 this.isConstructor, |
1136 this.isConstConstructor, | 1121 this.isConstConstructor, |
1137 this.isGenerativeConstructor, | 1122 this.isGenerativeConstructor, |
1138 this.isRedirectingConstructor, | 1123 this.isRedirectingConstructor, |
1139 this.isFactoryConstructor) | 1124 this.isFactoryConstructor) |
1140 : this.isOperator = _operators.contains(simpleName), | 1125 : this.isOperator = _operators.contains(simpleName), |
1141 super(reflectee, _s(simpleName)); | 1126 super(reflectee, _s(simpleName)); |
1142 | 1127 |
1143 static const _operators = const ["%", "&", "*", "+", "-", "/", "<", "<<", | |
1144 "<=", "==", ">", ">=", ">>", "[]", "[]=", "^", "|", "~", "unary-", "~/"]; | |
1145 | |
1146 final bool isStatic; | |
1147 final bool isAbstract; | |
1148 final bool isGetter; | |
1149 final bool isSetter; | |
1150 final bool isConstructor; | |
1151 final bool isConstConstructor; | |
1152 final bool isGenerativeConstructor; | |
1153 final bool isRedirectingConstructor; | |
1154 final bool isFactoryConstructor; | |
1155 final bool isOperator; | |
1156 | |
1157 DeclarationMirror _owner; | 1128 DeclarationMirror _owner; |
1158 DeclarationMirror get owner { | 1129 DeclarationMirror get owner { |
1159 // For nested closures it is possible, that the mirror for the owner has not | 1130 // For nested closures it is possible, that the mirror for the owner has not |
1160 // been created yet. | 1131 // been created yet. |
1161 if (_owner == null) { | 1132 if (_owner == null) { |
1162 _owner = _MethodMirror_owner(_reflectee); | 1133 _owner = _MethodMirror_owner(_reflectee); |
1163 } | 1134 } |
1164 return _owner; | 1135 return _owner; |
1165 } | 1136 } |
1166 | 1137 |
1167 bool get isPrivate => _n(simpleName).startsWith('_') || | 1138 bool get isPrivate => _n(simpleName).startsWith('_') || |
1168 _n(constructorName).startsWith('_'); | 1139 _n(constructorName).startsWith('_'); |
1169 | 1140 |
1170 bool get isTopLevel => owner is LibraryMirror; | 1141 bool get isTopLevel => owner is LibraryMirror; |
1171 | 1142 |
1172 SourceLocation get location { | 1143 SourceLocation get location { |
1173 throw new UnimplementedError('MethodMirror.location is not implemented'); | 1144 throw new UnimplementedError('MethodMirror.location is not implemented'); |
1174 } | 1145 } |
1175 | 1146 |
1176 Type get _instantiator { | 1147 Type get _instantiator { |
1177 var o = owner; | 1148 var o = owner; |
1178 while (o is MethodMirror) o = o.owner; | 1149 while (o is MethodMirror) o = o.owner; |
1179 return o._instantiator; | 1150 return o._instantiator; |
1180 } | 1151 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 | 1224 |
1254 List<ParameterMirror> _MethodMirror_parameters(reflectee) | 1225 List<ParameterMirror> _MethodMirror_parameters(reflectee) |
1255 native "MethodMirror_parameters"; | 1226 native "MethodMirror_parameters"; |
1256 | 1227 |
1257 static String _MethodMirror_source(reflectee) | 1228 static String _MethodMirror_source(reflectee) |
1258 native "MethodMirror_source"; | 1229 native "MethodMirror_source"; |
1259 } | 1230 } |
1260 | 1231 |
1261 class _LocalVariableMirror extends _LocalDeclarationMirror | 1232 class _LocalVariableMirror extends _LocalDeclarationMirror |
1262 implements VariableMirror { | 1233 implements VariableMirror { |
| 1234 final DeclarationMirror owner; |
| 1235 final bool isStatic; |
| 1236 final bool isFinal; |
| 1237 final bool isConst; |
| 1238 |
1263 _LocalVariableMirror(reflectee, | 1239 _LocalVariableMirror(reflectee, |
1264 String simpleName, | 1240 String simpleName, |
1265 this.owner, | 1241 this.owner, |
1266 this._type, | 1242 this._type, |
1267 this.isStatic, | 1243 this.isStatic, |
1268 this.isFinal, | 1244 this.isFinal, |
1269 this.isConst) | 1245 this.isConst) |
1270 : super(reflectee, _s(simpleName)); | 1246 : super(reflectee, _s(simpleName)); |
1271 | 1247 |
1272 final DeclarationMirror owner; | |
1273 final bool isStatic; | |
1274 final bool isFinal; | |
1275 final bool isConst; | |
1276 | |
1277 bool get isPrivate => _n(simpleName).startsWith('_'); | 1248 bool get isPrivate => _n(simpleName).startsWith('_'); |
1278 | 1249 |
1279 bool get isTopLevel => owner is LibraryMirror; | 1250 bool get isTopLevel => owner is LibraryMirror; |
1280 | 1251 |
1281 SourceLocation get location { | 1252 SourceLocation get location { |
1282 throw new UnimplementedError('VariableMirror.location is not implemented'); | 1253 throw new UnimplementedError('VariableMirror.location is not implemented'); |
1283 } | 1254 } |
1284 | 1255 |
1285 Type get _instantiator { | 1256 Type get _instantiator { |
1286 return owner._instantiator; | 1257 return owner._instantiator; |
1287 } | 1258 } |
1288 | 1259 |
1289 TypeMirror _type; | 1260 TypeMirror _type; |
1290 TypeMirror get type { | 1261 TypeMirror get type { |
1291 if (_type == null) { | 1262 if (_type == null) { |
1292 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator)); | 1263 _type = reflectType(_VariableMirror_type(_reflectee, _instantiator)); |
1293 } | 1264 } |
1294 return _type; | 1265 return _type; |
1295 } | 1266 } |
1296 | 1267 |
1297 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'"
; | 1268 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'"
; |
1298 | 1269 |
1299 static _VariableMirror_type(reflectee, instantiator) | 1270 static _VariableMirror_type(reflectee, instantiator) |
1300 native "VariableMirror_type"; | 1271 native "VariableMirror_type"; |
1301 } | 1272 } |
1302 | 1273 |
1303 class _LocalParameterMirror extends _LocalVariableMirror | 1274 class _LocalParameterMirror extends _LocalVariableMirror |
1304 implements ParameterMirror { | 1275 implements ParameterMirror { |
| 1276 final int _position; |
| 1277 final bool isOptional; |
| 1278 final bool isNamed; |
| 1279 final List _unmirroredMetadata; |
| 1280 |
1305 _LocalParameterMirror(reflectee, | 1281 _LocalParameterMirror(reflectee, |
1306 String simpleName, | 1282 String simpleName, |
1307 DeclarationMirror owner, | 1283 DeclarationMirror owner, |
1308 this._position, | 1284 this._position, |
1309 this.isOptional, | 1285 this.isOptional, |
1310 this.isNamed, | 1286 this.isNamed, |
1311 bool isFinal, | 1287 bool isFinal, |
1312 this._defaultValueReflectee, | 1288 this._defaultValueReflectee, |
1313 this._unmirroredMetadata) | 1289 this._unmirroredMetadata) |
1314 : super(reflectee, | 1290 : super(reflectee, |
1315 simpleName, | 1291 simpleName, |
1316 owner, | 1292 owner, |
1317 null, // We override the type. | 1293 null, // We override the type. |
1318 false, // isStatic does not apply. | 1294 false, // isStatic does not apply. |
1319 isFinal, | 1295 isFinal, |
1320 false // Not const. | 1296 false // Not const. |
1321 ); | 1297 ); |
1322 | 1298 |
1323 final int _position; | |
1324 final bool isOptional; | |
1325 final bool isNamed; | |
1326 final List _unmirroredMetadata; | |
1327 | |
1328 Object _defaultValueReflectee; | 1299 Object _defaultValueReflectee; |
1329 InstanceMirror _defaultValue; | 1300 InstanceMirror _defaultValue; |
1330 InstanceMirror get defaultValue { | 1301 InstanceMirror get defaultValue { |
1331 if (!isOptional) { | 1302 if (!isOptional) { |
1332 return null; | 1303 return null; |
1333 } | 1304 } |
1334 if (_defaultValue == null) { | 1305 if (_defaultValue == null) { |
1335 _defaultValue = reflect(_defaultValueReflectee); | 1306 _defaultValue = reflect(_defaultValueReflectee); |
1336 } | 1307 } |
1337 return _defaultValue; | 1308 return _defaultValue; |
(...skipping 22 matching lines...) Expand all Loading... |
1360 } | 1331 } |
1361 | 1332 |
1362 String toString() => "ParameterMirror on '${_n(simpleName)}'"; | 1333 String toString() => "ParameterMirror on '${_n(simpleName)}'"; |
1363 | 1334 |
1364 static Type _ParameterMirror_type(_reflectee, _position, instantiator) | 1335 static Type _ParameterMirror_type(_reflectee, _position, instantiator) |
1365 native "ParameterMirror_type"; | 1336 native "ParameterMirror_type"; |
1366 } | 1337 } |
1367 | 1338 |
1368 class _SpecialTypeMirror extends _LocalMirror | 1339 class _SpecialTypeMirror extends _LocalMirror |
1369 implements TypeMirror, DeclarationMirror { | 1340 implements TypeMirror, DeclarationMirror { |
| 1341 final Symbol simpleName; |
| 1342 |
1370 _SpecialTypeMirror(String name) : simpleName = _s(name); | 1343 _SpecialTypeMirror(String name) : simpleName = _s(name); |
1371 | 1344 |
1372 final bool isPrivate = false; | 1345 bool get isPrivate => false; |
1373 final DeclarationMirror owner = null; | 1346 bool get isTopLevel => true; |
1374 final Symbol simpleName; | 1347 |
1375 final bool isTopLevel = true; | 1348 DeclarationMirror get owner => null; |
1376 final List<InstanceMirror> metadata = emptyList; | 1349 |
| 1350 List<InstanceMirror> get metadata => emptyList; |
1377 | 1351 |
1378 List<TypeVariableMirror> get typeVariables => emptyList; | 1352 List<TypeVariableMirror> get typeVariables => emptyList; |
1379 List<TypeMirror> get typeArguments => emptyList; | 1353 List<TypeMirror> get typeArguments => emptyList; |
1380 | 1354 |
1381 bool get isOriginalDeclaration => true; | 1355 bool get isOriginalDeclaration => true; |
1382 TypeMirror get originalDeclaration => this; | 1356 TypeMirror get originalDeclaration => this; |
1383 | 1357 |
1384 SourceLocation get location { | 1358 SourceLocation get location { |
1385 throw new UnimplementedError('TypeMirror.location is not implemented'); | 1359 throw new UnimplementedError('TypeMirror.location is not implemented'); |
1386 } | 1360 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1451 if (typeMirror == null) { | 1425 if (typeMirror == null) { |
1452 typeMirror = makeLocalTypeMirror(key); | 1426 typeMirror = makeLocalTypeMirror(key); |
1453 _instanitationCache[key] = typeMirror; | 1427 _instanitationCache[key] = typeMirror; |
1454 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1428 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1455 _declarationCache[key] = typeMirror; | 1429 _declarationCache[key] = typeMirror; |
1456 } | 1430 } |
1457 } | 1431 } |
1458 return typeMirror; | 1432 return typeMirror; |
1459 } | 1433 } |
1460 } | 1434 } |
OLD | NEW |