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

Unified Diff: third_party/pkg/angular/lib/core_dom/directive_map.dart

Issue 176943008: Update the Angular/DI tests to latest from github. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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_dom/directive_map.dart
diff --git a/third_party/pkg/angular/lib/core_dom/directive_map.dart b/third_party/pkg/angular/lib/core_dom/directive_map.dart
new file mode 100644
index 0000000000000000000000000000000000000000..aff3f8c1e8687df6b3f85b411faec79308272692
--- /dev/null
+++ b/third_party/pkg/angular/lib/core_dom/directive_map.dart
@@ -0,0 +1,65 @@
+part of angular.core.dom;
+
+@NgInjectableService()
+class DirectiveMap extends AnnotationsMap<NgAnnotation> {
+ DirectiveSelector selector;
+
+ DirectiveMap(Injector injector, MetadataExtractor metadataExtractor,
+ FieldMetadataExtractor fieldMetadataExtractor)
+ : super(injector, metadataExtractor) {
+ Map<NgAnnotation, List<Type>> directives = {};
+ forEach((NgAnnotation annotation, Type type) {
+ var match;
+ var fieldMetadata = fieldMetadataExtractor(type);
+ if (fieldMetadata.isNotEmpty) {
+ var newMap = annotation.map == null ? {} : new Map.from(annotation.map);
+ fieldMetadata.forEach((String fieldName, AttrFieldAnnotation ann) {
+ var attrName = ann.attrName;
+ if (newMap.containsKey(attrName)) {
+ throw 'Mapping for attribute $attrName is already defined (while '
+ 'processing annottation for field $fieldName of $type)';
+ }
+ newMap[attrName] = '${ann.mappingSpec}$fieldName';
+ });
+ annotation = annotation.cloneWithNewMap(newMap);
+ }
+ directives.putIfAbsent(annotation, () => []).add(type);
+ });
+ map.clear();
+ map.addAll(directives);
+
+ selector = directiveSelectorFactory(this);
+ }
+}
+
+@NgInjectableService()
+class FieldMetadataExtractor {
+ List<TypeMirror> _fieldAnnotations = [reflectType(NgAttr),
+ reflectType(NgOneWay), reflectType(NgOneWayOneTime),
+ reflectType(NgTwoWay), reflectType(NgCallback)];
+
+ Map<String, AttrFieldAnnotation> call(Type type) {
+ ClassMirror cm = reflectType(type);
+ Map<String, AttrFieldAnnotation> fields = <String, AttrFieldAnnotation>{};
+ cm.declarations.forEach((Symbol name, DeclarationMirror decl) {
+ if (decl is VariableMirror ||
+ (decl is MethodMirror && (decl.isGetter || decl.isSetter))) {
+ var fieldName = MirrorSystem.getName(name);
+ if (decl is MethodMirror && decl.isSetter) {
+ // Remove = from the end of the setter.
+ fieldName = fieldName.substring(0, fieldName.length - 1);
+ }
+ decl.metadata.forEach((InstanceMirror meta) {
+ if (_fieldAnnotations.contains(meta.type)) {
+ if (fields[fieldName] != null) {
+ throw 'Attribute annotation for $fieldName is defined more '
+ 'than once in $type';
+ }
+ fields[fieldName] = meta.reflectee as AttrFieldAnnotation;
+ }
+ });
+ }
+ });
+ return fields;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698