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({}); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 buf.write(']'); | 115 buf.write(']'); |
116 } | 116 } |
117 buf.write(') -> '); | 117 buf.write(') -> '); |
118 buf.write(_n(returnType.qualifiedName)); | 118 buf.write(_n(returnType.qualifiedName)); |
119 return buf.toString(); | 119 return buf.toString(); |
120 } | 120 } |
121 | 121 |
122 List _metadata(reflectee) | 122 List _metadata(reflectee) |
123 native 'DeclarationMirror_metadata'; | 123 native 'DeclarationMirror_metadata'; |
124 | 124 |
125 class _LocalMirrorSystemImpl extends MirrorSystem { | 125 class _LocalMirrorSystem extends MirrorSystem { |
126 // Change parameter back to "this.libraries" when native code is changed. | 126 // Change parameter back to "this.libraries" when native code is changed. |
127 _LocalMirrorSystemImpl(List<LibraryMirror> libraries, this.isolate) | 127 _LocalMirrorSystem(List<LibraryMirror> libraries, this.isolate) |
128 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable( | 128 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable( |
129 libraries, key: (e) => e.uri); | 129 libraries, key: (e) => e.uri); |
130 | 130 |
131 final Map<Uri, LibraryMirror> libraries; | 131 final Map<Uri, LibraryMirror> libraries; |
132 final IsolateMirror isolate; | 132 final IsolateMirror isolate; |
133 | 133 |
134 TypeMirror _dynamicType = null; | 134 TypeMirror _dynamicType = null; |
135 TypeMirror get dynamicType { | 135 TypeMirror get dynamicType { |
136 if (_dynamicType == null) { | 136 if (_dynamicType == null) { |
137 _dynamicType = new _SpecialTypeMirrorImpl('dynamic'); | 137 _dynamicType = new _SpecialTypeMirror('dynamic'); |
138 } | 138 } |
139 return _dynamicType; | 139 return _dynamicType; |
140 } | 140 } |
141 | 141 |
142 TypeMirror _voidType = null; | 142 TypeMirror _voidType = null; |
143 TypeMirror get voidType { | 143 TypeMirror get voidType { |
144 if (_voidType == null) { | 144 if (_voidType == null) { |
145 _voidType = new _SpecialTypeMirrorImpl('void'); | 145 _voidType = new _SpecialTypeMirror('void'); |
146 } | 146 } |
147 return _voidType; | 147 return _voidType; |
148 } | 148 } |
149 | 149 |
150 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; | 150 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; |
151 } | 151 } |
152 | 152 |
153 abstract class _LocalMirrorImpl implements Mirror {} | 153 abstract class _LocalMirror implements Mirror {} |
154 | 154 |
155 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl | 155 class _LocalIsolateMirror extends _LocalMirror implements IsolateMirror { |
156 implements IsolateMirror { | 156 _LocalIsolateMirror (this.debugName, this.rootLibrary); |
157 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary); | |
158 | 157 |
159 final String debugName; | 158 final String debugName; |
160 final bool isCurrent = true; | 159 final bool isCurrent = true; |
161 final LibraryMirror rootLibrary; | 160 final LibraryMirror rootLibrary; |
162 | 161 |
163 String toString() => "IsolateMirror on '$debugName'"; | 162 String toString() => "IsolateMirror on '$debugName'"; |
164 } | 163 } |
165 | 164 |
166 class _InvocationTrampoline implements Function { | 165 class _InvocationTrampoline implements Function { |
167 ObjectMirror _receiver; | 166 ObjectMirror _receiver; |
168 Symbol _selector; | 167 Symbol _selector; |
169 _InvocationTrampoline(this._receiver, this._selector); | 168 _InvocationTrampoline(this._receiver, this._selector); |
170 noSuchMethod(Invocation msg) { | 169 noSuchMethod(Invocation msg) { |
171 if (msg.memberName != #call) return super.noSuchMethod(msg); | 170 if (msg.memberName != #call) return super.noSuchMethod(msg); |
172 return _receiver.invoke(_selector, | 171 return _receiver.invoke(_selector, |
173 msg.positionalArguments, | 172 msg.positionalArguments, |
174 msg.namedArguments); | 173 msg.namedArguments); |
175 } | 174 } |
176 } | 175 } |
177 | 176 |
178 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl | 177 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { |
179 implements ObjectMirror { | 178 _LocalObjectMirror(this._reflectee); |
180 _LocalObjectMirrorImpl(this._reflectee); | |
181 | 179 |
182 final _reflectee; // May be a MirrorReference or an ordinary object. | 180 final _reflectee; // May be a MirrorReference or an ordinary object. |
183 | 181 |
184 InstanceMirror invoke(Symbol memberName, | 182 InstanceMirror invoke(Symbol memberName, |
185 List positionalArguments, | 183 List positionalArguments, |
186 [Map<Symbol, dynamic> namedArguments]) { | 184 [Map<Symbol, dynamic> namedArguments]) { |
187 | 185 |
188 int numPositionalArguments = positionalArguments.length; | 186 int numPositionalArguments = positionalArguments.length; |
189 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; | 187 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; |
190 int numArguments = numPositionalArguments + numNamedArguments; | 188 int numArguments = numPositionalArguments + numNamedArguments; |
(...skipping 21 matching lines...) Expand all Loading... |
212 } | 210 } |
213 | 211 |
214 InstanceMirror setField(Symbol memberName, Object value) { | 212 InstanceMirror setField(Symbol memberName, Object value) { |
215 this._invokeSetter(_reflectee, | 213 this._invokeSetter(_reflectee, |
216 _n(memberName), | 214 _n(memberName), |
217 value); | 215 value); |
218 return reflect(value); | 216 return reflect(value); |
219 } | 217 } |
220 } | 218 } |
221 | 219 |
222 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl | 220 class _LocalInstanceMirror extends _LocalObjectMirror |
223 implements InstanceMirror { | 221 implements InstanceMirror { |
224 // TODO(ahe): This is a hack, see delegate below. | 222 // TODO(ahe): This is a hack, see delegate below. |
225 static Function _invokeOnClosure; | 223 static Function _invokeOnClosure; |
226 | 224 |
227 _LocalInstanceMirrorImpl(reflectee) : super(reflectee); | 225 _LocalInstanceMirror(reflectee) : super(reflectee); |
228 | 226 |
229 ClassMirror _type; | 227 ClassMirror _type; |
230 ClassMirror get type { | 228 ClassMirror get type { |
231 if (_type == null) { | 229 if (_type == null) { |
232 // Note it not safe to use reflectee.runtimeType because runtimeType may | 230 // Note it not safe to use reflectee.runtimeType because runtimeType may |
233 // be overridden. | 231 // be overridden. |
234 _type = reflectType(_computeType(reflectee)); | 232 _type = reflectType(_computeType(reflectee)); |
235 } | 233 } |
236 return _type; | 234 return _type; |
237 } | 235 } |
238 | 236 |
239 // LocalInstanceMirrors always reflect local instances | 237 // LocalInstanceMirrors always reflect local instances |
240 bool hasReflectee = true; | 238 bool hasReflectee = true; |
241 | 239 |
242 get reflectee => _reflectee; | 240 get reflectee => _reflectee; |
243 | 241 |
244 delegate(Invocation invocation) { | 242 delegate(Invocation invocation) { |
245 if (_invokeOnClosure == null) { | 243 if (_invokeOnClosure == null) { |
246 // TODO(ahe): This is a total hack. We're using the mirror | 244 // TODO(ahe): This is a total hack. We're using the mirror |
247 // system to access a private field in a different library. For | 245 // system to access a private field in a different library. For |
248 // some reason, that works. On the other hand, calling a | 246 // some reason, that works. On the other hand, calling a |
249 // private method does not work. | 247 // private method does not work. |
250 | 248 ClassMirror invocationImplClass = reflect(invocation).type; |
251 _LocalInstanceMirrorImpl mirror = | 249 Symbol fieldName = MirrorSystem.getSymbol('_invokeOnClosure', |
252 reflect(invocation); | 250 invocationImplClass.owner); |
253 _invokeOnClosure = reflectClass(invocation.runtimeType) | 251 _invokeOnClosure = invocationImplClass.getField(fieldName).reflectee; |
254 .getField(MirrorSystem.getSymbol('_invokeOnClosure', mirror.type.owner
)).reflectee; | |
255 } | 252 } |
256 return _invokeOnClosure(reflectee, invocation); | 253 return _invokeOnClosure(reflectee, invocation); |
257 } | 254 } |
258 | 255 |
259 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; | 256 String toString() => 'InstanceMirror on ${Error.safeToString(_reflectee)}'; |
260 | 257 |
261 bool operator ==(other) { | 258 bool operator ==(other) { |
262 return other is _LocalInstanceMirrorImpl && | 259 return other is _LocalInstanceMirror && |
263 identical(_reflectee, other._reflectee); | 260 identical(_reflectee, other._reflectee); |
264 } | 261 } |
265 | 262 |
266 int get hashCode { | 263 int get hashCode { |
267 // Avoid hash collisions with the reflectee. This constant is in Smi range | 264 // Avoid hash collisions with the reflectee. This constant is in Smi range |
268 // and happens to be the inner padding from RFC 2104. | 265 // and happens to be the inner padding from RFC 2104. |
269 return identityHashCode(_reflectee) ^ 0x36363636; | 266 return identityHashCode(_reflectee) ^ 0x36363636; |
270 } | 267 } |
271 | 268 |
272 Function operator [](Symbol selector) { | 269 Function operator [](Symbol selector) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 _invokeGetter(reflectee, getterName) | 315 _invokeGetter(reflectee, getterName) |
319 native 'InstanceMirror_invokeGetter'; | 316 native 'InstanceMirror_invokeGetter'; |
320 | 317 |
321 _invokeSetter(reflectee, setterName, value) | 318 _invokeSetter(reflectee, setterName, value) |
322 native 'InstanceMirror_invokeSetter'; | 319 native 'InstanceMirror_invokeSetter'; |
323 | 320 |
324 static _computeType(reflectee) | 321 static _computeType(reflectee) |
325 native 'InstanceMirror_computeType'; | 322 native 'InstanceMirror_computeType'; |
326 } | 323 } |
327 | 324 |
328 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl | 325 class _LocalClosureMirror extends _LocalInstanceMirror |
329 implements ClosureMirror { | 326 implements ClosureMirror { |
330 _LocalClosureMirrorImpl(reflectee) : super(reflectee); | 327 _LocalClosureMirror(reflectee) : super(reflectee); |
331 | 328 |
332 MethodMirror _function; | 329 MethodMirror _function; |
333 MethodMirror get function { | 330 MethodMirror get function { |
334 if (_function == null) { | 331 if (_function == null) { |
335 _function = _computeFunction(reflectee); | 332 _function = _computeFunction(reflectee); |
336 } | 333 } |
337 return _function; | 334 return _function; |
338 } | 335 } |
339 | 336 |
340 InstanceMirror apply(List<Object> positionalArguments, | 337 InstanceMirror apply(List<Object> positionalArguments, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 static _apply(arguments, argumentNames) | 390 static _apply(arguments, argumentNames) |
394 native 'ClosureMirror_apply'; | 391 native 'ClosureMirror_apply'; |
395 | 392 |
396 static _computeFunction(reflectee) | 393 static _computeFunction(reflectee) |
397 native 'ClosureMirror_function'; | 394 native 'ClosureMirror_function'; |
398 | 395 |
399 static _computeFindInContext(reflectee, name) | 396 static _computeFindInContext(reflectee, name) |
400 native 'ClosureMirror_find_in_context'; | 397 native 'ClosureMirror_find_in_context'; |
401 } | 398 } |
402 | 399 |
403 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl | 400 class _LocalClassMirror extends _LocalObjectMirror |
404 implements ClassMirror { | 401 implements ClassMirror { |
405 _LocalClassMirrorImpl(reflectee, | 402 _LocalClassMirror(reflectee, |
406 reflectedType, | 403 reflectedType, |
407 String simpleName, | 404 String simpleName, |
408 this._owner, | 405 this._owner, |
409 this._isGeneric, | 406 this._isGeneric, |
410 this._isMixinAlias, | 407 this._isMixinAlias, |
411 this._isGenericDeclaration) | 408 this._isGenericDeclaration) |
412 : this._simpleName = _s(simpleName), | 409 : this._simpleName = _s(simpleName), |
413 this._reflectedType = reflectedType, | 410 this._reflectedType = reflectedType, |
414 this._instantiator = reflectedType, | 411 this._instantiator = reflectedType, |
415 super(reflectee); | 412 super(reflectee); |
416 | 413 |
417 final Type _reflectedType; | 414 final Type _reflectedType; |
418 final bool _isGeneric; | 415 final bool _isGeneric; |
419 final bool _isMixinAlias; | 416 final bool _isMixinAlias; |
420 final bool _isGenericDeclaration; | 417 final bool _isGenericDeclaration; |
421 Type _instantiator; | 418 Type _instantiator; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 List<TypeVariableMirror> _typeVariables = null; | 603 List<TypeVariableMirror> _typeVariables = null; |
607 List<TypeVariableMirror> get typeVariables { | 604 List<TypeVariableMirror> get typeVariables { |
608 if (_typeVariables == null) { | 605 if (_typeVariables == null) { |
609 if (_isAnonymousMixinApplication) return _typeVariables = emptyList; | 606 if (_isAnonymousMixinApplication) return _typeVariables = emptyList; |
610 _typeVariables = new List<TypeVariableMirror>(); | 607 _typeVariables = new List<TypeVariableMirror>(); |
611 | 608 |
612 List params = _ClassMirror_type_variables(_reflectee); | 609 List params = _ClassMirror_type_variables(_reflectee); |
613 ClassMirror owner = originalDeclaration; | 610 ClassMirror owner = originalDeclaration; |
614 var mirror; | 611 var mirror; |
615 for (var i = 0; i < params.length; i += 2) { | 612 for (var i = 0; i < params.length; i += 2) { |
616 mirror = new _LocalTypeVariableMirrorImpl( | 613 mirror = new _LocalTypeVariableMirror( |
617 params[i + 1], params[i], owner); | 614 params[i + 1], params[i], owner); |
618 _typeVariables.add(mirror); | 615 _typeVariables.add(mirror); |
619 } | 616 } |
620 _typeVariables = new UnmodifiableListView(_typeVariables); | 617 _typeVariables = new UnmodifiableListView(_typeVariables); |
621 } | 618 } |
622 return _typeVariables; | 619 return _typeVariables; |
623 } | 620 } |
624 | 621 |
625 List<TypeMirror> _typeArguments = null; | 622 List<TypeMirror> _typeArguments = null; |
626 List<TypeMirror> get typeArguments { | 623 List<TypeMirror> get typeArguments { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 static _invokeConstructor(reflectee, type, constructorName, arguments, argumen
tNames) | 745 static _invokeConstructor(reflectee, type, constructorName, arguments, argumen
tNames) |
749 native 'ClassMirror_invokeConstructor'; | 746 native 'ClassMirror_invokeConstructor'; |
750 | 747 |
751 static _ClassMirror_type_variables(reflectee) | 748 static _ClassMirror_type_variables(reflectee) |
752 native "ClassMirror_type_variables"; | 749 native "ClassMirror_type_variables"; |
753 | 750 |
754 static _computeTypeArguments(reflectee) | 751 static _computeTypeArguments(reflectee) |
755 native "ClassMirror_type_arguments"; | 752 native "ClassMirror_type_arguments"; |
756 } | 753 } |
757 | 754 |
758 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl | 755 class _LocalFunctionTypeMirror extends _LocalClassMirror |
759 implements FunctionTypeMirror { | 756 implements FunctionTypeMirror { |
760 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType) | 757 _LocalFunctionTypeMirror(reflectee, reflectedType) |
761 : super(reflectee, reflectedType, null, null, false, false, false); | 758 : super(reflectee, reflectedType, null, null, false, false, false); |
762 | 759 |
763 bool get _isAnonymousMixinApplication => false; | 760 bool get _isAnonymousMixinApplication => false; |
764 | 761 |
765 // FunctionTypeMirrors have a simpleName generated from their signature. | 762 // FunctionTypeMirrors have a simpleName generated from their signature. |
766 Symbol _simpleName = null; | 763 Symbol _simpleName = null; |
767 Symbol get simpleName { | 764 Symbol get simpleName { |
768 if (_simpleName == null) { | 765 if (_simpleName == null) { |
769 _simpleName = _s(_makeSignatureString(returnType, parameters)); | 766 _simpleName = _s(_makeSignatureString(returnType, parameters)); |
770 } | 767 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 MethodMirror _FunctionTypeMirror_call_method(reflectee) | 807 MethodMirror _FunctionTypeMirror_call_method(reflectee) |
811 native "FunctionTypeMirror_call_method"; | 808 native "FunctionTypeMirror_call_method"; |
812 | 809 |
813 static Type _FunctionTypeMirror_return_type(reflectee, instantiator) | 810 static Type _FunctionTypeMirror_return_type(reflectee, instantiator) |
814 native "FunctionTypeMirror_return_type"; | 811 native "FunctionTypeMirror_return_type"; |
815 | 812 |
816 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) | 813 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) |
817 native "FunctionTypeMirror_parameters"; | 814 native "FunctionTypeMirror_parameters"; |
818 } | 815 } |
819 | 816 |
820 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl | 817 abstract class _LocalDeclarationMirror extends _LocalMirror |
821 implements DeclarationMirror { | 818 implements DeclarationMirror { |
822 _LocalDeclarationMirrorImpl(this._reflectee, this._simpleName); | 819 _LocalDeclarationMirror(this._reflectee, this._simpleName); |
823 | 820 |
824 final _reflectee; | 821 final _reflectee; |
825 | 822 |
826 Symbol _simpleName; | 823 Symbol _simpleName; |
827 Symbol get simpleName => _simpleName; | 824 Symbol get simpleName => _simpleName; |
828 | 825 |
829 Symbol _qualifiedName = null; | 826 Symbol _qualifiedName = null; |
830 Symbol get qualifiedName { | 827 Symbol get qualifiedName { |
831 if (_qualifiedName == null) { | 828 if (_qualifiedName == null) { |
832 _qualifiedName = _computeQualifiedName(owner, simpleName); | 829 _qualifiedName = _computeQualifiedName(owner, simpleName); |
833 } | 830 } |
834 return _qualifiedName; | 831 return _qualifiedName; |
835 } | 832 } |
836 | 833 |
837 List<InstanceMirror> get metadata { | 834 List<InstanceMirror> get metadata { |
838 // Get the metadata objects, convert them into InstanceMirrors using | 835 // Get the metadata objects, convert them into InstanceMirrors using |
839 // reflect() and then make them into a Dart list. | 836 // reflect() and then make them into a Dart list. |
840 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); | 837 return new UnmodifiableListView(_metadata(_reflectee).map(reflect)); |
841 } | 838 } |
842 | 839 |
843 bool operator ==(other) { | 840 bool operator ==(other) { |
844 return this.runtimeType == other.runtimeType && | 841 return this.runtimeType == other.runtimeType && |
845 this._reflectee == other._reflectee; | 842 this._reflectee == other._reflectee; |
846 } | 843 } |
847 | 844 |
848 int get hashCode => simpleName.hashCode; | 845 int get hashCode => simpleName.hashCode; |
849 } | 846 } |
850 | 847 |
851 class _LocalTypeVariableMirrorImpl extends _LocalDeclarationMirrorImpl | 848 class _LocalTypeVariableMirror extends _LocalDeclarationMirror |
852 implements TypeVariableMirror { | 849 implements TypeVariableMirror { |
853 _LocalTypeVariableMirrorImpl(reflectee, | 850 _LocalTypeVariableMirror(reflectee, |
854 String simpleName, | 851 String simpleName, |
855 this._owner) | 852 this._owner) |
856 : super(reflectee, _s(simpleName)); | 853 : super(reflectee, _s(simpleName)); |
857 | 854 |
858 DeclarationMirror _owner; | 855 DeclarationMirror _owner; |
859 DeclarationMirror get owner { | 856 DeclarationMirror get owner { |
860 if (_owner == null) { | 857 if (_owner == null) { |
861 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; | 858 _owner = _TypeVariableMirror_owner(_reflectee).originalDeclaration; |
862 } | 859 } |
863 return _owner; | 860 return _owner; |
864 } | 861 } |
865 | 862 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 int get hashCode => simpleName.hashCode; | 897 int get hashCode => simpleName.hashCode; |
901 | 898 |
902 static DeclarationMirror _TypeVariableMirror_owner(reflectee) | 899 static DeclarationMirror _TypeVariableMirror_owner(reflectee) |
903 native "TypeVariableMirror_owner"; | 900 native "TypeVariableMirror_owner"; |
904 | 901 |
905 static Type _TypeVariableMirror_upper_bound(reflectee) | 902 static Type _TypeVariableMirror_upper_bound(reflectee) |
906 native "TypeVariableMirror_upper_bound"; | 903 native "TypeVariableMirror_upper_bound"; |
907 } | 904 } |
908 | 905 |
909 | 906 |
910 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl | 907 class _LocalTypedefMirror extends _LocalDeclarationMirror |
911 implements TypedefMirror { | 908 implements TypedefMirror { |
912 _LocalTypedefMirrorImpl(reflectee, | 909 _LocalTypedefMirror(reflectee, |
913 this._reflectedType, | 910 this._reflectedType, |
914 String simpleName, | 911 String simpleName, |
915 this._isGeneric, | 912 this._isGeneric, |
916 this._isGenericDeclaration, | 913 this._isGenericDeclaration, |
917 this._owner) | 914 this._owner) |
918 : super(reflectee, _s(simpleName)); | 915 : super(reflectee, _s(simpleName)); |
919 | 916 |
920 final Type _reflectedType; | 917 final Type _reflectedType; |
921 final bool _isGeneric; | 918 final bool _isGeneric; |
922 final bool _isGenericDeclaration; | 919 final bool _isGenericDeclaration; |
923 | 920 |
924 bool get isTopLevel => true; | 921 bool get isTopLevel => true; |
925 bool get isPrivate => false; | 922 bool get isPrivate => false; |
926 | 923 |
927 DeclarationMirror _owner; | 924 DeclarationMirror _owner; |
928 DeclarationMirror get owner { | 925 DeclarationMirror get owner { |
929 if (_owner == null) { | 926 if (_owner == null) { |
930 _owner = _LocalClassMirrorImpl._library(_reflectee); | 927 _owner = _LocalClassMirror._library(_reflectee); |
931 } | 928 } |
932 return _owner; | 929 return _owner; |
933 } | 930 } |
934 | 931 |
935 SourceLocation get location { | 932 SourceLocation get location { |
936 throw new UnimplementedError('TypedefMirror.location is not implemented'); | 933 throw new UnimplementedError('TypedefMirror.location is not implemented'); |
937 } | 934 } |
938 | 935 |
939 TypeMirror _referent = null; | 936 TypeMirror _referent = null; |
940 TypeMirror get referent { | 937 TypeMirror get referent { |
(...skipping 11 matching lines...) Expand all Loading... |
952 return this; | 949 return this; |
953 } else { | 950 } else { |
954 return _nativeDeclaration(_reflectedType); | 951 return _nativeDeclaration(_reflectedType); |
955 } | 952 } |
956 } | 953 } |
957 | 954 |
958 List<TypeVariableMirror> _typeVariables = null; | 955 List<TypeVariableMirror> _typeVariables = null; |
959 List<TypeVariableMirror> get typeVariables { | 956 List<TypeVariableMirror> get typeVariables { |
960 if (_typeVariables == null) { | 957 if (_typeVariables == null) { |
961 _typeVariables = new List<TypeVariableMirror>(); | 958 _typeVariables = new List<TypeVariableMirror>(); |
962 List params = _LocalClassMirrorImpl._ClassMirror_type_variables(_reflectee
); | 959 List params = _LocalClassMirror._ClassMirror_type_variables(_reflectee); |
963 TypedefMirror owner = originalDeclaration; | 960 TypedefMirror owner = originalDeclaration; |
964 var mirror; | 961 var mirror; |
965 for (var i = 0; i < params.length; i += 2) { | 962 for (var i = 0; i < params.length; i += 2) { |
966 mirror = new _LocalTypeVariableMirrorImpl( | 963 mirror = new _LocalTypeVariableMirror( |
967 params[i + 1], params[i], owner); | 964 params[i + 1], params[i], owner); |
968 _typeVariables.add(mirror); | 965 _typeVariables.add(mirror); |
969 } | 966 } |
970 } | 967 } |
971 return _typeVariables; | 968 return _typeVariables; |
972 } | 969 } |
973 | 970 |
974 List<TypeMirror> _typeArguments = null; | 971 List<TypeMirror> _typeArguments = null; |
975 List<TypeMirror> get typeArguments { | 972 List<TypeMirror> get typeArguments { |
976 if(_typeArguments == null) { | 973 if(_typeArguments == null) { |
977 if(_isGenericDeclaration) { | 974 if(_isGenericDeclaration) { |
978 _typeArguments = emptyList; | 975 _typeArguments = emptyList; |
979 } else { | 976 } else { |
980 _typeArguments = new UnmodifiableListView( | 977 _typeArguments = new UnmodifiableListView( |
981 _LocalClassMirrorImpl._computeTypeArguments(_reflectedType)); | 978 _LocalClassMirror._computeTypeArguments(_reflectedType)); |
982 } | 979 } |
983 } | 980 } |
984 return _typeArguments; | 981 return _typeArguments; |
985 } | 982 } |
986 | 983 |
987 String toString() => "TypedefMirror on '${_n(simpleName)}'"; | 984 String toString() => "TypedefMirror on '${_n(simpleName)}'"; |
988 | 985 |
989 static _nativeReferent(reflectedType) | 986 static _nativeReferent(reflectedType) |
990 native "TypedefMirror_referent"; | 987 native "TypedefMirror_referent"; |
991 | 988 |
992 static _nativeDeclaration(reflectedType) | 989 static _nativeDeclaration(reflectedType) |
993 native "TypedefMirror_declaration"; | 990 native "TypedefMirror_declaration"; |
994 } | 991 } |
995 | 992 |
996 class _LocalLibraryMirrorImpl extends _LocalObjectMirrorImpl | 993 class _LocalLibraryMirror extends _LocalObjectMirror |
997 implements LibraryMirror { | 994 implements LibraryMirror { |
998 _LocalLibraryMirrorImpl(reflectee, | 995 _LocalLibraryMirror(reflectee, |
999 String simpleName, | 996 String simpleName, |
1000 String url) | 997 String url) |
1001 : this.simpleName = _s(simpleName), | 998 : this.simpleName = _s(simpleName), |
1002 this.uri = Uri.parse(url), | 999 this.uri = Uri.parse(url), |
1003 super(reflectee); | 1000 super(reflectee); |
1004 | 1001 |
1005 final Symbol simpleName; | 1002 final Symbol simpleName; |
1006 | 1003 |
1007 // The simple name and the qualified name are the same for a library. | 1004 // The simple name and the qualified name are the same for a library. |
1008 Symbol get qualifiedName => simpleName; | 1005 Symbol get qualifiedName => simpleName; |
1009 | 1006 |
1010 // Always null for libraries. | 1007 // Always null for libraries. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 _invokeGetter(reflectee, getterName) | 1116 _invokeGetter(reflectee, getterName) |
1120 native 'LibraryMirror_invokeGetter'; | 1117 native 'LibraryMirror_invokeGetter'; |
1121 | 1118 |
1122 _invokeSetter(reflectee, setterName, value) | 1119 _invokeSetter(reflectee, setterName, value) |
1123 native 'LibraryMirror_invokeSetter'; | 1120 native 'LibraryMirror_invokeSetter'; |
1124 | 1121 |
1125 _computeMembers(reflectee) | 1122 _computeMembers(reflectee) |
1126 native "LibraryMirror_members"; | 1123 native "LibraryMirror_members"; |
1127 } | 1124 } |
1128 | 1125 |
1129 class _LocalMethodMirrorImpl extends _LocalDeclarationMirrorImpl | 1126 class _LocalMethodMirror extends _LocalDeclarationMirror |
1130 implements MethodMirror { | 1127 implements MethodMirror { |
1131 _LocalMethodMirrorImpl(reflectee, | 1128 _LocalMethodMirror(reflectee, |
1132 String simpleName, | 1129 String simpleName, |
1133 this._owner, | 1130 this._owner, |
1134 this.isStatic, | 1131 this.isStatic, |
1135 this.isAbstract, | 1132 this.isAbstract, |
1136 this.isGetter, | 1133 this.isGetter, |
1137 this.isSetter, | 1134 this.isSetter, |
1138 this.isConstructor, | 1135 this.isConstructor, |
1139 this.isConstConstructor, | 1136 this.isConstConstructor, |
1140 this.isGenerativeConstructor, | 1137 this.isGenerativeConstructor, |
1141 this.isRedirectingConstructor, | 1138 this.isRedirectingConstructor, |
1142 this.isFactoryConstructor) | 1139 this.isFactoryConstructor) |
1143 : this.isOperator = _operators.contains(simpleName), | 1140 : this.isOperator = _operators.contains(simpleName), |
1144 super(reflectee, _s(simpleName)); | 1141 super(reflectee, _s(simpleName)); |
1145 | 1142 |
1146 static const _operators = const ["%", "&", "*", "+", "-", "/", "<", "<<", | 1143 static const _operators = const ["%", "&", "*", "+", "-", "/", "<", "<<", |
1147 "<=", "==", ">", ">=", ">>", "[]", "[]=", "^", "|", "~", "unary-", "~/"]; | 1144 "<=", "==", ">", ">=", ">>", "[]", "[]=", "^", "|", "~", "unary-", "~/"]; |
1148 | 1145 |
1149 final bool isStatic; | 1146 final bool isStatic; |
1150 final bool isAbstract; | 1147 final bool isAbstract; |
1151 final bool isGetter; | 1148 final bool isGetter; |
1152 final bool isSetter; | 1149 final bool isSetter; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 static dynamic _MethodMirror_return_type(reflectee, instantiator) | 1251 static dynamic _MethodMirror_return_type(reflectee, instantiator) |
1255 native "MethodMirror_return_type"; | 1252 native "MethodMirror_return_type"; |
1256 | 1253 |
1257 List<ParameterMirror> _MethodMirror_parameters(reflectee) | 1254 List<ParameterMirror> _MethodMirror_parameters(reflectee) |
1258 native "MethodMirror_parameters"; | 1255 native "MethodMirror_parameters"; |
1259 | 1256 |
1260 static String _MethodMirror_source(reflectee) | 1257 static String _MethodMirror_source(reflectee) |
1261 native "MethodMirror_source"; | 1258 native "MethodMirror_source"; |
1262 } | 1259 } |
1263 | 1260 |
1264 class _LocalVariableMirrorImpl extends _LocalDeclarationMirrorImpl | 1261 class _LocalVariableMirror extends _LocalDeclarationMirror |
1265 implements VariableMirror { | 1262 implements VariableMirror { |
1266 _LocalVariableMirrorImpl(reflectee, | 1263 _LocalVariableMirror(reflectee, |
1267 String simpleName, | 1264 String simpleName, |
1268 this.owner, | 1265 this.owner, |
1269 this._type, | 1266 this._type, |
1270 this.isStatic, | 1267 this.isStatic, |
1271 this.isFinal, | 1268 this.isFinal, |
1272 this.isConst) | 1269 this.isConst) |
1273 : super(reflectee, _s(simpleName)); | 1270 : super(reflectee, _s(simpleName)); |
1274 | 1271 |
1275 final DeclarationMirror owner; | 1272 final DeclarationMirror owner; |
1276 final bool isStatic; | 1273 final bool isStatic; |
1277 final bool isFinal; | 1274 final bool isFinal; |
1278 final bool isConst; | 1275 final bool isConst; |
1279 | 1276 |
1280 bool get isPrivate => _n(simpleName).startsWith('_'); | 1277 bool get isPrivate => _n(simpleName).startsWith('_'); |
1281 | 1278 |
1282 bool get isTopLevel => owner is LibraryMirror; | 1279 bool get isTopLevel => owner is LibraryMirror; |
(...skipping 13 matching lines...) Expand all Loading... |
1296 } | 1293 } |
1297 return _type; | 1294 return _type; |
1298 } | 1295 } |
1299 | 1296 |
1300 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'"
; | 1297 String toString() => "VariableMirror on '${MirrorSystem.getName(simpleName)}'"
; |
1301 | 1298 |
1302 static _VariableMirror_type(reflectee, instantiator) | 1299 static _VariableMirror_type(reflectee, instantiator) |
1303 native "VariableMirror_type"; | 1300 native "VariableMirror_type"; |
1304 } | 1301 } |
1305 | 1302 |
1306 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl | 1303 class _LocalParameterMirror extends _LocalVariableMirror |
1307 implements ParameterMirror { | 1304 implements ParameterMirror { |
1308 _LocalParameterMirrorImpl(reflectee, | 1305 _LocalParameterMirror(reflectee, |
1309 String simpleName, | 1306 String simpleName, |
1310 DeclarationMirror owner, | 1307 DeclarationMirror owner, |
1311 this._position, | 1308 this._position, |
1312 this.isOptional, | 1309 this.isOptional, |
1313 this.isNamed, | 1310 this.isNamed, |
1314 bool isFinal, | 1311 bool isFinal, |
1315 this._defaultValueReflectee, | 1312 this._defaultValueReflectee, |
1316 this._unmirroredMetadata) | 1313 this._unmirroredMetadata) |
1317 : super(reflectee, | 1314 : super(reflectee, |
1318 simpleName, | 1315 simpleName, |
1319 owner, | 1316 owner, |
1320 null, // We override the type. | 1317 null, // We override the type. |
1321 false, // isStatic does not apply. | 1318 false, // isStatic does not apply. |
1322 isFinal, | 1319 isFinal, |
1323 false // Not const. | 1320 false // Not const. |
1324 ); | 1321 ); |
1325 | 1322 |
1326 final int _position; | 1323 final int _position; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 } | 1358 } |
1362 return _type; | 1359 return _type; |
1363 } | 1360 } |
1364 | 1361 |
1365 String toString() => "ParameterMirror on '${_n(simpleName)}'"; | 1362 String toString() => "ParameterMirror on '${_n(simpleName)}'"; |
1366 | 1363 |
1367 static Type _ParameterMirror_type(_reflectee, _position, instantiator) | 1364 static Type _ParameterMirror_type(_reflectee, _position, instantiator) |
1368 native "ParameterMirror_type"; | 1365 native "ParameterMirror_type"; |
1369 } | 1366 } |
1370 | 1367 |
1371 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl | 1368 class _SpecialTypeMirror extends _LocalMirror |
1372 implements TypeMirror, DeclarationMirror { | 1369 implements TypeMirror, DeclarationMirror { |
1373 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); | 1370 _SpecialTypeMirror(String name) : simpleName = _s(name); |
1374 | 1371 |
1375 final bool isPrivate = false; | 1372 final bool isPrivate = false; |
1376 final DeclarationMirror owner = null; | 1373 final DeclarationMirror owner = null; |
1377 final Symbol simpleName; | 1374 final Symbol simpleName; |
1378 final bool isTopLevel = true; | 1375 final bool isTopLevel = true; |
1379 final List<InstanceMirror> metadata = emptyList; | 1376 final List<InstanceMirror> metadata = emptyList; |
1380 | 1377 |
1381 List<TypeVariableMirror> get typeVariables => emptyList; | 1378 List<TypeVariableMirror> get typeVariables => emptyList; |
1382 List<TypeMirror> get typeArguments => emptyList; | 1379 List<TypeMirror> get typeArguments => emptyList; |
1383 | 1380 |
1384 bool get isOriginalDeclaration => true; | 1381 bool get isOriginalDeclaration => true; |
1385 TypeMirror get originalDeclaration => this; | 1382 TypeMirror get originalDeclaration => this; |
1386 | 1383 |
1387 SourceLocation get location { | 1384 SourceLocation get location { |
1388 throw new UnimplementedError('TypeMirror.location is not implemented'); | 1385 throw new UnimplementedError('TypeMirror.location is not implemented'); |
1389 } | 1386 } |
1390 | 1387 |
1391 Symbol get qualifiedName => simpleName; | 1388 Symbol get qualifiedName => simpleName; |
1392 | 1389 |
1393 // TODO(11955): Remove once dynamicType and voidType are canonical objects in | 1390 // TODO(11955): Remove once dynamicType and voidType are canonical objects in |
1394 // the object store. | 1391 // the object store. |
1395 bool operator ==(other) { | 1392 bool operator ==(other) { |
1396 if (other is! _SpecialTypeMirrorImpl) { | 1393 if (other is! _SpecialTypeMirror) { |
1397 return false; | 1394 return false; |
1398 } | 1395 } |
1399 return this.simpleName == other.simpleName; | 1396 return this.simpleName == other.simpleName; |
1400 } | 1397 } |
1401 | 1398 |
1402 int get hashCode => simpleName.hashCode; | 1399 int get hashCode => simpleName.hashCode; |
1403 | 1400 |
1404 String toString() => "TypeMirror on '${_n(simpleName)}'"; | 1401 String toString() => "TypeMirror on '${_n(simpleName)}'"; |
1405 } | 1402 } |
1406 | 1403 |
(...skipping 11 matching lines...) Expand all Loading... |
1418 static MirrorSystem currentMirrorSystem() { | 1415 static MirrorSystem currentMirrorSystem() { |
1419 if (_currentMirrorSystem == null) { | 1416 if (_currentMirrorSystem == null) { |
1420 _currentMirrorSystem = makeLocalMirrorSystem(); | 1417 _currentMirrorSystem = makeLocalMirrorSystem(); |
1421 } | 1418 } |
1422 return _currentMirrorSystem; | 1419 return _currentMirrorSystem; |
1423 } | 1420 } |
1424 | 1421 |
1425 // Creates a new local mirror for some Object. | 1422 // Creates a new local mirror for some Object. |
1426 static InstanceMirror reflect(Object reflectee) { | 1423 static InstanceMirror reflect(Object reflectee) { |
1427 return reflectee is Function | 1424 return reflectee is Function |
1428 ? new _LocalClosureMirrorImpl(reflectee) | 1425 ? new _LocalClosureMirror(reflectee) |
1429 : new _LocalInstanceMirrorImpl(reflectee); | 1426 : new _LocalInstanceMirror(reflectee); |
1430 } | 1427 } |
1431 | 1428 |
1432 static ClassMirror makeLocalClassMirror(Type key) | 1429 static ClassMirror makeLocalClassMirror(Type key) |
1433 native "Mirrors_makeLocalClassMirror"; | 1430 native "Mirrors_makeLocalClassMirror"; |
1434 static TypeMirror makeLocalTypeMirror(Type key) | 1431 static TypeMirror makeLocalTypeMirror(Type key) |
1435 native "Mirrors_makeLocalTypeMirror"; | 1432 native "Mirrors_makeLocalTypeMirror"; |
1436 | 1433 |
1437 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); | 1434 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); |
1438 static Expando<TypeMirror> _instanitationCache = new Expando("TypeMirror"); | 1435 static Expando<TypeMirror> _instanitationCache = new Expando("TypeMirror"); |
1439 | 1436 |
(...skipping 14 matching lines...) Expand all Loading... |
1454 if (typeMirror == null) { | 1451 if (typeMirror == null) { |
1455 typeMirror = makeLocalTypeMirror(key); | 1452 typeMirror = makeLocalTypeMirror(key); |
1456 _instanitationCache[key] = typeMirror; | 1453 _instanitationCache[key] = typeMirror; |
1457 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1454 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1458 _declarationCache[key] = typeMirror; | 1455 _declarationCache[key] = typeMirror; |
1459 } | 1456 } |
1460 } | 1457 } |
1461 return typeMirror; | 1458 return typeMirror; |
1462 } | 1459 } |
1463 } | 1460 } |
OLD | NEW |