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

Side by Side Diff: utils/apidoc/html_diff.dart

Issue 9701029: Get apidoc working with latest frog. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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 /** 5 /**
6 * A script to assist in documenting the difference between the dart:html API 6 * A script to assist in documenting the difference between the dart:html API
7 * and the old DOM API. 7 * and the old DOM API.
8 */ 8 */
9 #library('html_diff'); 9 #library('html_diff');
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 final CommentMap comments; 51 final CommentMap comments;
52 52
53 static Library dom; 53 static Library dom;
54 54
55 /** 55 /**
56 * Perform static initialization of [world]. This should be run before 56 * Perform static initialization of [world]. This should be run before
57 * calling [HtmlDiff.run]. 57 * calling [HtmlDiff.run].
58 */ 58 */
59 static void initialize() { 59 static void initialize() {
60 world.processDartScript('dart:html'); 60 world.getOrAddLibrary('dart:dom');
61 world.getOrAddLibrary('dart:html');
61 world.resolveAll(); 62 world.resolveAll();
62 dom = world.libraries['dart:dom']; 63 dom = world.libraries['dart:dom'];
63 } 64 }
64 65
65 HtmlDiff() : 66 HtmlDiff() :
66 domToHtml = new Map<Member, Set<Member>>(), 67 domToHtml = new Map<Member, Set<Member>>(),
67 htmlToDom = new Map<Member, Set<Member>>(), 68 htmlToDom = new Map<Member, Set<Member>>(),
68 domTypesToHtml = new Map<Type, Set<Type>>(), 69 domTypesToHtml = new Map<Type, Set<Type>>(),
69 htmlTypesToDom = new Map<Type, Set<Type>>(), 70 htmlTypesToDom = new Map<Type, Set<Type>>(),
70 comments = new CommentMap(); 71 comments = new CommentMap();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 154 }
154 155
155 /** 156 /**
156 * Returns the `dart:html` [Member] that corresponds to [implMember] from 157 * Returns the `dart:html` [Member] that corresponds to [implMember] from
157 * `dart:html`, or `null` if there is no such correspondence. 158 * `dart:html`, or `null` if there is no such correspondence.
158 */ 159 */
159 Member htmlImplToHtmlMember(Member implMember) { 160 Member htmlImplToHtmlMember(Member implMember) {
160 var htmlType = htmlImplToHtmlType(implMember.declaringType); 161 var htmlType = htmlImplToHtmlType(implMember.declaringType);
161 if (htmlType == null) return null; 162 if (htmlType == null) return null;
162 163
163 bool getter, setter;
164 if (implMember.isConstructor || implMember.isFactory) { 164 if (implMember.isConstructor || implMember.isFactory) {
165 var constructor = htmlType.constructors[implMember.name]; 165 var constructor = htmlType.constructors[implMember.name];
166 if (constructor != null) return constructor; 166 if (constructor != null) return constructor;
167 167
168 // Look for a factory constructor whose type and name matches the member. 168 // Look for a factory constructor whose type and name matches the member.
169 return htmlType.factories.getFactoriesFor(implMember.name)[ 169 return htmlType.factories.getFactoriesFor(implMember.name)[
170 implMember.constructorName]; 170 implMember.constructorName];
171 } else if ((getter = implMember.name.startsWith('get:')) || 171 }
172 (setter = implMember.name.startsWith('set:'))) { 172
173 final getter = implMember.name.startsWith('get:');
174 final setter = implMember.name.startsWith('set:');
175
176 if (getter || setter) {
173 // Use getMember to follow interface inheritance chains. 177 // Use getMember to follow interface inheritance chains.
174 var htmlProperty = htmlType.getMember(implMember.name.substring(4)); 178 var htmlProperty = htmlType.getMember(implMember.name.substring(4));
175 if (htmlProperty != null) { 179
176 return getter ? htmlProperty.getter : htmlProperty.setter; 180 if (htmlProperty == null) return null;
177 } else { 181
178 return null; 182 // If it's a straight field, use that directly.
179 } 183 if (htmlProperty.isField) return htmlProperty;
180 } else { 184
181 return htmlType.getMember(implMember.name); 185 // Otherwise, it's a property, so use the appropriate getter or setter.
186 return getter ? htmlProperty.getter : htmlProperty.setter;
182 } 187 }
188
189 return htmlType.getMember(implMember.name);
183 } 190 }
184 191
185 /** 192 /**
186 * Returns the `dart:dom` [Type]s that correspond to [htmlType] from 193 * Returns the `dart:dom` [Type]s that correspond to [htmlType] from
187 * `dart:html`. This can be the empty list if no correspondence is found. 194 * `dart:html`. This can be the empty list if no correspondence is found.
188 */ 195 */
189 List<Type> htmlToDomTypes(Type htmlType) { 196 List<Type> htmlToDomTypes(Type htmlType) {
190 if (htmlType.name == null) return []; 197 if (htmlType.name == null) return [];
191 final tags = _getTags(comments.find(htmlType.span)); 198 final tags = _getTags(comments.find(htmlType.span));
192 199
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (t.members.containsKey(name)) members.add(t.members[name]); 287 if (t.members.containsKey(name)) members.add(t.members[name]);
281 }); 288 });
282 return members; 289 return members;
283 } 290 }
284 291
285 final splitName = name.split('.'); 292 final splitName = name.split('.');
286 if (splitName.length != 2) { 293 if (splitName.length != 2) {
287 print('Warning: invalid member name ${name}'); 294 print('Warning: invalid member name ${name}');
288 return new Set(); 295 return new Set();
289 } 296 }
297
290 var typeName = splitName[0]; 298 var typeName = splitName[0];
291 if (typeName == 'Window') typeName = 'DOMWindow'; 299 if (typeName == 'Window') typeName = 'DOMWindow';
300
292 final type = dom.types[typeName]; 301 final type = dom.types[typeName];
293 if (type == null) return new Set(); 302 if (type == null) return new Set();
303
294 final member = type.members[splitName[1]]; 304 final member = type.members[splitName[1]];
295 if (member == null) return new Set(); 305 if (member == null) return new Set();
306
296 return new Set.from([member]); 307 return new Set.from([member]);
297 } 308 }
298 309
299 /** 310 /**
300 * Returns the `dart:dom` [Member]s that are referred to in [stmt]. This only 311 * Returns the `dart:dom` [Member]s that are referred to in [stmt]. This only
301 * extracts references from relatively simple statements; methods containing 312 * extracts references from relatively simple statements; methods containing
302 * more complex wrappers should be manually annotated with `@domName`. 313 * more complex wrappers should be manually annotated with `@domName`.
303 * 314 *
304 * [domTypes] are the `dart:dom` [Type]s that correspond to the current 315 * [domTypes] are the `dart:dom` [Type]s that correspond to the current
305 * [Member]'s defining [Type]. 316 * [Member]'s defining [Type].
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 Map<String, String> _getTags(String comment) { 405 Map<String, String> _getTags(String comment) {
395 if (comment == null) return const <String>{}; 406 if (comment == null) return const <String>{};
396 final re = new RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); 407 final re = new RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)");
397 final tags = <String>{}; 408 final tags = <String>{};
398 for (var m in re.allMatches(comment.trim())) { 409 for (var m in re.allMatches(comment.trim())) {
399 tags[m[1]] = m[2]; 410 tags[m[1]] = m[2];
400 } 411 }
401 return tags; 412 return tags;
402 } 413 }
403 } 414 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698