| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// Contains logic to initialize polymer apps during development. This | 5 /// Contains logic to initialize polymer apps during development. This |
| 6 /// implementation uses dart:mirrors to load each library as they are discovered | 6 /// implementation uses dart:mirrors to load each library as they are discovered |
| 7 /// through HTML imports. This is only meant to be during development in | 7 /// through HTML imports. This is only meant to be during development in |
| 8 /// dartium, and the polymer transformers replace this implementation with | 8 /// dartium, and the polymer transformers replace this implementation with |
| 9 /// codege generation in the polymer-build steps. | 9 /// codege generation in the polymer-build steps. |
| 10 library polymer.src.mirror_loader; | 10 library polymer.src.mirror_loader; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // in dart2js, so they end up being called twice) | 155 // in dart2js, so they end up being called twice) |
| 156 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception, | 156 // - dartbug.com/12134 (sometimes "method.metadata" throws an exception, |
| 157 // we could wrap and hide those exceptions, but it's not ideal). | 157 // we could wrap and hide those exceptions, but it's not ideal). |
| 158 } | 158 } |
| 159 | 159 |
| 160 initializers.addAll(customTags.values); | 160 initializers.addAll(customTags.values); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void _loadCustomTags(LibraryMirror lib, ClassMirror cls, | 163 void _loadCustomTags(LibraryMirror lib, ClassMirror cls, |
| 164 LinkedHashMap registerFns) { | 164 LinkedHashMap registerFns) { |
| 165 if (cls == null || cls.reflectedType == HtmlElement) return; | 165 if (cls == null) return; |
| 166 if (cls.hasReflectedType && cls.reflectedType == HtmlElement) return; |
| 166 | 167 |
| 167 // Register superclass first. | 168 // Register superclass first. |
| 168 _loadCustomTags(lib, cls.superclass, registerFns); | 169 _loadCustomTags(lib, cls.superclass, registerFns); |
| 169 | 170 |
| 170 if (cls.owner != lib) { | 171 if (cls.owner != lib) { |
| 171 // Don't register classes from different libraries. | 172 // Don't register classes from different libraries. |
| 172 // TODO(jmesserly): @CustomTag does not currently respect re-export, because | 173 // TODO(jmesserly): @CustomTag does not currently respect re-export, because |
| 173 // LibraryMirror.declarations doesn't include these. | 174 // LibraryMirror.declarations doesn't include these. |
| 174 return; | 175 return; |
| 175 } | 176 } |
| 176 | 177 |
| 177 var meta = _getCustomTagMetadata(cls); | 178 var meta = _getCustomTagMetadata(cls); |
| 178 if (meta == null) return; | 179 if (meta == null) return; |
| 179 | 180 |
| 181 if (!cls.hasReflectedType) { |
| 182 var name = MirrorSystem.getName(cls.simpleName); |
| 183 new Completer().completeError(new UnsupportedError('Custom element classes ' |
| 184 'cannot have type-parameters: $name')); |
| 185 return; |
| 186 } |
| 187 |
| 180 registerFns.putIfAbsent(cls.reflectedType, () => | 188 registerFns.putIfAbsent(cls.reflectedType, () => |
| 181 () => Polymer.register(meta.tagName, cls.reflectedType)); | 189 () => Polymer.register(meta.tagName, cls.reflectedType)); |
| 182 } | 190 } |
| 183 | 191 |
| 184 /// Search for @CustomTag on a classemirror | 192 /// Search for @CustomTag on a classemirror |
| 185 CustomTag _getCustomTagMetadata(ClassMirror c) { | 193 CustomTag _getCustomTagMetadata(ClassMirror c) { |
| 186 for (var m in c.metadata) { | 194 for (var m in c.metadata) { |
| 187 var meta = m.reflectee; | 195 var meta = m.reflectee; |
| 188 if (meta is CustomTag) return meta; | 196 if (meta is CustomTag) return meta; |
| 189 } | 197 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 205 " ${method.simpleName} is not."); | 213 " ${method.simpleName} is not."); |
| 206 return; | 214 return; |
| 207 } | 215 } |
| 208 if (!method.parameters.where((p) => !p.isOptional).isEmpty) { | 216 if (!method.parameters.where((p) => !p.isOptional).isEmpty) { |
| 209 print("warning: methods marked with @initMethod should take no " | 217 print("warning: methods marked with @initMethod should take no " |
| 210 "arguments, ${method.simpleName} expects some."); | 218 "arguments, ${method.simpleName} expects some."); |
| 211 return; | 219 return; |
| 212 } | 220 } |
| 213 initializers.add(() => obj.invoke(method.simpleName, const [])); | 221 initializers.add(() => obj.invoke(method.simpleName, const [])); |
| 214 } | 222 } |
| OLD | NEW |