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 | 9 |
10 class _InternalMirrorError { | 10 class _InternalMirrorError { |
(...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1638 static InstanceMirror reflect(Object reflectee) { | 1638 static InstanceMirror reflect(Object reflectee) { |
1639 return reflectee is Function | 1639 return reflectee is Function |
1640 ? new _LocalClosureMirror(reflectee) | 1640 ? new _LocalClosureMirror(reflectee) |
1641 : new _LocalInstanceMirror(reflectee); | 1641 : new _LocalInstanceMirror(reflectee); |
1642 } | 1642 } |
1643 | 1643 |
1644 static ClassMirror makeLocalClassMirror(Type key) | 1644 static ClassMirror makeLocalClassMirror(Type key) |
1645 native "Mirrors_makeLocalClassMirror"; | 1645 native "Mirrors_makeLocalClassMirror"; |
1646 static TypeMirror makeLocalTypeMirror(Type key) | 1646 static TypeMirror makeLocalTypeMirror(Type key) |
1647 native "Mirrors_makeLocalTypeMirror"; | 1647 native "Mirrors_makeLocalTypeMirror"; |
| 1648 static Type instantiateGenericType(Type key, typeArguments) |
| 1649 native "Mirrors_instantiateGenericType"; |
1648 | 1650 |
1649 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); | 1651 static Expando<ClassMirror> _declarationCache = new Expando("ClassMirror"); |
1650 static Expando<TypeMirror> _instantiationCache = new Expando("TypeMirror"); | 1652 static Expando<TypeMirror> _instantiationCache = new Expando("TypeMirror"); |
1651 | 1653 |
1652 static ClassMirror reflectClass(Type key) { | 1654 static ClassMirror reflectClass(Type key) { |
1653 var classMirror = _declarationCache[key]; | 1655 var classMirror = _declarationCache[key]; |
1654 if (classMirror == null) { | 1656 if (classMirror == null) { |
1655 classMirror = makeLocalClassMirror(key); | 1657 classMirror = makeLocalClassMirror(key); |
1656 _declarationCache[key] = classMirror; | 1658 _declarationCache[key] = classMirror; |
1657 if (!classMirror._isGeneric) { | 1659 if (!classMirror._isGeneric) { |
1658 _instantiationCache[key] = classMirror; | 1660 _instantiationCache[key] = classMirror; |
1659 } | 1661 } |
1660 } | 1662 } |
1661 return classMirror; | 1663 return classMirror; |
1662 } | 1664 } |
1663 | 1665 |
1664 static TypeMirror reflectType(Type key) { | 1666 static TypeMirror reflectType(Type key, [List<Type> typeArguments]) { |
| 1667 if (typeArguments != null) { |
| 1668 key = _instantiateType(key, typeArguments); |
| 1669 } |
1665 var typeMirror = _instantiationCache[key]; | 1670 var typeMirror = _instantiationCache[key]; |
1666 if (typeMirror == null) { | 1671 if (typeMirror == null) { |
1667 typeMirror = makeLocalTypeMirror(key); | 1672 typeMirror = makeLocalTypeMirror(key); |
1668 _instantiationCache[key] = typeMirror; | 1673 _instantiationCache[key] = typeMirror; |
1669 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { | 1674 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { |
1670 _declarationCache[key] = typeMirror; | 1675 _declarationCache[key] = typeMirror; |
1671 } | 1676 } |
1672 } | 1677 } |
1673 return typeMirror; | 1678 return typeMirror; |
1674 } | 1679 } |
| 1680 |
| 1681 static Type _instantiateType(Type key, List<Type> typeArguments) { |
| 1682 if (typeArguments.isEmpty) { |
| 1683 throw new ArgumentError.value( |
| 1684 typeArguments, 'typeArguments', 'Type arguments list cannot be empty.'); |
| 1685 } |
| 1686 return instantiateGenericType(key, typeArguments.toList(growable: false)); |
| 1687 } |
1675 } | 1688 } |
OLD | NEW |