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

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

Issue 36023003: Add LibraryMirror.declarations and ClassMirror.declarations to the API and both implementations. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: typevars are not static Created 7 years, 2 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 final bool _isRoot; 246 final bool _isRoot;
247 final _globalObject; 247 final _globalObject;
248 List<JsMethodMirror> _cachedFunctionMirrors; 248 List<JsMethodMirror> _cachedFunctionMirrors;
249 List<JsVariableMirror> _cachedFields; 249 List<JsVariableMirror> _cachedFields;
250 UnmodifiableMapView<Symbol, ClassMirror> _cachedClasses; 250 UnmodifiableMapView<Symbol, ClassMirror> _cachedClasses;
251 UnmodifiableMapView<Symbol, MethodMirror> _cachedFunctions; 251 UnmodifiableMapView<Symbol, MethodMirror> _cachedFunctions;
252 UnmodifiableMapView<Symbol, MethodMirror> _cachedGetters; 252 UnmodifiableMapView<Symbol, MethodMirror> _cachedGetters;
253 UnmodifiableMapView<Symbol, MethodMirror> _cachedSetters; 253 UnmodifiableMapView<Symbol, MethodMirror> _cachedSetters;
254 UnmodifiableMapView<Symbol, VariableMirror> _cachedVariables; 254 UnmodifiableMapView<Symbol, VariableMirror> _cachedVariables;
255 UnmodifiableMapView<Symbol, Mirror> _cachedMembers; 255 UnmodifiableMapView<Symbol, Mirror> _cachedMembers;
256 UnmodifiableMapView<Symbol, DeclarationMirror> _cachedDeclarations;
256 UnmodifiableListView<InstanceMirror> _cachedMetadata; 257 UnmodifiableListView<InstanceMirror> _cachedMetadata;
257 258
258 JsLibraryMirror(Symbol simpleName, 259 JsLibraryMirror(Symbol simpleName,
259 this.uri, 260 this.uri,
260 this._classes, 261 this._classes,
261 this._functions, 262 this._functions,
262 this._metadata, 263 this._metadata,
263 this._compactFieldSpecification, 264 this._compactFieldSpecification,
264 this._isRoot, 265 this._isRoot,
265 this._globalObject) 266 this._globalObject)
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 addToResult(Symbol key, Mirror value) { 424 addToResult(Symbol key, Mirror value) {
424 result[key] = value; 425 result[key] = value;
425 } 426 }
426 functions.forEach(addToResult); 427 functions.forEach(addToResult);
427 getters.forEach(addToResult); 428 getters.forEach(addToResult);
428 setters.forEach(addToResult); 429 setters.forEach(addToResult);
429 variables.forEach(addToResult); 430 variables.forEach(addToResult);
430 return _cachedMembers = new UnmodifiableMapView<Symbol, Mirror>(result); 431 return _cachedMembers = new UnmodifiableMapView<Symbol, Mirror>(result);
431 } 432 }
432 433
434 Map<Symbol, DeclarationMirror> get declarations {
435 if (_cachedDeclarations != null) return _cachedDeclarations;
436 var result = new Map<Symbol, DeclarationMirror>();
437 addToResult(Symbol key, Mirror value) {
438 result[key] = value;
439 }
440 members.forEach(addToResult);
441 return _cachedDeclarations =
442 new UnmodifiableMapView<Symbol, DeclarationMirror>(result);
443 }
444
433 List<InstanceMirror> get metadata { 445 List<InstanceMirror> get metadata {
434 if (_cachedMetadata != null) return _cachedMetadata; 446 if (_cachedMetadata != null) return _cachedMetadata;
435 preserveMetadata(); 447 preserveMetadata();
436 return _cachedMetadata = 448 return _cachedMetadata =
437 new UnmodifiableListView<InstanceMirror>(_metadata.map(reflect)); 449 new UnmodifiableListView<InstanceMirror>(_metadata.map(reflect));
438 } 450 }
439 451
440 // TODO(ahe): Test this getter. 452 // TODO(ahe): Test this getter.
441 DeclarationMirror get owner => null; 453 DeclarationMirror get owner => null;
442 } 454 }
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 List _metadata; 991 List _metadata;
980 ClassMirror _superclass; 992 ClassMirror _superclass;
981 List<JsMethodMirror> _cachedMethods; 993 List<JsMethodMirror> _cachedMethods;
982 List<JsVariableMirror> _cachedFields; 994 List<JsVariableMirror> _cachedFields;
983 UnmodifiableMapView<Symbol, MethodMirror> _cachedConstructors; 995 UnmodifiableMapView<Symbol, MethodMirror> _cachedConstructors;
984 UnmodifiableMapView<Symbol, MethodMirror> _cachedMethodsMap; 996 UnmodifiableMapView<Symbol, MethodMirror> _cachedMethodsMap;
985 UnmodifiableMapView<Symbol, MethodMirror> _cachedGetters; 997 UnmodifiableMapView<Symbol, MethodMirror> _cachedGetters;
986 UnmodifiableMapView<Symbol, MethodMirror> _cachedSetters; 998 UnmodifiableMapView<Symbol, MethodMirror> _cachedSetters;
987 UnmodifiableMapView<Symbol, VariableMirror> _cachedVariables; 999 UnmodifiableMapView<Symbol, VariableMirror> _cachedVariables;
988 UnmodifiableMapView<Symbol, Mirror> _cachedMembers; 1000 UnmodifiableMapView<Symbol, Mirror> _cachedMembers;
1001 UnmodifiableMapView<Symbol, DeclarationMirror> _cachedDeclarations;
989 UnmodifiableListView<InstanceMirror> _cachedMetadata; 1002 UnmodifiableListView<InstanceMirror> _cachedMetadata;
990 UnmodifiableListView<ClassMirror> _cachedSuperinterfaces; 1003 UnmodifiableListView<ClassMirror> _cachedSuperinterfaces;
991 UnmodifiableListView<TypeVariableMirror> _cachedTypeVariables; 1004 UnmodifiableListView<TypeVariableMirror> _cachedTypeVariables;
992 1005
993 // Set as side-effect of accessing JsLibraryMirror.classes. 1006 // Set as side-effect of accessing JsLibraryMirror.classes.
994 JsLibraryMirror _owner; 1007 JsLibraryMirror _owner;
995 1008
996 JsClassMirror(Symbol simpleName, 1009 JsClassMirror(Symbol simpleName,
997 this._mangledName, 1010 this._mangledName,
998 this._jsConstructorOrInterceptor, 1011 this._jsConstructorOrInterceptor,
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 if (result[s(name)] is VariableMirror) continue; 1182 if (result[s(name)] is VariableMirror) continue;
1170 } 1183 }
1171 // Constructors aren't 'members'. 1184 // Constructors aren't 'members'.
1172 if (method.isConstructor) continue; 1185 if (method.isConstructor) continue;
1173 // Use putIfAbsent to filter-out getters corresponding to variables. 1186 // Use putIfAbsent to filter-out getters corresponding to variables.
1174 result.putIfAbsent(method.simpleName, () => method); 1187 result.putIfAbsent(method.simpleName, () => method);
1175 } 1188 }
1176 return _cachedMembers = new UnmodifiableMapView<Symbol, Mirror>(result); 1189 return _cachedMembers = new UnmodifiableMapView<Symbol, Mirror>(result);
1177 } 1190 }
1178 1191
1192 Map<Symbol, DeclarationMirror> get declarations {
1193 if (_cachedDeclarations != null) return _cachedDeclarations;
1194 var result = new Map<Symbol, DeclarationMirror>();
1195 addToResult(Symbol key, Mirror value) {
1196 result[key] = value;
1197 }
1198 members.forEach(addToResult);
1199 constructors.forEach(addToResult);
1200 typeVariables.forEach((tv) => result[tv.simpleName] = tv);
1201 return _cachedDeclarations =
1202 new UnmodifiableMapView<Symbol, DeclarationMirror>(result);
1203 }
1204
1179 InstanceMirror setField(Symbol fieldName, Object arg) { 1205 InstanceMirror setField(Symbol fieldName, Object arg) {
1180 JsVariableMirror mirror = variables[fieldName]; 1206 JsVariableMirror mirror = variables[fieldName];
1181 if (mirror != null && mirror.isStatic && !mirror.isFinal) { 1207 if (mirror != null && mirror.isStatic && !mirror.isFinal) {
1182 // '$' (JS_CURRENT_ISOLATE()) stores state which is stored directly, so 1208 // '$' (JS_CURRENT_ISOLATE()) stores state which is stored directly, so
1183 // we shouldn't use [JsLibraryMirror._globalObject] here. 1209 // we shouldn't use [JsLibraryMirror._globalObject] here.
1184 String jsName = mirror._jsName; 1210 String jsName = mirror._jsName;
1185 if (!JS('bool', '# in #', jsName, JS_CURRENT_ISOLATE())) { 1211 if (!JS('bool', '# in #', jsName, JS_CURRENT_ISOLATE())) {
1186 throw new RuntimeError('Cannot find "$jsName" in current isolate.'); 1212 throw new RuntimeError('Cannot find "$jsName" in current isolate.');
1187 } 1213 }
1188 JS('void', '#[#] = #', JS_CURRENT_ISOLATE(), jsName, arg); 1214 JS('void', '#[#] = #', JS_CURRENT_ISOLATE(), jsName, arg);
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 1984
1959 // TODO(ahe): Remove this class and call noSuchMethod instead. 1985 // TODO(ahe): Remove this class and call noSuchMethod instead.
1960 class UnimplementedNoSuchMethodError extends Error 1986 class UnimplementedNoSuchMethodError extends Error
1961 implements NoSuchMethodError { 1987 implements NoSuchMethodError {
1962 final String _message; 1988 final String _message;
1963 1989
1964 UnimplementedNoSuchMethodError(this._message); 1990 UnimplementedNoSuchMethodError(this._message);
1965 1991
1966 String toString() => "Unsupported operation: $_message"; 1992 String toString() => "Unsupported operation: $_message";
1967 } 1993 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698