Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of polymer; | 5 part of polymer; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * **Warning**: this class is experiental and subject to change. | 8 * **Warning**: this class is experiental and subject to change. |
| 9 * | 9 * |
| 10 * The implementation for the `polymer-element` element. | 10 * The implementation for the `polymer-element` element. |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 while (decl != null) { | 235 while (decl != null) { |
| 236 baseTag = decl.attributes['extends']; | 236 baseTag = decl.attributes['extends']; |
| 237 decl = decl.superDeclaration; | 237 decl = decl.superDeclaration; |
| 238 } | 238 } |
| 239 document.register(name, type, extendsTag: baseTag); | 239 document.register(name, type, extendsTag: baseTag); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void publishAttributes(ClassMirror cls, PolymerDeclaration superDecl) { | 242 void publishAttributes(ClassMirror cls, PolymerDeclaration superDecl) { |
| 243 // get properties to publish | 243 // get properties to publish |
| 244 if (superDecl != null && superDecl._publish != null) { | 244 if (superDecl != null && superDecl._publish != null) { |
| 245 // Dart note: even though we walk the type hierarchy in | |
| 246 // _getPublishedProperties, this will additionally include any names | |
| 247 // published via the `attributes` attribute. | |
| 245 _publish = new Map.from(superDecl._publish); | 248 _publish = new Map.from(superDecl._publish); |
| 246 } | 249 } |
| 247 _publish = _getProperties(cls, _publish, (x) => x is PublishedProperty); | 250 |
| 251 _publish = _getPublishedProperties(cls, _publish); | |
| 248 | 252 |
| 249 // merge names from 'attributes' attribute | 253 // merge names from 'attributes' attribute |
| 250 var attrs = attributes['attributes']; | 254 var attrs = attributes['attributes']; |
| 251 if (attrs != null) { | 255 if (attrs != null) { |
| 252 // names='a b c' or names='a,b,c' | 256 // names='a b c' or names='a,b,c' |
| 253 // record each name for publishing | 257 // record each name for publishing |
| 254 for (var attr in attrs.split(attrs.contains(',') ? ',' : ' ')) { | 258 for (var attr in attrs.split(attrs.contains(',') ? ',' : ' ')) { |
| 255 // remove excess ws | 259 // remove excess ws |
| 256 attr = attr.trim(); | 260 attr = attr.trim(); |
| 257 | 261 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 | 430 |
| 427 /** | 431 /** |
| 428 * fetch a list of all observable properties names in our inheritance chain | 432 * fetch a list of all observable properties names in our inheritance chain |
| 429 * above Polymer. | 433 * above Polymer. |
| 430 */ | 434 */ |
| 431 // TODO(sjmiles): perf: reflection is slow, relatively speaking | 435 // TODO(sjmiles): perf: reflection is slow, relatively speaking |
| 432 // If an element may take 6us to create, getCustomPropertyNames might | 436 // If an element may take 6us to create, getCustomPropertyNames might |
| 433 // cost 1.6us more. | 437 // cost 1.6us more. |
| 434 void inferObservers(ClassMirror cls) { | 438 void inferObservers(ClassMirror cls) { |
| 435 for (var method in cls.methods.values) { | 439 for (var method in cls.methods.values) { |
| 436 if (method.isStatic || !method.isRegularMethod) continue; | 440 if (method.isStatic || !method.isRegularMethod) continue; |
|
Jennifer Messerly
2013/10/29 02:20:26
should we do the same fix here too?
| |
| 437 | 441 |
| 438 String name = MirrorSystem.getName(method.simpleName); | 442 String name = MirrorSystem.getName(method.simpleName); |
| 439 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') { | 443 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') { |
| 440 if (_observe == null) _observe = new Map(); | 444 if (_observe == null) _observe = new Map(); |
| 441 name = name.substring(0, name.length - 7); | 445 name = name.substring(0, name.length - 7); |
| 442 _observe[new Symbol(name)] = method.simpleName; | 446 _observe[new Symbol(name)] = method.simpleName; |
| 443 } | 447 } |
| 444 } | 448 } |
| 445 } | 449 } |
| 446 | 450 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 } | 488 } |
| 485 | 489 |
| 486 /// track document.register'ed tag names and their declarations | 490 /// track document.register'ed tag names and their declarations |
| 487 final Map _declarations = new Map<String, PolymerDeclaration>(); | 491 final Map _declarations = new Map<String, PolymerDeclaration>(); |
| 488 | 492 |
| 489 bool _isRegistered(String name) => _declarations.containsKey(name); | 493 bool _isRegistered(String name) => _declarations.containsKey(name); |
| 490 PolymerDeclaration _getDeclaration(String name) => _declarations[name]; | 494 PolymerDeclaration _getDeclaration(String name) => _declarations[name]; |
| 491 | 495 |
| 492 final _objectType = reflectClass(Object); | 496 final _objectType = reflectClass(Object); |
| 493 | 497 |
| 494 Map _getProperties(ClassMirror cls, Map props, bool matches(metadata)) { | 498 Map _getPublishedProperties(ClassMirror cls, Map props) { |
| 499 if (cls == _objectType) return props; | |
| 500 props = _getPublishedProperties(cls.superclass, props); | |
| 495 for (var field in cls.variables.values) { | 501 for (var field in cls.variables.values) { |
| 496 if (field.isFinal || field.isStatic || field.isPrivate) continue; | 502 if (field.isFinal || field.isStatic || field.isPrivate) continue; |
| 497 | 503 |
| 498 for (var meta in field.metadata) { | 504 for (var meta in field.metadata) { |
| 499 if (matches(meta.reflectee)) { | 505 if (meta.reflectee is PublishedProperty) { |
| 500 if (props == null) props = {}; | 506 if (props == null) props = {}; |
| 501 props[field.simpleName] = field; | 507 props[field.simpleName] = field; |
| 502 break; | 508 break; |
| 503 } | 509 } |
| 504 } | 510 } |
| 505 } | 511 } |
| 506 | 512 |
| 507 for (var getter in cls.getters.values) { | 513 for (var getter in cls.getters.values) { |
| 508 if (getter.isStatic || getter.isPrivate) continue; | 514 if (getter.isStatic || getter.isPrivate) continue; |
| 509 | 515 |
| 510 for (var meta in getter.metadata) { | 516 for (var meta in getter.metadata) { |
| 511 if (matches(meta.reflectee)) { | 517 if (meta.reflectee is PublishedProperty) { |
| 512 if (_hasSetter(cls, getter)) { | 518 if (_hasSetter(cls, getter)) { |
| 513 if (props == null) props = {}; | 519 if (props == null) props = {}; |
| 514 props[getter.simpleName] = getter; | 520 props[getter.simpleName] = getter; |
| 515 } | 521 } |
| 516 break; | 522 break; |
| 517 } | 523 } |
| 518 } | 524 } |
| 519 } | 525 } |
| 520 | 526 |
| 521 return props; | 527 return props; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 598 return map; | 604 return map; |
| 599 }(); | 605 }(); |
| 600 | 606 |
| 601 // Dart note: we need this function because we have additional renames JS does | 607 // Dart note: we need this function because we have additional renames JS does |
| 602 // not have. The JS renames are simply case differences, whereas we have ones | 608 // not have. The JS renames are simply case differences, whereas we have ones |
| 603 // like doubleclick -> dblclick and stripping the webkit prefix. | 609 // like doubleclick -> dblclick and stripping the webkit prefix. |
| 604 String _eventNameFromType(String eventType) { | 610 String _eventNameFromType(String eventType) { |
| 605 final result = _reverseEventTranslations[eventType]; | 611 final result = _reverseEventTranslations[eventType]; |
| 606 return result != null ? result : eventType; | 612 return result != null ? result : eventType; |
| 607 } | 613 } |
| OLD | NEW |