OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // WARNING: Do not edit - generated code. | 5 // WARNING: Do not edit - generated code. |
6 | 6 |
7 part of $LIBRARYNAME; | 7 part of $LIBRARYNAME; |
8 | 8 |
9 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS { | 9 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS { |
10 $!MEMBERS | 10 $!MEMBERS |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 /** | 192 /** |
193 * Internal routine to find the DOM JS class name being extended for custom | 193 * Internal routine to find the DOM JS class name being extended for custom |
194 * elements. | 194 * elements. |
195 */ | 195 */ |
196 String _getJSClassName(ClassMirror classMirror) { | 196 String _getJSClassName(ClassMirror classMirror) { |
197 var jsClassName = null; | 197 var jsClassName = null; |
198 var isElement = false; | 198 var isElement = false; |
199 | 199 |
200 while (classMirror.superclass != null) { | 200 while (classMirror.superclass != null) { |
201 var fullName = classMirror.superclass.qualifiedName; | 201 var fullName = classMirror.superclass.qualifiedName; |
202 isElement = isElement || (fullName == #dart.dom.html.Element); | 202 isElement = isElement || |
203 (fullName == #dart.dom.html.Element || fullName == #dart.dom.svg.Eleme nt); | |
203 | 204 |
204 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); | 205 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); |
205 if (jsClassName == null && domLibrary) { | 206 if (jsClassName == null && domLibrary) { |
206 // Lookup JS class name (if not found). | 207 // Lookup JS class name (if not found). |
207 var metadatas = classMirror.metadata; | 208 var metadatas = classMirror.metadata; |
208 for (var metadata in metadatas) { | 209 for (var metadata in metadatas) { |
209 var metaDataMirror = metadata.reflectee; | 210 var metaDataMirror = metadata.reflectee; |
210 var metaType = reflectClass(metaDataMirror.runtimeType); | 211 var metaType = reflectClass(metaDataMirror.runtimeType); |
211 if (MirrorSystem.getName(metaType.simpleName) == 'DomName' && | 212 if (MirrorSystem.getName(metaType.simpleName) == 'DomName' && |
212 metaDataMirror.name.startsWith('HTML')) { | 213 (metaDataMirror.name.startsWith('HTML') || metaDataMirror.name.sta rtsWith('SVG'))) { |
213 jsClassName = metadata.reflectee.name; | 214 jsClassName = metadata.reflectee.name; |
214 } | 215 } |
215 } | 216 } |
216 } | 217 } |
217 | 218 |
218 classMirror = classMirror.superclass; | 219 classMirror = classMirror.superclass; |
219 } | 220 } |
220 | 221 |
221 // If we're an element then everything is okay. | 222 // If we're an element then everything is okay. |
222 return isElement ? jsClassName : null; | 223 return isElement ? jsClassName : null; |
223 } | 224 } |
224 | 225 |
225 /** | 226 /** |
227 * Get the class that immediately derived from a class in dart:html or | |
228 * dart:svg (has an attribute DomName of either HTML* or SVG*). | |
229 */ | |
230 ClassMirror _getDomSuperClass(ClassMirror classMirror) { | |
231 var isElement = false; | |
232 | |
233 while (classMirror.superclass != null) { | |
234 var fullName = classMirror.superclass.qualifiedName; | |
235 isElement = isElement || (fullName == #dart.dom.html.Element || fullName = = #dart.dom.svg.Element); | |
236 | |
237 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); | |
238 if (domLibrary) { | |
239 // Lookup JS class (if not found). | |
240 var metadatas = classMirror.metadata; | |
241 for (var metadata in metadatas) { | |
242 var metaDataMirror = metadata.reflectee; | |
243 var metaType = reflectClass(metaDataMirror.runtimeType); | |
244 if (MirrorSystem.getName(metaType.simpleName) == 'DomName' && | |
245 (metaDataMirror.name.startsWith('HTML') || metaDataMirror.name.sta rtsWith('SVG'))) { | |
Alan Knight
2015/09/28 22:31:42
Aren't there classes in HTML that don't start with
| |
246 if (isElement) return classMirror; | |
247 } | |
248 } | |
249 } | |
250 | |
251 classMirror = classMirror.superclass; | |
252 } | |
253 | |
254 return null; | |
255 } | |
256 | |
257 /** | |
226 * Does this CustomElement class have: | 258 * Does this CustomElement class have: |
227 * | 259 * |
228 * - a created constructor with no arguments? | 260 * - a created constructor with no arguments? |
229 * - a created constructor with a super.created() initializer? | 261 * - a created constructor with a super.created() initializer? |
230 * | 262 * |
231 * e.g., MyCustomClass.created() : super.created(); | 263 * e.g., MyCustomClass.created() : super.created(); |
232 */ | 264 */ |
233 bool _hasCreatedConstructor(ClassMirror classMirror) { | 265 bool _hasCreatedConstructor(ClassMirror classToRegister) { |
234 var createdParametersValid = false; | 266 var htmlClassMirror = _getDomSuperClass(classToRegister); |
235 var superCreatedCalled = false; | |
236 var className = MirrorSystem.getName(classMirror.simpleName); | |
237 var methodMirror = classMirror.declarations[new Symbol("$className.created") ]; | |
238 if (methodMirror != null) { | |
239 createdParametersValid = methodMirror.parameters.length == 0; | |
240 | 267 |
241 // Get the created constructor source and look at the initializer; | 268 var classMirror = classToRegister; |
242 // Must call super.created() if not its as an error. | 269 while (classMirror != null && classMirror != htmlClassMirror) { |
243 var createdSource = methodMirror.source; | 270 var createdParametersValid = false; |
244 RegExp regExp = new RegExp(r":(.*?)(;|}|\n)"); | 271 var superCreatedCalled = false; |
245 var match = regExp.firstMatch(createdSource); | 272 var className = MirrorSystem.getName(classMirror.simpleName); |
246 superCreatedCalled = match.input.substring(match.start,match.end).contains ("super.created()"); | 273 var methodMirror = classMirror.declarations[new Symbol("$className.created ")]; |
247 } | 274 if (methodMirror != null && methodMirror.isConstructor) { |
275 createdParametersValid = true; // Assume no parameters. | |
276 if (methodMirror.parameters.length != 0) { | |
277 // If any parameters each one must be optional. | |
278 methodMirror.parameters.forEach((parameter) { | |
279 createdParametersValid = createdParametersValid && parameter.isOptio nal; | |
280 }); | |
281 } | |
248 | 282 |
249 if (!superCreatedCalled) { | 283 // Get the created constructor source and look at the initializer; |
250 throw new DomException.jsInterop('created constructor initializer must cal l super.created()'); | 284 // Must call super.created() if not its as an error. |
251 } else if (!createdParametersValid) { | 285 var createdSource = methodMirror.source.replaceAll('\n', ' '); |
252 throw new DomException.jsInterop('created constructor must have no paramet ers'); | 286 RegExp regExp = new RegExp(r":(.*?)(;|}|\n)"); |
287 var match = regExp.firstMatch(createdSource); | |
288 superCreatedCalled = match.input.substring(match.start,match.end).contai ns("super.created("); | |
289 } | |
290 | |
291 if (!superCreatedCalled) { | |
292 throw new DomException.jsInterop('created constructor initializer must c all super.created()'); | |
293 } else if (!createdParametersValid) { | |
294 throw new DomException.jsInterop('created constructor must have no param eters'); | |
295 } | |
296 | |
297 classMirror = classMirror.superclass; | |
253 } | 298 } |
254 | 299 |
255 return true; | 300 return true; |
256 } | 301 } |
257 $endif | 302 $endif |
258 | 303 |
259 @Experimental() | 304 @Experimental() |
260 /** | 305 /** |
261 * Register a custom subclass of Element to be instantiatable by the DOM. | 306 * Register a custom subclass of Element to be instantiatable by the DOM. |
262 * | 307 * |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
439 /// parameter must be provided. | 484 /// parameter must be provided. |
440 @Experimental() | 485 @Experimental() |
441 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { | 486 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { |
442 $if DART2JS | 487 $if DART2JS |
443 return new _JSElementUpgrader(this, type, extendsTag); | 488 return new _JSElementUpgrader(this, type, extendsTag); |
444 $else | 489 $else |
445 return new _VMElementUpgrader(this, type, extendsTag); | 490 return new _VMElementUpgrader(this, type, extendsTag); |
446 $endif | 491 $endif |
447 } | 492 } |
448 } | 493 } |
OLD | NEW |