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:io'; | 7 import 'dart:io'; |
8 import 'dart:uri'; | 8 import 'dart:uri'; |
9 | 9 |
10 import '../../compiler.dart' as diagnostics; | 10 import '../../compiler.dart' as diagnostics; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 | 426 |
427 | 427 |
428 //------------------------------------------------------------------------------ | 428 //------------------------------------------------------------------------------ |
429 // Dart2Js specific extensions of mirror interfaces | 429 // Dart2Js specific extensions of mirror interfaces |
430 //------------------------------------------------------------------------------ | 430 //------------------------------------------------------------------------------ |
431 | 431 |
432 abstract class Dart2JsMirror implements Mirror { | 432 abstract class Dart2JsMirror implements Mirror { |
433 Dart2JsMirrorSystem get mirrors; | 433 Dart2JsMirrorSystem get mirrors; |
434 } | 434 } |
435 | 435 |
436 abstract class Dart2JsDeclarationMirror | 436 abstract class Dart2JsDeclarationMirror extends Dart2JsMirror |
437 implements Dart2JsMirror, DeclarationMirror { | 437 implements DeclarationMirror { |
438 | 438 |
439 bool get isTopLevel => owner != null && owner is LibraryMirror; | 439 bool get isTopLevel => owner != null && owner is LibraryMirror; |
440 | 440 |
441 bool get isPrivate => _isPrivate(simpleName); | 441 bool get isPrivate => _isPrivate(simpleName); |
442 | |
443 /** | |
444 * Returns the first token for the source of this declaration. | |
445 */ | |
446 Token getBeginToken(); | |
447 | |
448 /** | |
449 * Returns the last token for the source of this declaration. | |
450 */ | |
451 Token getEndToken(); | |
452 | |
453 /** | |
454 * Returns the script for the source of this declaration. | |
455 */ | |
456 Script getScript(); | |
457 | |
458 SourceLocation get location { | |
459 Token beginToken = getBeginToken(); | |
460 Script script = getScript(); | |
461 SourceSpan span; | |
462 if (beginToken == null) { | |
463 span = new SourceSpan(script.uri, 0, 0); | |
464 } else { | |
465 Token endToken = getEndToken(); | |
466 span = mirrors.compiler.spanFromTokens(beginToken, endToken, script.uri); | |
467 } | |
468 return new Dart2JsSourceLocation(script, span); | |
469 } | |
442 } | 470 } |
443 | 471 |
444 abstract class Dart2JsMemberMirror extends Dart2JsElementMirror | 472 abstract class Dart2JsMemberMirror extends Dart2JsElementMirror |
445 implements MemberMirror { | 473 implements MemberMirror { |
446 | 474 |
447 Dart2JsMemberMirror(Dart2JsMirrorSystem system, Element element) | 475 Dart2JsMemberMirror(Dart2JsMirrorSystem system, Element element) |
448 : super(system, element); | 476 : super(system, element); |
449 | 477 |
450 bool get isConstructor => false; | 478 bool get isConstructor => false; |
451 | 479 |
(...skipping 18 matching lines...) Expand all Loading... | |
470 | 498 |
471 Dart2JsElementMirror(this.mirrors, this._element) { | 499 Dart2JsElementMirror(this.mirrors, this._element) { |
472 assert (mirrors != null); | 500 assert (mirrors != null); |
473 assert (_element != null); | 501 assert (_element != null); |
474 } | 502 } |
475 | 503 |
476 String get simpleName => _element.name.slowToString(); | 504 String get simpleName => _element.name.slowToString(); |
477 | 505 |
478 String get displayName => simpleName; | 506 String get displayName => simpleName; |
479 | 507 |
480 SourceLocation get location => new Dart2JsSourceLocation( | 508 /** |
481 _element.getCompilationUnit().script, | 509 * Computes the first token for this declaration using the first metadata |
482 mirrors.compiler.spanFromElement(_element)); | 510 * annotation, the begin token of the element node or element position as |
511 * indicator. | |
512 */ | |
513 Token getBeginToken() { | |
514 if (!_element.metadata.isEmpty) { | |
515 for (MetadataAnnotation metadata in _element.metadata) { | |
516 if (metadata.beginToken != null) { | |
517 return metadata.beginToken; | |
518 } | |
519 } | |
520 } | |
521 // TODO(johnniwinther): Avoid calling [parseNode]. | |
522 Node node = _element.parseNode(mirrors.compiler); | |
523 if (node == null) { | |
524 return _element.position(); | |
525 } | |
526 return node.getBeginToken(); | |
527 } | |
528 | |
529 /** | |
530 * Computes the last token for this declaration using the end token of the | |
531 * element node or element position as indicator. | |
532 */ | |
533 Token getEndToken() { | |
534 // TODO(johnniwinther): Avoid calling [parseNode]. | |
535 Node node = _element.parseNode(mirrors.compiler); | |
536 if (node == null) { | |
537 return _element.position(); | |
538 } | |
539 return node.getEndToken(); | |
540 } | |
541 | |
542 Script getScript() => _element.getCompilationUnit().script; | |
483 | 543 |
484 String toString() => _element.toString(); | 544 String toString() => _element.toString(); |
485 | 545 |
486 int get hashCode => qualifiedName.hashCode; | 546 int get hashCode => qualifiedName.hashCode; |
487 | 547 |
488 List<InstanceMirror> get metadata { | 548 List<InstanceMirror> get metadata { |
489 if (_metadata == null) { | 549 if (_metadata == null) { |
490 _metadata = <InstanceMirror>[]; | 550 _metadata = <InstanceMirror>[]; |
491 for (MetadataAnnotation metadata in _element.metadata) { | 551 for (MetadataAnnotation metadata in _element.metadata) { |
492 metadata.ensureResolved(mirrors.compiler); | 552 metadata.ensureResolved(mirrors.compiler); |
493 _metadata.add( | 553 _metadata.add( |
494 _convertConstantToInstanceMirror(mirrors, metadata.value)); | 554 _convertConstantToInstanceMirror(mirrors, metadata.value)); |
495 } | 555 } |
496 } | 556 } |
497 // TODO(johnniwinther): Return an unmodifiable list instead. | 557 // TODO(johnniwinther): Return an unmodifiable list instead. |
498 return new List<InstanceMirror>.from(_metadata); | 558 return new List<InstanceMirror>.from(_metadata); |
499 } | 559 } |
500 } | 560 } |
501 | 561 |
502 abstract class Dart2JsProxyMirror extends Dart2JsDeclarationMirror { | |
503 final Dart2JsMirrorSystem mirrors; | |
504 | |
505 Dart2JsProxyMirror(this.mirrors); | |
506 | |
507 String get displayName => simpleName; | |
508 | |
509 int get hashCode => qualifiedName.hashCode; | |
510 } | |
511 | |
512 //------------------------------------------------------------------------------ | 562 //------------------------------------------------------------------------------ |
513 // Mirror system implementation. | 563 // Mirror system implementation. |
514 //------------------------------------------------------------------------------ | 564 //------------------------------------------------------------------------------ |
515 | 565 |
516 class Dart2JsMirrorSystem implements MirrorSystem, Dart2JsMirror { | 566 class Dart2JsMirrorSystem implements MirrorSystem { |
517 final api.Compiler compiler; | 567 final api.Compiler compiler; |
518 Map<String, Dart2JsLibraryMirror> _libraries; | 568 Map<String, Dart2JsLibraryMirror> _libraries; |
519 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap; | 569 Map<LibraryElement, Dart2JsLibraryMirror> _libraryMap; |
520 | 570 |
521 Dart2JsMirrorSystem(this.compiler) | 571 Dart2JsMirrorSystem(this.compiler) |
522 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>(); | 572 : _libraryMap = new Map<LibraryElement, Dart2JsLibraryMirror>(); |
523 | 573 |
524 void _ensureLibraries() { | 574 void _ensureLibraries() { |
525 if (_libraries == null) { | 575 if (_libraries == null) { |
526 _libraries = <String, Dart2JsLibraryMirror>{}; | 576 _libraries = <String, Dart2JsLibraryMirror>{}; |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 } | 722 } |
673 }); | 723 }); |
674 } | 724 } |
675 } | 725 } |
676 | 726 |
677 Map<String, ClassMirror> get classes { | 727 Map<String, ClassMirror> get classes { |
678 _ensureClasses(); | 728 _ensureClasses(); |
679 return new ImmutableMapWrapper<String, ClassMirror>(_classes); | 729 return new ImmutableMapWrapper<String, ClassMirror>(_classes); |
680 } | 730 } |
681 | 731 |
682 SourceLocation get location { | 732 /** |
683 var script = _library.getCompilationUnit().script; | 733 * Computes the first token of this library using the first metadata |
684 SourceSpan span; | 734 * annotation or the first library tag as indicator. |
735 */ | |
736 Token getBeginToken() { | |
737 if (!_element.metadata.isEmpty) { | |
738 for (MetadataAnnotation metadata in _element.metadata) { | |
739 if (metadata.beginToken != null) { | |
740 return metadata.beginToken; | |
741 } | |
742 } | |
743 } | |
685 if (_library.libraryTag != null) { | 744 if (_library.libraryTag != null) { |
686 span = mirrors.compiler.spanFromNode(_library.libraryTag, script.uri); | 745 return _library.libraryTag.getBeginToken(); |
687 } else { | 746 } else if (!_library.tags.isEmpty) { |
688 span = new SourceSpan(script.uri, 0, 0); | 747 return _library.tags.reverse().head.getBeginToken(); |
689 } | 748 } |
690 return new Dart2JsSourceLocation(script, span); | 749 return null; |
750 } | |
751 | |
752 /** | |
753 * Computes the first token of this library using the last library tag as | |
754 * indicator. | |
755 */ | |
756 Token getEndToken() { | |
757 if (!_library.tags.isEmpty) { | |
758 return _library.tags.head.getEndToken(); | |
759 } | |
760 return null; | |
691 } | 761 } |
692 } | 762 } |
693 | 763 |
694 class Dart2JsSourceLocation implements SourceLocation { | 764 class Dart2JsSourceLocation implements SourceLocation { |
695 final Script _script; | 765 final Script _script; |
696 final SourceSpan _span; | 766 final SourceSpan _span; |
697 int _line; | 767 int _line; |
698 int _column; | 768 int _column; |
699 | 769 |
700 Dart2JsSourceLocation(this._script, this._span); | 770 Dart2JsSourceLocation(this._script, this._span); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 | 932 |
863 Dart2JsClassMirror.fromLibrary(Dart2JsLibraryMirror library, | 933 Dart2JsClassMirror.fromLibrary(Dart2JsLibraryMirror library, |
864 ClassElement _class) | 934 ClassElement _class) |
865 : this.library = library, | 935 : this.library = library, |
866 super(library.mirrors, _class); | 936 super(library.mirrors, _class); |
867 | 937 |
868 DeclarationMirror get owner => library; | 938 DeclarationMirror get owner => library; |
869 | 939 |
870 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; | 940 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; |
871 | 941 |
872 SourceLocation get location { | |
873 if (_class is PartialClassElement) { | |
874 var node = _class.parseNode(mirrors.compiler); | |
875 if (node != null) { | |
876 var script = _class.getCompilationUnit().script; | |
877 var span = mirrors.compiler.spanFromNode(node, script.uri); | |
878 return new Dart2JsSourceLocation(script, span); | |
879 } | |
880 } | |
881 return super.location; | |
882 } | |
883 | |
884 void _ensureMembers() { | 942 void _ensureMembers() { |
885 if (_members == null) { | 943 if (_members == null) { |
886 _members = <String, Dart2JsMemberMirror>{}; | 944 _members = <String, Dart2JsMemberMirror>{}; |
887 _class.forEachMember((_, e) { | 945 _class.forEachMember((_, e) { |
888 for (var member in _convertElementMemberToMemberMirrors(this, e)) { | 946 for (var member in _convertElementMemberToMemberMirrors(this, e)) { |
889 assert(!_members.containsKey(member.simpleName)); | 947 assert(!_members.containsKey(member.simpleName)); |
890 _members[member.simpleName] = member; | 948 _members[member.simpleName] = member; |
891 } | 949 } |
892 }); | 950 }); |
893 } | 951 } |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
998 | 1056 |
999 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, | 1057 Dart2JsTypedefMirror.fromLibrary(Dart2JsLibraryMirror library, |
1000 TypedefType _typedef) | 1058 TypedefType _typedef) |
1001 : this._library = library, | 1059 : this._library = library, |
1002 super(library.mirrors, _typedef); | 1060 super(library.mirrors, _typedef); |
1003 | 1061 |
1004 TypedefType get _typedef => _type; | 1062 TypedefType get _typedef => _type; |
1005 | 1063 |
1006 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; | 1064 String get qualifiedName => '${library.qualifiedName}.${simpleName}'; |
1007 | 1065 |
1008 SourceLocation get location { | |
1009 var node = _typedef.element.parseNode(_diagnosticListener); | |
1010 if (node != null) { | |
1011 var script = _typedef.element.getCompilationUnit().script; | |
1012 var span = mirrors.compiler.spanFromNode(node, script.uri); | |
1013 return new Dart2JsSourceLocation(script, span); | |
1014 } | |
1015 return super.location; | |
1016 } | |
1017 | |
1018 LibraryMirror get library => _library; | 1066 LibraryMirror get library => _library; |
1019 | 1067 |
1020 bool get isTypedef => true; | 1068 bool get isTypedef => true; |
1021 | 1069 |
1022 List<TypeMirror> get typeArguments { | 1070 List<TypeMirror> get typeArguments { |
1023 throw new UnsupportedError( | 1071 throw new UnsupportedError( |
1024 'Declarations do not have type arguments'); | 1072 'Declarations do not have type arguments'); |
1025 } | 1073 } |
1026 | 1074 |
1027 List<TypeVariableMirror> get typeVariables { | 1075 List<TypeVariableMirror> get typeVariables { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 } | 1164 } |
1117 return qualifiedName == other.qualifiedName; | 1165 return qualifiedName == other.qualifiedName; |
1118 } | 1166 } |
1119 } | 1167 } |
1120 | 1168 |
1121 | 1169 |
1122 //------------------------------------------------------------------------------ | 1170 //------------------------------------------------------------------------------ |
1123 // Types | 1171 // Types |
1124 //------------------------------------------------------------------------------ | 1172 //------------------------------------------------------------------------------ |
1125 | 1173 |
1126 abstract class Dart2JsTypeElementMirror extends Dart2JsProxyMirror | 1174 abstract class Dart2JsTypeElementMirror extends Dart2JsElementMirror |
1127 implements Dart2JsTypeMirror { | 1175 implements Dart2JsTypeMirror { |
1128 final DartType _type; | 1176 final DartType _type; |
1129 List<InstanceMirror> _metadata; | |
1130 | 1177 |
1131 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, this._type) | 1178 Dart2JsTypeElementMirror(Dart2JsMirrorSystem system, DartType type) |
1132 : super(system); | 1179 : super(system, type.element), |
1180 this._type = type; | |
1133 | 1181 |
1134 String get simpleName => _type.name.slowToString(); | 1182 String get simpleName => _type.name.slowToString(); |
1135 | 1183 |
1136 SourceLocation get location { | |
1137 var script = _type.element.getCompilationUnit().script; | |
1138 return new Dart2JsSourceLocation(script, | |
1139 mirrors.compiler.spanFromElement(_type.element)); | |
1140 } | |
1141 | |
1142 DeclarationMirror get owner => library; | 1184 DeclarationMirror get owner => library; |
1143 | 1185 |
1144 LibraryMirror get library { | 1186 LibraryMirror get library { |
1145 return mirrors._getLibrary(_type.element.getLibrary()); | 1187 return mirrors._getLibrary(_type.element.getLibrary()); |
1146 } | 1188 } |
1147 | 1189 |
1148 bool get isObject => false; | 1190 bool get isObject => false; |
1149 | 1191 |
1150 bool get isVoid => false; | 1192 bool get isVoid => false; |
1151 | 1193 |
1152 bool get isDynamic => false; | 1194 bool get isDynamic => false; |
1153 | 1195 |
1154 bool get isTypeVariable => false; | 1196 bool get isTypeVariable => false; |
1155 | 1197 |
1156 bool get isTypedef => false; | 1198 bool get isTypedef => false; |
1157 | 1199 |
1158 bool get isFunction => false; | 1200 bool get isFunction => false; |
1159 | 1201 |
1160 String toString() => _type.element.toString(); | 1202 String toString() => _type.toString(); |
1161 | 1203 |
1162 Map<String, MemberMirror> get members => const <String, MemberMirror>{}; | 1204 Map<String, MemberMirror> get members => const <String, MemberMirror>{}; |
1163 | 1205 |
1164 Map<String, MethodMirror> get constructors => const <String, MethodMirror>{}; | 1206 Map<String, MethodMirror> get constructors => const <String, MethodMirror>{}; |
1165 | 1207 |
1166 Map<String, MethodMirror> get methods => const <String, MethodMirror>{}; | 1208 Map<String, MethodMirror> get methods => const <String, MethodMirror>{}; |
1167 | 1209 |
1168 Map<String, MethodMirror> get getters => const <String, MethodMirror>{}; | 1210 Map<String, MethodMirror> get getters => const <String, MethodMirror>{}; |
1169 | 1211 |
1170 Map<String, MethodMirror> get setters => const <String, MethodMirror>{}; | 1212 Map<String, MethodMirror> get setters => const <String, MethodMirror>{}; |
1171 | 1213 |
1172 Map<String, VariableMirror> get variables => const <String, VariableMirror>{}; | 1214 Map<String, VariableMirror> get variables => const <String, VariableMirror>{}; |
1173 | 1215 |
1174 ClassMirror get defaultFactory => null; | 1216 ClassMirror get defaultFactory => null; |
1175 | |
1176 // TODO(johnniwinther): Should a type show the metadata of its declaration? | |
1177 List<InstanceMirror> get metadata { | |
1178 if (_metadata == null) { | |
1179 var _metadata = <InstanceMirror>[]; | |
1180 for (MetadataAnnotation metadata in _type.element.metadata) { | |
1181 metadata.ensureResolved(mirrors.compiler); | |
1182 _metadata.add( | |
1183 _convertConstantToInstanceMirror(mirrors, metadata.value)); | |
1184 } | |
1185 } | |
1186 // TODO(johnniwinther): Return an unmodifiable list instead. | |
1187 return new List<InstanceMirror>.from(_metadata); | |
1188 } | |
1189 } | 1217 } |
1190 | 1218 |
1191 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror | 1219 class Dart2JsInterfaceTypeMirror extends Dart2JsTypeElementMirror |
1192 implements ClassMirror { | 1220 implements ClassMirror { |
1193 List<TypeMirror> _typeArguments; | 1221 List<TypeMirror> _typeArguments; |
1194 | 1222 |
1195 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, | 1223 Dart2JsInterfaceTypeMirror(Dart2JsMirrorSystem system, |
1196 InterfaceType interfaceType) | 1224 InterfaceType interfaceType) |
1197 : super(system, interfaceType); | 1225 : super(system, interfaceType); |
1198 | 1226 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1559 | 1587 |
1560 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING; | 1588 bool get isRedirectingConstructor => _kind == Dart2JsMethodKind.REDIRECTING; |
1561 | 1589 |
1562 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY; | 1590 bool get isFactoryConstructor => _kind == Dart2JsMethodKind.FACTORY; |
1563 | 1591 |
1564 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; | 1592 bool get isGetter => _kind == Dart2JsMethodKind.GETTER; |
1565 | 1593 |
1566 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; | 1594 bool get isSetter => _kind == Dart2JsMethodKind.SETTER; |
1567 | 1595 |
1568 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; | 1596 bool get isOperator => _kind == Dart2JsMethodKind.OPERATOR; |
1569 | |
1570 SourceLocation get location { | |
1571 var node = _function.parseNode(_diagnosticListener); | |
1572 if (node != null) { | |
1573 var script = _function.getCompilationUnit().script; | |
1574 var span = mirrors.compiler.spanFromNode(node, script.uri); | |
1575 return new Dart2JsSourceLocation(script, span); | |
1576 } | |
1577 return super.location; | |
1578 } | |
1579 | |
1580 } | 1597 } |
1581 | 1598 |
1582 class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror { | 1599 class Dart2JsFieldMirror extends Dart2JsMemberMirror implements VariableMirror { |
1583 Dart2JsContainerMirror _objectMirror; | 1600 Dart2JsContainerMirror _objectMirror; |
1584 VariableElement _variable; | 1601 VariableElement _variable; |
1585 | 1602 |
1586 Dart2JsFieldMirror(Dart2JsContainerMirror objectMirror, | 1603 Dart2JsFieldMirror(Dart2JsContainerMirror objectMirror, |
1587 VariableElement variable) | 1604 VariableElement variable) |
1588 : this._objectMirror = objectMirror, | 1605 : this._objectMirror = objectMirror, |
1589 this._variable = variable, | 1606 this._variable = variable, |
(...skipping 10 matching lines...) Expand all Loading... | |
1600 | 1617 |
1601 bool get isStatic => _variable.modifiers.isStatic(); | 1618 bool get isStatic => _variable.modifiers.isStatic(); |
1602 | 1619 |
1603 bool get isFinal => _variable.modifiers.isFinal(); | 1620 bool get isFinal => _variable.modifiers.isFinal(); |
1604 | 1621 |
1605 bool get isConst => _variable.modifiers.isConst(); | 1622 bool get isConst => _variable.modifiers.isConst(); |
1606 | 1623 |
1607 TypeMirror get type => _convertTypeToTypeMirror(mirrors, | 1624 TypeMirror get type => _convertTypeToTypeMirror(mirrors, |
1608 _variable.computeType(mirrors.compiler), | 1625 _variable.computeType(mirrors.compiler), |
1609 mirrors.compiler.types.dynamicType); | 1626 mirrors.compiler.types.dynamicType); |
1610 | |
1611 SourceLocation get location { | |
1612 var script = _variable.getCompilationUnit().script; | |
1613 var node = _variable.variables.parseNode(_diagnosticListener); | |
1614 if (node != null) { | |
1615 var span = mirrors.compiler.spanFromNode(node, script.uri); | |
1616 return new Dart2JsSourceLocation(script, span); | |
1617 } else { | |
1618 var span = mirrors.compiler.spanFromElement(_variable); | |
1619 return new Dart2JsSourceLocation(script, span); | |
1620 } | |
1621 } | |
1622 } | 1627 } |
1623 | 1628 |
1624 //////////////////////////////////////////////////////////////////////////////// | 1629 //////////////////////////////////////////////////////////////////////////////// |
1625 // Mirrors on constant values used for metadata. | 1630 // Mirrors on constant values used for metadata. |
1626 //////////////////////////////////////////////////////////////////////////////// | 1631 //////////////////////////////////////////////////////////////////////////////// |
1627 | 1632 |
1628 class Dart2JsConstantMirror extends InstanceMirror { | 1633 class Dart2JsConstantMirror extends InstanceMirror { |
1629 final Dart2JsMirrorSystem mirrors; | 1634 final Dart2JsMirrorSystem mirrors; |
1630 final Constant _constant; | 1635 final Constant _constant; |
1631 | 1636 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1705 | 1710 |
1706 int get length => _constant.length; | 1711 int get length => _constant.length; |
1707 | 1712 |
1708 Future<InstanceMirror> operator[](int index) { | 1713 Future<InstanceMirror> operator[](int index) { |
1709 if (index < 0) throw new RangeError('Negative index'); | 1714 if (index < 0) throw new RangeError('Negative index'); |
1710 if (index >= _constant.length) throw new RangeError('Index out of bounds'); | 1715 if (index >= _constant.length) throw new RangeError('Index out of bounds'); |
1711 return new Future<InstanceMirror>.immediate( | 1716 return new Future<InstanceMirror>.immediate( |
1712 _convertConstantToInstanceMirror(mirrors, _constant.entries[index])); | 1717 _convertConstantToInstanceMirror(mirrors, _constant.entries[index])); |
1713 } | 1718 } |
1714 } | 1719 } |
1715 | 1720 |
Johnni Winther
2013/01/04 09:57:56
The changes below are from https://codereview.chro
| |
1716 class Dart2JsMapConstantMirror extends Dart2JsConstantMirror | 1721 class Dart2JsMapConstantMirror extends Dart2JsConstantMirror |
1717 implements MapInstanceMirror { | 1722 implements MapInstanceMirror { |
1718 List<String> _listCache; | 1723 List<String> _listCache; |
1719 | 1724 |
1720 Dart2JsMapConstantMirror(Dart2JsMirrorSystem mirrors, | 1725 Dart2JsMapConstantMirror(Dart2JsMirrorSystem mirrors, |
1721 MapConstant constant) | 1726 MapConstant constant) |
1722 : super(mirrors, constant); | 1727 : super(mirrors, constant); |
1723 | 1728 |
1724 MapConstant get _constant => super._constant; | 1729 MapConstant get _constant => super._constant; |
1725 | 1730 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1790 | 1795 |
1791 Future<InstanceMirror> getField(String fieldName) { | 1796 Future<InstanceMirror> getField(String fieldName) { |
1792 Constant fieldConstant = _fieldMap[fieldName]; | 1797 Constant fieldConstant = _fieldMap[fieldName]; |
1793 if (fieldConstant != null) { | 1798 if (fieldConstant != null) { |
1794 return new Future<InstanceMirror>.immediate( | 1799 return new Future<InstanceMirror>.immediate( |
1795 _convertConstantToInstanceMirror(mirrors, fieldConstant)); | 1800 _convertConstantToInstanceMirror(mirrors, fieldConstant)); |
1796 } | 1801 } |
1797 return super.getField(fieldName); | 1802 return super.getField(fieldName); |
1798 } | 1803 } |
1799 } | 1804 } |
OLD | NEW |