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

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

Issue 23190003: ClassMirror.mixin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 import "dart:collection"; 7 import "dart:collection";
8 8
9 // These values are allowed to be passed directly over the wire. 9 // These values are allowed to be passed directly over the wire.
10 bool _isSimpleValue(var value) { 10 bool _isSimpleValue(var value) {
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 super(reflectee); 367 super(reflectee);
368 368
369 final Type _reflectedType; 369 final Type _reflectedType;
370 final bool _isGeneric; 370 final bool _isGeneric;
371 371
372 Symbol _simpleName; 372 Symbol _simpleName;
373 Symbol get simpleName { 373 Symbol get simpleName {
374 // dynamic, void and the function types have their names set eagerly in the 374 // dynamic, void and the function types have their names set eagerly in the
375 // constructor. 375 // constructor.
376 if(_simpleName == null) { 376 if(_simpleName == null) {
377 _simpleName = _s(_name(_reflectee)); 377 var simpleString = _name(_reflectee);
378 if (simpleString.contains('&')) {
379 _simpleName = this._computeMixinApplicationName;
380 } else {
381 _simpleName = _s(simpleString);
382 }
regis 2013/08/20 18:56:37 That answers my question about the missing name in
378 } 383 }
379 return _simpleName; 384 return _simpleName;
380 } 385 }
381 386
382 Symbol _qualifiedName = null; 387 Symbol _qualifiedName = null;
383 Symbol get qualifiedName { 388 Symbol get qualifiedName {
384 if (_qualifiedName == null) { 389 if (_qualifiedName == null) {
385 _qualifiedName = _computeQualifiedName(owner, simpleName); 390 _qualifiedName = _computeQualifiedName(owner, simpleName);
386 } 391 }
387 return _qualifiedName; 392 return _qualifiedName;
(...skipping 22 matching lines...) Expand all
410 ClassMirror get defaultFactory => null; 415 ClassMirror get defaultFactory => null;
411 416
412 ClassMirror _superclass; 417 ClassMirror _superclass;
413 ClassMirror get superclass { 418 ClassMirror get superclass {
414 if (_superclass == null) { 419 if (_superclass == null) {
415 Type supertype = _supertype(_reflectee); 420 Type supertype = _supertype(_reflectee);
416 if (supertype == null) { 421 if (supertype == null) {
417 // Object has no superclass. 422 // Object has no superclass.
418 return null; 423 return null;
419 } 424 }
420 _superclass = reflectClass(supertype); 425 _superclass = _Mirrors._reflectType(supertype);
421 } 426 }
422 return _superclass; 427 return _superclass;
423 } 428 }
424 429
425 var _superinterfaces; 430 var _superinterfaces;
426 List<ClassMirror> get superinterfaces { 431 List<ClassMirror> get superinterfaces {
427 if (_superinterfaces == null) { 432 if (_superinterfaces == null) {
428 _superinterfaces = _interfaces(_reflectee) 433 _superinterfaces = _interfaces(_reflectee)
429 .map((i) => reflectClass(i)).toList(growable:false); 434 .map((i) => _Mirrors._reflectType(i)).toList(growable:false);
430 } 435 }
431 return _superinterfaces; 436 return _superinterfaces;
432 } 437 }
433 438
439 get _computeMixinApplicationName {
440 var mixins = new List<ClassMirror>();
441 var klass = this;
442 while (_computeMixin(klass._reflectee) != null) {
443 mixins.add(klass.mixin);
444 klass = klass.superclass;
445 }
446 return _s(
447 _n(klass.qualifiedName)
448 + ' with '
449 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', '));
450 }
451
452 var _mixin;
453 ClassMirror get mixin {
454 if (_mixin == null) {
455 var mixinType = _computeMixin(_reflectee);
456 if (mixinType == null) {
457 // The reflectee is not a mixin application.
458 _mixin = this;
459 } else {
460 _mixin = _Mirrors._reflectType(mixinType);
461 }
462 }
463 return _mixin;
464 }
465
434 Map<Symbol, Mirror> _members; 466 Map<Symbol, Mirror> _members;
435 467
436 Map<Symbol, Mirror> get members { 468 Map<Symbol, Mirror> get members {
437 if (_members == null) { 469 if (_members == null) {
438 _members = _makeMemberMap(_computeMembers(_reflectee)); 470 _members = _makeMemberMap(mixin._computeMembers(_reflectee));
439 } 471 }
440 return _members; 472 return _members;
441 } 473 }
442 474
443 Map<Symbol, MethodMirror> _methods = null; 475 Map<Symbol, MethodMirror> _methods = null;
444 Map<Symbol, MethodMirror> _getters = null; 476 Map<Symbol, MethodMirror> _getters = null;
445 Map<Symbol, MethodMirror> _setters = null; 477 Map<Symbol, MethodMirror> _setters = null;
446 Map<Symbol, VariableMirror> _variables = null; 478 Map<Symbol, VariableMirror> _variables = null;
447 479
448 Map<Symbol, MethodMirror> get methods { 480 Map<Symbol, MethodMirror> get methods {
(...skipping 29 matching lines...) Expand all
478 members, 510 members,
479 (key, value) => (value is VariableMirror)); 511 (key, value) => (value is VariableMirror));
480 } 512 }
481 return _variables; 513 return _variables;
482 } 514 }
483 515
484 Map<Symbol, MethodMirror> _constructors; 516 Map<Symbol, MethodMirror> _constructors;
485 517
486 Map<Symbol, MethodMirror> get constructors { 518 Map<Symbol, MethodMirror> get constructors {
487 if (_constructors == null) { 519 if (_constructors == null) {
488 _constructors = _makeMemberMap(_computeConstructors(_reflectee)); 520 var constructorsList = _computeConstructors(_reflectee);
521 var stringName = _n(simpleName);
522 constructorsList.forEach((c) => c._patchConstructorName(stringName));
523 _constructors = _makeMemberMap(constructorsList);
489 } 524 }
490 return _constructors; 525 return _constructors;
491 } 526 }
492 527
493 Map<Symbol, TypeVariableMirror> _typeVariables = null; 528 Map<Symbol, TypeVariableMirror> _typeVariables = null;
494 529
495 Map<Symbol, TypeVariableMirror> get typeVariables { 530 Map<Symbol, TypeVariableMirror> get typeVariables {
496 if (_typeVariables == null) { 531 if (_typeVariables == null) {
497 List params = _ClassMirror_type_variables(_reflectee); 532 List params = _ClassMirror_type_variables(_reflectee);
498 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); 533 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 621
587 static _library(reflectee) 622 static _library(reflectee)
588 native "ClassMirror_library"; 623 native "ClassMirror_library";
589 624
590 static _supertype(reflectee) 625 static _supertype(reflectee)
591 native "ClassMirror_supertype"; 626 native "ClassMirror_supertype";
592 627
593 static _interfaces(reflectee) 628 static _interfaces(reflectee)
594 native "ClassMirror_interfaces"; 629 native "ClassMirror_interfaces";
595 630
631 static _computeMixin(reflectee)
632 native "ClassMirror_mixin";
633
596 _computeMembers(reflectee) 634 _computeMembers(reflectee)
597 native "ClassMirror_members"; 635 native "ClassMirror_members";
598 636
599 _computeConstructors(reflectee) 637 _computeConstructors(reflectee)
600 native "ClassMirror_constructors"; 638 native "ClassMirror_constructors";
601 639
602 _invoke(reflectee, memberName, positionalArguments) 640 _invoke(reflectee, memberName, positionalArguments)
603 native 'ClassMirror_invoke'; 641 native 'ClassMirror_invoke';
604 642
605 _invokeGetter(reflectee, getterName) 643 _invokeGetter(reflectee, getterName)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 706
669 static Type _FunctionTypeMirror_return_type(reflectee) 707 static Type _FunctionTypeMirror_return_type(reflectee)
670 native "FunctionTypeMirror_return_type"; 708 native "FunctionTypeMirror_return_type";
671 709
672 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) 710 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee)
673 native "FunctionTypeMirror_parameters"; 711 native "FunctionTypeMirror_parameters";
674 } 712 }
675 713
676 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl 714 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
677 implements DeclarationMirror { 715 implements DeclarationMirror {
678 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); 716 _LocalDeclarationMirrorImpl(this._reflectee, this._simpleName);
679 717
680 final _reflectee; 718 final _reflectee;
681 719
682 final Symbol simpleName; 720 Symbol _simpleName;
721 Symbol get simpleName => _simpleName;
683 722
684 Symbol _qualifiedName = null; 723 Symbol _qualifiedName = null;
685 Symbol get qualifiedName { 724 Symbol get qualifiedName {
686 if (_qualifiedName == null) { 725 if (_qualifiedName == null) {
687 _qualifiedName = _computeQualifiedName(owner, simpleName); 726 _qualifiedName = _computeQualifiedName(owner, simpleName);
688 } 727 }
689 return _qualifiedName; 728 return _qualifiedName;
690 } 729 }
691 730
692 List<InstanceMirror> get metadata { 731 List<InstanceMirror> get metadata {
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 } else if (parts.length == 2) { 1036 } else if (parts.length == 2) {
998 _constructorName = _s(parts[1]); 1037 _constructorName = _s(parts[1]);
999 } else { 1038 } else {
1000 _constructorName = _s(''); 1039 _constructorName = _s('');
1001 } 1040 }
1002 } 1041 }
1003 } 1042 }
1004 return _constructorName; 1043 return _constructorName;
1005 } 1044 }
1006 1045
1046 void _patchConstructorName(ownerName) {
1047 var cn = _n(constructorName);
1048 if(cn == ''){
1049 _simpleName = _s(ownerName);
1050 } else {
1051 _simpleName = _s(ownerName + "." + cn);
1052 }
1053 }
1054
1007 final bool isConstConstructor; 1055 final bool isConstConstructor;
1008 final bool isGenerativeConstructor; 1056 final bool isGenerativeConstructor;
1009 final bool isRedirectingConstructor; 1057 final bool isRedirectingConstructor;
1010 final bool isFactoryConstructor; 1058 final bool isFactoryConstructor;
1011 1059
1012 String toString() => "MethodMirror on '${_n(simpleName)}'"; 1060 String toString() => "MethodMirror on '${_n(simpleName)}'";
1013 1061
1014 static dynamic _MethodMirror_owner(reflectee) 1062 static dynamic _MethodMirror_owner(reflectee)
1015 native "MethodMirror_owner"; 1063 native "MethodMirror_owner";
1016 1064
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 if (typeMirror == null) { 1260 if (typeMirror == null) {
1213 typeMirror = makeLocalTypeMirror(key); 1261 typeMirror = makeLocalTypeMirror(key);
1214 _instanitationCache[key] = typeMirror; 1262 _instanitationCache[key] = typeMirror;
1215 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1263 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1216 _declarationCache[key] = typeMirror; 1264 _declarationCache[key] = typeMirror;
1217 } 1265 }
1218 } 1266 }
1219 return typeMirror; 1267 return typeMirror;
1220 } 1268 }
1221 } 1269 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698