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

Side by Side Diff: lib/html/templates/html/impl/impl_Element.darttemplate

Issue 11262012: Migrate to getter for isEmpty. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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
OLDNEW
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 // TODO(jacobr): use _Lists.dart to remove some of the duplicated 5 // TODO(jacobr): use _Lists.dart to remove some of the duplicated
6 // functionality. 6 // functionality.
7 class _ChildrenElementList implements List { 7 class _ChildrenElementList implements List {
8 // Raw Element. 8 // Raw Element.
9 final _ElementImpl _element; 9 final _ElementImpl _element;
10 final _HTMLCollectionImpl _childElements; 10 final _HTMLCollectionImpl _childElements;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 Collection map(f(Element element)) { 60 Collection map(f(Element element)) {
61 final out = []; 61 final out = [];
62 for (Element el in this) { 62 for (Element el in this) {
63 out.add(f(el)); 63 out.add(f(el));
64 } 64 }
65 return out; 65 return out;
66 } 66 }
67 67
68 bool isEmpty() { 68 bool get isEmpty {
69 return _element.$dom_firstElementChild == null; 69 return _element.$dom_firstElementChild == null;
70 } 70 }
71 71
72 int get length { 72 int get length {
73 return _childElements.length; 73 return _childElements.length;
74 } 74 }
75 75
76 _ElementImpl operator [](int index) { 76 _ElementImpl operator [](int index) {
77 return _childElements[index]; 77 return _childElements[index];
78 } 78 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 bool some(bool f(Element element)) { 202 bool some(bool f(Element element)) {
203 for(Element element in this) { 203 for(Element element in this) {
204 if (f(element)) { 204 if (f(element)) {
205 return true; 205 return true;
206 } 206 }
207 }; 207 };
208 return false; 208 return false;
209 } 209 }
210 210
211 bool isEmpty() => _nodeList.isEmpty(); 211 bool get isEmpty => _nodeList.isEmpty;
212 212
213 int get length => _nodeList.length; 213 int get length => _nodeList.length;
214 214
215 Element operator [](int index) => _nodeList[index]; 215 Element operator [](int index) => _nodeList[index];
216 216
217 void operator []=(int index, Element value) { 217 void operator []=(int index, Element value) {
218 throw new UnsupportedError(''); 218 throw new UnsupportedError('');
219 } 219 }
220 220
221 void set length(int newLength) { 221 void set length(int newLength) {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 /** 375 /**
376 * The number of {key, value} pairs in the map. 376 * The number of {key, value} pairs in the map.
377 */ 377 */
378 int get length { 378 int get length {
379 return _element.$dom_attributes.length; 379 return _element.$dom_attributes.length;
380 } 380 }
381 381
382 /** 382 /**
383 * Returns true if there is no {key, value} pair in the map. 383 * Returns true if there is no {key, value} pair in the map.
384 */ 384 */
385 bool isEmpty() { 385 bool get isEmpty {
386 return length == 0; 386 return length == 0;
387 } 387 }
388 } 388 }
389 389
390 /** 390 /**
391 * Provides a Map abstraction on top of data-* attributes, similar to the 391 * Provides a Map abstraction on top of data-* attributes, similar to the
392 * dataSet in the old DOM. 392 * dataSet in the old DOM.
393 */ 393 */
394 class _DataAttributeMap implements AttributeMap { 394 class _DataAttributeMap implements AttributeMap {
395 395
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (_matches(key)) { 446 if (_matches(key)) {
447 values.add(value); 447 values.add(value);
448 } 448 }
449 }); 449 });
450 return values; 450 return values;
451 } 451 }
452 452
453 int get length => getKeys().length; 453 int get length => getKeys().length;
454 454
455 // TODO: Use lazy iterator when it is available on Map. 455 // TODO: Use lazy iterator when it is available on Map.
456 bool isEmpty() => length == 0; 456 bool get isEmpty => length == 0;
457 457
458 // Helpers. 458 // Helpers.
459 String _attr(String key) => 'data-$key'; 459 String _attr(String key) => 'data-$key';
460 bool _matches(String key) => key.startsWith('data-'); 460 bool _matches(String key) => key.startsWith('data-');
461 String _strip(String key) => key.substring(5); 461 String _strip(String key) => key.substring(5);
462 } 462 }
463 463
464 class _CssClassSet implements CSSClassSet { 464 class _CssClassSet implements CSSClassSet {
465 465
466 final _ElementImpl _element; 466 final _ElementImpl _element;
(...skipping 12 matching lines...) Expand all
479 } 479 }
480 480
481 Collection map(f(String element)) => _read().map(f); 481 Collection map(f(String element)) => _read().map(f);
482 482
483 Collection<String> filter(bool f(String element)) => _read().filter(f); 483 Collection<String> filter(bool f(String element)) => _read().filter(f);
484 484
485 bool every(bool f(String element)) => _read().every(f); 485 bool every(bool f(String element)) => _read().every(f);
486 486
487 bool some(bool f(String element)) => _read().some(f); 487 bool some(bool f(String element)) => _read().some(f);
488 488
489 bool isEmpty() => _read().isEmpty(); 489 bool get isEmpty => _read().isEmpty;
490 490
491 bool get frozen => false; 491 bool get frozen => false;
492 492
493 int get length =>_read().length; 493 int get length =>_read().length;
494 494
495 // interface Collection - END 495 // interface Collection - END
496 496
497 // interface Set - BEGIN 497 // interface Set - BEGIN
498 bool contains(String value) => _read().contains(value); 498 bool contains(String value) => _read().contains(value);
499 499
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 563
564 /** 564 /**
565 * Read the class names from the Element class property, 565 * Read the class names from the Element class property,
566 * and put them into a set (duplicates are discarded). 566 * and put them into a set (duplicates are discarded).
567 */ 567 */
568 Set<String> _read() { 568 Set<String> _read() {
569 // TODO(mattsh) simplify this once split can take regex. 569 // TODO(mattsh) simplify this once split can take regex.
570 Set<String> s = new Set<String>(); 570 Set<String> s = new Set<String>();
571 for (String name in _classname().split(' ')) { 571 for (String name in _classname().split(' ')) {
572 String trimmed = name.trim(); 572 String trimmed = name.trim();
573 if (!trimmed.isEmpty()) { 573 if (!trimmed.isEmpty) {
574 s.add(trimmed); 574 s.add(trimmed);
575 } 575 }
576 } 576 }
577 return s; 577 return s;
578 } 578 }
579 579
580 /** 580 /**
581 * Read the class names as a space-separated string. This is meant to be 581 * Read the class names as a space-separated string. This is meant to be
582 * overridden by subclasses. 582 * overridden by subclasses.
583 */ 583 */
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 $if DART2JS 871 $if DART2JS
872 // Optimization to improve performance until the dart2js compiler inlines this 872 // Optimization to improve performance until the dart2js compiler inlines this
873 // method. 873 // method.
874 static Element createElement_tag(String tag) => 874 static Element createElement_tag(String tag) =>
875 JS('Element', 'document.createElement(#)', tag); 875 JS('Element', 'document.createElement(#)', tag);
876 $else 876 $else
877 static Element createElement_tag(String tag) => 877 static Element createElement_tag(String tag) =>
878 _document.$dom_createElement(tag); 878 _document.$dom_createElement(tag);
879 $endif 879 $endif
880 } 880 }
OLDNEW
« no previous file with comments | « lib/html/templates/html/impl/impl_DocumentFragment.darttemplate ('k') | lib/html/templates/html/impl/impl_Node.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698