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

Side by Side Diff: sdk/lib/_internal/lib/js_mirrors.dart

Issue 24197003: Support typeVariables in ClassMirror. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments. Created 7 years, 3 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 dart._js_mirrors; 5 library dart._js_mirrors;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show UnmodifiableListView; 8 import 'dart:collection' show UnmodifiableListView;
9 import 'dart:mirrors'; 9 import 'dart:mirrors';
10 10
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 171 }
172 172
173 _invoke(List positionalArguments, Map<Symbol, dynamic> namedArguments) { 173 _invoke(List positionalArguments, Map<Symbol, dynamic> namedArguments) {
174 throw new RuntimeError('Should not call _invoke'); 174 throw new RuntimeError('Should not call _invoke');
175 } 175 }
176 176
177 // TODO(ahe): Implement this. 177 // TODO(ahe): Implement this.
178 SourceLocation get location => throw new UnimplementedError(); 178 SourceLocation get location => throw new UnimplementedError();
179 } 179 }
180 180
181 class JsTypeVariableMirror extends JsTypeMirror {
182 final TypeMirror upperBound;
183 final DeclarationMirror owner;
184
185 JsTypeVariableMirror(Symbol simpleName, this.upperBound, this.owner)
186 : super(simpleName);
187
188 bool operator ==(other) {
189 return (other is JsTypeVariableMirror &&
190 simpleName == other.simpleName &&
191 owner == other.owner);
192 }
193
194 String get _prettyName => 'TypeVariableMirror';
195 }
196
181 class JsTypeMirror extends JsDeclarationMirror implements TypeMirror { 197 class JsTypeMirror extends JsDeclarationMirror implements TypeMirror {
182 JsTypeMirror(Symbol simpleName) 198 JsTypeMirror(Symbol simpleName)
183 : super(simpleName); 199 : super(simpleName);
184 200
185 String get _prettyName => 'TypeMirror'; 201 String get _prettyName => 'TypeMirror';
186 202
187 DeclarationMirror get owner => null; 203 DeclarationMirror get owner => null;
188 204
189 // TODO(ahe): Doesn't match the specification, see http://dartbug.com/11569. 205 // TODO(ahe): Doesn't match the specification, see http://dartbug.com/11569.
190 bool get isTopLevel => true; 206 bool get isTopLevel => true;
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 List<JsMethodMirror> _cachedMethods; 908 List<JsMethodMirror> _cachedMethods;
893 List<JsVariableMirror> _cachedFields; 909 List<JsVariableMirror> _cachedFields;
894 UnmodifiableMapView<Symbol, MethodMirror> _cachedConstructors; 910 UnmodifiableMapView<Symbol, MethodMirror> _cachedConstructors;
895 UnmodifiableMapView<Symbol, MethodMirror> _cachedMethodsMap; 911 UnmodifiableMapView<Symbol, MethodMirror> _cachedMethodsMap;
896 UnmodifiableMapView<Symbol, MethodMirror> _cachedGetters; 912 UnmodifiableMapView<Symbol, MethodMirror> _cachedGetters;
897 UnmodifiableMapView<Symbol, MethodMirror> _cachedSetters; 913 UnmodifiableMapView<Symbol, MethodMirror> _cachedSetters;
898 UnmodifiableMapView<Symbol, VariableMirror> _cachedVariables; 914 UnmodifiableMapView<Symbol, VariableMirror> _cachedVariables;
899 UnmodifiableMapView<Symbol, Mirror> _cachedMembers; 915 UnmodifiableMapView<Symbol, Mirror> _cachedMembers;
900 UnmodifiableListView<InstanceMirror> _cachedMetadata; 916 UnmodifiableListView<InstanceMirror> _cachedMetadata;
901 UnmodifiableListView<ClassMirror> _cachedSuperinterfaces; 917 UnmodifiableListView<ClassMirror> _cachedSuperinterfaces;
918 UnmodifiableListView<TypeVariableMirror> _cachedTypeVariables;
902 919
903 // Set as side-effect of accessing JsLibraryMirror.classes. 920 // Set as side-effect of accessing JsLibraryMirror.classes.
904 JsLibraryMirror _owner; 921 JsLibraryMirror _owner;
905 922
906 JsClassMirror(Symbol simpleName, 923 JsClassMirror(Symbol simpleName,
907 this._mangledName, 924 this._mangledName,
908 this._jsConstructorOrInterceptor, 925 this._jsConstructorOrInterceptor,
909 this._fieldsDescriptor, 926 this._fieldsDescriptor,
910 this._fieldsMetadata) 927 this._fieldsMetadata)
911 : super(simpleName); 928 : super(simpleName);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 ClassMirror lookupType(int i) { 1253 ClassMirror lookupType(int i) {
1237 var type = JS('=Object', 'init.metadata[#]', i); 1254 var type = JS('=Object', 'init.metadata[#]', i);
1238 return typeMirrorFromRuntimeTypeRepresentation(type); 1255 return typeMirrorFromRuntimeTypeRepresentation(type);
1239 } 1256 }
1240 result = interfaces.map(lookupType).toList(); 1257 result = interfaces.map(lookupType).toList();
1241 } 1258 }
1242 return _cachedSuperinterfaces = 1259 return _cachedSuperinterfaces =
1243 new UnmodifiableListView<ClassMirror>(result); 1260 new UnmodifiableListView<ClassMirror>(result);
1244 } 1261 }
1245 1262
1246 // TODO(ahe): Implement these. 1263 List<TypeVariableMirror> get typeVariables {
1247 List<TypeVariableMirror> get typeVariables 1264 if (_cachedTypeVariables != null) return _cachedTypeVariables;
1248 => throw new UnimplementedError(); 1265 List result = new List();
1266 List typeVars =
1267 JS('JSExtendableArray|Null', '#.prototype["<>"]', _jsConstructor);
1268 if (typeVars == null) return result;
1269 for (int i = 0; i < typeVars.length; i += 2) {
1270 TypeMirror upperBound =
1271 typeMirrorFromRuntimeTypeRepresentation(JS('', 'init.metadata[#]',
1272 typeVars[i+1]));
1273 var typeMirror =
1274 new JsTypeVariableMirror(s(typeVars[i]), upperBound, this);
1275 result.add(typeMirror);
1276 }
1277 return _cachedTypeVariables = new UnmodifiableListView(result);
1278 }
1279
1249 List<TypeMirror> get typeArguments => new List(); 1280 List<TypeMirror> get typeArguments => new List();
1250 } 1281 }
1251 1282
1252 class JsVariableMirror extends JsDeclarationMirror implements VariableMirror { 1283 class JsVariableMirror extends JsDeclarationMirror implements VariableMirror {
1253 static final int REFLECTION_MARKER = 45; 1284 static final int REFLECTION_MARKER = 45;
1254 1285
1255 // TODO(ahe): The values in these fields are virtually untested. 1286 // TODO(ahe): The values in these fields are virtually untested.
1256 final String _jsName; 1287 final String _jsName;
1257 final bool isFinal; 1288 final bool isFinal;
1258 final bool isStatic; 1289 final bool isStatic;
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 void operator []=(K key, V value) => _throw(); 1875 void operator []=(K key, V value) => _throw();
1845 1876
1846 V putIfAbsent(K key, V ifAbsent()) { _throw(); } 1877 V putIfAbsent(K key, V ifAbsent()) { _throw(); }
1847 1878
1848 void addAll(Map<K, V> other) => _throw(); 1879 void addAll(Map<K, V> other) => _throw();
1849 1880
1850 V remove(K key) { _throw(); } 1881 V remove(K key) { _throw(); }
1851 1882
1852 void clear() => _throw(); 1883 void clear() => _throw();
1853 } 1884 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart ('k') | tests/lib/mirrors/generics_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698