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

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

Issue 246833003: Revert "Remove unmodifiable map wrappers that could instead use UnmodifiableMapView." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 final emptyList = new UnmodifiableListView([]); 9 final emptyList = new UnmodifiableListView([]);
10 final emptyMap = new UnmodifiableMapView({}); 10 final emptyMap = new _UnmodifiableMapView({});
11
12 // TODO(14314): Move to dart:collection.
13 class _UnmodifiableMapView<K, V> implements Map<K, V> {
14 final Map<K, V> _source;
15
16 _UnmodifiableMapView(Map<K, V> source) : _source = source;
17
18 static void _throw() {
19 throw new UnsupportedError("Cannot modify an unmodifiable Map");
20 }
21
22 int get length => _source.length;
23 bool get isEmpty => _source.isEmpty;
24 bool get isNotEmpty => _source.isNotEmpty;
25 V operator [](K key) => _source[key];
26 bool containsKey(K key) => _source.containsKey(key);
27 bool containsValue(V value) => _source.containsValue(value);
28 void forEach(void f(K key, V value)) => _source.forEach(f);
29 Iterable<K> get keys => _source.keys;
30 Iterable<V> get values => _source.values;
31 void operator []=(K key, V value) => _throw();
32 V putIfAbsent(K key, V ifAbsent()) { _throw(); }
33 void addAll(Map<K, V> other) => _throw();
34 V remove(K key) { _throw(); }
35 void clear() => _throw();
36 }
11 37
12 class _InternalMirrorError { 38 class _InternalMirrorError {
13 final String _msg; 39 final String _msg;
14 const _InternalMirrorError(String this._msg); 40 const _InternalMirrorError(String this._msg);
15 String toString() => _msg; 41 String toString() => _msg;
16 } 42 }
17 43
18 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) { 44 Map _filterMap(Map<Symbol, dynamic> old_map, bool filter(Symbol key, value)) {
19 Map new_map = new Map<Symbol, dynamic>(); 45 Map new_map = new Map<Symbol, dynamic>();
20 old_map.forEach((key, value) { 46 old_map.forEach((key, value) {
21 if (filter(key, value)) { 47 if (filter(key, value)) {
22 new_map[key] = value; 48 new_map[key] = value;
23 } 49 }
24 }); 50 });
25 return new UnmodifiableMapView(new_map); 51 return new _UnmodifiableMapView(new_map);
26 } 52 }
27 53
28 Map _makeMemberMap(List mirrors) { 54 Map _makeMemberMap(List mirrors) {
29 return new UnmodifiableMapView<Symbol, DeclarationMirror>( 55 return new _UnmodifiableMapView<Symbol, DeclarationMirror>(
30 new Map<Symbol, DeclarationMirror>.fromIterable( 56 new Map<Symbol, DeclarationMirror>.fromIterable(
31 mirrors, key: (e) => e.simpleName)); 57 mirrors, key: (e) => e.simpleName));
32 } 58 }
33 59
34 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol); 60 String _n(Symbol symbol) => _symbol_dev.Symbol.getName(symbol);
35 61
36 Symbol _s(String name) { 62 Symbol _s(String name) {
37 if (name == null) return null; 63 if (name == null) return null;
38 return new _symbol_dev.Symbol.unvalidated(name); 64 return new _symbol_dev.Symbol.unvalidated(name);
39 } 65 }
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 result[getterName] = 633 result[getterName] =
608 new _SyntheticAccessor(this, getterName, true, true, false, decl); 634 new _SyntheticAccessor(this, getterName, true, true, false, decl);
609 if (!decl.isFinal) { 635 if (!decl.isFinal) {
610 var setterName = _asSetter(decl.simpleName, this.owner); 636 var setterName = _asSetter(decl.simpleName, this.owner);
611 result[setterName] = new _SyntheticAccessor( 637 result[setterName] = new _SyntheticAccessor(
612 this, setterName, false, true, false, decl); 638 this, setterName, false, true, false, decl);
613 } 639 }
614 } 640 }
615 }); 641 });
616 _cachedStaticMembers = 642 _cachedStaticMembers =
617 new UnmodifiableMapView<Symbol, MethodMirror>(result); 643 new _UnmodifiableMapView<Symbol, MethodMirror>(result);
618 } 644 }
619 return _cachedStaticMembers; 645 return _cachedStaticMembers;
620 } 646 }
621 647
622 var _cachedInstanceMembers; 648 var _cachedInstanceMembers;
623 Map<Symbol, MethodMirror> get instanceMembers { 649 Map<Symbol, MethodMirror> get instanceMembers {
624 if (_cachedInstanceMembers == null) { 650 if (_cachedInstanceMembers == null) {
625 var result = new Map<Symbol, MethodMirror>(); 651 var result = new Map<Symbol, MethodMirror>();
626 if (superclass != null) { 652 if (superclass != null) {
627 result.addAll(superclass.instanceMembers); 653 result.addAll(superclass.instanceMembers);
628 } 654 }
629 declarations.values.forEach((decl) { 655 declarations.values.forEach((decl) {
630 if (decl is MethodMirror && !decl.isStatic && 656 if (decl is MethodMirror && !decl.isStatic &&
631 !decl.isConstructor && !decl.isAbstract) { 657 !decl.isConstructor && !decl.isAbstract) {
632 result[decl.simpleName] = decl; 658 result[decl.simpleName] = decl;
633 } 659 }
634 if (decl is VariableMirror && !decl.isStatic) { 660 if (decl is VariableMirror && !decl.isStatic) {
635 var getterName = decl.simpleName; 661 var getterName = decl.simpleName;
636 result[getterName] = 662 result[getterName] =
637 new _SyntheticAccessor(this, getterName, true, false, false, decl) ; 663 new _SyntheticAccessor(this, getterName, true, false, false, decl) ;
638 if (!decl.isFinal) { 664 if (!decl.isFinal) {
639 var setterName = _asSetter(decl.simpleName, this.owner); 665 var setterName = _asSetter(decl.simpleName, this.owner);
640 result[setterName] = new _SyntheticAccessor( 666 result[setterName] = new _SyntheticAccessor(
641 this, setterName, false, false, false, decl); 667 this, setterName, false, false, false, decl);
642 } 668 }
643 } 669 }
644 }); 670 });
645 _cachedInstanceMembers = 671 _cachedInstanceMembers =
646 new UnmodifiableMapView<Symbol, MethodMirror>(result); 672 new _UnmodifiableMapView<Symbol, MethodMirror>(result);
647 } 673 }
648 return _cachedInstanceMembers; 674 return _cachedInstanceMembers;
649 } 675 }
650 676
651 Map<Symbol, DeclarationMirror> _declarations; 677 Map<Symbol, DeclarationMirror> _declarations;
652 Map<Symbol, DeclarationMirror> get declarations { 678 Map<Symbol, DeclarationMirror> get declarations {
653 if (_declarations != null) return _declarations; 679 if (_declarations != null) return _declarations;
654 var decls = new Map<Symbol, DeclarationMirror>(); 680 var decls = new Map<Symbol, DeclarationMirror>();
655 decls.addAll(_members); 681 decls.addAll(_members);
656 decls.addAll(_constructors); 682 decls.addAll(_constructors);
657 typeVariables.forEach((tv) => decls[tv.simpleName] = tv); 683 typeVariables.forEach((tv) => decls[tv.simpleName] = tv);
658 return _declarations = 684 return _declarations =
659 new UnmodifiableMapView<Symbol, DeclarationMirror>(decls); 685 new _UnmodifiableMapView<Symbol, DeclarationMirror>(decls);
660 } 686 }
661 687
662 Map<Symbol, Mirror> _cachedMembers; 688 Map<Symbol, Mirror> _cachedMembers;
663 Map<Symbol, Mirror> get _members { 689 Map<Symbol, Mirror> get _members {
664 if (_cachedMembers == null) { 690 if (_cachedMembers == null) {
665 var whoseMembers = _isMixinAlias ? _trueSuperclass : this; 691 var whoseMembers = _isMixinAlias ? _trueSuperclass : this;
666 _cachedMembers = _makeMemberMap(mixin._computeMembers(whoseMembers._reflec tee)); 692 _cachedMembers = _makeMemberMap(mixin._computeMembers(whoseMembers._reflec tee));
667 } 693 }
668 return _cachedMembers; 694 return _cachedMembers;
669 } 695 }
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 1012
987 List<TypeVariableMirror> get typeVariables => emptyList; 1013 List<TypeVariableMirror> get typeVariables => emptyList;
988 List<TypeMirror> get typeArguments => emptyList; 1014 List<TypeMirror> get typeArguments => emptyList;
989 1015
990 bool get isOriginalDeclaration => true; 1016 bool get isOriginalDeclaration => true;
991 TypeMirror get originalDeclaration => this; 1017 TypeMirror get originalDeclaration => this;
992 1018
993 String toString() => "TypeVariableMirror on '${_n(simpleName)}'"; 1019 String toString() => "TypeVariableMirror on '${_n(simpleName)}'";
994 1020
995 operator ==(other) { 1021 operator ==(other) {
996 return other is TypeVariableMirror 1022 return other is TypeVariableMirror
997 && simpleName == other.simpleName 1023 && simpleName == other.simpleName
998 && owner == other.owner; 1024 && owner == other.owner;
999 } 1025 }
1000 int get hashCode => simpleName.hashCode; 1026 int get hashCode => simpleName.hashCode;
1001 1027
1002 bool isSubtypeOf(TypeMirror other) { 1028 bool isSubtypeOf(TypeMirror other) {
1003 if (other == currentMirrorSystem().dynamicType) return true; 1029 if (other == currentMirrorSystem().dynamicType) return true;
1004 if (other == currentMirrorSystem().voidType) return false; 1030 if (other == currentMirrorSystem().voidType) return false;
1005 return _subtypeTest(_reflectedType, other._reflectedType); 1031 return _subtypeTest(_reflectedType, other._reflectedType);
1006 } 1032 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 Type get _instantiator => null; 1181 Type get _instantiator => null;
1156 1182
1157 SourceLocation get location { 1183 SourceLocation get location {
1158 throw new UnimplementedError('LibraryMirror.location is not implemented'); 1184 throw new UnimplementedError('LibraryMirror.location is not implemented');
1159 } 1185 }
1160 1186
1161 Map<Symbol, DeclarationMirror> _declarations; 1187 Map<Symbol, DeclarationMirror> _declarations;
1162 Map<Symbol, DeclarationMirror> get declarations { 1188 Map<Symbol, DeclarationMirror> get declarations {
1163 if (_declarations != null) return _declarations; 1189 if (_declarations != null) return _declarations;
1164 return _declarations = 1190 return _declarations =
1165 new UnmodifiableMapView<Symbol, DeclarationMirror>(_members); 1191 new _UnmodifiableMapView<Symbol, DeclarationMirror>(_members);
1166 } 1192 }
1167 1193
1168 Map<Symbol, Mirror> _cachedMembers; 1194 Map<Symbol, Mirror> _cachedMembers;
1169 Map<Symbol, Mirror> get _members { 1195 Map<Symbol, Mirror> get _members {
1170 if (_cachedMembers == null) { 1196 if (_cachedMembers == null) {
1171 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee)); 1197 _cachedMembers = _makeMemberMap(_computeMembers(_reflectee));
1172 } 1198 }
1173 return _cachedMembers; 1199 return _cachedMembers;
1174 } 1200 }
1175 1201
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 if (typeMirror == null) { 1618 if (typeMirror == null) {
1593 typeMirror = makeLocalTypeMirror(key); 1619 typeMirror = makeLocalTypeMirror(key);
1594 _instanitationCache[key] = typeMirror; 1620 _instanitationCache[key] = typeMirror;
1595 if (typeMirror is ClassMirror && !typeMirror._isGeneric) { 1621 if (typeMirror is ClassMirror && !typeMirror._isGeneric) {
1596 _declarationCache[key] = typeMirror; 1622 _declarationCache[key] = typeMirror;
1597 } 1623 }
1598 } 1624 }
1599 return typeMirror; 1625 return typeMirror;
1600 } 1626 }
1601 } 1627 }
OLDNEW
« no previous file with comments | « pkg/yaml/lib/src/yaml_map.dart ('k') | sdk/lib/_internal/compiler/implementation/mirrors/util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698