OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 18 matching lines...) Expand all Loading... | |
29 var htmlTypeName = htmlMember.declaringType.name; | 29 var htmlTypeName = htmlMember.declaringType.name; |
30 var htmlName = '$htmlTypeName.${htmlMember.name}'; | 30 var htmlName = '$htmlTypeName.${htmlMember.name}'; |
31 if (htmlMember.isConstructor || htmlMember.isFactory) { | 31 if (htmlMember.isConstructor || htmlMember.isFactory) { |
32 final separator = htmlMember.constructorName == '' ? '' : '.'; | 32 final separator = htmlMember.constructorName == '' ? '' : '.'; |
33 htmlName = 'new $htmlTypeName$separator${htmlMember.constructorName}'; | 33 htmlName = 'new $htmlTypeName$separator${htmlMember.constructorName}'; |
34 } | 34 } |
35 print('${domMember.declaringType.name}.${domMember.name} -> ${htmlName}'); | 35 print('${domMember.declaringType.name}.${domMember.name} -> ${htmlName}'); |
36 } | 36 } |
37 }); | 37 }); |
38 | 38 |
39 for (var type in world.dom.types.getValues()) { | 39 for (var type in diff.dom.types.getValues()) { |
Jennifer Messerly
2012/01/06 21:36:29
I was trying to get rid of "world.dom" completely.
| |
40 if (type.name == null) continue; | 40 if (type.name == null) continue; |
41 if (type.definition is FunctionTypeDefinition) continue; | 41 if (type.definition is FunctionTypeDefinition) continue; |
42 for (var member in type.members.getValues()) { | 42 for (var member in type.members.getValues()) { |
43 if (!member.isPrivate && member.name != 'typeName' && | 43 if (!member.isPrivate && member.name != 'typeName' && |
44 !diff.domToHtml.containsKey(member) && | 44 !diff.domToHtml.containsKey(member) && |
45 (member is MethodMember || member is PropertyMember)) { | 45 (member is MethodMember || member is PropertyMember)) { |
46 print('No dart:html wrapper for ${type.name}.${member.name}'); | 46 print('No dart:html wrapper for ${type.name}.${member.name}'); |
47 } | 47 } |
48 } | 48 } |
49 } | 49 } |
(...skipping 28 matching lines...) Expand all Loading... | |
78 final Map<Member, Set<Member>> htmlToDom; | 78 final Map<Member, Set<Member>> htmlToDom; |
79 | 79 |
80 /** A map from `dart:dom` types to corresponding `dart:html` types. */ | 80 /** A map from `dart:dom` types to corresponding `dart:html` types. */ |
81 final Map<Type, Set<Type>> domTypesToHtml; | 81 final Map<Type, Set<Type>> domTypesToHtml; |
82 | 82 |
83 /** A map from `dart:html` types to corresponding `dart:dom` types. */ | 83 /** A map from `dart:html` types to corresponding `dart:dom` types. */ |
84 final Map<Type, Set<Type>> htmlTypesToDom; | 84 final Map<Type, Set<Type>> htmlTypesToDom; |
85 | 85 |
86 final CommentMap comments; | 86 final CommentMap comments; |
87 | 87 |
88 final Library dom; | |
89 | |
88 /** | 90 /** |
89 * Perform static initialization of [world]. This should be run before | 91 * Perform static initialization of [world]. This should be run before |
90 * calling [HtmlDiff.run]. | 92 * calling [HtmlDiff.run]. |
91 */ | 93 */ |
92 static void initialize() { | 94 static void initialize() { |
93 world.processDartScript('dart:htmlimpl'); | 95 world.processDartScript('dart:htmlimpl'); |
94 world.resolveAll(); | 96 world.resolveAll(); |
97 dom = world.libraries['dart:dom']; | |
95 } | 98 } |
96 | 99 |
97 HtmlDiff() : | 100 HtmlDiff() : |
98 domToHtml = new Map<Member, Set<Member>>(), | 101 domToHtml = new Map<Member, Set<Member>>(), |
99 htmlToDom = new Map<Member, Set<Member>>(), | 102 htmlToDom = new Map<Member, Set<Member>>(), |
100 domTypesToHtml = new Map<Type, Set<Type>>(), | 103 domTypesToHtml = new Map<Type, Set<Type>>(), |
101 htmlTypesToDom = new Map<Type, Set<Type>>(), | 104 htmlTypesToDom = new Map<Type, Set<Type>>(), |
102 comments = new CommentMap(); | 105 comments = new CommentMap(); |
103 | 106 |
104 /** | 107 /** |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 List<Type> htmlToDomTypes(Type htmlType) { | 223 List<Type> htmlToDomTypes(Type htmlType) { |
221 if (htmlType.name == null) return []; | 224 if (htmlType.name == null) return []; |
222 final tags = _getTags(comments.find(htmlType.span)); | 225 final tags = _getTags(comments.find(htmlType.span)); |
223 | 226 |
224 if (tags.containsKey('domName')) { | 227 if (tags.containsKey('domName')) { |
225 var domNames = map(tags['domName'].split(','), (s) => s.trim()); | 228 var domNames = map(tags['domName'].split(','), (s) => s.trim()); |
226 if (domNames.length == 1 && domNames[0] == 'none') return []; | 229 if (domNames.length == 1 && domNames[0] == 'none') return []; |
227 return map(domNames, (domName) { | 230 return map(domNames, (domName) { |
228 // DOMWindow is Chrome-specific, so we don't use it in our annotations. | 231 // DOMWindow is Chrome-specific, so we don't use it in our annotations. |
229 if (domName == 'Window') domName = 'DOMWindow'; | 232 if (domName == 'Window') domName = 'DOMWindow'; |
230 final domType = world.dom.types[domName]; | 233 final domType = dom.types[domName]; |
231 if (domType == null) print('Warning: no dart:dom type named $domName'); | 234 if (domType == null) print('Warning: no dart:dom type named $domName'); |
232 return domType; | 235 return domType; |
233 }); | 236 }); |
234 } else { | 237 } else { |
235 if (!htmlType.name.endsWith('WrappingImplementation')) return []; | 238 if (!htmlType.name.endsWith('WrappingImplementation')) return []; |
236 final domName = htmlType.name.replaceFirst('WrappingImplementation', ''); | 239 final domName = htmlType.name.replaceFirst('WrappingImplementation', ''); |
237 var domType = world.dom.types[domName]; | 240 var domType = dom.types[domName]; |
238 if (domType == null && domName.endsWith('Element')) { | 241 if (domType == null && domName.endsWith('Element')) { |
239 domType = world.dom.types['HTML$domName']; | 242 domType = dom.types['HTML$domName']; |
240 } | 243 } |
241 if (domType == null) domType = world.dom.types['WebKit$domName']; | 244 if (domType == null) domType = dom.types['WebKit$domName']; |
242 if (domType == null) { | 245 if (domType == null) { |
243 print('Warning: no dart:dom type matches dart:htmlimpl ' + | 246 print('Warning: no dart:dom type matches dart:htmlimpl ' + |
244 htmlType.name); | 247 htmlType.name); |
245 return []; | 248 return []; |
246 } | 249 } |
247 return [domType]; | 250 return [domType]; |
248 } | 251 } |
249 } | 252 } |
250 | 253 |
251 /** | 254 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 return members; | 316 return members; |
314 } | 317 } |
315 | 318 |
316 final splitName = name.split('.'); | 319 final splitName = name.split('.'); |
317 if (splitName.length != 2) { | 320 if (splitName.length != 2) { |
318 print('Warning: invalid member name ${name}'); | 321 print('Warning: invalid member name ${name}'); |
319 return new Set(); | 322 return new Set(); |
320 } | 323 } |
321 var typeName = splitName[0]; | 324 var typeName = splitName[0]; |
322 if (typeName == 'Window') typeName = 'DOMWindow'; | 325 if (typeName == 'Window') typeName = 'DOMWindow'; |
323 final type = world.dom.types[typeName]; | 326 final type = dom.types[typeName]; |
324 if (type == null) return new Set(); | 327 if (type == null) return new Set(); |
325 final member = type.members[splitName[1]]; | 328 final member = type.members[splitName[1]]; |
326 if (member == null) return new Set(); | 329 if (member == null) return new Set(); |
327 return new Set.from([member]); | 330 return new Set.from([member]); |
328 } | 331 } |
329 | 332 |
330 /** | 333 /** |
331 * Returns the `dart:dom` [Member]s that are referred to in [stmt]. This only | 334 * Returns the `dart:dom` [Member]s that are referred to in [stmt]. This only |
332 * extracts references from relatively simple statements; methods containing | 335 * extracts references from relatively simple statements; methods containing |
333 * more complex wrappers should be manually annotated with `@domName`. | 336 * more complex wrappers should be manually annotated with `@domName`. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 Map<String, String> _getTags(String comment) { | 428 Map<String, String> _getTags(String comment) { |
426 if (comment == null) return const <String>{}; | 429 if (comment == null) return const <String>{}; |
427 final re = new RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); | 430 final re = new RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); |
428 final tags = <String>{}; | 431 final tags = <String>{}; |
429 for (var m in re.allMatches(comment.trim())) { | 432 for (var m in re.allMatches(comment.trim())) { |
430 tags[m[1]] = m[2]; | 433 tags[m[1]] = m[2]; |
431 } | 434 } |
432 return tags; | 435 return tags; |
433 } | 436 } |
434 } | 437 } |
OLD | NEW |