| OLD | NEW |
| (Empty) | |
| 1 part of angular.core; |
| 2 |
| 3 abstract class AnnotationMap<K> { |
| 4 final Map<K, Type> _map = {}; |
| 5 |
| 6 AnnotationMap(Injector injector, MetadataExtractor extractMetadata) { |
| 7 injector.types.forEach((type) { |
| 8 var meta = extractMetadata(type) |
| 9 .where((annotation) => annotation is K) |
| 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; |
| 17 }); |
| 18 }); |
| 19 } |
| 20 |
| 21 Type operator[](K annotation) { |
| 22 var value = _map[annotation]; |
| 23 if (value == null) { |
| 24 throw 'No $annotation found!'; |
| 25 } |
| 26 return value; |
| 27 } |
| 28 |
| 29 forEach(fn(K, Type)) => _map.forEach(fn); |
| 30 |
| 31 List<K> annotationsFor(Type type) { |
| 32 var res = <K>[]; |
| 33 forEach((ann, annType) { |
| 34 if (annType == type) { |
| 35 res.add(ann); |
| 36 } |
| 37 }); |
| 38 return res; |
| 39 } |
| 40 } |
| 41 |
| 42 @NgInjectableService() |
| 43 class MetadataExtractor { |
| 44 |
| 45 Iterable call(Type type) { |
| 46 var metadata = reflectClass(type).metadata; |
| 47 if (metadata == null) return []; |
| 48 return metadata.map((InstanceMirror im) => im.reflectee); |
| 49 } |
| 50 } |
| OLD | NEW |