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

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

Issue 10916252: Implement more of the mirrors library, primarily stuff to do with types. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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) 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 // These values are allowed to be passed directly over the wire. 7 // These values are allowed to be passed directly over the wire.
8 bool isSimpleValue(var value) { 8 bool _isSimpleValue(var value) {
9 return (value === null || value is num || value is String || value is bool); 9 return (value === null || value is num || value is String || value is bool);
10 } 10 }
11 11
12 Map filterMap(Map old_map, bool filter(key, value)) { 12 Map _filterMap(Map old_map, bool filter(key, value)) {
13 Map new_map = new Map(); 13 Map new_map = new Map();
14 old_map.forEach((key, value) { 14 old_map.forEach((key, value) {
15 if (filter(key, value)) { 15 if (filter(key, value)) {
16 new_map[key] = value; 16 new_map[key] = value;
17 } 17 }
18 }); 18 });
19 return new_map; 19 return new_map;
20 } 20 }
21 21
22 String _makeSignatureString(TypeMirror returnType,
23 List<ParameterMirror> parameters) {
24 StringBuffer buf = new StringBuffer();
25 buf.add(returnType.qualifiedName);
26 buf.add(' (');
27 bool found_optional_param = false;
28 for (int i = 0; i < parameters.length; i++) {
29 var param = parameters[i];
30 if (param.isOptional && !found_optional_param) {
31 buf.add('[');
32 found_optional_param = true;
33 }
34 buf.add(param.type.qualifiedName);
35 if (i < (parameters.length - 1)) {
36 buf.add(', ');
37 }
38 }
39 if (found_optional_param) {
40 buf.add(']');
41 }
42 buf.add(')');
43 return buf.toString();
44 }
45
22 class _LocalMirrorSystemImpl implements MirrorSystem { 46 class _LocalMirrorSystemImpl implements MirrorSystem {
23 _LocalMirrorSystemImpl(this.libraries, this.isolate) {} 47 _LocalMirrorSystemImpl(this.libraries, this.isolate)
48 : _functionTypes = new Map<String, FunctionTypeMirror>() {}
24 49
25 final Map<String, LibraryMirror> libraries; 50 final Map<String, LibraryMirror> libraries;
26 final IsolateMirror isolate; 51 final IsolateMirror isolate;
27 52
28 TypeMirror _dynamicType = null; 53 TypeMirror _dynamicType = null;
29 54
30 TypeMirror get dynamicType() { 55 TypeMirror get dynamicType() {
31 if (_dynamicType === null) { 56 if (_dynamicType === null) {
32 _dynamicType = 57 _dynamicType =
33 new _LocalClassMirrorImpl( 58 new _LocalClassMirrorImpl(
34 null, 'Dynamic', false, null, null, [], null, const {}); 59 null, 'Dynamic', false, null, null, [], null, const {}, const {});
35 } 60 }
36 return _dynamicType; 61 return _dynamicType;
37 } 62 }
38 63
39 TypeMirror _voidType = null; 64 TypeMirror _voidType = null;
40 65
41 TypeMirror get voidType() { 66 TypeMirror get voidType() {
42 if (_voidType === null) { 67 if (_voidType === null) {
43 _voidType = 68 _voidType =
44 new _LocalClassMirrorImpl( 69 new _LocalClassMirrorImpl(
45 null, 'void', false, null, null, [], null, const {}); 70 null, 'void', false, null, null, [], null, const {}, const {});
46 } 71 }
47 return _voidType; 72 return _voidType;
48 } 73 }
49 74
75 final Map<String, FunctionTypeMirror> _functionTypes;
76 FunctionTypeMirror _lookupFunctionTypeMirror(
77 TypeMirror returnType,
78 List<ParameterMirror> parameters) {
79 var sigString = _makeSignatureString(returnType, parameters);
80 var mirror = _functionTypes[sigString];
81 if (mirror === null) {
cshapiro 2012/09/12 18:52:07 You don't need === anymore for speed.
turnidge 2012/09/12 21:39:30 Replaced all in this file.
82 mirror = new _LocalFunctionTypeMirrorImpl(null,
83 sigString,
84 returnType,
85 parameters);
86 _functionTypes[sigString] = mirror;
87 }
88 return mirror;
89 }
90
50 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; 91 String toString() => "MirrorSystem for isolate '${isolate.debugName}'";
51 } 92 }
52 93
53 abstract class _LocalMirrorImpl implements Mirror { 94 abstract class _LocalMirrorImpl implements Mirror {
54 int hashCode() { 95 int hashCode() {
55 throw new NotImplementedException('Mirror.hashCode() not yet implemented'); 96 throw new NotImplementedException('Mirror.hashCode() not yet implemented');
56 } 97 }
57 98
58 // Local mirrors always return the same MirrorSystem. This field 99 // Local mirrors always return the same MirrorSystem. This field
59 // is more interesting once we implement remote mirrors. 100 // is more interesting once we implement remote mirrors.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 return completer.future; 183 return completer.future;
143 } 184 }
144 185
145 static _validateArgument(int i, Object arg) 186 static _validateArgument(int i, Object arg)
146 { 187 {
147 if (arg is Mirror) { 188 if (arg is Mirror) {
148 if (arg is! InstanceMirror) { 189 if (arg is! InstanceMirror) {
149 throw new MirrorException( 190 throw new MirrorException(
150 'positional argument $i ($arg) was not an InstanceMirror'); 191 'positional argument $i ($arg) was not an InstanceMirror');
151 } 192 }
152 } else if (!isSimpleValue(arg)) { 193 } else if (!_isSimpleValue(arg)) {
153 throw new MirrorException( 194 throw new MirrorException(
154 'positional argument $i ($arg) was not a simple value'); 195 'positional argument $i ($arg) was not a simple value');
155 } 196 }
156 } 197 }
157 198
158 static _invoke(ref, memberName, positionalArguments) 199 static _invoke(ref, memberName, positionalArguments)
159 native 'LocalObjectMirrorImpl_invoke'; 200 native 'LocalObjectMirrorImpl_invoke';
160 201
161 static _getField(ref, fieldName) 202 static _getField(ref, fieldName)
162 native 'LocalObjectMirrorImpl_getField'; 203 native 'LocalObjectMirrorImpl_getField';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 255 }
215 256
216 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl 257 class _LocalInstanceMirrorImpl extends _LocalObjectMirrorImpl
217 implements InstanceMirror { 258 implements InstanceMirror {
218 _LocalInstanceMirrorImpl(ref, 259 _LocalInstanceMirrorImpl(ref,
219 this._type, 260 this._type,
220 this._reflectee) : super(ref) {} 261 this._reflectee) : super(ref) {}
221 262
222 var _type; 263 var _type;
223 ClassMirror get type() { 264 ClassMirror get type() {
224 if (_type is _LazyClassMirror) { 265 if (_type is! Mirror) {
225 _type = _type.resolve(mirrors); 266 _type = _type.resolve(mirrors);
226 } 267 }
227 return _type; 268 return _type;
228 } 269 }
229 270
230 // LocalInstanceMirrors always reflect local instances 271 // LocalInstanceMirrors always reflect local instances
231 bool hasReflectee = true; 272 bool hasReflectee = true;
232 273
233 var _reflectee; 274 var _reflectee;
234 get reflectee() => _reflectee; 275 get reflectee() => _reflectee;
235 276
236 String toString() { 277 String toString() {
237 if (isSimpleValue(_reflectee)) { 278 if (_isSimpleValue(_reflectee)) {
238 if (_reflectee is String) { 279 if (_reflectee is String) {
239 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>"; 280 return "InstanceMirror on <'${_dartEscape(_reflectee)}'>";
240 } else { 281 } else {
241 return "InstanceMirror on <$_reflectee>"; 282 return "InstanceMirror on <$_reflectee>";
242 } 283 }
243 } else { 284 } else {
244 return "InstanceMirror on instance of '${type.simpleName}'"; 285 return "InstanceMirror on instance of '${type.simpleName}'";
245 } 286 }
246 } 287 }
247 } 288 }
248 289
249 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl 290 class _LocalClosureMirrorImpl extends _LocalInstanceMirrorImpl
250 implements ClosureMirror { 291 implements ClosureMirror {
251 _LocalClosureMirrorImpl(ref, 292 _LocalClosureMirrorImpl(ref,
252 klass, 293 type,
253 reflectee) : super(ref, klass, reflectee) {} 294 reflectee,
295 this.function) : super(ref, type, reflectee) {}
254 296
255 MethodMirror _function; 297 final MethodMirror function;
256 MethodMirror function() => _function;
257 298
258 String get source() { 299 String get source() {
259 throw new NotImplementedException('ClosureMirror.source not implemented'); 300 throw new NotImplementedException('ClosureMirror.source not implemented');
260 } 301 }
261 302
262 Future<ObjectMirror> apply(List<Object> positionalArguments, 303 Future<InstanceMirror> apply(List<Object> positionalArguments,
263 [Map<String,Object> namedArguments]) { 304 [Map<String,Object> namedArguments]) {
264 if (namedArguments !== null) { 305 if (namedArguments !== null) {
265 throw new NotImplementedException('named arguments not implemented'); 306 throw new NotImplementedException('named arguments not implemented');
266 } 307 }
267 // Walk the arguments and make sure they are legal. 308 // Walk the arguments and make sure they are legal.
268 for (int i = 0; i < positionalArguments.length; i++) { 309 for (int i = 0; i < positionalArguments.length; i++) {
269 var arg = positionalArguments[i]; 310 var arg = positionalArguments[i];
270 _LocalObjectMirrorImpl._validateArgument(i, arg); 311 _LocalObjectMirrorImpl._validateArgument(i, arg);
271 } 312 }
272 Completer<InstanceMirror> completer = new Completer<InstanceMirror>(); 313 Completer<InstanceMirror> completer = new Completer<InstanceMirror>();
273 try { 314 try {
274 completer.complete( 315 completer.complete(
275 _apply(this, positionalArguments)); 316 _apply(this, positionalArguments));
276 } catch (exception) { 317 } catch (exception) {
277 completer.completeException(exception); 318 completer.completeException(exception);
278 } 319 }
279 return completer.future; 320 return completer.future;
280 } 321 }
281 322
282 Future<ObjectMirror> findInContext(String name) { 323 Future<InstanceMirror> findInContext(String name) {
283 throw new NotImplementedException( 324 throw new NotImplementedException(
284 'ClosureMirror.findInContext() not implemented'); 325 'ClosureMirror.findInContext() not implemented');
285 } 326 }
286 327
287 static _apply(ref, positionalArguments) 328 static _apply(ref, positionalArguments)
288 native 'LocalClosureMirrorImpl_apply'; 329 native 'LocalClosureMirrorImpl_apply';
289 } 330 }
290 331
291 class _LazyClassMirror { 332 class _LazyTypeMirror {
292 _LazyClassMirror(this.libraryName, this.interfaceName) {} 333 _LazyTypeMirror(this.libraryName, this.typeName) {}
293 334
294 ClassMirror resolve(MirrorSystem mirrors) { 335 TypeMirror resolve(MirrorSystem mirrors) {
295 if (libraryName === null) { 336 if (libraryName === null) {
296 if (interfaceName == 'Dynamic') { 337 if (typeName == 'Dynamic') {
297 return mirrors.dynamicType(); 338 return mirrors.dynamicType;
298 } else if (interfaceName == 'void') { 339 } else if (typeName == 'void') {
299 return mirrors.voidType(); 340 return mirrors.voidType;
300 } else { 341 } else {
301 throw new NotImplementedException( 342 throw new NotImplementedException(
302 "Mirror for type '$interfaceName' not implemented"); 343 "Mirror for type '$typeName' not implemented");
303 } 344 }
304 } 345 }
305 return mirrors.libraries[libraryName].members[interfaceName]; 346 var resolved = mirrors.libraries[libraryName].members[typeName];
347 if (resolved === null) {
cshapiro 2012/09/12 18:52:07 ditto
348 throw new NotImplementedException(
349 "Mirror for type '$typeName' not implemented");
cshapiro 2012/09/12 18:52:07 "is not..." or "is unimplemented"
turnidge 2012/09/12 21:39:30 Fixed here and elsewhere.
350 }
351 return resolved;
306 } 352 }
307 353
308 final String libraryName; 354 final String libraryName;
309 final String interfaceName; 355 final String typeName;
310 } 356 }
311 357
312 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 358 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
313 implements ClassMirror { 359 implements ClassMirror {
314 _LocalClassMirrorImpl(ref, 360 _LocalClassMirrorImpl(ref,
315 this.simpleName, 361 this.simpleName,
316 this.isClass, 362 this.isClass,
317 this._owner, 363 this._owner,
318 this._superclass, 364 this._superclass,
319 this._superinterfaces, 365 this._superinterfaces,
320 this._defaultFactory, 366 this._defaultFactory,
321 this.members) : super(ref) {} 367 this.members,
368 this.typeVariables) : super(ref) {}
322 369
323 final String simpleName; 370 final String simpleName;
324 371
325 String _qualifiedName = null; 372 String _qualifiedName = null;
326 String get qualifiedName() { 373 String get qualifiedName() {
327 if (_qualifiedName === null) { 374 if (_owner !== null) {
328 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; 375 if (_qualifiedName === null) {
376 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
377 }
378 } else {
379 // The owner of a ClassMirror is null in certain odd cases, like
380 // 'void', 'Dynamic' and function type mirrors.
381 _qualifiedName = simpleName;
329 } 382 }
330 return _qualifiedName; 383 return _qualifiedName;
331 } 384 }
332 385
333 var _owner; 386 var _owner;
334 DeclarationMirror get owner() { 387 DeclarationMirror get owner() {
335 if (_owner is! Mirror) { 388 if (_owner !== null && _owner is! Mirror) {
336 _owner = _owner.resolve(mirrors); 389 _owner = _owner.resolve(mirrors);
337 } 390 }
338 return _owner; 391 return _owner;
339 } 392 }
340 393
341 bool get isPrivate() => simpleName.startsWith('_'); 394 bool get isPrivate() => simpleName.startsWith('_');
342 395
343 final bool isTopLevel = true; 396 final bool isTopLevel = true;
344 397
345 SourceLocation get location() { 398 SourceLocation get location() {
346 throw new NotImplementedException( 399 throw new NotImplementedException(
347 'ClassMirror.location not yet implemented'); 400 'ClassMirror.location not yet implemented');
348 } 401 }
349 402
350 final bool isClass; 403 final bool isClass;
351 404
352 var _superclass; 405 var _superclass;
353 ClassMirror get superclass() { 406 ClassMirror get superclass() {
354 if (_superclass is _LazyClassMirror) { 407 if (_superclass is! Mirror) {
355 _superclass = _superclass.resolve(mirrors); 408 _superclass = _superclass.resolve(mirrors);
356 } 409 }
357 return _superclass; 410 return _superclass;
358 } 411 }
359 412
360 var _superinterfaces; 413 var _superinterfaces;
361 List<ClassMirror> get superinterfaces() { 414 List<ClassMirror> get superinterfaces() {
362 if (_superinterfaces.length > 0 && 415 if (_superinterfaces.length > 0 &&
363 _superinterfaces[0] is _LazyClassMirror) { 416 _superinterfaces[0] is! Mirror) {
364 List<ClassMirror> resolved = new List<ClassMirror>(); 417 List<ClassMirror> resolved = new List<ClassMirror>();
365 for (int i = 0; i < _superinterfaces.length; i++) { 418 for (int i = 0; i < _superinterfaces.length; i++) {
366 resolved.add(_superinterfaces[i].resolve(mirrors)); 419 resolved.add(_superinterfaces[i].resolve(mirrors));
367 } 420 }
368 _superinterfaces = resolved; 421 _superinterfaces = resolved;
369 } 422 }
370 return _superinterfaces; 423 return _superinterfaces;
371 } 424 }
372 425
373 var _defaultFactory; 426 var _defaultFactory;
374 ClassMirror get defaultFactory() { 427 ClassMirror get defaultFactory() {
375 if (_defaultFactory is _LazyClassMirror) { 428 if (_defaultFactory !== null && _defaultFactory is! Mirror) {
376 _defaultFactory = _defaultFactory.resolve(mirrors); 429 _defaultFactory = _defaultFactory.resolve(mirrors);
377 } 430 }
378 return _defaultFactory; 431 return _defaultFactory;
379 } 432 }
380 433
381 final Map<String, Mirror> members; 434 final Map<String, Mirror> members;
382 435
383 Map<String, MethodMirror> _methods = null; 436 Map<String, MethodMirror> _methods = null;
384 Map<String, MethodMirror> _constructors = null; 437 Map<String, MethodMirror> _constructors = null;
385 Map<String, MethodMirror> _getters = null; 438 Map<String, MethodMirror> _getters = null;
386 Map<String, MethodMirror> _setters = null; 439 Map<String, MethodMirror> _setters = null;
387 Map<String, VariableMirror> _variables = null; 440 Map<String, VariableMirror> _variables = null;
388 441
389 Map<String, MethodMirror> get methods() { 442 Map<String, MethodMirror> get methods() {
390 if (_methods == null) { 443 if (_methods === null) {
cshapiro 2012/09/12 18:52:07 ==
391 _methods = filterMap(members, 444 _methods = _filterMap(members,
392 (key, value) => (value is MethodMirror)); 445 (key, value) => (value is MethodMirror));
393 } 446 }
394 return _methods; 447 return _methods;
395 } 448 }
396 449
397 Map<String, MethodMirror> get constructors() { 450 Map<String, MethodMirror> get constructors() {
398 if (_constructors == null) { 451 if (_constructors === null) {
cshapiro 2012/09/12 18:52:07 ==
399 _constructors = filterMap(methods, 452 _constructors = _filterMap(methods,
400 (key, value) => (value.isConstructor)); 453 (key, value) => (value.isConstructor));
401 } 454 }
402 return _constructors; 455 return _constructors;
403 } 456 }
404 457
405 Map<String, MethodMirror> get getters() { 458 Map<String, MethodMirror> get getters() {
406 if (_getters == null) { 459 if (_getters === null) {
cshapiro 2012/09/12 18:52:07 more of the same, here and below
407 _getters = filterMap(methods, 460 _getters = _filterMap(methods,
408 (key, value) => (value.isGetter)); 461 (key, value) => (value.isGetter));
409 } 462 }
410 return _getters; 463 return _getters;
411 } 464 }
412 465
413 Map<String, MethodMirror> get setters() { 466 Map<String, MethodMirror> get setters() {
414 if (_setters == null) { 467 if (_setters === null) {
415 _setters = filterMap(methods, 468 _setters = _filterMap(methods,
416 (key, value) => (value.isSetter)); 469 (key, value) => (value.isSetter));
417 } 470 }
418 return _setters; 471 return _setters;
419 } 472 }
420 473
421 Map<String, VariableMirror> get variables() { 474 Map<String, VariableMirror> get variables() {
422 if (_variables == null) { 475 if (_variables === null) {
423 _variables = filterMap(members, 476 _variables = _filterMap(members,
424 (key, value) => (value is VariableMirror)); 477 (key, value) => (value is VariableMirror));
425 } 478 }
426 return _variables; 479 return _variables;
427 } 480 }
428 481
429 List<TypeVariableMirror> get typeVariables() { 482 Map<String, TypeVariableMirror> typeVariables;
430 throw new NotImplementedException(
431 'ClassMirror.typeVariables not yet implemented');
432 }
433 483
434 List<TypeMirror> get typeArguments() { 484 Map<String, TypeMirror> get typeArguments() {
435 throw new NotImplementedException( 485 throw new NotImplementedException(
436 'ClassMirror.typeArguments not yet implemented'); 486 'ClassMirror.typeArguments not yet implemented');
437 } 487 }
438 488
439 bool isGenericDeclaration() { 489 bool isGenericDeclaration() {
440 throw new NotImplementedException( 490 throw new NotImplementedException(
441 'ClassMirror.isGenericDeclaration not yet implemented'); 491 'ClassMirror.isGenericDeclaration not yet implemented');
442 } 492 }
443 493
444 ClassMirror genericDeclaration() { 494 ClassMirror genericDeclaration() {
(...skipping 21 matching lines...) Expand all
466 } catch (exception) { 516 } catch (exception) {
467 completer.completeException(exception); 517 completer.completeException(exception);
468 } 518 }
469 return completer.future; 519 return completer.future;
470 } 520 }
471 521
472 static _invokeConstructor(ref, constructorName, positionalArguments) 522 static _invokeConstructor(ref, constructorName, positionalArguments)
473 native 'LocalClassMirrorImpl_invokeConstructor'; 523 native 'LocalClassMirrorImpl_invokeConstructor';
474 } 524 }
475 525
526 class _LazyFunctionTypeMirror {
527 _LazyFunctionTypeMirror(this.returnType, this.parameters) {}
528
529 ClassMirror resolve(MirrorSystem mirrors) {
530 return mirrors._lookupFunctionTypeMirror(returnType.resolve(mirrors),
531 parameters);
532 }
533
534 final returnType;
535 final List<ParameterMirror> parameters;
536 }
537
538 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
539 implements FunctionTypeMirror {
540 _LocalFunctionTypeMirrorImpl(ref,
541 simpleName,
542 this._returnType,
543 this.parameters)
544 : super(ref,
545 simpleName,
546 true,
547 null,
548 new _LazyTypeMirror('dart:core', 'Object'),
549 [ new _LazyTypeMirror('dart:core', 'Function') ],
550 null,
551 const {},
552 const {});
553
554 var _returnType;
555 TypeMirror get returnType() {
556 if (_returnType is! Mirror) {
557 _returnType = _returnType.resolve(mirrors);
558 }
559 return _returnType;
560 }
561
562 final List<ParameterMirror> parameters;
563
564 String toString() => "FunctionTypeMirror on '$simpleName'";
565 }
566
567
568 class _LazyTypeVariableMirror {
569 _LazyTypeVariableMirror(this._variableName, this._owner) {}
570
571 TypeVariableMirror resolve(MirrorSystem mirrors) {
572 ClassMirror owner = _owner.resolve(mirrors);
573 return owner.typeVariables[_variableName];
574 }
575
576 final String _variableName;
577 final _LazyTypeMirror _owner;
578 }
579
580 class _LocalTypeVariableMirrorImpl extends _LocalMirrorImpl
581 implements TypeVariableMirror {
582 _LocalTypeVariableMirrorImpl(this.simpleName,
583 this._owner,
584 this._upperBound) {}
585 final String simpleName;
586
587 String _qualifiedName = null;
588 String get qualifiedName() {
589 if (_qualifiedName === null) {
590 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
591 }
592 return _qualifiedName;
593 }
594
595 var _owner;
596 DeclarationMirror get owner() {
597 if (_owner is! Mirror) {
598 _owner = _owner.resolve(mirrors);
599 }
600 return _owner;
601 }
602
603 bool get isPrivate() => false;
604
605 final bool isTopLevel = false;
606
607 SourceLocation get location() {
608 throw new NotImplementedException(
609 'TypeVariableMirror.location not yet implemented');
610 }
611
612 var _upperBound;
613 TypeMirror get upperBound() {
cshapiro 2012/09/12 18:52:07 no () here and around here
turnidge 2012/09/12 21:39:30 Done.
614 if (_upperBound is! Mirror) {
615 _upperBound = _upperBound.resolve(mirrors);
616 }
617 return _upperBound;
618 }
619
620 String toString() => "TypeVariableMirror on '$simpleName'";
621 }
622
623
624 class _LocalTypedefMirrorImpl extends _LocalMirrorImpl
625 implements TypedefMirror {
626 _LocalTypedefMirrorImpl(this.simpleName,
627 this._owner,
628 this._referent) {}
629 final String simpleName;
630
631 String _qualifiedName = null;
632 String get qualifiedName() {
633 if (_qualifiedName === null) {
634 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
635 }
636 return _qualifiedName;
637 }
638
639 var _owner;
640 DeclarationMirror get owner() {
641 if (_owner is! Mirror) {
642 _owner = _owner.resolve(mirrors);
643 }
644 return _owner;
645 }
646
647 bool get isPrivate() => false;
648
649 final bool isTopLevel = true;
650
651 SourceLocation get location() {
652 throw new NotImplementedException(
653 'TypedefMirror.location not yet implemented');
654 }
655
656 var _referent;
657 TypeMirror get referent() {
658 if (_referent is! Mirror) {
659 _referent = _referent.resolve(mirrors);
660 }
661 return _referent;
662 }
663
664 String toString() => "TypedefMirror on '$simpleName'";
665 }
666
667
476 class _LazyLibraryMirror { 668 class _LazyLibraryMirror {
477 _LazyLibraryMirror(this.libraryName) {} 669 _LazyLibraryMirror(this.libraryName) {}
478 670
479 LibraryMirror resolve(MirrorSystem mirrors) { 671 LibraryMirror resolve(MirrorSystem mirrors) {
480 return mirrors.libraries[libraryName]; 672 return mirrors.libraries[libraryName];
481 } 673 }
482 674
483 final String libraryName; 675 final String libraryName;
484 } 676 }
485 677
(...skipping 26 matching lines...) Expand all
512 final String url; 704 final String url;
513 final Map<String, Mirror> members; 705 final Map<String, Mirror> members;
514 706
515 Map<String, ClassMirror> _classes = null; 707 Map<String, ClassMirror> _classes = null;
516 Map<String, MethodMirror> _functions = null; 708 Map<String, MethodMirror> _functions = null;
517 Map<String, MethodMirror> _getters = null; 709 Map<String, MethodMirror> _getters = null;
518 Map<String, MethodMirror> _setters = null; 710 Map<String, MethodMirror> _setters = null;
519 Map<String, VariableMirror> _variables = null; 711 Map<String, VariableMirror> _variables = null;
520 712
521 Map<String, ClassMirror> get classes() { 713 Map<String, ClassMirror> get classes() {
522 if (_classes == null) { 714 if (_classes === null) {
523 _classes = filterMap(members, 715 _classes = _filterMap(members,
524 (key, value) => (value is ClassMirror)); 716 (key, value) => (value is ClassMirror));
525 } 717 }
526 return _classes; 718 return _classes;
527 } 719 }
528 720
529 Map<String, MethodMirror> get functions() { 721 Map<String, MethodMirror> get functions() {
530 if (_functions == null) { 722 if (_functions === null) {
531 _functions = filterMap(members, 723 _functions = _filterMap(members,
532 (key, value) => (value is MethodMirror)); 724 (key, value) => (value is MethodMirror));
533 } 725 }
534 return _functions; 726 return _functions;
535 } 727 }
536 728
537 Map<String, MethodMirror> get getters() { 729 Map<String, MethodMirror> get getters() {
538 if (_getters == null) { 730 if (_getters === null) {
539 _getters = filterMap(functions, 731 _getters = _filterMap(functions,
540 (key, value) => (value.isGetter)); 732 (key, value) => (value.isGetter));
541 } 733 }
542 return _getters; 734 return _getters;
543 } 735 }
544 736
545 Map<String, MethodMirror> get setters() { 737 Map<String, MethodMirror> get setters() {
546 if (_setters == null) { 738 if (_setters === null) {
547 _setters = filterMap(functions, 739 _setters = _filterMap(functions,
548 (key, value) => (value.isSetter)); 740 (key, value) => (value.isSetter));
549 } 741 }
550 return _setters; 742 return _setters;
551 } 743 }
552 744
553 Map<String, VariableMirror> get variables() { 745 Map<String, VariableMirror> get variables() {
554 if (_variables == null) { 746 if (_variables === null) {
555 _variables = filterMap(members, 747 _variables = _filterMap(members,
556 (key, value) => (value is VariableMirror)); 748 (key, value) => (value is VariableMirror));
557 } 749 }
558 return _variables; 750 return _variables;
559 } 751 }
560 752
561 String toString() => "LibraryMirror on '$simpleName'"; 753 String toString() => "LibraryMirror on '$simpleName'";
562 } 754 }
563 755
564 class _LocalMethodMirrorImpl extends _LocalMirrorImpl 756 class _LocalMethodMirrorImpl extends _LocalMirrorImpl
565 implements MethodMirror { 757 implements MethodMirror {
566 _LocalMethodMirrorImpl(this.simpleName, 758 _LocalMethodMirrorImpl(this.simpleName,
567 this._owner, 759 this._owner,
568 this.parameters, 760 this.parameters,
761 this._returnType,
569 this.isStatic, 762 this.isStatic,
570 this.isAbstract, 763 this.isAbstract,
571 this.isGetter, 764 this.isGetter,
572 this.isSetter, 765 this.isSetter,
573 this.isConstructor, 766 this.isConstructor,
574 this.isConstConstructor, 767 this.isConstConstructor,
575 this.isGenerativeConstructor, 768 this.isGenerativeConstructor,
576 this.isRedirectingConstructor, 769 this.isRedirectingConstructor,
577 this.isFactoryConstructor) {} 770 this.isFactoryConstructor) {}
578 771
(...skipping 19 matching lines...) Expand all
598 return simpleName.startsWith('_') || constructorName.startsWith('_'); 791 return simpleName.startsWith('_') || constructorName.startsWith('_');
599 } 792 }
600 793
601 bool get isTopLevel() => owner is LibraryMirror; 794 bool get isTopLevel() => owner is LibraryMirror;
602 795
603 SourceLocation get location() { 796 SourceLocation get location() {
604 throw new NotImplementedException( 797 throw new NotImplementedException(
605 'MethodMirror.location not yet implemented'); 798 'MethodMirror.location not yet implemented');
606 } 799 }
607 800
801 var _returnType;
608 TypeMirror get returnType() { 802 TypeMirror get returnType() {
609 throw new NotImplementedException( 803 if (_returnType is! Mirror) {
610 'MethodMirror.returnType not yet implemented'); 804 _returnType = _returnType.resolve(mirrors);
805 }
806 return _returnType;
611 } 807 }
612 808
613 final List<ParameterMirror> parameters; 809 final List<ParameterMirror> parameters;
614 810
615 final bool isStatic; 811 final bool isStatic;
616 final bool isAbstract; 812 final bool isAbstract;
617 813
618 bool get isRegularMethod() => !isGetter && !isSetter && !isConstructor; 814 bool get isRegularMethod() => !isGetter && !isSetter && !isConstructor;
619 815
620 TypeMirror get isOperator() { 816 TypeMirror get isOperator() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 final bool isRedirectingConstructor; 848 final bool isRedirectingConstructor;
653 final bool isFactoryConstructor; 849 final bool isFactoryConstructor;
654 850
655 String toString() => "MethodMirror on '$simpleName'"; 851 String toString() => "MethodMirror on '$simpleName'";
656 } 852 }
657 853
658 class _LocalVariableMirrorImpl extends _LocalMirrorImpl 854 class _LocalVariableMirrorImpl extends _LocalMirrorImpl
659 implements VariableMirror { 855 implements VariableMirror {
660 _LocalVariableMirrorImpl(this.simpleName, 856 _LocalVariableMirrorImpl(this.simpleName,
661 this._owner, 857 this._owner,
858 this._type,
662 this.isStatic, 859 this.isStatic,
663 this.isFinal) {} 860 this.isFinal) {}
664 861
665 final String simpleName; 862 final String simpleName;
666 863
667 String _qualifiedName = null; 864 String _qualifiedName = null;
668 String get qualifiedName() { 865 String get qualifiedName() {
669 if (_qualifiedName === null) { 866 if (_qualifiedName === null) {
670 _qualifiedName = '${owner.qualifiedName}.${simpleName}'; 867 _qualifiedName = '${owner.qualifiedName}.${simpleName}';
671 } 868 }
(...skipping 14 matching lines...) Expand all
686 883
687 bool get isTopLevel() { 884 bool get isTopLevel() {
688 return owner is LibraryMirror; 885 return owner is LibraryMirror;
689 } 886 }
690 887
691 SourceLocation get location() { 888 SourceLocation get location() {
692 throw new NotImplementedException( 889 throw new NotImplementedException(
693 'VariableMirror.location not yet implemented'); 890 'VariableMirror.location not yet implemented');
694 } 891 }
695 892
893 var _type;
696 TypeMirror get type() { 894 TypeMirror get type() {
697 throw new NotImplementedException( 895 if (_type is! Mirror) {
698 'VariableMirror.type not yet implemented'); 896 _type = _type.resolve(mirrors);
897 }
898 return _type;
699 } 899 }
700 900
701 final bool isStatic; 901 final bool isStatic;
702 final bool isFinal; 902 final bool isFinal;
703 903
704 String toString() => "VariableMirror on '$simpleName'"; 904 String toString() => "VariableMirror on '$simpleName'";
705 } 905 }
706 906
707 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 907 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
708 implements ParameterMirror { 908 implements ParameterMirror {
709 // TODO(rmacnak): Fill these mirrors will real information 909 _LocalParameterMirrorImpl(type, this.isOptional)
710 _LocalParameterMirrorImpl(this.isOptional) 910 : super('<TODO:unnamed>', null, type, false, false) {}
cshapiro 2012/09/12 18:52:07 Strange. Why not leave the TODO comment?
turnidge 2012/09/12 21:39:30 Every class in this file has things that need to b
711 : super(null, null, false, false) {}
712 911
713 final bool isOptional; 912 final bool isOptional;
714 913
715 TypeMirror get type() {
716 throw new NotImplementedException(
717 'ParameterMirror.type not yet implemented');
718 }
719
720 String get defaultValue() { 914 String get defaultValue() {
721 throw new NotImplementedException( 915 throw new NotImplementedException(
722 'ParameterMirror.defaultValue not yet implemented'); 916 'ParameterMirror.defaultValue not yet implemented');
723 } 917 }
724 918
725 bool get hasDefaultValue() { 919 bool get hasDefaultValue() {
726 throw new NotImplementedException( 920 throw new NotImplementedException(
727 'ParameterMirror.hasDefaultValue not yet implemented'); 921 'ParameterMirror.hasDefaultValue not yet implemented');
728 } 922 }
729 } 923 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 958
765 // Creates a new local InstanceMirror 959 // Creates a new local InstanceMirror
766 static InstanceMirror makeLocalInstanceMirror(Object reflectee) 960 static InstanceMirror makeLocalInstanceMirror(Object reflectee)
767 native 'Mirrors_makeLocalInstanceMirror'; 961 native 'Mirrors_makeLocalInstanceMirror';
768 962
769 // Creates a new local mirror for some Object. 963 // Creates a new local mirror for some Object.
770 static InstanceMirror reflect(Object reflectee) { 964 static InstanceMirror reflect(Object reflectee) {
771 return makeLocalInstanceMirror(reflectee); 965 return makeLocalInstanceMirror(reflectee);
772 } 966 }
773 } 967 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698