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

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: rebase 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
« 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 // 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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 355
356 static _computeFunction(reflectee) 356 static _computeFunction(reflectee)
357 native 'ClosureMirror_function'; 357 native 'ClosureMirror_function';
358 } 358 }
359 359
360 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl 360 class _LocalClassMirrorImpl extends _LocalObjectMirrorImpl
361 implements ClassMirror { 361 implements ClassMirror {
362 _LocalClassMirrorImpl(reflectee, 362 _LocalClassMirrorImpl(reflectee,
363 this._reflectedType, 363 this._reflectedType,
364 String simpleName, 364 String simpleName,
365 this._isGeneric) 365 this._isGeneric,
366 this._isMixinTypedef)
366 : this._simpleName = _s(simpleName), 367 : this._simpleName = _s(simpleName),
367 super(reflectee); 368 super(reflectee);
368 369
369 final Type _reflectedType; 370 final Type _reflectedType;
370 final bool _isGeneric; 371 final bool _isGeneric;
372 final bool _isMixinTypedef;
371 373
372 bool get hasReflectedType => _reflectedType != null; 374 bool get hasReflectedType => _reflectedType != null;
373 Type get reflectedType { 375 Type get reflectedType {
374 if (!hasReflectedType) { 376 if (!hasReflectedType) {
375 throw new UnsupportedError( 377 throw new UnsupportedError(
376 "Declarations of generics have no reflected type"); 378 "Declarations of generics have no reflected type");
377 } 379 }
378 return _reflectedType; 380 return _reflectedType;
379 } 381 }
380 382
381 Symbol _simpleName; 383 Symbol _simpleName;
382 Symbol get simpleName { 384 Symbol get simpleName {
383 // dynamic, void and the function types have their names set eagerly in the 385 // dynamic, void and the function types have their names set eagerly in the
384 // constructor. 386 // constructor.
385 if(_simpleName == null) { 387 if(_simpleName == null) {
386 _simpleName = _s(_name(_reflectee)); 388 var simpleString = _name(_reflectee);
389 if (simpleString.contains('&')) {
390 _simpleName = this._mixinApplicationName;
391 } else {
392 _simpleName = _s(simpleString);
393 }
387 } 394 }
388 return _simpleName; 395 return _simpleName;
389 } 396 }
390 397
391 Symbol _qualifiedName = null; 398 Symbol _qualifiedName = null;
392 Symbol get qualifiedName { 399 Symbol get qualifiedName {
393 if (_qualifiedName == null) { 400 if (_qualifiedName == null) {
394 _qualifiedName = _computeQualifiedName(owner, simpleName); 401 _qualifiedName = _computeQualifiedName(owner, simpleName);
395 } 402 }
396 return _qualifiedName; 403 return _qualifiedName;
(...skipping 14 matching lines...) Expand all
411 SourceLocation get location { 418 SourceLocation get location {
412 throw new UnimplementedError( 419 throw new UnimplementedError(
413 'ClassMirror.location is not implemented'); 420 'ClassMirror.location is not implemented');
414 } 421 }
415 422
416 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces 423 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces
417 // once we send out a breaking change. 424 // once we send out a breaking change.
418 bool get isClass => true; 425 bool get isClass => true;
419 ClassMirror get defaultFactory => null; 426 ClassMirror get defaultFactory => null;
420 427
421 ClassMirror _superclass; 428 ClassMirror _trueSuperclassField;
422 ClassMirror get superclass { 429 ClassMirror get _trueSuperclass {
423 if (_superclass == null) { 430 if (_trueSuperclassField == null) {
424 Type supertype = _supertype(_reflectee); 431 Type supertype = _supertype(_reflectee);
425 if (supertype == null) { 432 if (supertype == null) {
426 // Object has no superclass. 433 // Object has no superclass.
427 return null; 434 return null;
428 } 435 }
429 _superclass = _Mirrors._reflectType(supertype); 436 _trueSuperclassField = _Mirrors._reflectType(supertype);
430 } 437 }
431 return _superclass; 438 return _trueSuperclassField;
439 }
440 ClassMirror get superclass {
441 return _isMixinTypedef ? _trueSuperclass._trueSuperclass : _trueSuperclass;
432 } 442 }
433 443
434 var _superinterfaces; 444 var _superinterfaces;
435 List<ClassMirror> get superinterfaces { 445 List<ClassMirror> get superinterfaces {
436 if (_superinterfaces == null) { 446 if (_superinterfaces == null) {
437 _superinterfaces = _interfaces(_reflectee) 447 _superinterfaces = _interfaces(_reflectee)
438 .map((i) => reflectClass(i)).toList(growable:false); 448 .map((i) => _Mirrors._reflectType(i)).toList(growable:false);
439 } 449 }
440 return _superinterfaces; 450 return _superinterfaces;
441 } 451 }
442 452
453 get _mixinApplicationName {
454 var mixins = new List<ClassMirror>();
455 var klass = this;
456 while (_computeMixin(klass._reflectee) != null) {
457 mixins.add(klass.mixin);
458 klass = klass.superclass;
459 }
460 return _s(
461 _n(klass.qualifiedName)
462 + ' with '
463 + mixins.reversed.map((m)=>_n(m.qualifiedName)).join(', '));
464 }
465
466 var _mixin;
467 ClassMirror get mixin {
468 if (_mixin == null) {
469 if (_isMixinTypedef) {
470 _mixin = _trueSuperclass.mixin;
471 } else {
472 var mixinType = _computeMixin(_reflectee);
473 if (mixinType == null) {
474 // The reflectee is not a mixin application.
475 _mixin = this;
476 } else {
477 _mixin = _Mirrors._reflectType(mixinType);
478 }
479 }
480 }
481 return _mixin;
482 }
483
443 Map<Symbol, Mirror> _members; 484 Map<Symbol, Mirror> _members;
444 485
445 Map<Symbol, Mirror> get members { 486 Map<Symbol, Mirror> get members {
446 if (_members == null) { 487 if (_members == null) {
447 _members = _makeMemberMap(_computeMembers(_reflectee)); 488 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this;
489 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee));
448 } 490 }
449 return _members; 491 return _members;
450 } 492 }
451 493
452 Map<Symbol, MethodMirror> _methods = null; 494 Map<Symbol, MethodMirror> _methods = null;
453 Map<Symbol, MethodMirror> _getters = null; 495 Map<Symbol, MethodMirror> _getters = null;
454 Map<Symbol, MethodMirror> _setters = null; 496 Map<Symbol, MethodMirror> _setters = null;
455 Map<Symbol, VariableMirror> _variables = null; 497 Map<Symbol, VariableMirror> _variables = null;
456 498
457 Map<Symbol, MethodMirror> get methods { 499 Map<Symbol, MethodMirror> get methods {
(...skipping 29 matching lines...) Expand all
487 members, 529 members,
488 (key, value) => (value is VariableMirror)); 530 (key, value) => (value is VariableMirror));
489 } 531 }
490 return _variables; 532 return _variables;
491 } 533 }
492 534
493 Map<Symbol, MethodMirror> _constructors; 535 Map<Symbol, MethodMirror> _constructors;
494 536
495 Map<Symbol, MethodMirror> get constructors { 537 Map<Symbol, MethodMirror> get constructors {
496 if (_constructors == null) { 538 if (_constructors == null) {
497 _constructors = _makeMemberMap(_computeConstructors(_reflectee)); 539 var constructorsList = _computeConstructors(_reflectee);
498 } 540 var stringName = _n(simpleName);
499 return _constructors; 541 constructorsList.forEach((c) => c._patchConstructorName(stringName));
542 _constructors = _makeMemberMap(constructorsList);
543 }
544 return _constructors;
500 } 545 }
501 546
502 Map<Symbol, TypeVariableMirror> _typeVariables = null; 547 Map<Symbol, TypeVariableMirror> _typeVariables = null;
503 548
504 Map<Symbol, TypeVariableMirror> get typeVariables { 549 Map<Symbol, TypeVariableMirror> get typeVariables {
505 if (_typeVariables == null) { 550 if (_typeVariables == null) {
506 List params = _ClassMirror_type_variables(_reflectee); 551 List params = _ClassMirror_type_variables(_reflectee);
507 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); 552 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
508 var mirror; 553 var mirror;
509 for (var i = 0; i < params.length; i += 2) { 554 for (var i = 0; i < params.length; i += 2) {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 640
596 static _library(reflectee) 641 static _library(reflectee)
597 native "ClassMirror_library"; 642 native "ClassMirror_library";
598 643
599 static _supertype(reflectee) 644 static _supertype(reflectee)
600 native "ClassMirror_supertype"; 645 native "ClassMirror_supertype";
601 646
602 static _interfaces(reflectee) 647 static _interfaces(reflectee)
603 native "ClassMirror_interfaces"; 648 native "ClassMirror_interfaces";
604 649
650 static _computeMixin(reflectee)
651 native "ClassMirror_mixin";
652
605 _computeMembers(reflectee) 653 _computeMembers(reflectee)
606 native "ClassMirror_members"; 654 native "ClassMirror_members";
607 655
608 _computeConstructors(reflectee) 656 _computeConstructors(reflectee)
609 native "ClassMirror_constructors"; 657 native "ClassMirror_constructors";
610 658
611 _invoke(reflectee, memberName, positionalArguments) 659 _invoke(reflectee, memberName, positionalArguments)
612 native 'ClassMirror_invoke'; 660 native 'ClassMirror_invoke';
613 661
614 _invokeGetter(reflectee, getterName) 662 _invokeGetter(reflectee, getterName)
615 native 'ClassMirror_invokeGetter'; 663 native 'ClassMirror_invokeGetter';
616 664
617 _invokeSetter(reflectee, setterName, value) 665 _invokeSetter(reflectee, setterName, value)
618 native 'ClassMirror_invokeSetter'; 666 native 'ClassMirror_invokeSetter';
619 667
620 static _invokeConstructor(reflectee, constructorName, positionalArguments) 668 static _invokeConstructor(reflectee, constructorName, positionalArguments)
621 native 'ClassMirror_invokeConstructor'; 669 native 'ClassMirror_invokeConstructor';
622 670
623 static _ClassMirror_type_variables(reflectee) 671 static _ClassMirror_type_variables(reflectee)
624 native "ClassMirror_type_variables"; 672 native "ClassMirror_type_variables";
625 673
626 static _computeTypeArguments(reflectee) 674 static _computeTypeArguments(reflectee)
627 native "ClassMirror_type_arguments"; 675 native "ClassMirror_type_arguments";
628 } 676 }
629 677
630 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl 678 class _LocalFunctionTypeMirrorImpl extends _LocalClassMirrorImpl
631 implements FunctionTypeMirror { 679 implements FunctionTypeMirror {
632 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType) 680 _LocalFunctionTypeMirrorImpl(reflectee, reflectedType)
633 : super(reflectee, reflectedType, null, false); 681 : super(reflectee, reflectedType, null, false, false);
634 682
635 // FunctionTypeMirrors have a simpleName generated from their signature. 683 // FunctionTypeMirrors have a simpleName generated from their signature.
636 Symbol _simpleName = null; 684 Symbol _simpleName = null;
637 Symbol get simpleName { 685 Symbol get simpleName {
638 if (_simpleName == null) { 686 if (_simpleName == null) {
639 _simpleName = _s(_makeSignatureString(returnType, parameters)); 687 _simpleName = _s(_makeSignatureString(returnType, parameters));
640 } 688 }
641 return _simpleName; 689 return _simpleName;
642 } 690 }
643 691
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 725
678 static Type _FunctionTypeMirror_return_type(reflectee) 726 static Type _FunctionTypeMirror_return_type(reflectee)
679 native "FunctionTypeMirror_return_type"; 727 native "FunctionTypeMirror_return_type";
680 728
681 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee) 729 List<ParameterMirror> _FunctionTypeMirror_parameters(reflectee)
682 native "FunctionTypeMirror_parameters"; 730 native "FunctionTypeMirror_parameters";
683 } 731 }
684 732
685 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl 733 abstract class _LocalDeclarationMirrorImpl extends _LocalMirrorImpl
686 implements DeclarationMirror { 734 implements DeclarationMirror {
687 _LocalDeclarationMirrorImpl(this._reflectee, this.simpleName); 735 _LocalDeclarationMirrorImpl(this._reflectee, this._simpleName);
688 736
689 final _reflectee; 737 final _reflectee;
690 738
691 final Symbol simpleName; 739 Symbol _simpleName;
740 Symbol get simpleName => _simpleName;
692 741
693 Symbol _qualifiedName = null; 742 Symbol _qualifiedName = null;
694 Symbol get qualifiedName { 743 Symbol get qualifiedName {
695 if (_qualifiedName == null) { 744 if (_qualifiedName == null) {
696 _qualifiedName = _computeQualifiedName(owner, simpleName); 745 _qualifiedName = _computeQualifiedName(owner, simpleName);
697 } 746 }
698 return _qualifiedName; 747 return _qualifiedName;
699 } 748 }
700 749
701 List<InstanceMirror> get metadata { 750 List<InstanceMirror> get metadata {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1018 1067
1019 String _source = null; 1068 String _source = null;
1020 String get source { 1069 String get source {
1021 if (_source == null) { 1070 if (_source == null) {
1022 _source = _MethodMirror_source(_reflectee); 1071 _source = _MethodMirror_source(_reflectee);
1023 assert(_source != null); 1072 assert(_source != null);
1024 } 1073 }
1025 return _source; 1074 return _source;
1026 } 1075 }
1027 1076
1077 void _patchConstructorName(ownerName) {
1078 var cn = _n(constructorName);
1079 if(cn == ''){
1080 _simpleName = _s(ownerName);
1081 } else {
1082 _simpleName = _s(ownerName + "." + cn);
1083 }
1084 }
1085
1028 String toString() => "MethodMirror on '${_n(simpleName)}'"; 1086 String toString() => "MethodMirror on '${_n(simpleName)}'";
1029 1087
1030 static dynamic _MethodMirror_owner(reflectee) 1088 static dynamic _MethodMirror_owner(reflectee)
1031 native "MethodMirror_owner"; 1089 native "MethodMirror_owner";
1032 1090
1033 static dynamic _MethodMirror_return_type(reflectee) 1091 static dynamic _MethodMirror_return_type(reflectee)
1034 native "MethodMirror_return_type"; 1092 native "MethodMirror_return_type";
1035 1093
1036 List<ParameterMirror> _MethodMirror_parameters(reflectee) 1094 List<ParameterMirror> _MethodMirror_parameters(reflectee)
1037 native "MethodMirror_parameters"; 1095 native "MethodMirror_parameters";
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1237 if (typeMirror == null) { 1295 if (typeMirror == null) {
1238 typeMirror = makeLocalTypeMirror(key); 1296 typeMirror = makeLocalTypeMirror(key);
1239 _instanitationCache[key] = typeMirror; 1297 _instanitationCache[key] = typeMirror;
1240 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1298 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1241 _declarationCache[key] = typeMirror; 1299 _declarationCache[key] = typeMirror;
1242 } 1300 }
1243 } 1301 }
1244 return typeMirror; 1302 return typeMirror;
1245 } 1303 }
1246 } 1304 }
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