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

Side by Side Diff: lib/src/observable_transform.dart

Issue 20863002: Introduce boot.js: this finally makes it possible to load and run Todomvc (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: review comments, fixed build.dart Created 7 years, 4 months 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
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 /** 5 /**
6 * Code transform for @observable. The core transformation is relatively 6 * Code transform for @observable. The core transformation is relatively
7 * straightforward, and essentially like an editor refactoring. You can find the 7 * straightforward, and essentially like an editor refactoring. You can find the
8 * core implementation in [transformClass], which is ultimately called by 8 * core implementation in [transformClass], which is ultimately called by
9 * [transformObservables], the entry point to this library. 9 * [transformObservables], the entry point to this library.
10 */ 10 */
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 void transformClass(ClassDeclaration cls, TextEditTransaction code, 80 void transformClass(ClassDeclaration cls, TextEditTransaction code,
81 SourceFile file, Messages messages) { 81 SourceFile file, Messages messages) {
82 82
83 if (hasObservable(cls)) { 83 if (hasObservable(cls)) {
84 messages.warning('@observable on a class no longer has any effect. ' 84 messages.warning('@observable on a class no longer has any effect. '
85 'It should be placed on individual fields.', 85 'It should be placed on individual fields.',
86 _getSpan(file, cls)); 86 _getSpan(file, cls));
87 } 87 }
88 88
89 var declaresObservable = false;
90 if (cls.extendsClause != null) {
91 var id = cls.extendsClause.superclass.name;
92 if (id is PrefixedIdentifier) {
Jennifer Messerly 2013/07/30 00:56:12 it's only used in 2 places but this might be a goo
Siggi Cherem (dart-lang) 2013/07/30 23:32:04 Done.
93 id = id.identifier;
94 }
95 if (id.name == "ObservableBase") {
96 code.edit(id.offset, id.end, "ChangeNotifierBase");
97 declaresObservable = true;
98 } else if (id.name == "ChangeNotifierBase") {
99 declaresObservable = true;
100 }
101 }
102 if (!declaresObservable && cls.withClause != null) {
103 for (var type in cls.withClause.mixinTypes) {
104 var id = type.name;
105 if (id is PrefixedIdentifier) {
106 id = id.identifier;
107 }
108 if (id.name == "ObservableMixin") {
109 code.edit(id.offset, id.end, "ChangeNotifierMixin");
110 declaresObservable = true;
111 break;
112 } else if (id.name == "ChangeNotifierMixin") {
113 declaresObservable = true;
114 break;
115 }
116 }
117 }
118
89 // Track fields that were transformed. 119 // Track fields that were transformed.
90 var instanceFields = new Set<String>(); 120 var instanceFields = new Set<String>();
91 var getters = new List<String>(); 121 var getters = new List<String>();
92 var setters = new List<String>(); 122 var setters = new List<String>();
93 123
94 for (var member in cls.members) { 124 for (var member in cls.members) {
95 if (member is FieldDeclaration) { 125 if (member is FieldDeclaration) {
96 bool isStatic = hasKeyword(member.keyword, Keyword.STATIC); 126 bool isStatic = hasKeyword(member.keyword, Keyword.STATIC);
97 if (isStatic) { 127 if (isStatic) {
98 if (hasObservable(member)){ 128 if (hasObservable(member)){
99 messages.warning('Static fields can no longer be observable. ' 129 messages.warning('Static fields can no longer be observable. '
100 'Observable fields should be put in an observable objects.', 130 'Observable fields should be put in an observable objects.',
101 _getSpan(file, member)); 131 _getSpan(file, member));
102 } 132 }
103 continue; 133 continue;
104 } 134 }
105 if (hasObservable(member)) { 135 if (hasObservable(member)) {
136 if (!declaresObservable) {
Jennifer Messerly 2013/07/30 00:56:12 I'm not sure this warning is correct. What if Obse
Siggi Cherem (dart-lang) 2013/07/30 23:32:04 Good point. Since we are not going to do a type an
Jennifer Messerly 2013/07/31 00:59:51 Hmm, sounds a little better, but I get nervous any
Siggi Cherem (dart-lang) 2013/07/31 01:39:17 good ideas, I'll think more about them. For now I
137 messages.warning('Observable fields should be put in an observable'
138 ' objects. Please declare that this class extends from '
139 'ObservableBase or includes ObservableMixin.',
140 _getSpan(file, member));
141
142 }
106 transformFields(member.fields, code, member.offset, member.end); 143 transformFields(member.fields, code, member.offset, member.end);
107 144
108 var names = member.fields.variables.map((v) => v.name.name); 145 var names = member.fields.variables.map((v) => v.name.name);
109 146
110 getters.addAll(names); 147 getters.addAll(names);
111 if (!_isReadOnly(member.fields)) { 148 if (!_isReadOnly(member.fields)) {
112 setters.addAll(names); 149 setters.addAll(names);
113 instanceFields.addAll(names); 150 instanceFields.addAll(names);
114 } 151 }
115 } 152 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 $type __\$$name$initializer; 298 $type __\$$name$initializer;
262 $type get $name => __\$$name; 299 $type get $name => __\$$name;
263 set $name($type value) { 300 set $name($type value) {
264 __\$$name = notifyPropertyChange(const Symbol('$name'), __\$$name, value); 301 __\$$name = notifyPropertyChange(const Symbol('$name'), __\$$name, value);
265 } 302 }
266 '''.replaceAll('\n', '\n$indent')); 303 '''.replaceAll('\n', '\n$indent'));
267 } 304 }
268 305
269 code.edit(begin, end, '$replace'); 306 code.edit(begin, end, '$replace');
270 } 307 }
OLDNEW
« lib/src/emitters.dart ('K') | « lib/src/emitters.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698