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 library mirrors_dart2js; | 5 library mirrors_dart2js; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection' show LinkedHashMap; | 8 import 'dart:collection' show LinkedHashMap; |
9 import 'dart:io' show Path; | 9 import 'dart:io' show Path; |
10 import 'dart:uri'; | 10 import 'dart:uri'; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 return new Dart2JsVoidMirror(system, type); | 80 return new Dart2JsVoidMirror(system, type); |
81 } else if (type is TypedefType) { | 81 } else if (type is TypedefType) { |
82 return new Dart2JsTypedefMirror(system, type); | 82 return new Dart2JsTypedefMirror(system, type); |
83 } else if (type is MalformedType) { | 83 } else if (type is MalformedType) { |
84 // TODO(johnniwinther): We need a mirror on malformed types. | 84 // TODO(johnniwinther): We need a mirror on malformed types. |
85 return system.dynamicType; | 85 return system.dynamicType; |
86 } | 86 } |
87 system.compiler.internalError("Unexpected type $type of kind ${type.kind}"); | 87 system.compiler.internalError("Unexpected type $type of kind ${type.kind}"); |
88 } | 88 } |
89 | 89 |
90 Collection<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( | 90 Iterable<Dart2JsMemberMirror> _convertElementMemberToMemberMirrors( |
91 Dart2JsContainerMirror library, Element element) { | 91 Dart2JsContainerMirror library, Element element) { |
92 if (element.isSynthesized) { | 92 if (element.isSynthesized) { |
93 return const <Dart2JsMemberMirror>[]; | 93 return const <Dart2JsMemberMirror>[]; |
94 } else if (element is VariableElement) { | 94 } else if (element is VariableElement) { |
95 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; | 95 return <Dart2JsMemberMirror>[new Dart2JsFieldMirror(library, element)]; |
96 } else if (element is FunctionElement) { | 96 } else if (element is FunctionElement) { |
97 return <Dart2JsMemberMirror>[new Dart2JsMethodMirror(library, element)]; | 97 return <Dart2JsMemberMirror>[new Dart2JsMethodMirror(library, element)]; |
98 } else if (element is AbstractFieldElement) { | 98 } else if (element is AbstractFieldElement) { |
99 var members = <Dart2JsMemberMirror>[]; | 99 var members = <Dart2JsMemberMirror>[]; |
100 if (element.getter != null) { | 100 if (element.getter != null) { |
(...skipping 1547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 for (StringConstant keyConstant in _constant.keys.entries) { | 1648 for (StringConstant keyConstant in _constant.keys.entries) { |
1649 _listCache[index] = keyConstant.value.slowToString(); | 1649 _listCache[index] = keyConstant.value.slowToString(); |
1650 index++; | 1650 index++; |
1651 } | 1651 } |
1652 } | 1652 } |
1653 return _listCache; | 1653 return _listCache; |
1654 } | 1654 } |
1655 | 1655 |
1656 int get length => _constant.length; | 1656 int get length => _constant.length; |
1657 | 1657 |
1658 Collection<String> get keys { | 1658 Iterable<String> get keys { |
1659 // TODO(johnniwinther): Return an unmodifiable list instead. | 1659 // TODO(johnniwinther): Return an unmodifiable list instead. |
1660 return new List<String>.from(_list); | 1660 return new List<String>.from(_list); |
1661 } | 1661 } |
1662 | 1662 |
1663 Future<InstanceMirror> operator[](String key) { | 1663 Future<InstanceMirror> operator[](String key) { |
1664 int index = _list.indexOf(key); | 1664 int index = _list.indexOf(key); |
1665 if (index == -1) return null; | 1665 if (index == -1) return null; |
1666 return new Future<InstanceMirror>.immediate( | 1666 return new Future<InstanceMirror>.immediate( |
1667 _convertConstantToInstanceMirror(mirrors, _constant.values[index])); | 1667 _convertConstantToInstanceMirror(mirrors, _constant.values[index])); |
1668 } | 1668 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 return new Future.immediate( | 1751 return new Future.immediate( |
1752 new Dart2JsStringConstantMirror.fromString(mirrors, text)); | 1752 new Dart2JsStringConstantMirror.fromString(mirrors, text)); |
1753 } else if (fieldName == 'trimmedText') { | 1753 } else if (fieldName == 'trimmedText') { |
1754 return new Future.immediate( | 1754 return new Future.immediate( |
1755 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); | 1755 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); |
1756 } | 1756 } |
1757 // TODO(johnniwinther): Which exception/error should be thrown here? | 1757 // TODO(johnniwinther): Which exception/error should be thrown here? |
1758 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1758 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1759 } | 1759 } |
1760 } | 1760 } |
OLD | NEW |