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

Side by Side Diff: reflectable/lib/src/reflectable_transformer_based.dart

Issue 1391013008: Adds limited support for private classes. (Closed) Base URL: https://github.com/dart-lang/reflectable.git@master
Patch Set: Improved on treatment of uri Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this 1 // Copyright (c) 2015, the Dart Team. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in 2 // source code is governed by a BSD-style license that can be found in
3 // the LICENSE file. 3 // the LICENSE file.
4 4
5 library reflectable.src.mirrors_unimpl; 5 library reflectable.src.mirrors_unimpl;
6 6
7 import 'dart:collection' show UnmodifiableMapView, UnmodifiableListView; 7 import 'dart:collection' show UnmodifiableMapView, UnmodifiableListView;
8 8
9 import '../capability.dart'; 9 import '../capability.dart';
10 import '../mirrors.dart'; 10 import '../mirrors.dart';
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (_typeToClassMirrorCache == null) { 102 if (_typeToClassMirrorCache == null) {
103 if (classMirrors.isEmpty) { 103 if (classMirrors.isEmpty) {
104 // This is the case when the capabilities do not include a 104 // This is the case when the capabilities do not include a
105 // `TypeCapability`; it is also the case when there are no 105 // `TypeCapability`; it is also the case when there are no
106 // supported classes but even then we can do the following. 106 // supported classes but even then we can do the following.
107 _typeToClassMirrorCache = <Type, ClassMirror>{}; 107 _typeToClassMirrorCache = <Type, ClassMirror>{};
108 } else { 108 } else {
109 _typeToClassMirrorCache = new Map.fromIterables(types, classMirrors); 109 _typeToClassMirrorCache = new Map.fromIterables(types, classMirrors);
110 } 110 }
111 } 111 }
112 return _typeToClassMirrorCache[type]; 112 return _typeToClassMirrorCache[type];
113 } 113 }
114 } 114 }
115 115
116 /// This mapping contains the mirror-data for each reflector. 116 /// This mapping contains the mirror-data for each reflector.
117 /// It will be initialized in the generated code. 117 /// It will be initialized in the generated code.
118 Map<Reflectable, ReflectorData> data = 118 Map<Reflectable, ReflectorData> data =
119 throw new StateError("Reflectable has not been initialized. " 119 throw new StateError("Reflectable has not been initialized. "
120 "Did you forget to add the main file to the " 120 "Did you forget to add the main file to the "
121 "reflectable transformer's entry_points in pubspec.yaml?"); 121 "reflectable transformer's entry_points in pubspec.yaml?");
122 122
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 492 }
493 493
494 String toString() => "ClassMirrorImpl($qualifiedName)"; 494 String toString() => "ClassMirrorImpl($qualifiedName)";
495 495
496 // Because we take care to only ever create one instance for each 496 // Because we take care to only ever create one instance for each
497 // type/reflector-combination we can rely on the default `hashCode` and `==` 497 // type/reflector-combination we can rely on the default `hashCode` and `==`
498 // operations. 498 // operations.
499 } 499 }
500 500
501 class LibraryMirrorImpl extends _DataCaching implements LibraryMirror { 501 class LibraryMirrorImpl extends _DataCaching implements LibraryMirror {
502 LibraryMirrorImpl( 502 LibraryMirrorImpl(this.simpleName, this.uri, this._reflector,
503 this.simpleName, 503 this._declarationIndices, this.getters, this.setters, this._metadata);
504 this.uri,
505 this._reflector,
506 this._declarationIndices,
507 this.getters,
508 this.setters,
509 this._metadata);
510 504
511 final ReflectableImpl _reflector; 505 final ReflectableImpl _reflector;
512 506
513 /// A list of the indices in [ReflectorData.memberMirrors] of the 507 /// A list of the indices in [ReflectorData.memberMirrors] of the
514 /// declarations of the reflected class. This includes method mirrors for 508 /// declarations of the reflected class. This includes method mirrors for
515 /// top level functions of this library and it directly corresponds to 509 /// top level functions of this library and it directly corresponds to
516 /// `declarations`. Exception: When the given `_reflector.capabilities` do 510 /// `declarations`. Exception: When the given `_reflector.capabilities` do
517 /// not support the operation `declarations`, this will be 511 /// not support the operation `declarations`, this will be
518 /// `<int>[NO_CAPABILITY_INDEX]`. It is enough to check that the list is 512 /// `<int>[NO_CAPABILITY_INDEX]`. It is enough to check that the list is
519 /// non-empty and first element is NO_CAPABILITY_INDEX to detect this 513 /// non-empty and first element is NO_CAPABILITY_INDEX to detect this
(...skipping 24 matching lines...) Expand all
544 // need not have stellar performance, it is almost always a bug to do 538 // need not have stellar performance, it is almost always a bug to do
545 // that. 539 // that.
546 if (declarationIndex == NO_CAPABILITY_INDEX) { 540 if (declarationIndex == NO_CAPABILITY_INDEX) {
547 throw new NoSuchCapabilityError( 541 throw new NoSuchCapabilityError(
548 "Requesting declarations of '$qualifiedName' without capability"); 542 "Requesting declarations of '$qualifiedName' without capability");
549 } 543 }
550 DeclarationMirror declarationMirror = 544 DeclarationMirror declarationMirror =
551 _data.memberMirrors[declarationIndex]; 545 _data.memberMirrors[declarationIndex];
552 result[declarationMirror.simpleName] = declarationMirror; 546 result[declarationMirror.simpleName] = declarationMirror;
553 } 547 }
548 _data.classMirrors.forEach((ClassMirror classMirror) {
549 if (classMirror.owner == this) {
550 result[classMirror.simpleName] = classMirror;
551 }
552 });
554 _declarations = 553 _declarations =
555 new UnmodifiableMapView<String, DeclarationMirror>(result); 554 new UnmodifiableMapView<String, DeclarationMirror>(result);
556 } 555 }
557 return _declarations; 556 return _declarations;
558 } 557 }
559 558
560 @override 559 @override
561 Object invoke(String memberName, List positionalArguments, 560 Object invoke(String memberName, List positionalArguments,
562 [Map<Symbol, dynamic> namedArguments]) { 561 [Map<Symbol, dynamic> namedArguments]) {
563 _StaticGetter getter = getters[memberName]; 562 _StaticGetter getter = getters[memberName];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 604 }
606 return _metadata; 605 return _metadata;
607 } 606 }
608 607
609 @override 608 @override
610 DeclarationMirror get owner => null; 609 DeclarationMirror get owner => null;
611 610
612 @override 611 @override
613 String get qualifiedName => simpleName; 612 String get qualifiedName => simpleName;
614 613
615 bool operator ==(other) => _unsupported(); 614 bool operator ==(other) {
616 int get hashCode => _unsupported(); 615 return other is LibraryMirrorImpl &&
616 other.uri == uri &&
617 other._reflector == _reflector &&
618 other._declarationIndices == _declarationIndices;
619 }
620
621 int get hashCode =>
622 uri.hashCode ^ _reflector.hashCode ^ _declarationIndices.hashCode;
617 623
618 // TODO(sigurdm) implement: Need to implement this. Probably only when a given 624 // TODO(sigurdm) implement: Need to implement this. Probably only when a given
619 // capability is enabled. 625 // capability is enabled.
620 List<LibraryDependencyMirror> get libraryDependencies => _unsupported(); 626 List<LibraryDependencyMirror> get libraryDependencies => _unsupported();
621 } 627 }
622 628
623 class MethodMirrorImpl extends _DataCaching implements MethodMirror { 629 class MethodMirrorImpl extends _DataCaching implements MethodMirror {
624 /// An encoding of the attributes and kind of this mirror. 630 /// An encoding of the attributes and kind of this mirror.
625 final int _descriptor; 631 final int _descriptor;
626 632
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 } 1254 }
1249 return new UnmodifiableMapView(result); 1255 return new UnmodifiableMapView(result);
1250 } 1256 }
1251 1257
1252 @override 1258 @override
1253 Iterable<ClassMirror> get annotatedClasses { 1259 Iterable<ClassMirror> get annotatedClasses {
1254 return new UnmodifiableListView<ClassMirror>(data[this].classMirrors); 1260 return new UnmodifiableListView<ClassMirror>(data[this].classMirrors);
1255 } 1261 }
1256 } 1262 }
1257 1263
1258 // For mixin-applications we need to construct objects that represents their 1264 // For mixin-applications and private classes we need to construct objects
1259 // type. 1265 // that represents their type.
1260 class FakeType implements Type { 1266 class FakeType implements Type {
1261 const FakeType(this.description); 1267 const FakeType(this.description);
1262 1268
1263 final String description; 1269 final String description;
1264 1270
1265 String toString() => "Type($description)"; 1271 String toString() => "Type($description)";
1266 } 1272 }
OLDNEW
« no previous file with comments | « reflectable/lib/src/reflectable_mirror_based.dart ('k') | reflectable/lib/src/transformer_implementation.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698