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

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

Issue 10918063: Remove dom_deprecated from everywhere but lib/dom and lib/html (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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 | « utils/apidoc/html_diff.dart ('k') | 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
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
8 * renamed to `dart:html` methods without changing their semantics,
9 * and `dart:dom_deprecated` methods that have been removed in
10 * `dart:html`. As a heuristic, a `dart:html` method doesn't change
11 * the semantics of the corresponding `dart:dom_deprecated` method if
12 * it's the only corresponding HTML method and it has the
13 * corresponding return type.
14 *
15 * The format of the output is as follows:
16 *
17 * {
18 * "renamed": { domName: htmlName, ... },
19 * "removed": [name, ...]
20 * }
21 *
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
24 * `MediaElement.get:textTracks`.
25 */
26 #library('html_diff_dump');
27
28 #import('dart:json');
29 #import('dart:io');
30 #import('html_diff.dart');
31 #import('../../pkg/dartdoc/mirrors/mirrors.dart');
32 #import('../../pkg/dartdoc/mirrors/mirrors_util.dart');
33
34 HtmlDiff diff;
35
36 /** Whether or not a domType represents the same type as an htmlType. */
37 bool sameType(MemberMirror domMember, MemberMirror htmlMember) {
38 TypeMirror domType = domMember is FieldMirror
39 ? domMember.type
40 : domMember.returnType;
41 TypeMirror htmlType = htmlMember is FieldMirror
42 ? htmlMember.type
43 : htmlMember.returnType;
44 if (domType.isVoid || htmlType.isVoid) {
45 return domType.isVoid && htmlType.isVoid;
46 }
47
48 final htmlTypes = diff.domTypesToHtml[domType.qualifiedName];
49 return htmlTypes != null && htmlTypes.some((t) => t == htmlType);
50 }
51
52 /** Returns the name of a member, including `get:` if it's a field. */
53 String memberName(MemberMirror m) => m.simpleName;
54
55 /**
56 * Returns a string describing the name of a member. If [type] is passed, it's
57 * used in place of the member's real type name.
58 */
59 String memberDesc(MemberMirror m, [ObjectMirror type = null]) {
60 if (type == null) type = m.surroundingDeclaration;
61 return '${type.simpleName}.${memberName(m)}';
62 }
63
64 /**
65 * Same as [memberDesc], but if [m] is a `dart:dom_deprecated` type
66 * its `dart:html` typename is used instead.
67 */
68 String htmlishMemberDesc(MemberMirror m) {
69 var type = m.surroundingDeclaration;
70 final htmlTypes = diff.domTypesToHtml[type.qualifiedName];
71 if (htmlTypes != null && htmlTypes.length == 1) {
72 type = htmlTypes.iterator().next();
73 }
74 return memberDesc(m, type);
75 }
76
77 /**
78 * Add an entry to the map of `dart:dom_deprecated` names to
79 * `dart:html` names if [domMember] was renamed to [htmlMembers] with
80 * the same semantics.
81 */
82 void maybeAddRename(Map<String, String> renamed,
83 MemberMirror domMember,
84 Collection<MemberMirror> htmlMembers) {
85 if (htmlMembers.length != 1) return;
86 final htmlMember = htmlMembers.iterator().next();
87 if (memberName(domMember) != memberName(htmlMember) &&
88 sameType(domMember, htmlMember)) {
89 renamed[memberDesc(domMember)] = memberDesc(htmlMember);
90 }
91 }
92
93 void main() {
94 var libPath = const Path('../../');
95 HtmlDiff.initialize(libPath);
96 diff = new HtmlDiff();
97 diff.run();
98
99 final renamed = <String, String>{};
100 diff.domToHtml.forEach((MemberMirror domMember,
101 Set<MemberMirror> htmlMembers) {
102 maybeAddRename(renamed, domMember, htmlMembers);
103 });
104
105 final removed = <String>[];
106
107 for (InterfaceMirror type in HtmlDiff.dom.types.getValues()) {
108 if (type.declaredMembers.getValues().every((m) =>
109 !diff.domToHtml.containsKey(m))) {
110 removed.add('${type.simpleName}.*');
111 } else {
112 for (MemberMirror member in type.declaredMembers.getValues()) {
113 if (!diff.domToHtml.containsKey(member)) {
114 removed.add(htmlishMemberDesc(member));
115 }
116 }
117 }
118 }
119
120 print(JSON.stringify({'renamed': renamed, 'removed': removed}));
121 }
OLDNEW
« no previous file with comments | « utils/apidoc/html_diff.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698