Chromium Code Reviews

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

Issue 23455028: Mirrors overhaul. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r29550. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « dart/pkg/path/lib/path.dart ('k') | dart/pkg/polymer/test/unbind_test.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 247 matching lines...)
258 for (var attr in attrs.split(attrs.contains(',') ? ',' : ' ')) { 258 for (var attr in attrs.split(attrs.contains(',') ? ',' : ' ')) {
259 // remove excess ws 259 // remove excess ws
260 attr = attr.trim(); 260 attr = attr.trim();
261 261
262 // do not override explicit entries 262 // do not override explicit entries
263 if (attr != '' && _publish != null && _publish.containsKey(attr)) { 263 if (attr != '' && _publish != null && _publish.containsKey(attr)) {
264 continue; 264 continue;
265 } 265 }
266 266
267 var property = new Symbol(attr); 267 var property = new Symbol(attr);
268 var mirror = cls.variables[property]; 268 var mirror = cls.declarations[property];
269 if (mirror == null) { 269 if (mirror is MethodMirror) {
270 mirror = cls.getters[property]; 270 if (!mirror.isGetter || !_hasSetter(cls, mirror)) mirror = null;
271 if (mirror != null && !_hasSetter(cls, mirror)) mirror = null; 271 } else if (mirror is! VariableMirror) {
272 mirror = null;
272 } 273 }
273 if (mirror == null) { 274 if (mirror == null) {
274 window.console.warn('property for attribute $attr of polymer-element ' 275 window.console.warn('property for attribute $attr of polymer-element '
275 'name=$name not found.'); 276 'name=$name not found.');
276 continue; 277 continue;
277 } 278 }
278 if (_publish == null) _publish = {}; 279 if (_publish == null) _publish = {};
279 _publish[property] = mirror; 280 _publish[property] = mirror;
280 } 281 }
281 } 282 }
(...skipping 147 matching lines...)
429 } 430 }
430 431
431 /** 432 /**
432 * fetch a list of all observable properties names in our inheritance chain 433 * fetch a list of all observable properties names in our inheritance chain
433 * above Polymer. 434 * above Polymer.
434 */ 435 */
435 // TODO(sjmiles): perf: reflection is slow, relatively speaking 436 // TODO(sjmiles): perf: reflection is slow, relatively speaking
436 // If an element may take 6us to create, getCustomPropertyNames might 437 // If an element may take 6us to create, getCustomPropertyNames might
437 // cost 1.6us more. 438 // cost 1.6us more.
438 void inferObservers(ClassMirror cls) { 439 void inferObservers(ClassMirror cls) {
439 for (var method in cls.methods.values) { 440 for (var method in cls.declarations.values) {
440 if (method.isStatic || !method.isRegularMethod) continue; 441 if (method is! MethodMirror || method.isStatic
442 || !method.isRegularMethod) continue;
441 443
442 String name = MirrorSystem.getName(method.simpleName); 444 String name = MirrorSystem.getName(method.simpleName);
443 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') { 445 if (name.endsWith(_OBSERVE_SUFFIX) && name != 'attributeChanged') {
444 if (_observe == null) _observe = new Map(); 446 if (_observe == null) _observe = new Map();
445 name = name.substring(0, name.length - 7); 447 name = name.substring(0, name.length - 7);
446 _observe[new Symbol(name)] = method.simpleName; 448 _observe[new Symbol(name)] = method.simpleName;
447 } 449 }
448 } 450 }
449 } 451 }
450 452
(...skipping 40 matching lines...)
491 final Map _declarations = new Map<String, PolymerDeclaration>(); 493 final Map _declarations = new Map<String, PolymerDeclaration>();
492 494
493 bool _isRegistered(String name) => _declarations.containsKey(name); 495 bool _isRegistered(String name) => _declarations.containsKey(name);
494 PolymerDeclaration _getDeclaration(String name) => _declarations[name]; 496 PolymerDeclaration _getDeclaration(String name) => _declarations[name];
495 497
496 final _objectType = reflectClass(Object); 498 final _objectType = reflectClass(Object);
497 499
498 Map _getPublishedProperties(ClassMirror cls, Map props) { 500 Map _getPublishedProperties(ClassMirror cls, Map props) {
499 if (cls == _objectType) return props; 501 if (cls == _objectType) return props;
500 props = _getPublishedProperties(cls.superclass, props); 502 props = _getPublishedProperties(cls.superclass, props);
501 for (var field in cls.variables.values) { 503 for (var field in cls.declarations.values) {
502 if (field.isFinal || field.isStatic || field.isPrivate) continue; 504 if (field is! VariableMirror ||
505 field.isFinal || field.isStatic || field.isPrivate) continue;
503 506
504 for (var meta in field.metadata) { 507 for (var meta in field.metadata) {
505 if (meta.reflectee is PublishedProperty) { 508 if (meta.reflectee is PublishedProperty) {
506 if (props == null) props = {}; 509 if (props == null) props = {};
507 props[field.simpleName] = field; 510 props[field.simpleName] = field;
508 break; 511 break;
509 } 512 }
510 } 513 }
511 } 514 }
512 515
513 for (var getter in cls.getters.values) { 516 for (var getter in cls.declarations.values) {
514 if (getter.isStatic || getter.isPrivate) continue; 517 if (getter is! MethodMirror || !getter.isGetter ||
518 getter.isStatic || getter.isPrivate) continue;
515 519
516 for (var meta in getter.metadata) { 520 for (var meta in getter.metadata) {
517 if (meta.reflectee is PublishedProperty) { 521 if (meta.reflectee is PublishedProperty) {
518 if (_hasSetter(cls, getter)) { 522 if (_hasSetter(cls, getter)) {
519 if (props == null) props = {}; 523 if (props == null) props = {};
520 props[getter.simpleName] = getter; 524 props[getter.simpleName] = getter;
521 } 525 }
522 break; 526 break;
523 } 527 }
524 } 528 }
525 } 529 }
526 530
527 return props; 531 return props;
528 } 532 }
529 533
530 bool _hasSetter(ClassMirror cls, MethodMirror getter) { 534 bool _hasSetter(ClassMirror cls, MethodMirror getter) {
531 var setterName = new Symbol('${MirrorSystem.getName(getter.simpleName)}='); 535 var setterName = new Symbol('${MirrorSystem.getName(getter.simpleName)}=');
532 return cls.setters.containsKey(setterName); 536 var mirror = cls.declarations[setterName];
537 return mirror is MethodMirror && mirror.isSetter;
533 } 538 }
534 539
535 540
536 /** Attribute prefix used for declarative event handlers. */ 541 /** Attribute prefix used for declarative event handlers. */
537 const _EVENT_PREFIX = 'on-'; 542 const _EVENT_PREFIX = 'on-';
538 543
539 /** Whether an attribute declares an event. */ 544 /** Whether an attribute declares an event. */
540 bool _hasEventPrefix(String attr) => attr.startsWith(_EVENT_PREFIX); 545 bool _hasEventPrefix(String attr) => attr.startsWith(_EVENT_PREFIX);
541 546
542 String _removeEventPrefix(String name) => name.substring(_EVENT_PREFIX.length); 547 String _removeEventPrefix(String name) => name.substring(_EVENT_PREFIX.length);
(...skipping 61 matching lines...)
604 return map; 609 return map;
605 }(); 610 }();
606 611
607 // Dart note: we need this function because we have additional renames JS does 612 // Dart note: we need this function because we have additional renames JS does
608 // not have. The JS renames are simply case differences, whereas we have ones 613 // not have. The JS renames are simply case differences, whereas we have ones
609 // like doubleclick -> dblclick and stripping the webkit prefix. 614 // like doubleclick -> dblclick and stripping the webkit prefix.
610 String _eventNameFromType(String eventType) { 615 String _eventNameFromType(String eventType) {
611 final result = _reverseEventTranslations[eventType]; 616 final result = _reverseEventTranslations[eventType];
612 return result != null ? result : eventType; 617 return result != null ? result : eventType;
613 } 618 }
OLDNEW
« no previous file with comments | « dart/pkg/path/lib/path.dart ('k') | dart/pkg/polymer/test/unbind_test.dart » ('j') | no next file with comments »

Powered by Google App Engine