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

Side by Side Diff: pkg/polymer/lib/src/declaration.dart

Issue 79353003: [polymer.dart] fix *Changed observers inheriting (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/polymer/lib/src/instance.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 432 }
433 433
434 /** 434 /**
435 * fetch a list of all observable properties names in our inheritance chain 435 * fetch a list of all observable properties names in our inheritance chain
436 * above Polymer. 436 * above Polymer.
437 */ 437 */
438 // TODO(sjmiles): perf: reflection is slow, relatively speaking 438 // TODO(sjmiles): perf: reflection is slow, relatively speaking
439 // If an element may take 6us to create, getCustomPropertyNames might 439 // If an element may take 6us to create, getCustomPropertyNames might
440 // cost 1.6us more. 440 // cost 1.6us more.
441 void inferObservers(ClassMirror cls) { 441 void inferObservers(ClassMirror cls) {
442 if (cls == _objectType) return;
443 inferObservers(cls.superclass);
442 for (var method in cls.declarations.values) { 444 for (var method in cls.declarations.values) {
443 if (method is! MethodMirror || method.isStatic 445 if (method is! MethodMirror || method.isStatic
444 || !method.isRegularMethod) continue; 446 || !method.isRegularMethod) continue;
445 447
446 String name = MirrorSystem.getName(method.simpleName); 448 String name = MirrorSystem.getName(method.simpleName);
447 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') { 449 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') {
448 if (_observe == null) _observe = new Map(); 450 if (_observe == null) _observe = new Map();
449 name = name.substring(0, name.length - 7); 451 name = name.substring(0, name.length - 7);
450 _observe[new Symbol(name)] = method.simpleName; 452 _observe[new Symbol(name)] = method.simpleName;
451 } 453 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 494 }
493 495
494 /// track document.register'ed tag names and their declarations 496 /// track document.register'ed tag names and their declarations
495 final Map _declarations = new Map<String, PolymerDeclaration>(); 497 final Map _declarations = new Map<String, PolymerDeclaration>();
496 498
497 bool _isRegistered(String name) => _declarations.containsKey(name); 499 bool _isRegistered(String name) => _declarations.containsKey(name);
498 PolymerDeclaration _getDeclaration(String name) => _declarations[name]; 500 PolymerDeclaration _getDeclaration(String name) => _declarations[name];
499 501
500 final _objectType = reflectClass(Object); 502 final _objectType = reflectClass(Object);
501 503
504
502 Map _getPublishedProperties(ClassMirror cls, Map props) { 505 Map _getPublishedProperties(ClassMirror cls, Map props) {
503 if (cls == _objectType) return props; 506 if (cls == _objectType) return props;
504 props = _getPublishedProperties(cls.superclass, props); 507 props = _getPublishedProperties(cls.superclass, props);
505 for (var field in cls.declarations.values) { 508 for (var member in cls.declarations.values) {
506 if (field is! VariableMirror || 509 if (member.isStatic || member.isPrivate) continue;
507 field.isFinal || field.isStatic || field.isPrivate) continue;
508 510
509 for (var meta in field.metadata) { 511 if (member is VariableMirror && !member.isFinal
510 if (meta.reflectee is PublishedProperty) { 512 || member is MethodMirror && member.isGetter) {
511 if (props == null) props = {}; 513
512 props[field.simpleName] = field; 514 for (var meta in member.metadata) {
513 break; 515 if (meta.reflectee is PublishedProperty) {
516 // Note: we delay the setter check until we find @published because
517 // it's a tad expensive.
518 if (member is! MethodMirror || _hasSetter(cls, member)) {
519 if (props == null) props = {};
520 props[member.simpleName] = member;
521 }
522 break;
523 }
514 } 524 }
515 } 525 }
516 } 526 }
517
518 for (var getter in cls.declarations.values) {
Jennifer Messerly 2013/11/21 00:07:34 with .declarations, we don't need this duplication
519 if (getter is! MethodMirror || !getter.isGetter ||
520 getter.isStatic || getter.isPrivate) continue;
521
522 for (var meta in getter.metadata) {
523 if (meta.reflectee is PublishedProperty) {
524 if (_hasSetter(cls, getter)) {
525 if (props == null) props = {};
526 props[getter.simpleName] = getter;
527 }
528 break;
529 }
530 }
531 }
532 527
533 return props; 528 return props;
534 } 529 }
535 530
536 bool _hasSetter(ClassMirror cls, MethodMirror getter) { 531 bool _hasSetter(ClassMirror cls, MethodMirror getter) {
537 var setterName = new Symbol('${MirrorSystem.getName(getter.simpleName)}='); 532 var setterName = new Symbol('${MirrorSystem.getName(getter.simpleName)}=');
538 var mirror = cls.declarations[setterName]; 533 var mirror = cls.declarations[setterName];
539 return mirror is MethodMirror && mirror.isSetter; 534 return mirror is MethodMirror && mirror.isSetter;
540 } 535 }
541 536
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 return map; 606 return map;
612 }(); 607 }();
613 608
614 // Dart note: we need this function because we have additional renames JS does 609 // Dart note: we need this function because we have additional renames JS does
615 // not have. The JS renames are simply case differences, whereas we have ones 610 // not have. The JS renames are simply case differences, whereas we have ones
616 // like doubleclick -> dblclick and stripping the webkit prefix. 611 // like doubleclick -> dblclick and stripping the webkit prefix.
617 String _eventNameFromType(String eventType) { 612 String _eventNameFromType(String eventType) {
618 final result = _reverseEventTranslations[eventType]; 613 final result = _reverseEventTranslations[eventType];
619 return result != null ? result : eventType; 614 return result != null ? result : eventType;
620 } 615 }
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/lib/src/instance.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698