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

Side by Side Diff: third_party/pkg/angular/lib/core/registry.dart

Issue 176943008: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 part of angular.core; 1 part of angular.core;
2 2
3 abstract class AnnotationMap<K> { 3 abstract class AnnotationMap<K> {
4 final Map<K, Type> _map = {}; 4 final Map<K, Type> _map = {};
5 5
6 AnnotationMap(Injector injector, MetadataExtractor extractMetadata) { 6 AnnotationMap(Injector injector, MetadataExtractor extractMetadata) {
7 injector.types.forEach((type) { 7 injector.types.forEach((type) {
8 var meta = extractMetadata(type) 8 var meta = extractMetadata(type)
9 .where((annotation) => annotation is K) 9 .where((annotation) => annotation is K)
10 .forEach((annotation) { 10 .forEach((annotation) {
11 _map[annotation] = type; 11 _map[annotation] = type;
12 }); 12 });
13 }); 13 });
14 } 14 }
15 15
16 Type operator[](K annotation) { 16 Type operator[](K annotation) {
17 var value = _map[annotation]; 17 var value = _map[annotation];
18 if (value == null) { 18 if (value == null) throw 'No $annotation found!';
19 throw 'No $annotation found!';
20 }
21 return value; 19 return value;
22 } 20 }
23 21
24 forEach(fn(K, Type)) => _map.forEach(fn); 22 forEach(fn(K, Type)) => _map.forEach(fn);
25 23
26 List<K> annotationsFor(Type type) { 24 List<K> annotationsFor(Type type) {
27 var res = <K>[]; 25 var res = <K>[];
28 forEach((ann, annType) { 26 forEach((ann, annType) {
29 if (annType == type) { 27 if (annType == type) res.add(ann);
30 res.add(ann);
31 }
32 }); 28 });
33 return res; 29 return res;
34 } 30 }
35 } 31 }
36 32
37 abstract class AnnotationsMap<K> { 33 abstract class AnnotationsMap<K> {
38 final Map<K, List<Type>> _map = {}; 34 final Map<K, List<Type>> map = {};
39 35
40 AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) { 36 AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) {
41 injector.types.forEach((type) { 37 injector.types.forEach((type) {
42 var meta = extractMetadata(type) 38 var meta = extractMetadata(type)
43 .where((annotation) => annotation is K) 39 .where((annotation) => annotation is K)
44 .forEach((annotation) { 40 .forEach((annotation) {
45 _map.putIfAbsent(annotation, () => []).add(type); 41 map.putIfAbsent(annotation, () => []).add(type);
46 }); 42 });
47 }); 43 });
48 } 44 }
49 45
50 List operator[](K annotation) { 46 List operator[](K annotation) {
51 var value = _map[annotation]; 47 var value = map[annotation];
52 if (value == null) { 48 if (value == null) throw 'No $annotation found!';
53 throw 'No $annotation found!';
54 }
55 return value; 49 return value;
56 } 50 }
57 51
58 forEach(fn(K, Type)) { 52 forEach(fn(K, Type)) {
59 _map.forEach((annotation, types) { 53 map.forEach((annotation, types) {
60 types.forEach((type) { 54 types.forEach((type) {
61 fn(annotation, type); 55 fn(annotation, type);
62 }); 56 });
63 }); 57 });
64 } 58 }
65 59
66 List<K> annotationsFor(Type type) { 60 List<K> annotationsFor(Type type) {
67 var res = <K>[]; 61 var res = <K>[];
68 forEach((ann, annType) { 62 forEach((ann, annType) {
69 if (annType == type) { 63 if (annType == type) res.add(ann);
70 res.add(ann);
71 }
72 }); 64 });
73 return res; 65 return res;
74 } 66 }
75 } 67 }
76 68
77 69
78 @NgInjectableService() 70 @NgInjectableService()
79 class MetadataExtractor { 71 class MetadataExtractor {
80
81 Iterable call(Type type) { 72 Iterable call(Type type) {
73 if (reflectType(type) is TypedefMirror) return [];
82 var metadata = reflectClass(type).metadata; 74 var metadata = reflectClass(type).metadata;
83 if (metadata == null) return []; 75 if (metadata == null) return [];
84 return metadata.map((InstanceMirror im) => im.reflectee); 76 return metadata.map((InstanceMirror im) => im.reflectee);
85 } 77 }
86 } 78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698