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

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

Issue 148453003: Updating Angular version (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 if (_map.containsKey(annotation)) {
12 var annotationType = K;
13 throw "Duplicate annotation found: $annotationType: $annotation. " +
14 "Exisitng: ${_map[annotation]}; New: $type.";
15 }
16 _map[annotation] = type; 11 _map[annotation] = type;
17 }); 12 });
18 }); 13 });
19 } 14 }
20 15
21 Type operator[](K annotation) { 16 Type operator[](K annotation) {
22 var value = _map[annotation]; 17 var value = _map[annotation];
23 if (value == null) { 18 if (value == null) {
24 throw 'No $annotation found!'; 19 throw 'No $annotation found!';
25 } 20 }
26 return value; 21 return value;
27 } 22 }
28 23
29 forEach(fn(K, Type)) => _map.forEach(fn); 24 forEach(fn(K, Type)) => _map.forEach(fn);
30 25
31 List<K> annotationsFor(Type type) { 26 List<K> annotationsFor(Type type) {
32 var res = <K>[]; 27 var res = <K>[];
33 forEach((ann, annType) { 28 forEach((ann, annType) {
34 if (annType == type) { 29 if (annType == type) {
35 res.add(ann); 30 res.add(ann);
36 } 31 }
37 }); 32 });
38 return res; 33 return res;
39 } 34 }
40 } 35 }
41 36
37 abstract class AnnotationsMap<K> {
38 final Map<K, List<Type>> _map = {};
39
40 AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) {
41 injector.types.forEach((type) {
42 var meta = extractMetadata(type)
43 .where((annotation) => annotation is K)
44 .forEach((annotation) {
45 _map.putIfAbsent(annotation, () => []).add(type);
46 });
47 });
48 }
49
50 List operator[](K annotation) {
51 var value = _map[annotation];
52 if (value == null) {
53 throw 'No $annotation found!';
54 }
55 return value;
56 }
57
58 forEach(fn(K, Type)) {
59 _map.forEach((annotation, types) {
60 types.forEach((type) {
61 fn(annotation, type);
62 });
63 });
64 }
65
66 List<K> annotationsFor(Type type) {
67 var res = <K>[];
68 forEach((ann, annType) {
69 if (annType == type) {
70 res.add(ann);
71 }
72 });
73 return res;
74 }
75 }
76
77
42 @NgInjectableService() 78 @NgInjectableService()
43 class MetadataExtractor { 79 class MetadataExtractor {
44 80
45 Iterable call(Type type) { 81 Iterable call(Type type) {
46 var metadata = reflectClass(type).metadata; 82 var metadata = reflectClass(type).metadata;
47 if (metadata == null) return []; 83 if (metadata == null) return [];
48 return metadata.map((InstanceMirror im) => im.reflectee); 84 return metadata.map((InstanceMirror im) => im.reflectee);
49 } 85 }
50 } 86 }
OLDNEW
« no previous file with comments | « third_party/pkg/angular/lib/core/parser/utils.dart ('k') | third_party/pkg/angular/lib/core/scope.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698