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

Unified Diff: third_party/pkg/angular/lib/core/registry.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/core/registry.dart
diff --git a/third_party/pkg/angular/lib/core/registry.dart b/third_party/pkg/angular/lib/core/registry.dart
new file mode 100644
index 0000000000000000000000000000000000000000..39932a25625b6f09f8af3d227056d6af3a6dd5d5
--- /dev/null
+++ b/third_party/pkg/angular/lib/core/registry.dart
@@ -0,0 +1,50 @@
+part of angular.core;
+
+abstract class AnnotationMap<K> {
+ final Map<K, Type> _map = {};
+
+ AnnotationMap(Injector injector, MetadataExtractor extractMetadata) {
+ injector.types.forEach((type) {
+ var meta = extractMetadata(type)
+ .where((annotation) => annotation is K)
+ .forEach((annotation) {
+ if (_map.containsKey(annotation)) {
+ var annotationType = K;
+ throw "Duplicate annotation found: $annotationType: $annotation. " +
+ "Exisitng: ${_map[annotation]}; New: $type.";
+ }
+ _map[annotation] = type;
+ });
+ });
+ }
+
+ Type operator[](K annotation) {
+ var value = _map[annotation];
+ if (value == null) {
+ throw 'No $annotation found!';
+ }
+ return value;
+ }
+
+ forEach(fn(K, Type)) => _map.forEach(fn);
+
+ List<K> annotationsFor(Type type) {
+ var res = <K>[];
+ forEach((ann, annType) {
+ if (annType == type) {
+ res.add(ann);
+ }
+ });
+ return res;
+ }
+}
+
+@NgInjectableService()
+class MetadataExtractor {
+
+ Iterable call(Type type) {
+ var metadata = reflectClass(type).metadata;
+ if (metadata == null) return [];
+ return metadata.map((InstanceMirror im) => im.reflectee);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698