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

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

Issue 10823257: Refactored accessors in mirrors from methods to properties. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Missing updates Created 8 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 | Annotate | Revision Log
« no previous file with comments | « utils/apidoc/apidoc.dart ('k') | utils/apidoc/html_diff_dump.dart » ('j') | 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 /** 82 /**
83 * Perform static initialization of [world]. This should be run before 83 * Perform static initialization of [world]. This should be run before
84 * calling [HtmlDiff.run]. 84 * calling [HtmlDiff.run].
85 */ 85 */
86 static void initialize(Path libDir) { 86 static void initialize(Path libDir) {
87 _compilation = new Compilation.library( 87 _compilation = new Compilation.library(
88 const <Path>[ 88 const <Path>[
89 const Path(DOM_LIBRARY_NAME), 89 const Path(DOM_LIBRARY_NAME),
90 const Path(HTML_LIBRARY_NAME) 90 const Path(HTML_LIBRARY_NAME)
91 ], libDir); 91 ], libDir);
92 _mirrors = _compilation.mirrors(); 92 _mirrors = _compilation.mirrors;
93 93
94 // Find 'dart:dom_deprecated' by its library tag 'dom'. 94 // Find 'dart:dom_deprecated' by its library tag 'dom'.
95 dom = findMirror(_mirrors.libraries(), DOM_LIBRARY_NAME); 95 dom = findMirror(_mirrors.libraries, DOM_LIBRARY_NAME);
96 } 96 }
97 97
98 HtmlDiff([bool printWarnings = false]) : 98 HtmlDiff([bool printWarnings = false]) :
99 _printWarnings = printWarnings, 99 _printWarnings = printWarnings,
100 domToHtml = new Map<MemberMirror, Set<MemberMirror>>(), 100 domToHtml = new Map<MemberMirror, Set<MemberMirror>>(),
101 htmlToDom = new Map<String, Set<MemberMirror>>(), 101 htmlToDom = new Map<String, Set<MemberMirror>>(),
102 domTypesToHtml = new Map<String, Set<InterfaceMirror>>(), 102 domTypesToHtml = new Map<String, Set<InterfaceMirror>>(),
103 htmlTypesToDom = new Map<String, Set<InterfaceMirror>>(), 103 htmlTypesToDom = new Map<String, Set<InterfaceMirror>>(),
104 comments = new CommentMap(); 104 comments = new CommentMap();
105 105
106 void warn(String s) { 106 void warn(String s) {
107 if (_printWarnings) { 107 if (_printWarnings) {
108 print('Warning: $s'); 108 print('Warning: $s');
109 } 109 }
110 } 110 }
111 111
112 /** 112 /**
113 * Computes the `dart:dom_deprecated` to `dart:html` mapping, and 113 * Computes the `dart:dom_deprecated` to `dart:html` mapping, and
114 * places it in [domToHtml], [htmlToDom], [domTypesToHtml], and 114 * places it in [domToHtml], [htmlToDom], [domTypesToHtml], and
115 * [htmlTypesToDom]. Before this is run, Frog should be initialized 115 * [htmlTypesToDom]. Before this is run, Frog should be initialized
116 * (via [parseOptions] and [initializeWorld]) and 116 * (via [parseOptions] and [initializeWorld]) and
117 * [HtmlDiff.initialize] should be called. 117 * [HtmlDiff.initialize] should be called.
118 */ 118 */
119 void run() { 119 void run() {
120 LibraryMirror htmlLib = findMirror(_mirrors.libraries(), HTML_LIBRARY_NAME); 120 LibraryMirror htmlLib = findMirror(_mirrors.libraries, HTML_LIBRARY_NAME);
121 if (htmlLib === null) { 121 if (htmlLib === null) {
122 warn('Could not find $HTML_LIBRARY_NAME'); 122 warn('Could not find $HTML_LIBRARY_NAME');
123 return; 123 return;
124 } 124 }
125 for (InterfaceMirror htmlType in htmlLib.types().getValues()) { 125 for (InterfaceMirror htmlType in htmlLib.types.getValues()) {
126 final domTypes = htmlToDomTypes(htmlType); 126 final domTypes = htmlToDomTypes(htmlType);
127 if (domTypes.isEmpty()) continue; 127 if (domTypes.isEmpty()) continue;
128 128
129 htmlTypesToDom.putIfAbsent(htmlType.qualifiedName(), 129 htmlTypesToDom.putIfAbsent(htmlType.qualifiedName,
130 () => new Set()).addAll(domTypes); 130 () => new Set()).addAll(domTypes);
131 domTypes.forEach((t) => 131 domTypes.forEach((t) =>
132 domTypesToHtml.putIfAbsent(t.qualifiedName(), 132 domTypesToHtml.putIfAbsent(t.qualifiedName,
133 () => new Set()).add(htmlType)); 133 () => new Set()).add(htmlType));
134 134
135 htmlType.declaredMembers().forEach( 135 htmlType.declaredMembers.forEach(
136 (_, m) => _addMemberDiff(m, domTypes)); 136 (_, m) => _addMemberDiff(m, domTypes));
137 } 137 }
138 } 138 }
139 139
140 /** 140 /**
141 * Records the `dart:dom_deprecated` to `dart:html` mapping for 141 * Records the `dart:dom_deprecated` to `dart:html` mapping for
142 * [implMember] (from `dart:html`). [domTypes] are the 142 * [implMember] (from `dart:html`). [domTypes] are the
143 * `dart:dom_deprecated` [Type]s that correspond to [implMember]'s 143 * `dart:dom_deprecated` [Type]s that correspond to [implMember]'s
144 * defining [Type]. 144 * defining [Type].
145 */ 145 */
146 void _addMemberDiff(MemberMirror htmlMember, List<TypeMirror> domTypes) { 146 void _addMemberDiff(MemberMirror htmlMember, List<TypeMirror> domTypes) {
147 var domMembers = htmlToDomMembers(htmlMember, domTypes); 147 var domMembers = htmlToDomMembers(htmlMember, domTypes);
148 if (htmlMember == null && !domMembers.isEmpty()) { 148 if (htmlMember == null && !domMembers.isEmpty()) {
149 warn('$HTML_LIBRARY_NAME member ' 149 warn('$HTML_LIBRARY_NAME member '
150 '${htmlMember.surroundingDeclaration().simpleName()}.' 150 '${htmlMember.surroundingDeclaration.simpleName}.'
151 '${htmlMember.simpleName()} has no corresponding ' 151 '${htmlMember.simpleName} has no corresponding '
152 '$HTML_LIBRARY_NAME member.'); 152 '$HTML_LIBRARY_NAME member.');
153 } 153 }
154 154
155 if (htmlMember == null) return; 155 if (htmlMember == null) return;
156 if (!domMembers.isEmpty()) { 156 if (!domMembers.isEmpty()) {
157 htmlToDom[htmlMember.qualifiedName()] = domMembers; 157 htmlToDom[htmlMember.qualifiedName] = domMembers;
158 } 158 }
159 domMembers.forEach((m) => 159 domMembers.forEach((m) =>
160 domToHtml.putIfAbsent(m, () => new Set()).add(htmlMember)); 160 domToHtml.putIfAbsent(m, () => new Set()).add(htmlMember));
161 } 161 }
162 162
163 /** 163 /**
164 * Returns the `dart:dom_deprecated` [Type]s that correspond to 164 * Returns the `dart:dom_deprecated` [Type]s that correspond to
165 * [htmlType] from `dart:html`. This can be the empty list if no 165 * [htmlType] from `dart:html`. This can be the empty list if no
166 * correspondence is found. 166 * correspondence is found.
167 */ 167 */
168 List<InterfaceMirror> htmlToDomTypes(InterfaceMirror htmlType) { 168 List<InterfaceMirror> htmlToDomTypes(InterfaceMirror htmlType) {
169 if (htmlType.simpleName() == null) return []; 169 if (htmlType.simpleName == null) return [];
170 final tags = _getTags(comments.find(htmlType.location())); 170 final tags = _getTags(comments.find(htmlType.location));
171 if (tags.containsKey('domName')) { 171 if (tags.containsKey('domName')) {
172 var domNames = <String>[]; 172 var domNames = <String>[];
173 for (var s in tags['domName'].split(',')) { 173 for (var s in tags['domName'].split(',')) {
174 domNames.add(s.trim()); 174 domNames.add(s.trim());
175 } 175 }
176 if (domNames.length == 1 && domNames[0] == 'none') return []; 176 if (domNames.length == 1 && domNames[0] == 'none') return [];
177 var domTypes = <InterfaceMirror>[]; 177 var domTypes = <InterfaceMirror>[];
178 for (var domName in domNames) { 178 for (var domName in domNames) {
179 final domType = findMirror(dom.types(), domName); 179 final domType = findMirror(dom.types, domName);
180 if (domType == null) { 180 if (domType == null) {
181 warn('no $DOM_LIBRARY_NAME type named $domName'); 181 warn('no $DOM_LIBRARY_NAME type named $domName');
182 } else { 182 } else {
183 domTypes.add(domType); 183 domTypes.add(domType);
184 } 184 }
185 } 185 }
186 return domTypes; 186 return domTypes;
187 } 187 }
188 return <InterfaceMirror>[]; 188 return <InterfaceMirror>[];
189 } 189 }
190 190
191 /** 191 /**
192 * Returns the `dart:dom_deprecated` [Member]s that correspond to 192 * Returns the `dart:dom_deprecated` [Member]s that correspond to
193 * [htmlMember] from `dart:html`. This can be the empty set if no 193 * [htmlMember] from `dart:html`. This can be the empty set if no
194 * correspondence is found. [domTypes] are the 194 * correspondence is found. [domTypes] are the
195 * `dart:dom_deprecated` [Type]s that correspond to [implMember]'s 195 * `dart:dom_deprecated` [Type]s that correspond to [implMember]'s
196 * defining [Type]. 196 * defining [Type].
197 */ 197 */
198 Set<MemberMirror> htmlToDomMembers(MemberMirror htmlMember, 198 Set<MemberMirror> htmlToDomMembers(MemberMirror htmlMember,
199 List<InterfaceMirror> domTypes) { 199 List<InterfaceMirror> domTypes) {
200 if (htmlMember.isPrivate) return new Set(); 200 if (htmlMember.isPrivate) return new Set();
201 final tags = _getTags(comments.find(htmlMember.location())); 201 final tags = _getTags(comments.find(htmlMember.location));
202 if (tags.containsKey('domName')) { 202 if (tags.containsKey('domName')) {
203 var domNames = <String>[]; 203 var domNames = <String>[];
204 for (var s in tags['domName'].split(',')) { 204 for (var s in tags['domName'].split(',')) {
205 domNames.add(s.trim()); 205 domNames.add(s.trim());
206 } 206 }
207 if (domNames.length == 1 && domNames[0] == 'none') return new Set(); 207 if (domNames.length == 1 && domNames[0] == 'none') return new Set();
208 final members = new Set(); 208 final members = new Set();
209 domNames.forEach((name) { 209 domNames.forEach((name) {
210 var nameMembers = _membersFromName(name, domTypes); 210 var nameMembers = _membersFromName(name, domTypes);
211 if (nameMembers.isEmpty()) { 211 if (nameMembers.isEmpty()) {
212 if (name.contains('.')) { 212 if (name.contains('.')) {
213 warn('no member $name'); 213 warn('no member $name');
214 } else { 214 } else {
215 final options = <String>[]; 215 final options = <String>[];
216 for (var t in domTypes) { 216 for (var t in domTypes) {
217 options.add('${t.simpleName()}.${name}'); 217 options.add('${t.simpleName}.${name}');
218 } 218 }
219 Strings.join(options, ' or '); 219 Strings.join(options, ' or ');
220 warn('no member $options'); 220 warn('no member $options');
221 } 221 }
222 } 222 }
223 members.addAll(nameMembers); 223 members.addAll(nameMembers);
224 }); 224 });
225 return members; 225 return members;
226 } 226 }
227 227
(...skipping 10 matching lines...) Expand all
238 */ 238 */
239 Set<MemberMirror> _membersFromName(String name, 239 Set<MemberMirror> _membersFromName(String name,
240 List<InterfaceMirror> defaultTypes) { 240 List<InterfaceMirror> defaultTypes) {
241 if (!name.contains('.', 0)) { 241 if (!name.contains('.', 0)) {
242 if (defaultTypes.isEmpty()) { 242 if (defaultTypes.isEmpty()) {
243 warn('no default type for ${name}'); 243 warn('no default type for ${name}');
244 return new Set(); 244 return new Set();
245 } 245 }
246 final members = new Set<MemberMirror>(); 246 final members = new Set<MemberMirror>();
247 defaultTypes.forEach((t) { 247 defaultTypes.forEach((t) {
248 MemberMirror member = findMirror(t.declaredMembers(), name); 248 MemberMirror member = findMirror(t.declaredMembers, name);
249 if (member !== null) { 249 if (member !== null) {
250 members.add(member); 250 members.add(member);
251 } 251 }
252 }); 252 });
253 return members; 253 return members;
254 } 254 }
255 255
256 final splitName = name.split('.'); 256 final splitName = name.split('.');
257 if (splitName.length != 2) { 257 if (splitName.length != 2) {
258 warn('invalid member name ${name}'); 258 warn('invalid member name ${name}');
259 return new Set(); 259 return new Set();
260 } 260 }
261 261
262 var typeName = splitName[0]; 262 var typeName = splitName[0];
263 263
264 InterfaceMirror type = findMirror(dom.types(), typeName); 264 InterfaceMirror type = findMirror(dom.types, typeName);
265 if (type == null) return new Set(); 265 if (type == null) return new Set();
266 266
267 MemberMirror member = findMirror(type.declaredMembers(), splitName[1]); 267 MemberMirror member = findMirror(type.declaredMembers, splitName[1]);
268 if (member == null) return new Set(); 268 if (member == null) return new Set();
269 269
270 return new Set.from([member]); 270 return new Set.from([member]);
271 } 271 }
272 272
273 /** 273 /**
274 * Extracts a [Map] from tag names to values from [comment], which is parsed 274 * Extracts a [Map] from tag names to values from [comment], which is parsed
275 * from a Dart source file via dartdoc. Tags are of the form `@NAME VALUE`, 275 * from a Dart source file via dartdoc. Tags are of the form `@NAME VALUE`,
276 * where `NAME` is alphabetic and `VALUE` can contain any character other than 276 * where `NAME` is alphabetic and `VALUE` can contain any character other than
277 * `;`. Multiple tags can be separated by semicolons. 277 * `;`. Multiple tags can be separated by semicolons.
278 * 278 *
279 * At time of writing, the only tag that's used is `@domName`. 279 * At time of writing, the only tag that's used is `@domName`.
280 */ 280 */
281 Map<String, String> _getTags(String comment) { 281 Map<String, String> _getTags(String comment) {
282 if (comment == null) return const <String>{}; 282 if (comment == null) return const <String>{};
283 final re = const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"); 283 final re = const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)");
284 final tags = <String>{}; 284 final tags = <String>{};
285 for (var m in re.allMatches(comment.trim())) { 285 for (var m in re.allMatches(comment.trim())) {
286 tags[m[1]] = m[2]; 286 tags[m[1]] = m[2];
287 } 287 }
288 return tags; 288 return tags;
289 } 289 }
290 } 290 }
OLDNEW
« no previous file with comments | « utils/apidoc/apidoc.dart ('k') | utils/apidoc/html_diff_dump.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698