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

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

Issue 23451052: Mirrors cleanup. No semantic changes. (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
« no previous file with comments | « no previous file | no next file » | 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) {
11 return (value == null || value is num || value is String || value is bool); 11 return (value == null || value is num || value is String || value is bool);
12 } 12 }
13 13
14 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { 14 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) {
15 Map new_map = new Map<Symbol, dynamic>(); 15 Map new_map = new Map<Symbol, dynamic>();
16 old_map.forEach((key, value) { 16 old_map.forEach((key, value) {
17 if (filter(key, value)) { 17 if (filter(key, value)) {
18 new_map[key] = value; 18 new_map[key] = value;
19 } 19 }
20 }); 20 });
21 return new_map; 21 return new_map;
22 } 22 }
23 23
24 Map _makeMemberMap(List mirrors) { 24 Map _makeMemberMap(List mirrors) => new Map<Symbol, dynamic>.fromIterable(
25 Map result = new Map<Symbol, dynamic>(); 25 mirrors, key: (e) => e.simpleName);
26 mirrors.forEach((mirror) => result[mirror.simpleName] = mirror);
27 return result;
28 }
29 26
30 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 27 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
31 28
32 Symbol _s(String name) { 29 Symbol _s(String name) {
33 if (name == null) return null; 30 if (name == null) return null;
34 return new _symbol_dev.Symbol.unvalidated(name); 31 return new _symbol_dev.Symbol.unvalidated(name);
35 } 32 }
36 33
37 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) { 34 Symbol _computeQualifiedName(DeclarationMirror owner, Symbol simpleName) {
38 if (owner == null) return simpleName; 35 if (owner == null) return simpleName;
39 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}'); 36 return _s('${_n(owner.qualifiedName)}.${_n(simpleName)}');
40 } 37 }
41 38
42 Map<Symbol, dynamic> _convertStringToSymbolMap(Map<String, dynamic> map) {
43 if (map == null) return null;
44 Map<Symbol, dynamic> result = new Map<Symbol, dynamic>();
45 map.forEach((name, value) => result[_s(name)] = value);
46 return result;
47 }
48
49 String _makeSignatureString(TypeMirror returnType, 39 String _makeSignatureString(TypeMirror returnType,
50 List<ParameterMirror> parameters) { 40 List<ParameterMirror> parameters) {
51 StringBuffer buf = new StringBuffer(); 41 StringBuffer buf = new StringBuffer();
52 buf.write('('); 42 buf.write('(');
53 bool found_optional_positional = false; 43 bool found_optional_positional = false;
54 bool found_optional_named = false; 44 bool found_optional_named = false;
55 45
56 for (int i = 0; i < parameters.length; i++) { 46 for (int i = 0; i < parameters.length; i++) {
57 var param = parameters[i]; 47 var param = parameters[i];
58 if (param.isOptional && param.isNamed && !found_optional_named) { 48 if (param.isOptional && param.isNamed && !found_optional_named) {
(...skipping 17 matching lines...) Expand all
76 buf.write('}'); 66 buf.write('}');
77 } 67 }
78 if (found_optional_positional) { 68 if (found_optional_positional) {
79 buf.write(']'); 69 buf.write(']');
80 } 70 }
81 buf.write(') -> '); 71 buf.write(') -> ');
82 buf.write(_n(returnType.qualifiedName)); 72 buf.write(_n(returnType.qualifiedName));
83 return buf.toString(); 73 return buf.toString();
84 } 74 }
85 75
86 Map<Uri, LibraryMirror> _createLibrariesMap(List<LibraryMirror> list) {
87 var map = new Map<Uri, LibraryMirror>();
88 list.forEach((LibraryMirror mirror) => map[mirror.uri] = mirror);
89 return map;
90 }
91
92 List _metadata(reflectee) 76 List _metadata(reflectee)
93 native 'DeclarationMirror_metadata'; 77 native 'DeclarationMirror_metadata';
94 78
95 // This will verify the argument types, unwrap them, and ensure we have a fixed 79 // This will verify the argument types, unwrap them, and ensure we have a fixed
96 // array. 80 // array.
97 List _unwarpAsyncPositionals(wrappedArgs) { 81 List _unwrapAsyncPositionals(wrappedArgs) {
98 List unwrappedArgs = new List(wrappedArgs.length); 82 List unwrappedArgs = new List(wrappedArgs.length);
99 for(int i = 0; i < wrappedArgs.length; i++){ 83 for(int i = 0; i < wrappedArgs.length; i++){
100 var wrappedArg = wrappedArgs[i]; 84 var wrappedArg = wrappedArgs[i];
101 if(_isSimpleValue(wrappedArg)) { 85 if(_isSimpleValue(wrappedArg)) {
102 unwrappedArgs[i] = wrappedArg; 86 unwrappedArgs[i] = wrappedArg;
103 } else if(wrappedArg is InstanceMirror) { 87 } else if(wrappedArg is InstanceMirror) {
104 unwrappedArgs[i] = wrappedArg._reflectee; 88 unwrappedArgs[i] = wrappedArg._reflectee;
105 } else { 89 } else {
106 throw "positional argument $i ($wrappedArg) was " 90 throw "positional argument $i ($wrappedArg) was "
107 "not a simple value or InstanceMirror"; 91 "not a simple value or InstanceMirror";
108 } 92 }
109 } 93 }
110 return unwrappedArgs; 94 return unwrappedArgs;
111 } 95 }
112 Map _unwarpAsyncNamed(wrappedArgs) { 96
97 Map _unwrapAsyncNamed(wrappedArgs) {
113 if (wrappedArgs==null) return null; 98 if (wrappedArgs==null) return null;
114 Map unwrappedArgs = new Map(); 99 Map unwrappedArgs = new Map();
115 wrappedArgs.forEach((name, wrappedArg){ 100 wrappedArgs.forEach((name, wrappedArg){
116 if(_isSimpleValue(wrappedArg)) { 101 if(_isSimpleValue(wrappedArg)) {
117 unwrappedArgs[name] = wrappedArg; 102 unwrappedArgs[name] = wrappedArg;
118 } else if(wrappedArg is InstanceMirror) { 103 } else if(wrappedArg is InstanceMirror) {
119 unwrappedArgs[name] = wrappedArg._reflectee; 104 unwrappedArgs[name] = wrappedArg._reflectee;
120 } else { 105 } else {
121 throw "named argument ${_n(name)} ($wrappedArg) was " 106 throw "named argument ${_n(name)} ($wrappedArg) was "
122 "not a simple value or InstanceMirror"; 107 "not a simple value or InstanceMirror";
123 } 108 }
124 }); 109 });
125 return unwrappedArgs; 110 return unwrappedArgs;
126 } 111 }
127 112
128 class _LocalMirrorSystemImpl extends MirrorSystem { 113 class _LocalMirrorSystemImpl extends MirrorSystem {
129 // Change parameter back to "this.libraries" when native code is changed. 114 // Change parameter back to "this.libraries" when native code is changed.
130 _LocalMirrorSystemImpl(List<LibraryMirror> libraries, this.isolate) 115 _LocalMirrorSystemImpl(List<LibraryMirror> libraries, this.isolate)
131 : this.libraries = _createLibrariesMap(libraries); 116 : this.libraries = new Map<Uri, LibraryMirror>.fromIterable(
117 libraries, key: (e) => e.uri);
132 118
133 final Map<Uri, LibraryMirror> libraries; 119 final Map<Uri, LibraryMirror> libraries;
134 final IsolateMirror isolate; 120 final IsolateMirror isolate;
135 121
136 TypeMirror _dynamicType = null; 122 TypeMirror _dynamicType = null;
137
138 TypeMirror get dynamicType { 123 TypeMirror get dynamicType {
139 if (_dynamicType == null) { 124 if (_dynamicType == null) {
140 _dynamicType = new _SpecialTypeMirrorImpl('dynamic'); 125 _dynamicType = new _SpecialTypeMirrorImpl('dynamic');
141 } 126 }
142 return _dynamicType; 127 return _dynamicType;
143 } 128 }
144 129
145 TypeMirror _voidType = null; 130 TypeMirror _voidType = null;
146
147 TypeMirror get voidType { 131 TypeMirror get voidType {
148 if (_voidType == null) { 132 if (_voidType == null) {
149 _voidType = new _SpecialTypeMirrorImpl('void'); 133 _voidType = new _SpecialTypeMirrorImpl('void');
150 } 134 }
151 return _voidType; 135 return _voidType;
152 } 136 }
153 137
154 String toString() => "MirrorSystem for isolate '${isolate.debugName}'"; 138 String toString() => "MirrorSystem for isolate '${isolate.debugName}'";
155 } 139 }
156 140
157 abstract class _LocalMirrorImpl implements Mirror { 141 abstract class _LocalMirrorImpl implements Mirror {
158 int get hashCode { 142 int get hashCode {
159 throw new UnimplementedError('Mirror.hashCode is not implemented'); 143 throw new UnimplementedError('Mirror.hashCode is not implemented');
160 } 144 }
161 145
162 // Local mirrors always return the same MirrorSystem. This field 146 // Local mirrors always return the same MirrorSystem. This field
163 // is more interesting once we implement remote mirrors. 147 // is more interesting once we implement remote mirrors.
164 MirrorSystem get mirrors => _Mirrors.currentMirrorSystem(); 148 MirrorSystem get mirrors => _Mirrors.currentMirrorSystem();
165 } 149 }
166 150
167 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl 151 class _LocalIsolateMirrorImpl extends _LocalMirrorImpl
168 implements IsolateMirror { 152 implements IsolateMirror {
169 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary) {} 153 _LocalIsolateMirrorImpl(this.debugName, this.rootLibrary);
170 154
171 final String debugName; 155 final String debugName;
172 final bool isCurrent = true; 156 final bool isCurrent = true;
173 final LibraryMirror rootLibrary; 157 final LibraryMirror rootLibrary;
174 158
175 String toString() => "IsolateMirror on '$debugName'"; 159 String toString() => "IsolateMirror on '$debugName'";
176 } 160 }
177 161
178 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl 162 abstract class _LocalObjectMirrorImpl extends _LocalMirrorImpl
179 implements ObjectMirror { 163 implements ObjectMirror {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 _n(memberName), 200 _n(memberName),
217 value); 201 value);
218 return reflect(value); 202 return reflect(value);
219 } 203 }
220 204
221 Future<InstanceMirror> invokeAsync(Symbol memberName, 205 Future<InstanceMirror> invokeAsync(Symbol memberName,
222 List positionalArguments, 206 List positionalArguments,
223 [Map<Symbol, dynamic> namedArguments]) { 207 [Map<Symbol, dynamic> namedArguments]) {
224 return new Future(() { 208 return new Future(() {
225 return this.invoke(memberName, 209 return this.invoke(memberName,
226 _unwarpAsyncPositionals(positionalArguments), 210 _unwrapAsyncPositionals(positionalArguments),
227 _unwarpAsyncNamed(namedArguments)); 211 _unwrapAsyncNamed(namedArguments));
228 }); 212 });
229 } 213 }
230 214
231 Future<InstanceMirror> getFieldAsync(Symbol memberName) { 215 Future<InstanceMirror> getFieldAsync(Symbol memberName) {
232 try { 216 try {
233 var result = this._invokeGetter(_reflectee, 217 var result = this._invokeGetter(_reflectee,
234 _n(memberName)); 218 _n(memberName));
235 return new Future.value(reflect(result)); 219 return new Future.value(reflect(result));
236 } catch(e) { 220 } catch(e) {
237 return new Future.error(e); 221 return new Future.error(e);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 393 }
410 394
411 // It is tempting to implement this in terms of Function.apply, but then 395 // It is tempting to implement this in terms of Function.apply, but then
412 // lazy compilation errors would be fatal. 396 // lazy compilation errors would be fatal.
413 return reflect(_apply(_reflectee, arguments, names)); 397 return reflect(_apply(_reflectee, arguments, names));
414 } 398 }
415 399
416 Future<InstanceMirror> applyAsync(List positionalArguments, 400 Future<InstanceMirror> applyAsync(List positionalArguments,
417 [Map<Symbol, dynamic> namedArguments]) { 401 [Map<Symbol, dynamic> namedArguments]) {
418 return new Future(() { 402 return new Future(() {
419 return this.apply(_unwarpAsyncPositionals(positionalArguments), 403 return this.apply(_unwrapAsyncPositionals(positionalArguments),
420 _unwarpAsyncNamed(namedArguments)); 404 _unwrapAsyncNamed(namedArguments));
421 }); 405 });
422 } 406 }
423 407
424 Future<InstanceMirror> findInContext(Symbol name) { 408 Future<InstanceMirror> findInContext(Symbol name) {
425 throw new UnimplementedError( 409 throw new UnimplementedError(
426 'ClosureMirror.findInContext() is not implemented'); 410 'ClosureMirror.findInContext() is not implemented');
427 } 411 }
428 412
429 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'"; 413 String toString() => "ClosureMirror on '${Error.safeToString(_reflectee)}'";
430 414
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 _owner = _library(_reflectee); 467 _owner = _library(_reflectee);
484 } 468 }
485 return _owner; 469 return _owner;
486 } 470 }
487 471
488 bool get isPrivate => _n(simpleName).startsWith('_'); 472 bool get isPrivate => _n(simpleName).startsWith('_');
489 473
490 final bool isTopLevel = true; 474 final bool isTopLevel = true;
491 475
492 SourceLocation get location { 476 SourceLocation get location {
493 throw new UnimplementedError( 477 throw new UnimplementedError('ClassMirror.location is not implemented');
494 'ClassMirror.location is not implemented');
495 } 478 }
496 479
497 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces 480 // TODO(rmacnak): Remove these left-overs from the days of separate interfaces
498 // once we send out a breaking change. 481 // once we send out a breaking change.
499 bool get isClass => true; 482 bool get isClass => true;
500 ClassMirror get defaultFactory => null; 483 ClassMirror get defaultFactory => null;
501 484
502 ClassMirror _trueSuperclassField; 485 ClassMirror _trueSuperclassField;
503 ClassMirror get _trueSuperclass { 486 ClassMirror get _trueSuperclass {
504 if (_trueSuperclassField == null) { 487 if (_trueSuperclassField == null) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 _mixin = this; 532 _mixin = this;
550 } else { 533 } else {
551 _mixin = _Mirrors._reflectType(mixinType); 534 _mixin = _Mirrors._reflectType(mixinType);
552 } 535 }
553 } 536 }
554 } 537 }
555 return _mixin; 538 return _mixin;
556 } 539 }
557 540
558 Map<Symbol, Mirror> _members; 541 Map<Symbol, Mirror> _members;
559
560 Map<Symbol, Mirror> get members { 542 Map<Symbol, Mirror> get members {
561 if (_members == null) { 543 if (_members == null) {
562 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this; 544 var whoseMembers = _isMixinTypedef ? _trueSuperclass : this;
563 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee)); 545 _members = _makeMemberMap(mixin._computeMembers(whoseMembers._reflectee));
564 } 546 }
565 return _members; 547 return _members;
566 } 548 }
567 549
568 Map<Symbol, MethodMirror> _methods = null; 550 Map<Symbol, MethodMirror> _methods;
569 Map<Symbol, MethodMirror> _getters = null;
570 Map<Symbol, MethodMirror> _setters = null;
571 Map<Symbol, VariableMirror> _variables = null;
572
573 Map<Symbol, MethodMirror> get methods { 551 Map<Symbol, MethodMirror> get methods {
574 if (_methods == null) { 552 if (_methods == null) {
575 _methods = _filterMap( 553 _methods = _filterMap(
576 members, 554 members,
577 (key, value) => (value is MethodMirror && value.isRegularMethod)); 555 (key, value) => (value is MethodMirror && value.isRegularMethod));
578 } 556 }
579 return _methods; 557 return _methods;
580 } 558 }
581 559
560 Map<Symbol, MethodMirror> _getters;
582 Map<Symbol, MethodMirror> get getters { 561 Map<Symbol, MethodMirror> get getters {
583 if (_getters == null) { 562 if (_getters == null) {
584 _getters = _filterMap( 563 _getters = _filterMap(
585 members, 564 members,
586 (key, value) => (value is MethodMirror && value.isGetter)); 565 (key, value) => (value is MethodMirror && value.isGetter));
587 } 566 }
588 return _getters; 567 return _getters;
589 } 568 }
590 569
570 Map<Symbol, MethodMirror> _setters;
591 Map<Symbol, MethodMirror> get setters { 571 Map<Symbol, MethodMirror> get setters {
592 if (_setters == null) { 572 if (_setters == null) {
593 _setters = _filterMap( 573 _setters = _filterMap(
594 members, 574 members,
595 (key, value) => (value is MethodMirror && value.isSetter)); 575 (key, value) => (value is MethodMirror && value.isSetter));
596 } 576 }
597 return _setters; 577 return _setters;
598 } 578 }
599 579
580 Map<Symbol, VariableMirror> _variables;
600 Map<Symbol, VariableMirror> get variables { 581 Map<Symbol, VariableMirror> get variables {
601 if (_variables == null) { 582 if (_variables == null) {
602 _variables = _filterMap( 583 _variables = _filterMap(
603 members, 584 members,
604 (key, value) => (value is VariableMirror)); 585 (key, value) => (value is VariableMirror));
605 } 586 }
606 return _variables; 587 return _variables;
607 } 588 }
608 589
609 Map<Symbol, MethodMirror> _constructors; 590 Map<Symbol, MethodMirror> _constructors;
610
611 Map<Symbol, MethodMirror> get constructors { 591 Map<Symbol, MethodMirror> get constructors {
612 if (_constructors == null) { 592 if (_constructors == null) {
613 var constructorsList = _computeConstructors(_reflectee); 593 var constructorsList = _computeConstructors(_reflectee);
614 var stringName = _n(simpleName); 594 var stringName = _n(simpleName);
615 constructorsList.forEach((c) => c._patchConstructorName(stringName)); 595 constructorsList.forEach((c) => c._patchConstructorName(stringName));
616 _constructors = _makeMemberMap(constructorsList); 596 _constructors = _makeMemberMap(constructorsList);
617 } 597 }
618 return _constructors; 598 return _constructors;
619 } 599 }
620 600
621 Map<Symbol, TypeVariableMirror> _typeVariables = null; 601 Map<Symbol, TypeVariableMirror> _typeVariables = null;
622
623 Map<Symbol, TypeVariableMirror> get typeVariables { 602 Map<Symbol, TypeVariableMirror> get typeVariables {
624 if (_typeVariables == null) { 603 if (_typeVariables == null) {
625 List params = _ClassMirror_type_variables(_reflectee); 604 List params = _ClassMirror_type_variables(_reflectee);
626 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>(); 605 _typeVariables = new LinkedHashMap<Symbol, TypeVariableMirror>();
627 var mirror; 606 var mirror;
628 for (var i = 0; i < params.length; i += 2) { 607 for (var i = 0; i < params.length; i += 2) {
629 mirror = new _LocalTypeVariableMirrorImpl( 608 mirror = new _LocalTypeVariableMirrorImpl(
630 params[i + 1], params[i], this); 609 params[i + 1], params[i], this);
631 _typeVariables[mirror.simpleName] = mirror; 610 _typeVariables[mirror.simpleName] = mirror;
632 } 611 }
633 } 612 }
634 return _typeVariables; 613 return _typeVariables;
635 } 614 }
636 615
637 Map<Symbol, TypeMirror> _typeArguments = null; 616 Map<Symbol, TypeMirror> _typeArguments = null;
638 Map<Symbol, TypeMirror> get typeArguments { 617 Map<Symbol, TypeMirror> get typeArguments {
639 if(_typeArguments == null) { 618 if(_typeArguments == null) {
640 if(_isGenericDeclaration) { 619 if(_isGenericDeclaration) {
641 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>(); 620 _typeArguments = new LinkedHashMap<Symbol, TypeMirror>();
642 } else { 621 } else {
643 _typeArguments = 622 _typeArguments =
644 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(typeVariables.ke ys, 623 new LinkedHashMap<Symbol, TypeMirror>.fromIterables(
645 _computeTypeArgu ments(_reflectedType)); 624 typeVariables.keys, _computeTypeArguments(_reflectedType));
646 } 625 }
647 } 626 }
648 return _typeArguments; 627 return _typeArguments;
649 } 628 }
650 629
651 bool get isOriginalDeclaration { 630 bool get isOriginalDeclaration => !_isGeneric || _isGenericDeclaration;
652 return !_isGeneric || _isGenericDeclaration;
653 }
654 631
655 ClassMirror get originalDeclaration { 632 ClassMirror get originalDeclaration {
656 if (isOriginalDeclaration) { 633 if (isOriginalDeclaration) {
657 return this; 634 return this;
658 } else { 635 } else {
659 return reflectClass(_reflectedType); 636 return reflectClass(_reflectedType);
660 } 637 }
661 } 638 }
662 639
663 String toString() { 640 String toString() => "ClassMirror on '${_n(simpleName)}'";
664 return "ClassMirror on '${_n(simpleName)}'";
665 }
666 641
667 InstanceMirror newInstance(Symbol constructorName, 642 InstanceMirror newInstance(Symbol constructorName,
668 List positionalArguments, 643 List positionalArguments,
669 [Map<Symbol, dynamic> namedArguments]) { 644 [Map<Symbol, dynamic> namedArguments]) {
670 // Native code will add the 1 or 2 implicit arguments depending on whether 645 // Native code will add the 1 or 2 implicit arguments depending on whether
671 // we end up invoking a factory or constructor respectively. 646 // we end up invoking a factory or constructor respectively.
672 int numPositionalArguments = positionalArguments.length; 647 int numPositionalArguments = positionalArguments.length;
673 int numNamedArguments = namedArguments != null ? namedArguments.length : 0; 648 int numNamedArguments = namedArguments != null ? namedArguments.length : 0;
674 int numArguments = numPositionalArguments + numNamedArguments; 649 int numArguments = numPositionalArguments + numNamedArguments;
675 List arguments = new List(numArguments); 650 List arguments = new List(numArguments);
(...skipping 13 matching lines...) Expand all
689 _n(constructorName), 664 _n(constructorName),
690 arguments, 665 arguments,
691 names)); 666 names));
692 } 667 }
693 668
694 Future<InstanceMirror> newInstanceAsync(Symbol constructorName, 669 Future<InstanceMirror> newInstanceAsync(Symbol constructorName,
695 List positionalArguments, 670 List positionalArguments,
696 [Map<Symbol, dynamic> namedArguments]) { 671 [Map<Symbol, dynamic> namedArguments]) {
697 return new Future(() { 672 return new Future(() {
698 return this.newInstance(constructorName, 673 return this.newInstance(constructorName,
699 _unwarpAsyncPositionals(positionalArguments), 674 _unwrapAsyncPositionals(positionalArguments),
700 _unwarpAsyncNamed(namedArguments)); 675 _unwrapAsyncNamed(namedArguments));
701 }); 676 });
702 } 677 }
703 678
704 List<InstanceMirror> get metadata { 679 List<InstanceMirror> get metadata {
705 // Get the metadata objects, convert them into InstanceMirrors using 680 // Get the metadata objects, convert them into InstanceMirrors using
706 // reflect() and then make them into a Dart list. 681 // reflect() and then make them into a Dart list.
707 return _metadata(_reflectee).map(reflect).toList(growable:false); 682 return _metadata(_reflectee).map(reflect).toList(growable:false);
708 } 683 }
709 684
710 bool operator ==(other) { 685 bool operator ==(other) {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 } 865 }
891 866
892 867
893 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl 868 class _LocalTypedefMirrorImpl extends _LocalDeclarationMirrorImpl
894 implements TypedefMirror { 869 implements TypedefMirror {
895 _LocalTypedefMirrorImpl(reflectee, 870 _LocalTypedefMirrorImpl(reflectee,
896 String simpleName, 871 String simpleName,
897 this._owner) 872 this._owner)
898 : super(reflectee, _s(simpleName)); 873 : super(reflectee, _s(simpleName));
899 874
875 final bool isTopLevel = true;
876
900 // TODO(12282): Deal with generic typedefs. 877 // TODO(12282): Deal with generic typedefs.
901 bool get _isGeneric => false; 878 bool get _isGeneric => false;
902 879
880 bool get isPrivate => false;
881
903 DeclarationMirror _owner; 882 DeclarationMirror _owner;
904 DeclarationMirror get owner { 883 DeclarationMirror get owner {
905 if (_owner == null) { 884 if (_owner == null) {
906 _owner = _LocalClassMirrorImpl._library(_reflectee); 885 _owner = _LocalClassMirrorImpl._library(_reflectee);
907 } 886 }
908 return _owner; 887 return _owner;
909 } 888 }
910 889
911 bool get isPrivate => false;
912
913 final bool isTopLevel = true;
914
915 SourceLocation get location { 890 SourceLocation get location {
916 throw new UnimplementedError( 891 throw new UnimplementedError('TypedefMirror.location is not implemented');
917 'TypedefMirror.location is not implemented');
918 } 892 }
919 893
920 TypeMirror _referent = null; 894 TypeMirror _referent = null;
921 TypeMirror get referent { 895 TypeMirror get referent {
922 if (_referent == null) { 896 if (_referent == null) {
923 // TODO(12282): Deal with generic typedef. 897 // TODO(12282): Deal with generic typedef.
924 return new _LocalFunctionTypeMirrorImpl( 898 return new _LocalFunctionTypeMirrorImpl(
925 _TypedefMirror_referent(_reflectee), null); 899 _TypedefMirror_referent(_reflectee), null);
926 } 900 }
927 return _referent; 901 return _referent;
(...skipping 22 matching lines...) Expand all
950 // Always null for libraries. 924 // Always null for libraries.
951 final DeclarationMirror owner = null; 925 final DeclarationMirror owner = null;
952 926
953 // Always false for libraries. 927 // Always false for libraries.
954 final bool isPrivate = false; 928 final bool isPrivate = false;
955 929
956 // Always false for libraries. 930 // Always false for libraries.
957 final bool isTopLevel = false; 931 final bool isTopLevel = false;
958 932
959 SourceLocation get location { 933 SourceLocation get location {
960 throw new UnimplementedError( 934 throw new UnimplementedError('LibraryMirror.location is not implemented');
961 'LibraryMirror.location is not implemented');
962 } 935 }
963 936
964 final Uri uri; 937 final Uri uri;
965 938
966 Map<Symbol, Mirror> _members; 939 Map<Symbol, Mirror> _members;
967
968 Map<Symbol, Mirror> get members { 940 Map<Symbol, Mirror> get members {
969 if (_members == null) { 941 if (_members == null) {
970 _members = _makeMemberMap(_computeMembers(_reflectee)); 942 _members = _makeMemberMap(_computeMembers(_reflectee));
971 } 943 }
972 return _members; 944 return _members;
973 } 945 }
974 946
975 Map<Symbol, ClassMirror> _classes = null; 947 Map<Symbol, ClassMirror> _classes;
976 Map<Symbol, MethodMirror> _functions = null;
977 Map<Symbol, MethodMirror> _getters = null;
978 Map<Symbol, MethodMirror> _setters = null;
979 Map<Symbol, VariableMirror> _variables = null;
980
981 Map<Symbol, ClassMirror> get classes { 948 Map<Symbol, ClassMirror> get classes {
982 if (_classes == null) { 949 if (_classes == null) {
983 _classes = _filterMap(members, 950 _classes = _filterMap(members,
984 (key, value) => (value is ClassMirror)); 951 (key, value) => (value is ClassMirror));
985 } 952 }
986 return _classes; 953 return _classes;
987 } 954 }
988 955
956 Map<Symbol, MethodMirror> _functions;
989 Map<Symbol, MethodMirror> get functions { 957 Map<Symbol, MethodMirror> get functions {
990 if (_functions == null) { 958 if (_functions == null) {
991 _functions = _filterMap(members, 959 _functions = _filterMap(members, (key, value) => (value is MethodMirror));
992 (key, value) => (value is MethodMirror));
993 } 960 }
994 return _functions; 961 return _functions;
995 } 962 }
996 963
964 Map<Symbol, MethodMirror> _getters;
997 Map<Symbol, MethodMirror> get getters { 965 Map<Symbol, MethodMirror> get getters {
998 if (_getters == null) { 966 if (_getters == null) {
999 _getters = _filterMap(functions, 967 _getters = _filterMap(functions, (key, value) => (value.isGetter));
1000 (key, value) => (value.isGetter));
1001 } 968 }
1002 return _getters; 969 return _getters;
1003 } 970 }
1004 971
972 Map<Symbol, MethodMirror> _setters;
1005 Map<Symbol, MethodMirror> get setters { 973 Map<Symbol, MethodMirror> get setters {
1006 if (_setters == null) { 974 if (_setters == null) {
1007 _setters = _filterMap(functions, 975 _setters = _filterMap(functions, (key, value) => (value.isSetter));
1008 (key, value) => (value.isSetter));
1009 } 976 }
1010 return _setters; 977 return _setters;
1011 } 978 }
1012 979
980 Map<Symbol, VariableMirror> _variables;
1013 Map<Symbol, VariableMirror> get variables { 981 Map<Symbol, VariableMirror> get variables {
1014 if (_variables == null) { 982 if (_variables == null) {
1015 _variables = _filterMap(members, 983 _variables = _filterMap(members,
1016 (key, value) => (value is VariableMirror)); 984 (key, value) => (value is VariableMirror));
1017 } 985 }
1018 return _variables; 986 return _variables;
1019 } 987 }
1020 988
1021 List<InstanceMirror> get metadata { 989 List<InstanceMirror> get metadata {
1022 // Get the metadata objects, convert them into InstanceMirrors using 990 // Get the metadata objects, convert them into InstanceMirrors using
1023 // reflect() and then make them into a Dart list. 991 // reflect() and then make them into a Dart list.
1024 return _metadata(_reflectee).map(reflect).toList(growable:false); 992 return _metadata(_reflectee).map(reflect).toList(growable:false);
1025 } 993 }
1026 994
1027 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1028
1029 bool operator ==(other) { 995 bool operator ==(other) {
1030 return this.runtimeType == other.runtimeType && 996 return this.runtimeType == other.runtimeType &&
1031 this._reflectee == other._reflectee; 997 this._reflectee == other._reflectee;
1032 } 998 }
1033 999
1034 int get hashCode => simpleName.hashCode; 1000 int get hashCode => simpleName.hashCode;
1035 1001
1002 String toString() => "LibraryMirror on '${_n(simpleName)}'";
1003
1036 _invoke(reflectee, memberName, arguments, argumentNames) 1004 _invoke(reflectee, memberName, arguments, argumentNames)
1037 native 'LibraryMirror_invoke'; 1005 native 'LibraryMirror_invoke';
1038 1006
1039 _invokeGetter(reflectee, getterName) 1007 _invokeGetter(reflectee, getterName)
1040 native 'LibraryMirror_invokeGetter'; 1008 native 'LibraryMirror_invokeGetter';
1041 1009
1042 _invokeSetter(reflectee, setterName, value) 1010 _invokeSetter(reflectee, setterName, value)
1043 native 'LibraryMirror_invokeSetter'; 1011 native 'LibraryMirror_invokeSetter';
1044 1012
1045 _computeMembers(reflectee) 1013 _computeMembers(reflectee)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 DeclarationMirror _owner; 1048 DeclarationMirror _owner;
1081 DeclarationMirror get owner { 1049 DeclarationMirror get owner {
1082 // For nested closures it is possible, that the mirror for the owner has not 1050 // For nested closures it is possible, that the mirror for the owner has not
1083 // been created yet. 1051 // been created yet.
1084 if (_owner == null) { 1052 if (_owner == null) {
1085 _owner = _MethodMirror_owner(_reflectee); 1053 _owner = _MethodMirror_owner(_reflectee);
1086 } 1054 }
1087 return _owner; 1055 return _owner;
1088 } 1056 }
1089 1057
1090 bool get isPrivate { 1058 bool get isPrivate => _n(simpleName).startsWith('_') ||
1091 return _n(simpleName).startsWith('_') || 1059 _n(constructorName).startsWith('_');
1092 _n(constructorName).startsWith('_');
1093 }
1094 1060
1095 bool get isTopLevel => owner is LibraryMirror; 1061 bool get isTopLevel => owner is LibraryMirror;
1096 1062
1097 SourceLocation get location { 1063 SourceLocation get location {
1098 throw new UnimplementedError( 1064 throw new UnimplementedError('MethodMirror.location is not implemented');
1099 'MethodMirror.location is not implemented');
1100 } 1065 }
1101 1066
1102 TypeMirror _returnType = null; 1067 TypeMirror _returnType = null;
1103 TypeMirror get returnType { 1068 TypeMirror get returnType {
1104 if (_returnType == null) { 1069 if (_returnType == null) {
1105 if (isConstructor) { 1070 if (isConstructor) {
1106 _returnType = owner; 1071 _returnType = owner;
1107 } else { 1072 } else {
1108 _returnType = 1073 _returnType =
1109 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee)); 1074 _Mirrors._reflectType(_MethodMirror_return_type(_reflectee));
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 implements VariableMirror { 1145 implements VariableMirror {
1181 _LocalVariableMirrorImpl(reflectee, 1146 _LocalVariableMirrorImpl(reflectee,
1182 String simpleName, 1147 String simpleName,
1183 this.owner, 1148 this.owner,
1184 this._type, 1149 this._type,
1185 this.isStatic, 1150 this.isStatic,
1186 this.isFinal) 1151 this.isFinal)
1187 : super(reflectee, _s(simpleName)); 1152 : super(reflectee, _s(simpleName));
1188 1153
1189 final DeclarationMirror owner; 1154 final DeclarationMirror owner;
1155 final bool isStatic;
1156 final bool isFinal;
1190 1157
1191 bool get isPrivate { 1158 bool get isPrivate => _n(simpleName).startsWith('_');
1192 return _n(simpleName).startsWith('_');
1193 }
1194 1159
1195 bool get isTopLevel { 1160 bool get isTopLevel => owner is LibraryMirror;
1196 return owner is LibraryMirror;
1197 }
1198 1161
1199 SourceLocation get location { 1162 SourceLocation get location {
1200 throw new UnimplementedError( 1163 throw new UnimplementedError('VariableMirror.location is not implemented');
1201 'VariableMirror.location is not implemented');
1202 } 1164 }
1203 1165
1204 TypeMirror _type; 1166 TypeMirror _type;
1205 TypeMirror get type { 1167 TypeMirror get type {
1206 if (_type == null) { 1168 if (_type == null) {
1207 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee)); 1169 _type = _Mirrors._reflectType(_VariableMirror_type(_reflectee));
1208 } 1170 }
1209 return _type; 1171 return _type;
1210 } 1172 }
1211 1173
1212 final bool isStatic;
1213 final bool isFinal;
1214
1215 String toString() => "VariableMirror on '${_n(simpleName)}'"; 1174 String toString() => "VariableMirror on '${_n(simpleName)}'";
1216 1175
1217 static _VariableMirror_type(reflectee) 1176 static _VariableMirror_type(reflectee)
1218 native "VariableMirror_type"; 1177 native "VariableMirror_type";
1219 } 1178 }
1220 1179
1221 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl 1180 class _LocalParameterMirrorImpl extends _LocalVariableMirrorImpl
1222 implements ParameterMirror { 1181 implements ParameterMirror {
1223 _LocalParameterMirrorImpl(reflectee, 1182 _LocalParameterMirrorImpl(reflectee,
1224 String simpleName, 1183 String simpleName,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 1232
1274 static Type _ParameterMirror_type(_reflectee, _position) 1233 static Type _ParameterMirror_type(_reflectee, _position)
1275 native "ParameterMirror_type"; 1234 native "ParameterMirror_type";
1276 } 1235 }
1277 1236
1278 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl 1237 class _SpecialTypeMirrorImpl extends _LocalMirrorImpl
1279 implements TypeMirror, DeclarationMirror { 1238 implements TypeMirror, DeclarationMirror {
1280 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name); 1239 _SpecialTypeMirrorImpl(String name) : simpleName = _s(name);
1281 1240
1282 final bool isPrivate = false; 1241 final bool isPrivate = false;
1242 final DeclarationMirror owner = null;
1243 final Symbol simpleName;
1283 final bool isTopLevel = true; 1244 final bool isTopLevel = true;
1284
1285 // Fixed length 0, therefore immutable. 1245 // Fixed length 0, therefore immutable.
1286 final List<InstanceMirror> metadata = new List(0); 1246 final List<InstanceMirror> metadata = new List(0);
1287 1247
1288 final DeclarationMirror owner = null;
1289 final Symbol simpleName;
1290
1291 SourceLocation get location { 1248 SourceLocation get location {
1292 throw new UnimplementedError( 1249 throw new UnimplementedError('TypeMirror.location is not implemented');
1293 'TypeMirror.location is not implemented');
1294 } 1250 }
1295 1251
1296 Symbol get qualifiedName { 1252 Symbol get qualifiedName => simpleName;
1297 return simpleName;
1298 }
1299
1300 String toString() => "TypeMirror on '${_n(simpleName)}'";
1301 1253
1302 // TODO(11955): Remove once dynamicType and voidType are canonical objects in 1254 // TODO(11955): Remove once dynamicType and voidType are canonical objects in
1303 // the object store. 1255 // the object store.
1304 bool operator ==(other) { 1256 bool operator ==(other) {
1305 if (other is! _SpecialTypeMirrorImpl) { 1257 if (other is! _SpecialTypeMirrorImpl) {
1306 return false; 1258 return false;
1307 } 1259 }
1308 return this.simpleName == other.simpleName; 1260 return this.simpleName == other.simpleName;
1309 } 1261 }
1310 1262
1311 int get hashCode => simpleName.hashCode; 1263 int get hashCode => simpleName.hashCode;
1264
1265 String toString() => "TypeMirror on '${_n(simpleName)}'";
1312 } 1266 }
1313 1267
1314 class _Mirrors { 1268 class _Mirrors {
1315 // Does a port refer to our local isolate? 1269 // Does a port refer to our local isolate?
1316 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort'; 1270 static bool isLocalPort(SendPort port) native 'Mirrors_isLocalPort';
1317 1271
1318 static MirrorSystem _currentMirrorSystem = null; 1272 static MirrorSystem _currentMirrorSystem = null;
1319 1273
1320 // Creates a new local MirrorSystem. 1274 // Creates a new local MirrorSystem.
1321 static MirrorSystem makeLocalMirrorSystem() 1275 static MirrorSystem makeLocalMirrorSystem()
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 if (typeMirror == null) { 1330 if (typeMirror == null) {
1377 typeMirror = makeLocalTypeMirror(key); 1331 typeMirror = makeLocalTypeMirror(key);
1378 _instanitationCache[key] = typeMirror; 1332 _instanitationCache[key] = typeMirror;
1379 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1333 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1380 _declarationCache[key] = typeMirror; 1334 _declarationCache[key] = typeMirror;
1381 } 1335 }
1382 } 1336 }
1383 return typeMirror; 1337 return typeMirror;
1384 } 1338 }
1385 } 1339 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698