| OLD | NEW |
| 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) throw 'No $annotation found!'; | 18 if (value == null) { |
| 19 throw 'No $annotation found!'; |
| 20 } |
| 19 return value; | 21 return value; |
| 20 } | 22 } |
| 21 | 23 |
| 22 forEach(fn(K, Type)) => _map.forEach(fn); | 24 forEach(fn(K, Type)) => _map.forEach(fn); |
| 23 | 25 |
| 24 List<K> annotationsFor(Type type) { | 26 List<K> annotationsFor(Type type) { |
| 25 var res = <K>[]; | 27 var res = <K>[]; |
| 26 forEach((ann, annType) { | 28 forEach((ann, annType) { |
| 27 if (annType == type) res.add(ann); | 29 if (annType == type) { |
| 30 res.add(ann); |
| 31 } |
| 28 }); | 32 }); |
| 29 return res; | 33 return res; |
| 30 } | 34 } |
| 31 } | 35 } |
| 32 | 36 |
| 33 abstract class AnnotationsMap<K> { | 37 abstract class AnnotationsMap<K> { |
| 34 final Map<K, List<Type>> map = {}; | 38 final Map<K, List<Type>> _map = {}; |
| 35 | 39 |
| 36 AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) { | 40 AnnotationsMap(Injector injector, MetadataExtractor extractMetadata) { |
| 37 injector.types.forEach((type) { | 41 injector.types.forEach((type) { |
| 38 var meta = extractMetadata(type) | 42 var meta = extractMetadata(type) |
| 39 .where((annotation) => annotation is K) | 43 .where((annotation) => annotation is K) |
| 40 .forEach((annotation) { | 44 .forEach((annotation) { |
| 41 map.putIfAbsent(annotation, () => []).add(type); | 45 _map.putIfAbsent(annotation, () => []).add(type); |
| 42 }); | 46 }); |
| 43 }); | 47 }); |
| 44 } | 48 } |
| 45 | 49 |
| 46 List operator[](K annotation) { | 50 List operator[](K annotation) { |
| 47 var value = map[annotation]; | 51 var value = _map[annotation]; |
| 48 if (value == null) throw 'No $annotation found!'; | 52 if (value == null) { |
| 53 throw 'No $annotation found!'; |
| 54 } |
| 49 return value; | 55 return value; |
| 50 } | 56 } |
| 51 | 57 |
| 52 forEach(fn(K, Type)) { | 58 forEach(fn(K, Type)) { |
| 53 map.forEach((annotation, types) { | 59 _map.forEach((annotation, types) { |
| 54 types.forEach((type) { | 60 types.forEach((type) { |
| 55 fn(annotation, type); | 61 fn(annotation, type); |
| 56 }); | 62 }); |
| 57 }); | 63 }); |
| 58 } | 64 } |
| 59 | 65 |
| 60 List<K> annotationsFor(Type type) { | 66 List<K> annotationsFor(Type type) { |
| 61 var res = <K>[]; | 67 var res = <K>[]; |
| 62 forEach((ann, annType) { | 68 forEach((ann, annType) { |
| 63 if (annType == type) res.add(ann); | 69 if (annType == type) { |
| 70 res.add(ann); |
| 71 } |
| 64 }); | 72 }); |
| 65 return res; | 73 return res; |
| 66 } | 74 } |
| 67 } | 75 } |
| 68 | 76 |
| 69 | 77 |
| 70 @NgInjectableService() | 78 @NgInjectableService() |
| 71 class MetadataExtractor { | 79 class MetadataExtractor { |
| 80 |
| 72 Iterable call(Type type) { | 81 Iterable call(Type type) { |
| 73 if (reflectType(type) is TypedefMirror) return []; | |
| 74 var metadata = reflectClass(type).metadata; | 82 var metadata = reflectClass(type).metadata; |
| 75 if (metadata == null) return []; | 83 if (metadata == null) return []; |
| 76 return metadata.map((InstanceMirror im) => im.reflectee); | 84 return metadata.map((InstanceMirror im) => im.reflectee); |
| 77 } | 85 } |
| 78 } | 86 } |
| OLD | NEW |