| 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 var dirty = false; | 7 var _dirty = false; |
| 8 final emptyList = new UnmodifiableListView([]); | 8 final _emptyList = new UnmodifiableListView([]); |
| 9 final emptyMap = new UnmodifiableMapView({}); | |
| 10 | 9 |
| 11 class _InternalMirrorError { | 10 class _InternalMirrorError { |
| 12 final String _msg; | 11 final String _msg; |
| 13 const _InternalMirrorError(String this._msg); | 12 const _InternalMirrorError(String this._msg); |
| 14 String toString() => _msg; | 13 String toString() => _msg; |
| 15 } | 14 } |
| 16 | 15 |
| 17 String _n(Symbol symbol) => internal.Symbol.getName(symbol); | 16 String _n(Symbol symbol) => internal.Symbol.getName(symbol); |
| 18 | 17 |
| 19 Symbol _s(String name) { | 18 Symbol _s(String name) { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 return assoc.value; | 212 return assoc.value; |
| 214 } | 213 } |
| 215 } | 214 } |
| 216 | 215 |
| 217 class _LocalMirrorSystem extends MirrorSystem { | 216 class _LocalMirrorSystem extends MirrorSystem { |
| 218 final TypeMirror dynamicType = new _SpecialTypeMirror('dynamic'); | 217 final TypeMirror dynamicType = new _SpecialTypeMirror('dynamic'); |
| 219 final TypeMirror voidType = new _SpecialTypeMirror('void'); | 218 final TypeMirror voidType = new _SpecialTypeMirror('void'); |
| 220 | 219 |
| 221 var _libraries; | 220 var _libraries; |
| 222 Map<Uri, LibraryMirror> get libraries { | 221 Map<Uri, LibraryMirror> get libraries { |
| 223 if ((_libraries == null) || dirty) { | 222 if ((_libraries == null) || _dirty) { |
| 224 _libraries = new Map<Uri, LibraryMirror>.fromIterable( | 223 _libraries = new Map<Uri, LibraryMirror>.fromIterable( |
| 225 _computeLibraries(), key: (e) => e.uri); | 224 _computeLibraries(), key: (e) => e.uri); |
| 226 dirty = false; | 225 _dirty = false; |
| 227 } | 226 } |
| 228 return _libraries; | 227 return _libraries; |
| 229 } | 228 } |
| 230 static _computeLibraries() native "MirrorSystem_libraries"; | 229 static _computeLibraries() native "MirrorSystem_libraries"; |
| 231 | 230 |
| 232 var _isolate; | 231 var _isolate; |
| 233 IsolateMirror get isolate { | 232 IsolateMirror get isolate { |
| 234 if (_isolate == null) { | 233 if (_isolate == null) { |
| 235 _isolate = _computeIsolate(); | 234 _isolate = _computeIsolate(); |
| 236 } | 235 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 bool get isAbstract => false; | 295 bool get isAbstract => false; |
| 297 | 296 |
| 298 bool get isSetter => !isGetter; | 297 bool get isSetter => !isGetter; |
| 299 bool get isPrivate => _n(simpleName).startsWith('_'); | 298 bool get isPrivate => _n(simpleName).startsWith('_'); |
| 300 | 299 |
| 301 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName); | 300 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName); |
| 302 Symbol get constructorName => const Symbol(''); | 301 Symbol get constructorName => const Symbol(''); |
| 303 | 302 |
| 304 TypeMirror get returnType => _target.type; | 303 TypeMirror get returnType => _target.type; |
| 305 List<ParameterMirror> get parameters { | 304 List<ParameterMirror> get parameters { |
| 306 if (isGetter) return emptyList; | 305 if (isGetter) return _emptyList; |
| 307 return new UnmodifiableListView( | 306 return new UnmodifiableListView( |
| 308 [new _SyntheticSetterParameter(this, this._target)]); | 307 [new _SyntheticSetterParameter(this, this._target)]); |
| 309 } | 308 } |
| 310 | 309 |
| 311 SourceLocation get location => null; | 310 SourceLocation get location => null; |
| 312 List<InstanceMirror> get metadata => emptyList; | 311 List<InstanceMirror> get metadata => _emptyList; |
| 313 String get source => null; | 312 String get source => null; |
| 314 } | 313 } |
| 315 | 314 |
| 316 class _SyntheticSetterParameter implements ParameterMirror { | 315 class _SyntheticSetterParameter implements ParameterMirror { |
| 317 final DeclarationMirror owner; | 316 final DeclarationMirror owner; |
| 318 final VariableMirror _target; | 317 final VariableMirror _target; |
| 319 | 318 |
| 320 _SyntheticSetterParameter(this.owner, this._target); | 319 _SyntheticSetterParameter(this.owner, this._target); |
| 321 | 320 |
| 322 Symbol get simpleName => _target.simpleName; | 321 Symbol get simpleName => _target.simpleName; |
| 323 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName); | 322 Symbol get qualifiedName => _computeQualifiedName(owner, simpleName); |
| 324 TypeMirror get type => _target.type; | 323 TypeMirror get type => _target.type; |
| 325 | 324 |
| 326 bool get isOptional => false; | 325 bool get isOptional => false; |
| 327 bool get isNamed => false; | 326 bool get isNamed => false; |
| 328 bool get isStatic => false; | 327 bool get isStatic => false; |
| 329 bool get isTopLevel => false; | 328 bool get isTopLevel => false; |
| 330 bool get isConst => false; | 329 bool get isConst => false; |
| 331 bool get isFinal => true; | 330 bool get isFinal => true; |
| 332 bool get isPrivate => false; | 331 bool get isPrivate => false; |
| 333 bool get hasDefaultValue => false; | 332 bool get hasDefaultValue => false; |
| 334 InstanceMirror get defaultValue => null; | 333 InstanceMirror get defaultValue => null; |
| 335 SourceLocation get location => null; | 334 SourceLocation get location => null; |
| 336 List<InstanceMirror> get metadata => emptyList; | 335 List<InstanceMirror> get metadata => _emptyList; |
| 337 } | 336 } |
| 338 | 337 |
| 339 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { | 338 abstract class _LocalObjectMirror extends _LocalMirror implements ObjectMirror { |
| 340 final _reflectee; // May be a MirrorReference or an ordinary object. | 339 final _reflectee; // May be a MirrorReference or an ordinary object. |
| 341 | 340 |
| 342 _LocalObjectMirror(this._reflectee); | 341 _LocalObjectMirror(this._reflectee); |
| 343 | 342 |
| 344 InstanceMirror invoke(Symbol memberName, | 343 InstanceMirror invoke(Symbol memberName, |
| 345 List positionalArguments, | 344 List positionalArguments, |
| 346 [Map<Symbol, dynamic> namedArguments]) { | 345 [Map<Symbol, dynamic> namedArguments]) { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 | 779 |
| 781 bool get _isAnonymousMixinApplication { | 780 bool get _isAnonymousMixinApplication { |
| 782 if (_isMixinAlias) return false; // Named mixin application. | 781 if (_isMixinAlias) return false; // Named mixin application. |
| 783 if (mixin == this) return false; // Not a mixin application. | 782 if (mixin == this) return false; // Not a mixin application. |
| 784 return true; | 783 return true; |
| 785 } | 784 } |
| 786 | 785 |
| 787 List<TypeVariableMirror> _typeVariables = null; | 786 List<TypeVariableMirror> _typeVariables = null; |
| 788 List<TypeVariableMirror> get typeVariables { | 787 List<TypeVariableMirror> get typeVariables { |
| 789 if (_typeVariables == null) { | 788 if (_typeVariables == null) { |
| 790 if (_isAnonymousMixinApplication) return _typeVariables = emptyList; | 789 if (_isAnonymousMixinApplication) return _typeVariables = _emptyList; |
| 791 _typeVariables = new List<TypeVariableMirror>(); | 790 _typeVariables = new List<TypeVariableMirror>(); |
| 792 | 791 |
| 793 List params = _ClassMirror_type_variables(_reflectee); | 792 List params = _ClassMirror_type_variables(_reflectee); |
| 794 ClassMirror owner = originalDeclaration; | 793 ClassMirror owner = originalDeclaration; |
| 795 var mirror; | 794 var mirror; |
| 796 for (var i = 0; i < params.length; i += 2) { | 795 for (var i = 0; i < params.length; i += 2) { |
| 797 mirror = new _LocalTypeVariableMirror( | 796 mirror = new _LocalTypeVariableMirror( |
| 798 params[i + 1], params[i], owner); | 797 params[i + 1], params[i], owner); |
| 799 _typeVariables.add(mirror); | 798 _typeVariables.add(mirror); |
| 800 } | 799 } |
| 801 _typeVariables = new UnmodifiableListView(_typeVariables); | 800 _typeVariables = new UnmodifiableListView(_typeVariables); |
| 802 } | 801 } |
| 803 return _typeVariables; | 802 return _typeVariables; |
| 804 } | 803 } |
| 805 | 804 |
| 806 List<TypeMirror> _typeArguments = null; | 805 List<TypeMirror> _typeArguments = null; |
| 807 List<TypeMirror> get typeArguments { | 806 List<TypeMirror> get typeArguments { |
| 808 if(_typeArguments == null) { | 807 if(_typeArguments == null) { |
| 809 if(_isGenericDeclaration || _isAnonymousMixinApplication) { | 808 if(_isGenericDeclaration || _isAnonymousMixinApplication) { |
| 810 _typeArguments = emptyList; | 809 _typeArguments = _emptyList; |
| 811 } else { | 810 } else { |
| 812 _typeArguments = | 811 _typeArguments = |
| 813 new UnmodifiableListView(_computeTypeArguments(_reflectedType)); | 812 new UnmodifiableListView(_computeTypeArguments(_reflectedType)); |
| 814 } | 813 } |
| 815 } | 814 } |
| 816 return _typeArguments; | 815 return _typeArguments; |
| 817 } | 816 } |
| 818 | 817 |
| 819 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; | 818 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration; |
| 820 | 819 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 979 List<ParameterMirror> get parameters { | 978 List<ParameterMirror> get parameters { |
| 980 if (_parameters == null) { | 979 if (_parameters == null) { |
| 981 _parameters = _FunctionTypeMirror_parameters(_functionReflectee); | 980 _parameters = _FunctionTypeMirror_parameters(_functionReflectee); |
| 982 _parameters = new UnmodifiableListView(_parameters); | 981 _parameters = new UnmodifiableListView(_parameters); |
| 983 } | 982 } |
| 984 return _parameters; | 983 return _parameters; |
| 985 } | 984 } |
| 986 | 985 |
| 987 bool get isOriginalDeclaration => true; | 986 bool get isOriginalDeclaration => true; |
| 988 get originalDeclaration => this; | 987 get originalDeclaration => this; |
| 989 get typeVariables => emptyList; | 988 get typeVariables => _emptyList; |
| 990 get typeArguments => emptyList; | 989 get typeArguments => _emptyList; |
| 991 get metadata => emptyList; | 990 get metadata => _emptyList; |
| 992 get location => null; | 991 get location => null; |
| 993 | 992 |
| 994 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; | 993 String toString() => "FunctionTypeMirror on '${_n(simpleName)}'"; |
| 995 | 994 |
| 996 MethodMirror _FunctionTypeMirror_call_method(functionReflectee) | 995 MethodMirror _FunctionTypeMirror_call_method(functionReflectee) |
| 997 native "FunctionTypeMirror_call_method"; | 996 native "FunctionTypeMirror_call_method"; |
| 998 | 997 |
| 999 static Type _FunctionTypeMirror_return_type(functionReflectee, instantiator) | 998 static Type _FunctionTypeMirror_return_type(functionReflectee, instantiator) |
| 1000 native "FunctionTypeMirror_return_type"; | 999 native "FunctionTypeMirror_return_type"; |
| 1001 | 1000 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 } | 1064 } |
| 1066 return _upperBound; | 1065 return _upperBound; |
| 1067 } | 1066 } |
| 1068 | 1067 |
| 1069 bool get hasReflectedType => false; | 1068 bool get hasReflectedType => false; |
| 1070 Type get reflectedType { | 1069 Type get reflectedType { |
| 1071 throw new UnsupportedError('Type variables have no reflected type'); | 1070 throw new UnsupportedError('Type variables have no reflected type'); |
| 1072 } | 1071 } |
| 1073 Type get _reflectedType => _reflectee; | 1072 Type get _reflectedType => _reflectee; |
| 1074 | 1073 |
| 1075 List<TypeVariableMirror> get typeVariables => emptyList; | 1074 List<TypeVariableMirror> get typeVariables => _emptyList; |
| 1076 List<TypeMirror> get typeArguments => emptyList; | 1075 List<TypeMirror> get typeArguments => _emptyList; |
| 1077 | 1076 |
| 1078 bool get isOriginalDeclaration => true; | 1077 bool get isOriginalDeclaration => true; |
| 1079 TypeMirror get originalDeclaration => this; | 1078 TypeMirror get originalDeclaration => this; |
| 1080 | 1079 |
| 1081 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; | 1080 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; |
| 1082 | 1081 |
| 1083 operator ==(other) { | 1082 operator ==(other) { |
| 1084 return other is TypeVariableMirror | 1083 return other is TypeVariableMirror |
| 1085 && simpleName == other.simpleName | 1084 && simpleName == other.simpleName |
| 1086 && owner == other.owner; | 1085 && owner == other.owner; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 _typeVariables.add(mirror); | 1173 _typeVariables.add(mirror); |
| 1175 } | 1174 } |
| 1176 } | 1175 } |
| 1177 return _typeVariables; | 1176 return _typeVariables; |
| 1178 } | 1177 } |
| 1179 | 1178 |
| 1180 List<TypeMirror> _typeArguments = null; | 1179 List<TypeMirror> _typeArguments = null; |
| 1181 List<TypeMirror> get typeArguments { | 1180 List<TypeMirror> get typeArguments { |
| 1182 if(_typeArguments == null) { | 1181 if(_typeArguments == null) { |
| 1183 if(_isGenericDeclaration) { | 1182 if(_isGenericDeclaration) { |
| 1184 _typeArguments = emptyList; | 1183 _typeArguments = _emptyList; |
| 1185 } else { | 1184 } else { |
| 1186 _typeArguments = new UnmodifiableListView( | 1185 _typeArguments = new UnmodifiableListView( |
| 1187 _LocalClassMirror._computeTypeArguments(_reflectedType)); | 1186 _LocalClassMirror._computeTypeArguments(_reflectedType)); |
| 1188 } | 1187 } |
| 1189 } | 1188 } |
| 1190 return _typeArguments; | 1189 return _typeArguments; |
| 1191 } | 1190 } |
| 1192 | 1191 |
| 1193 String toString() => "TypedefMirror on '${_n(simpleName)}'"; | 1192 String toString() => "TypedefMirror on '${_n(simpleName)}'"; |
| 1194 | 1193 |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1551 return _defaultValue; | 1550 return _defaultValue; |
| 1552 } | 1551 } |
| 1553 | 1552 |
| 1554 bool get hasDefaultValue => _defaultValueReflectee != null; | 1553 bool get hasDefaultValue => _defaultValueReflectee != null; |
| 1555 | 1554 |
| 1556 SourceLocation get location { | 1555 SourceLocation get location { |
| 1557 throw new UnsupportedError("ParameterMirror.location unimplemented"); | 1556 throw new UnsupportedError("ParameterMirror.location unimplemented"); |
| 1558 } | 1557 } |
| 1559 | 1558 |
| 1560 List<InstanceMirror> get metadata { | 1559 List<InstanceMirror> get metadata { |
| 1561 if (_unmirroredMetadata == null) return emptyList; | 1560 if (_unmirroredMetadata == null) return _emptyList; |
| 1562 return new UnmodifiableListView(_unmirroredMetadata.map(reflect)); | 1561 return new UnmodifiableListView(_unmirroredMetadata.map(reflect)); |
| 1563 } | 1562 } |
| 1564 | 1563 |
| 1565 Type get _instantiator { | 1564 Type get _instantiator { |
| 1566 return owner._instantiator; | 1565 return owner._instantiator; |
| 1567 } | 1566 } |
| 1568 | 1567 |
| 1569 TypeMirror _type = null; | 1568 TypeMirror _type = null; |
| 1570 TypeMirror get type { | 1569 TypeMirror get type { |
| 1571 if (_type == null) { | 1570 if (_type == null) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1586 final Symbol simpleName; | 1585 final Symbol simpleName; |
| 1587 | 1586 |
| 1588 _SpecialTypeMirror(String name) : simpleName = _s(name); | 1587 _SpecialTypeMirror(String name) : simpleName = _s(name); |
| 1589 | 1588 |
| 1590 bool get isPrivate => false; | 1589 bool get isPrivate => false; |
| 1591 bool get isTopLevel => true; | 1590 bool get isTopLevel => true; |
| 1592 | 1591 |
| 1593 DeclarationMirror get owner => null; | 1592 DeclarationMirror get owner => null; |
| 1594 | 1593 |
| 1595 SourceLocation get location => null; | 1594 SourceLocation get location => null; |
| 1596 List<InstanceMirror> get metadata => emptyList; | 1595 List<InstanceMirror> get metadata => _emptyList; |
| 1597 | 1596 |
| 1598 bool get hasReflectedType => simpleName == #dynamic; | 1597 bool get hasReflectedType => simpleName == #dynamic; |
| 1599 Type get reflectedType { | 1598 Type get reflectedType { |
| 1600 if (simpleName == #dynamic) return dynamic; | 1599 if (simpleName == #dynamic) return dynamic; |
| 1601 throw new UnsupportedError("void has no reflected type"); | 1600 throw new UnsupportedError("void has no reflected type"); |
| 1602 } | 1601 } |
| 1603 | 1602 |
| 1604 List<TypeVariableMirror> get typeVariables => emptyList; | 1603 List<TypeVariableMirror> get typeVariables => _emptyList; |
| 1605 List<TypeMirror> get typeArguments => emptyList; | 1604 List<TypeMirror> get typeArguments => _emptyList; |
| 1606 | 1605 |
| 1607 bool get isOriginalDeclaration => true; | 1606 bool get isOriginalDeclaration => true; |
| 1608 TypeMirror get originalDeclaration => this; | 1607 TypeMirror get originalDeclaration => this; |
| 1609 | 1608 |
| 1610 Symbol get qualifiedName => simpleName; | 1609 Symbol get qualifiedName => simpleName; |
| 1611 | 1610 |
| 1612 bool operator ==(other) { | 1611 bool operator ==(other) { |
| 1613 if (other is! _SpecialTypeMirror) { | 1612 if (other is! _SpecialTypeMirror) { |
| 1614 return false; | 1613 return false; |
| 1615 } | 1614 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 if (typeMirror == null) { | 1666 if (typeMirror == null) { |
| 1668 typeMirror = makeLocalTypeMirror(key); | 1667 typeMirror = makeLocalTypeMirror(key); |
| 1669 _instantiationCache[key] = typeMirror; | 1668 _instantiationCache[key] = typeMirror; |
| 1670 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1669 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
| 1671 _declarationCache[key] = typeMirror; | 1670 _declarationCache[key] = typeMirror; |
| 1672 } | 1671 } |
| 1673 } | 1672 } |
| 1674 return typeMirror; | 1673 return typeMirror; |
| 1675 } | 1674 } |
| 1676 } | 1675 } |
| OLD | NEW |