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:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 _constant.computeType(mirrors.compiler).element); | 1476 _constant.computeType(mirrors.compiler).element); |
1477 } | 1477 } |
1478 | 1478 |
1479 bool get hasReflectee => false; | 1479 bool get hasReflectee => false; |
1480 | 1480 |
1481 get reflectee { | 1481 get reflectee { |
1482 // TODO(johnniwinther): Which exception/error should be thrown here? | 1482 // TODO(johnniwinther): Which exception/error should be thrown here? |
1483 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1483 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1484 } | 1484 } |
1485 | 1485 |
1486 Future<InstanceMirror> getField(String fieldName) { | 1486 InstanceMirror getField(String fieldName) { |
1487 // TODO(johnniwinther): Which exception/error should be thrown here? | 1487 // TODO(johnniwinther): Which exception/error should be thrown here? |
1488 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1488 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1489 } | 1489 } |
1490 } | 1490 } |
1491 | 1491 |
1492 class Dart2JsNullConstantMirror extends Dart2JsConstantMirror { | 1492 class Dart2JsNullConstantMirror extends Dart2JsConstantMirror { |
1493 Dart2JsNullConstantMirror(Dart2JsMirrorSystem mirrors, NullConstant constant) | 1493 Dart2JsNullConstantMirror(Dart2JsMirrorSystem mirrors, NullConstant constant) |
1494 : super(mirrors, constant); | 1494 : super(mirrors, constant); |
1495 | 1495 |
1496 NullConstant get _constant => super._constant; | 1496 NullConstant get _constant => super._constant; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 class Dart2JsListConstantMirror extends Dart2JsConstantMirror | 1546 class Dart2JsListConstantMirror extends Dart2JsConstantMirror |
1547 implements ListInstanceMirror { | 1547 implements ListInstanceMirror { |
1548 Dart2JsListConstantMirror(Dart2JsMirrorSystem mirrors, | 1548 Dart2JsListConstantMirror(Dart2JsMirrorSystem mirrors, |
1549 ListConstant constant) | 1549 ListConstant constant) |
1550 : super(mirrors, constant); | 1550 : super(mirrors, constant); |
1551 | 1551 |
1552 ListConstant get _constant => super._constant; | 1552 ListConstant get _constant => super._constant; |
1553 | 1553 |
1554 int get length => _constant.length; | 1554 int get length => _constant.length; |
1555 | 1555 |
1556 Future<InstanceMirror> operator[](int index) { | 1556 InstanceMirror operator[](int index) { |
1557 if (index < 0) throw new RangeError('Negative index'); | 1557 if (index < 0) throw new RangeError('Negative index'); |
1558 if (index >= _constant.length) throw new RangeError('Index out of bounds'); | 1558 if (index >= _constant.length) throw new RangeError('Index out of bounds'); |
1559 return new Future<InstanceMirror>.value( | 1559 return _convertConstantToInstanceMirror(mirrors, _constant.entries[index]); |
1560 _convertConstantToInstanceMirror(mirrors, _constant.entries[index])); | |
1561 } | 1560 } |
1562 } | 1561 } |
1563 | 1562 |
1564 class Dart2JsMapConstantMirror extends Dart2JsConstantMirror | 1563 class Dart2JsMapConstantMirror extends Dart2JsConstantMirror |
1565 implements MapInstanceMirror { | 1564 implements MapInstanceMirror { |
1566 List<String> _listCache; | 1565 List<String> _listCache; |
1567 | 1566 |
1568 Dart2JsMapConstantMirror(Dart2JsMirrorSystem mirrors, | 1567 Dart2JsMapConstantMirror(Dart2JsMirrorSystem mirrors, |
1569 MapConstant constant) | 1568 MapConstant constant) |
1570 : super(mirrors, constant); | 1569 : super(mirrors, constant); |
(...skipping 12 matching lines...) Expand all Loading... |
1583 return _listCache; | 1582 return _listCache; |
1584 } | 1583 } |
1585 | 1584 |
1586 int get length => _constant.length; | 1585 int get length => _constant.length; |
1587 | 1586 |
1588 Iterable<String> get keys { | 1587 Iterable<String> get keys { |
1589 // TODO(johnniwinther): Return an unmodifiable list instead. | 1588 // TODO(johnniwinther): Return an unmodifiable list instead. |
1590 return new List<String>.from(_list); | 1589 return new List<String>.from(_list); |
1591 } | 1590 } |
1592 | 1591 |
1593 Future<InstanceMirror> operator[](String key) { | 1592 InstanceMirror operator[](String key) { |
1594 int index = _list.indexOf(key); | 1593 int index = _list.indexOf(key); |
1595 if (index == -1) return null; | 1594 if (index == -1) return null; |
1596 return new Future<InstanceMirror>.value( | 1595 return _convertConstantToInstanceMirror(mirrors, _constant.values[index]); |
1597 _convertConstantToInstanceMirror(mirrors, _constant.values[index])); | |
1598 } | 1596 } |
1599 } | 1597 } |
1600 | 1598 |
1601 class Dart2JsTypeConstantMirror extends Dart2JsConstantMirror | 1599 class Dart2JsTypeConstantMirror extends Dart2JsConstantMirror |
1602 implements TypeInstanceMirror { | 1600 implements TypeInstanceMirror { |
1603 | 1601 |
1604 Dart2JsTypeConstantMirror(Dart2JsMirrorSystem mirrors, | 1602 Dart2JsTypeConstantMirror(Dart2JsMirrorSystem mirrors, |
1605 TypeConstant constant) | 1603 TypeConstant constant) |
1606 : super(mirrors, constant); | 1604 : super(mirrors, constant); |
1607 | 1605 |
(...skipping 21 matching lines...) Expand all Loading... |
1629 element.forEachInstanceField((_, Element field) { | 1627 element.forEachInstanceField((_, Element field) { |
1630 String fieldName = field.name.slowToString(); | 1628 String fieldName = field.name.slowToString(); |
1631 _fieldMapCache.putIfAbsent(fieldName, () => _constant.fields[index]); | 1629 _fieldMapCache.putIfAbsent(fieldName, () => _constant.fields[index]); |
1632 index++; | 1630 index++; |
1633 }, includeBackendMembers: true, includeSuperMembers: true); | 1631 }, includeBackendMembers: true, includeSuperMembers: true); |
1634 } | 1632 } |
1635 } | 1633 } |
1636 return _fieldMapCache; | 1634 return _fieldMapCache; |
1637 } | 1635 } |
1638 | 1636 |
1639 Future<InstanceMirror> getField(String fieldName) { | 1637 InstanceMirror getField(String fieldName) { |
1640 Constant fieldConstant = _fieldMap[fieldName]; | 1638 Constant fieldConstant = _fieldMap[fieldName]; |
1641 if (fieldConstant != null) { | 1639 if (fieldConstant != null) { |
1642 return new Future<InstanceMirror>.value( | 1640 return _convertConstantToInstanceMirror(mirrors, fieldConstant); |
1643 _convertConstantToInstanceMirror(mirrors, fieldConstant)); | |
1644 } | 1641 } |
1645 return super.getField(fieldName); | 1642 return super.getField(fieldName); |
1646 } | 1643 } |
1647 } | 1644 } |
1648 | 1645 |
1649 class Dart2JsCommentInstanceMirror implements CommentInstanceMirror { | 1646 class Dart2JsCommentInstanceMirror implements CommentInstanceMirror { |
1650 final Dart2JsMirrorSystem mirrors; | 1647 final Dart2JsMirrorSystem mirrors; |
1651 final String text; | 1648 final String text; |
1652 String _trimmedText; | 1649 String _trimmedText; |
1653 | 1650 |
(...skipping 12 matching lines...) Expand all Loading... |
1666 return _trimmedText; | 1663 return _trimmedText; |
1667 } | 1664 } |
1668 | 1665 |
1669 bool get hasReflectee => false; | 1666 bool get hasReflectee => false; |
1670 | 1667 |
1671 get reflectee { | 1668 get reflectee { |
1672 // TODO(johnniwinther): Which exception/error should be thrown here? | 1669 // TODO(johnniwinther): Which exception/error should be thrown here? |
1673 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1670 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1674 } | 1671 } |
1675 | 1672 |
1676 Future<InstanceMirror> getField(String fieldName) { | 1673 InstanceMirror getField(String fieldName) { |
1677 if (fieldName == 'isDocComment') { | 1674 if (fieldName == 'isDocComment') { |
1678 return new Future.value( | 1675 return new Dart2JsBoolConstantMirror.fromBool(mirrors, isDocComment); |
1679 new Dart2JsBoolConstantMirror.fromBool(mirrors, isDocComment)); | |
1680 } else if (fieldName == 'text') { | 1676 } else if (fieldName == 'text') { |
1681 return new Future.value( | 1677 return new Dart2JsStringConstantMirror.fromString(mirrors, text); |
1682 new Dart2JsStringConstantMirror.fromString(mirrors, text)); | |
1683 } else if (fieldName == 'trimmedText') { | 1678 } else if (fieldName == 'trimmedText') { |
1684 return new Future.value( | 1679 return new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText); |
1685 new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText)); | |
1686 } | 1680 } |
1687 // TODO(johnniwinther): Which exception/error should be thrown here? | 1681 // TODO(johnniwinther): Which exception/error should be thrown here? |
1688 throw new UnsupportedError('InstanceMirror does not have a reflectee'); | 1682 throw new UnsupportedError('InstanceMirror does not have a reflectee'); |
1689 } | 1683 } |
1690 } | 1684 } |
OLD | NEW |