OLD | NEW |
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 for printing a JSON dump of HTML diff data. In particular, | 6 * A script for printing a JSON dump of HTML diff data. In particular, |
7 * this lists a map of `dart:dom_deprecated` methods that have been | 7 * this lists a map of `dart:dom_deprecated` methods that have been |
8 * renamed to `dart:html` methods without changing their semantics, | 8 * renamed to `dart:html` methods without changing their semantics, |
9 * and `dart:dom_deprecated` methods that have been removed in | 9 * and `dart:dom_deprecated` methods that have been removed in |
10 * `dart:html`. As a heuristic, a `dart:html` method doesn't change | 10 * `dart:html`. As a heuristic, a `dart:html` method doesn't change |
11 * the semantics of the corresponding `dart:dom_deprecated` method if | 11 * the semantics of the corresponding `dart:dom_deprecated` method if |
12 * it's the only corresponding HTML method and it has the | 12 * it's the only corresponding HTML method and it has the |
13 * corresponding return type. | 13 * corresponding return type. |
14 * | 14 * |
15 * The format of the output is as follows: | 15 * The format of the output is as follows: |
16 * | 16 * |
17 * { | 17 * { |
18 * "renamed": { domName: htmlName, ... }, | 18 * "renamed": { domName: htmlName, ... }, |
19 * "removed": [name, ...] | 19 * "removed": [name, ...] |
20 * } | 20 * } |
21 * | 21 * |
22 * Note that the removed members are listed with the names they would have in | 22 * Note that the removed members are listed with the names they would have in |
23 * HTML where possible; e.g. `HTMLMediaElement.get:textTracks` is listed as | 23 * HTML where possible; e.g. `HTMLMediaElement.get:textTracks` is listed as |
24 * `MediaElement.get:textTracks`. | 24 * `MediaElement.get:textTracks`. |
25 */ | 25 */ |
26 #library('html_diff_dump'); | 26 #library('html_diff_dump'); |
27 | 27 |
28 #import('dart:json'); | 28 #import('dart:json'); |
29 #import('html_diff.dart'); | 29 #import('html_diff.dart'); |
30 #import('../../frog/lang.dart'); | 30 #import('../../lib/dartdoc/mirrors/mirrors.dart'); |
| 31 #import('../../lib/dartdoc/mirrors/mirrors_util.dart'); |
31 | 32 |
32 HtmlDiff diff; | 33 HtmlDiff diff; |
33 | 34 |
34 /** Whether or not a domType represents the same type as an htmlType. */ | 35 /** Whether or not a domType represents the same type as an htmlType. */ |
35 bool sameType(Type domType, Type htmlType) { | 36 bool sameType(MemberMirror domMember, MemberMirror htmlMember) { |
| 37 TypeMirror domType = domMember is FieldMirror |
| 38 ? domMember.type() |
| 39 : domMember.returnType(); |
| 40 TypeMirror htmlType = htmlMember is FieldMirror |
| 41 ? htmlMember.type() |
| 42 : htmlMember.returnType(); |
36 if (domType.isVoid || htmlType.isVoid) { | 43 if (domType.isVoid || htmlType.isVoid) { |
37 return domType.isVoid && htmlType.isVoid; | 44 return domType.isVoid && htmlType.isVoid; |
38 } | 45 } |
39 | 46 |
40 final htmlTypes = diff.domTypesToHtml[domType]; | 47 final htmlTypes = diff.domTypesToHtml[domType.qualifiedName()]; |
41 return htmlTypes != null && htmlTypes.some((t) => t == htmlType); | 48 return htmlTypes != null && htmlTypes.some((t) => t == htmlType); |
42 } | 49 } |
43 | 50 |
44 /** Returns the name of a member, including `get:` if it's a field. */ | 51 /** Returns the name of a member, including `get:` if it's a field. */ |
45 String memberName(Member m) => m is FieldMember ? 'get:${m.name}' : m.name; | 52 String memberName(MemberMirror m) => m.simpleName(); |
46 | 53 |
47 /** | 54 /** |
48 * Returns a string describing the name of a member. If [type] is passed, it's | 55 * Returns a string describing the name of a member. If [type] is passed, it's |
49 * used in place of the member's real type name. | 56 * used in place of the member's real type name. |
50 */ | 57 */ |
51 String memberDesc(Member m, [Type type = null]) { | 58 String memberDesc(MemberMirror m, [ObjectMirror type = null]) { |
52 if (type == null) type = m.declaringType; | 59 if (type == null) type = m.surroundingDeclaration(); |
53 return '${type.name}.${memberName(m)}'; | 60 return '${type.simpleName()}.${memberName(m)}'; |
54 } | 61 } |
55 | 62 |
56 /** | 63 /** |
57 * Same as [memberDesc], but if [m] is a `dart:dom_deprecated` type | 64 * Same as [memberDesc], but if [m] is a `dart:dom_deprecated` type |
58 * its `dart:html` typename is used instead. | 65 * its `dart:html` typename is used instead. |
59 */ | 66 */ |
60 String htmlishMemberDesc(Member m) { | 67 String htmlishMemberDesc(MemberMirror m) { |
61 var type = m.declaringType; | 68 var type = m.surroundingDeclaration(); |
62 final htmlTypes = diff.domTypesToHtml[type]; | 69 final htmlTypes = diff.domTypesToHtml[type.qualifiedName()]; |
63 if (htmlTypes != null && htmlTypes.length == 1) { | 70 if (htmlTypes != null && htmlTypes.length == 1) { |
64 type = htmlTypes.iterator().next(); | 71 type = htmlTypes.iterator().next(); |
65 } | 72 } |
66 return memberDesc(m, type); | 73 return memberDesc(m, type); |
67 } | 74 } |
68 | 75 |
69 bool isGetter(Member member) => member.name.startsWith('get:'); | |
70 bool isSetter(Member member) => member.name.startsWith('set:'); | |
71 | |
72 /** | 76 /** |
73 * Add an entry to the map of `dart:dom_deprecated` names to | 77 * Add an entry to the map of `dart:dom_deprecated` names to |
74 * `dart:html` names if [domMember] was renamed to [htmlMembers] with | 78 * `dart:html` names if [domMember] was renamed to [htmlMembers] with |
75 * the same semantics. | 79 * the same semantics. |
76 */ | 80 */ |
77 void maybeAddRename(Map<String, String> renamed, Member domMember, | 81 void maybeAddRename(Map<String, String> renamed, |
78 Collection<Member> htmlMembers) { | 82 MemberMirror domMember, |
| 83 Collection<MemberMirror> htmlMembers) { |
79 if (htmlMembers.length != 1) return; | 84 if (htmlMembers.length != 1) return; |
80 final htmlMember = htmlMembers.iterator().next(); | 85 final htmlMember = htmlMembers.iterator().next(); |
81 if (memberName(domMember) != memberName(htmlMember) && | 86 if (memberName(domMember) != memberName(htmlMember) && |
82 sameType(domMember.returnType, htmlMember.returnType)) { | 87 sameType(domMember, htmlMember)) { |
83 renamed[memberDesc(domMember)] = memberDesc(htmlMember); | 88 renamed[memberDesc(domMember)] = memberDesc(htmlMember); |
84 } | 89 } |
85 } | 90 } |
86 | 91 |
87 void main() { | 92 void main() { |
88 var files = new NodeFileSystem(); | 93 var libPath = '../../'; |
89 parseOptions('../../frog', [] /* args */, files); | 94 HtmlDiff.initialize(libPath); |
90 initializeWorld(files); | |
91 | |
92 HtmlDiff.initialize(); | |
93 diff = new HtmlDiff(); | 95 diff = new HtmlDiff(); |
94 diff.run(); | 96 diff.run(); |
95 | 97 |
96 final renamed = <String>{}; | 98 final renamed = <String>{}; |
97 diff.domToHtml.forEach((domMember, htmlMembers) { | 99 diff.domToHtml.forEach((MemberMirror domMember, |
98 if (domMember is PropertyMember) { | 100 Set<MemberMirror> htmlMembers) { |
99 if (domMember.canGet) { | 101 maybeAddRename(renamed, domMember, htmlMembers); |
100 maybeAddRename(renamed, domMember.getter, htmlMembers.filter(isGetter)); | |
101 } | |
102 if (domMember.canSet) { | |
103 maybeAddRename(renamed, domMember.setter, htmlMembers.filter(isSetter)); | |
104 } | |
105 } else { | |
106 maybeAddRename(renamed, domMember, htmlMembers); | |
107 return; | |
108 } | |
109 }); | 102 }); |
110 | 103 |
111 final removed = <Set>[]; | 104 final removed = <String>[]; |
112 for (final type in world.libraries['dart:dom_deprecated'].types.getValues()) { | 105 |
113 if (type.members.getValues().every((m) => | 106 for (InterfaceMirror type in HtmlDiff.dom.types().getValues()) { |
| 107 if (type.declaredMembers().getValues().every((m) => |
114 !diff.domToHtml.containsKey(m))) { | 108 !diff.domToHtml.containsKey(m))) { |
115 removed.add('${type.name}.*'); | 109 removed.add('${type.simpleName()}.*'); |
116 } else { | 110 } else { |
117 for (final member in type.members.getValues()) { | 111 for (MemberMirror member in type.declaredMembers().getValues()) { |
118 if (!diff.domToHtml.containsKey(member)) { | 112 if (!diff.domToHtml.containsKey(member)) { |
119 if (member is PropertyMember) { | |
120 if (member.canGet) removed.add(htmlishMemberDesc(member.getter)); | |
121 if (member.canSet) removed.add(htmlishMemberDesc(member.setter)); | |
122 } else { | |
123 removed.add(htmlishMemberDesc(member)); | 113 removed.add(htmlishMemberDesc(member)); |
124 } | |
125 } else if (member is PropertyMember) { | |
126 final htmlMembers = diff.domToHtml[member]; | |
127 if (member.canGet && !htmlMembers.some((m) => m.name.startsWith('get:'
))) { | |
128 removed.add(htmlishMemberDesc(member.getter)); | |
129 } | |
130 if (member.canSet && !htmlMembers.some((m) => m.name.startsWith('set:'
))) { | |
131 removed.add(htmlishMemberDesc(member.setter)); | |
132 } | |
133 } | 114 } |
134 } | 115 } |
135 } | 116 } |
136 } | 117 } |
137 | 118 |
138 print(JSON.stringify({'renamed': renamed, 'removed': removed})); | 119 print(JSON.stringify({'renamed': renamed, 'removed': removed})); |
139 } | 120 } |
OLD | NEW |