| OLD | NEW |
| 1 library angular.core.registry; | 1 part of angular.core; |
| 2 | 2 |
| 3 import 'package:di/di.dart' show Injector; | |
| 4 | |
| 5 abstract class AnnotationMap<K> { | 3 abstract class AnnotationMap<K> { |
| 6 final Map<K, Type> _map = {}; | 4 final Map<K, Type> _map = {}; |
| 7 | 5 |
| 8 AnnotationMap(Injector injector, MetadataExtractor extractMetadata) { | 6 AnnotationMap(Injector injector, MetadataExtractor extractMetadata) { |
| 9 injector.types.forEach((type) { | 7 injector.types.forEach((type) { |
| 10 extractMetadata(type) | 8 var meta = extractMetadata(type) |
| 11 .where((annotation) => annotation is K) | 9 .where((annotation) => annotation is K) |
| 12 .forEach((annotation) { | 10 .forEach((annotation) { |
| 13 _map[annotation] = type; | 11 _map[annotation] = type; |
| 14 }); | 12 }); |
| 15 }); | 13 }); |
| 16 } | 14 } |
| 17 | 15 |
| 18 Type operator[](K annotation) { | 16 Type operator[](K annotation) { |
| 19 var value = _map[annotation]; | 17 var value = _map[annotation]; |
| 20 if (value == null) throw 'No $annotation found!'; | 18 if (value == null) throw 'No $annotation found!'; |
| 21 return value; | 19 return value; |
| 22 } | 20 } |
| 23 | 21 |
| 24 void forEach(fn(K, Type)) { | 22 forEach(fn(K, Type)) => _map.forEach(fn); |
| 25 _map.forEach(fn); | |
| 26 } | |
| 27 | 23 |
| 28 List<K> annotationsFor(Type type) { | 24 List<K> annotationsFor(Type type) { |
| 29 final res = <K>[]; | 25 var res = <K>[]; |
| 30 forEach((ann, annType) { | 26 forEach((ann, annType) { |
| 31 if (annType == type) res.add(ann); | 27 if (annType == type) res.add(ann); |
| 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 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) throw 'No $annotation found!'; | 48 if (value == null) throw 'No $annotation found!'; |
| 53 return value; | 49 return value; |
| 54 } | 50 } |
| 55 | 51 |
| 56 void forEach(fn(K, Type)) { | 52 forEach(fn(K, Type)) { |
| 57 map.forEach((annotation, types) { | 53 map.forEach((annotation, types) { |
| 58 types.forEach((type) { | 54 types.forEach((type) { |
| 59 fn(annotation, type); | 55 fn(annotation, type); |
| 60 }); | 56 }); |
| 61 }); | 57 }); |
| 62 } | 58 } |
| 63 | 59 |
| 64 List<K> annotationsFor(Type type) { | 60 List<K> annotationsFor(Type type) { |
| 65 var res = <K>[]; | 61 var res = <K>[]; |
| 66 forEach((ann, annType) { | 62 forEach((ann, annType) { |
| 67 if (annType == type) res.add(ann); | 63 if (annType == type) res.add(ann); |
| 68 }); | 64 }); |
| 69 return res; | 65 return res; |
| 70 } | 66 } |
| 71 } | 67 } |
| 72 | 68 |
| 73 abstract class MetadataExtractor { | 69 |
| 74 Iterable call(Type type); | 70 @NgInjectableService() |
| 71 class MetadataExtractor { |
| 72 Iterable call(Type type) { |
| 73 if (reflectType(type) is TypedefMirror) return []; |
| 74 var metadata = reflectClass(type).metadata; |
| 75 if (metadata == null) return []; |
| 76 return metadata.map((InstanceMirror im) => im.reflectee); |
| 77 } |
| 75 } | 78 } |
| OLD | NEW |