Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: runtime/lib/mirrors_impl.dart

Issue 126823004: Add TypeMirror.isSubtypeOf, TypeMirror.isAssignableTo, ClassMirror.isSubclassOf (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: mark source mirrors as failing Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import "dart:collection"; 7 import "dart:collection";
8 8
9 final emptyList = new UnmodifiableListView([]); 9 final emptyList = new UnmodifiableListView([]);
10 final emptyMap = new _UnmodifiableMapView({}); 10 final emptyMap = new _UnmodifiableMapView({});
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 buf.write(']'); 102 buf.write(']');
103 } 103 }
104 buf.write(') -> '); 104 buf.write(') -> ');
105 buf.write(_n(returnType.qualifiedName)); 105 buf.write(_n(returnType.qualifiedName));
106 return buf.toString(); 106 return buf.toString();
107 } 107 }
108 108
109 List _metadata(reflectee) 109 List _metadata(reflectee)
110 native 'DeclarationMirror_metadata'; 110 native 'DeclarationMirror_metadata';
111 111
112 bool _subtypeTest(Type a, Type b)
113 native 'TypeMirror_subtypeTest';
114
115 bool _moreSpecificTest(Type a, Type b)
116 native 'TypeMirror_moreSpecificTest';
117
112 class _LocalMirrorSystem extends MirrorSystem { 118 class _LocalMirrorSystem extends MirrorSystem {
113 final Map<Uri, LibraryMirror> libraries; 119 final Map<Uri, LibraryMirror> libraries;
114 final IsolateMirror isolate; 120 final IsolateMirror isolate;
115 121
116 _LocalMirrorSystem(List<LibraryMirror> libraries, this.isolate) 122 _LocalMirrorSystem(List<LibraryMirror> libraries, this.isolate)
117 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable( 123 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable(
118 libraries, key: (e) => e.uri); 124 libraries, key: (e) => e.uri);
119 125
120 TypeMirror _dynamicType = null; 126 TypeMirror _dynamicType = null;
121 TypeMirror get dynamicType { 127 TypeMirror get dynamicType {
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
844 850
845 bool operator ==(other) { 851 bool operator ==(other) {
846 return this.runtimeType == other.runtimeType && 852 return this.runtimeType == other.runtimeType &&
847 this._reflectee == other._reflectee && 853 this._reflectee == other._reflectee &&
848 this._reflectedType == other._reflectedType && 854 this._reflectedType == other._reflectedType &&
849 this._isGenericDeclaration == other._isGenericDeclaration; 855 this._isGenericDeclaration == other._isGenericDeclaration;
850 } 856 }
851 857
852 int get hashCode => simpleName.hashCode; 858 int get hashCode => simpleName.hashCode;
853 859
860 bool isSubtypeOf(TypeMirror other) {
861 if (other == currentMirrorSystem().dynamicType) return true;
862 if (other == currentMirrorSystem().voidType) return false;
863 return _subtypeTest(_reflectedType, other._reflectedType);
864 }
865
866 bool isAssignableTo(TypeMirror other) {
867 if (other == currentMirrorSystem().dynamicType) return true;
868 if (other == currentMirrorSystem().voidType) return false;
869 return _moreSpecificTest(_reflectedType, other._reflectedType)
870 || _moreSpecificTest(other._reflectedType, _reflectedType);
871 }
872
873 bool isSubclassOf(ClassMirror other) {
874 if (other is! ClassMirror) throw new ArgumentError(other);
875 ClassMirror otherDeclaration = other.originalDeclaration;
876 ClassMirror c = this;
877 while (c != null) {
878 c = c.originalDeclaration;
879 if (c == otherDeclaration) return true;
880 c = c.superclass;
881 }
882 return false;
883 }
884
854 static _library(reflectee) 885 static _library(reflectee)
855 native "ClassMirror_library"; 886 native "ClassMirror_library";
856 887
857 static _supertype(reflectedType) 888 static _supertype(reflectedType)
858 native "ClassMirror_supertype"; 889 native "ClassMirror_supertype";
859 890
860 static _supertypeInstantiated(reflectedType) 891 static _supertypeInstantiated(reflectedType)
861 native "ClassMirror_supertype_instantiated"; 892 native "ClassMirror_supertype_instantiated";
862 893
863 static _nativeInterfaces(reflectedType) 894 static _nativeInterfaces(reflectedType)
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 1047
1017 TypeMirror _upperBound = null; 1048 TypeMirror _upperBound = null;
1018 TypeMirror get upperBound { 1049 TypeMirror get upperBound {
1019 if (_upperBound == null) { 1050 if (_upperBound == null) {
1020 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee)); 1051 _upperBound = reflectType(_TypeVariableMirror_upper_bound(_reflectee));
1021 } 1052 }
1022 return _upperBound; 1053 return _upperBound;
1023 } 1054 }
1024 1055
1025 bool get hasReflectedType => false; 1056 bool get hasReflectedType => false;
1026 Type get reflectedType => throw new UnsupportedError() ; 1057 Type get reflectedType => throw new UnsupportedError();
1058 Type get _reflectedType => _reflectee;
1027 1059
1028 List<TypeVariableMirror> get typeVariables => emptyList; 1060 List<TypeVariableMirror> get typeVariables => emptyList;
1029 List<TypeMirror> get typeArguments => emptyList; 1061 List<TypeMirror> get typeArguments => emptyList;
1030 1062
1031 bool get isOriginalDeclaration => true; 1063 bool get isOriginalDeclaration => true;
1032 TypeMirror get originalDeclaration => this; 1064 TypeMirror get originalDeclaration => this;
1033 1065
1034 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; 1066 String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
1035 1067
1036 operator ==(other) { 1068 operator ==(other) {
1037 return other is TypeVariableMirror 1069 return other is TypeVariableMirror
1038 && simpleName == other.simpleName 1070 && simpleName == other.simpleName
1039 && owner == other.owner; 1071 && owner == other.owner;
1040 } 1072 }
1041 int get hashCode => simpleName.hashCode; 1073 int get hashCode => simpleName.hashCode;
1042 1074
1075 bool isSubtypeOf(TypeMirror other) {
1076 if (other == currentMirrorSystem().dynamicType) return true;
1077 if (other == currentMirrorSystem().voidType) return false;
1078 return _subtypeTest(_reflectedType, other._reflectedType);
1079 }
1080
1081 bool isAssignableTo(TypeMirror other) {
1082 if (other == currentMirrorSystem().dynamicType) return true;
1083 if (other == currentMirrorSystem().voidType) return false;
1084 return _moreSpecificTest(_reflectedType, other._reflectedType)
1085 || _moreSpecificTest(other._reflectedType, _reflectedType);
1086 }
1087
1043 static DeclarationMirror _TypeVariableMirror_owner(reflectee) 1088 static DeclarationMirror _TypeVariableMirror_owner(reflectee)
1044 native "TypeVariableMirror_owner"; 1089 native "TypeVariableMirror_owner";
1045 1090
1046 static Type _TypeVariableMirror_upper_bound(reflectee) 1091 static Type _TypeVariableMirror_upper_bound(reflectee)
1047 native "TypeVariableMirror_upper_bound"; 1092 native "TypeVariableMirror_upper_bound";
1048 } 1093 }
1049 1094
1050 1095
1051 class _LocalTypedefMirror extends _LocalDeclarationMirror 1096 class _LocalTypedefMirror extends _LocalDeclarationMirror
1052 implements TypedefMirror { 1097 implements TypedefMirror {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } else { 1165 } else {
1121 _typeArguments = new UnmodifiableListView( 1166 _typeArguments = new UnmodifiableListView(
1122 _LocalClassMirror._computeTypeArguments(_reflectedType)); 1167 _LocalClassMirror._computeTypeArguments(_reflectedType));
1123 } 1168 }
1124 } 1169 }
1125 return _typeArguments; 1170 return _typeArguments;
1126 } 1171 }
1127 1172
1128 String toString() => "TypedefMirror on '${_n(simpleName)}'"; 1173 String toString() => "TypedefMirror on '${_n(simpleName)}'";
1129 1174
1175 bool isSubtypeOf(TypeMirror other) {
1176 if (other == currentMirrorSystem().dynamicType) return true;
1177 if (other == currentMirrorSystem().voidType) return false;
1178 return _subtypeTest(_reflectedType, other._reflectedType);
1179 }
1180
1181 bool isAssignableTo(TypeMirror other) {
1182 if (other == currentMirrorSystem().dynamicType) return true;
1183 if (other == currentMirrorSystem().voidType) return false;
1184 return _moreSpecificTest(_reflectedType, other._reflectedType)
1185 || _moreSpecificTest(other._reflectedType, _reflectedType);
1186 }
1187
1130 static _nativeReferent(reflectedType) 1188 static _nativeReferent(reflectedType)
1131 native "TypedefMirror_referent"; 1189 native "TypedefMirror_referent";
1132 1190
1133 static _nativeDeclaration(reflectedType) 1191 static _nativeDeclaration(reflectedType)
1134 native "TypedefMirror_declaration"; 1192 native "TypedefMirror_declaration";
1135 } 1193 }
1136 1194
1137 Symbol _asSetter(Symbol getter, LibraryMirror library) { 1195 Symbol _asSetter(Symbol getter, LibraryMirror library) {
1138 var unwrapped = MirrorSystem.getName(getter); 1196 var unwrapped = MirrorSystem.getName(getter);
1139 return MirrorSystem.getSymbol('${unwrapped}=', library); 1197 return MirrorSystem.getSymbol('${unwrapped}=', library);
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 bool operator ==(other) { 1582 bool operator ==(other) {
1525 if (other is! _SpecialTypeMirror) { 1583 if (other is! _SpecialTypeMirror) {
1526 return false; 1584 return false;
1527 } 1585 }
1528 return this.simpleName == other.simpleName; 1586 return this.simpleName == other.simpleName;
1529 } 1587 }
1530 1588
1531 int get hashCode => simpleName.hashCode; 1589 int get hashCode => simpleName.hashCode;
1532 1590
1533 String toString() => "TypeMirror on '${_n(simpleName)}'"; 1591 String toString() => "TypeMirror on '${_n(simpleName)}'";
1592
1593 bool isSubtypeOf(TypeMirror other) {
1594 return simpleName == #dynamic || other is _SpecialTypeMirror;
1595 }
1596
1597 bool isAssignableTo(TypeMirror other) {
1598 return simpleName == #dynamic || other is _SpecialTypeMirror;
1599 }
1534 } 1600 }
1535 1601
1536 class _Mirrors { 1602 class _Mirrors {
1537 static MirrorSystem _currentMirrorSystem = null; 1603 static MirrorSystem _currentMirrorSystem = null;
1538 1604
1539 // Creates a new local MirrorSystem. 1605 // Creates a new local MirrorSystem.
1540 static MirrorSystem makeLocalMirrorSystem() 1606 static MirrorSystem makeLocalMirrorSystem()
1541 native 'Mirrors_makeLocalMirrorSystem'; 1607 native 'Mirrors_makeLocalMirrorSystem';
1542 1608
1543 // The MirrorSystem for the current isolate. 1609 // The MirrorSystem for the current isolate.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1580 if (typeMirror == null) { 1646 if (typeMirror == null) {
1581 typeMirror = makeLocalTypeMirror(key); 1647 typeMirror = makeLocalTypeMirror(key);
1582 _instanitationCache[key] = typeMirror; 1648 _instanitationCache[key] = typeMirror;
1583 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1649 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1584 _declarationCache[key] = typeMirror; 1650 _declarationCache[key] = typeMirror;
1585 } 1651 }
1586 } 1652 }
1587 return typeMirror; 1653 return typeMirror;
1588 } 1654 }
1589 } 1655 }
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/vm/bootstrap_natives.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698