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

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

Issue 10701091: Dartdoc and Apidoc updated to use dart2js through the mirror system. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed cf. rnystrom's comments. Created 8 years, 5 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
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 * This generates the reference documentation for the core libraries that come 6 * This generates the reference documentation for the core libraries that come
7 * with dart. It is built on top of dartdoc, which is a general-purpose library 7 * with dart. It is built on top of dartdoc, which is a general-purpose library
8 * for generating docs from any Dart code. This library extends that to include 8 * for generating docs from any Dart code. This library extends that to include
9 * additional information and styling specific to our standard library. 9 * additional information and styling specific to our standard library.
10 * 10 *
11 * Usage: 11 * Usage:
12 * 12 *
13 * $ dart apidoc.dart [--out=<output directory>] 13 * $ dart apidoc.dart [--out=<output directory>]
14 */ 14 */
15 15
16 #library('apidoc'); 16 #library('apidoc');
17 17
18 #import('dart:io'); 18 #import('dart:io');
19 #import('dart:json'); 19 #import('dart:json');
20 #import('html_diff.dart'); 20 #import('html_diff.dart');
21 21 #import('../../lib/dartdoc/mirrors/mirrors.dart');
22 #import('../../lib/dartdoc/frog/lang.dart'); 22 #import('../../lib/dartdoc/mirrors/mirrors_util.dart');
23 #import('../../lib/dartdoc/frog/file_system_vm.dart');
24 #import('../../lib/dartdoc/frog/file_system.dart');
25 #import('../../lib/dartdoc/dartdoc.dart', prefix: 'doc'); 23 #import('../../lib/dartdoc/dartdoc.dart', prefix: 'doc');
26 24
27 HtmlDiff _diff; 25 HtmlDiff _diff;
28 26
29 final GET_PREFIX = 'get:';
30
31 void main() { 27 void main() {
32 final args = new Options().arguments; 28 final args = new Options().arguments;
33 29
34 int mode = doc.MODE_STATIC; 30 int mode = doc.MODE_STATIC;
35 String outputDir = 'docs'; 31 String outputDir = 'docs';
36 String compilerPath; 32 String compilerPath;
37 bool generateAppCache = false; 33 bool generateAppCache = false;
38 34
39 // Parse the command-line arguments. 35 // Parse the command-line arguments.
40 for (int i = 0; i < args.length; i++) { 36 for (int i = 0; i < args.length; i++) {
(...skipping 18 matching lines...) Expand all
59 } else if (arg.startsWith('--compiler=')) { 55 } else if (arg.startsWith('--compiler=')) {
60 compilerPath = arg.substring('--compiler='.length); 56 compilerPath = arg.substring('--compiler='.length);
61 } else { 57 } else {
62 print('Unknown option: $arg'); 58 print('Unknown option: $arg');
63 return; 59 return;
64 } 60 }
65 break; 61 break;
66 } 62 }
67 } 63 }
68 64
69 final frogPath = joinPaths(doc.scriptDir, '../../lib/dartdoc/frog/'); 65 final libPath = '${doc.scriptDir}/../../';
70
71 if (compilerPath === null) {
72 compilerPath
73 = Platform.operatingSystem == 'windows' ? 'dart2js.bat' : 'dart2js';
74 }
75 66
76 doc.cleanOutputDirectory(outputDir); 67 doc.cleanOutputDirectory(outputDir);
77 68
78 // Compile the client-side code to JS. 69 // Compile the client-side code to JS.
79 // TODO(bob): Right path. 70 // TODO(bob): Right path.
80 71
81 final clientScript = (mode == doc.MODE_STATIC) ? 72 final clientScript = (mode == doc.MODE_STATIC) ?
82 'static' : 'live-nav'; 73 'static' : 'live-nav';
83 final Future scriptCompiled = doc.compileScript(compilerPath, 74 doc.compileScript(
84 '${doc.scriptDir}/../../lib/dartdoc/client-$clientScript.dart', 75 '${doc.scriptDir}/../../lib/dartdoc/client-$clientScript.dart',
85 '${outputDir}/client-$clientScript.js'); 76 '${outputDir}/client-$clientScript.js');
86 77
87 // TODO(rnystrom): Use platform-specific path separator. 78 // TODO(rnystrom): Use platform-specific path separator.
88 // The basic dartdoc-provided static content. 79 // The basic dartdoc-provided static content.
89 final Future copiedStatic = doc.copyFiles( 80 final Future copiedStatic = doc.copyFiles(
90 '${doc.scriptDir}/../../lib/dartdoc/static', outputDir); 81 '${doc.scriptDir}/../../lib/dartdoc/static', outputDir);
91 82
92 // The apidoc-specific static content. 83 // The apidoc-specific static content.
93 final Future copiedApiDocStatic = doc.copyFiles('${doc.scriptDir}/static', 84 final Future copiedApiDocStatic = doc.copyFiles('${doc.scriptDir}/static',
94 outputDir); 85 outputDir);
95 86
96 var files = new VMFileSystem();
97 parseOptions(frogPath, ['', '', '--libdir=../../lib'], files);
98 initializeWorld(files);
99
100 print('Parsing MDN data...'); 87 print('Parsing MDN data...');
101 final mdnFile = new File('${doc.scriptDir}/mdn/database.json'); 88 final mdnFile = new File('${doc.scriptDir}/mdn/database.json');
102 final mdn = JSON.parse(mdnFile.readAsTextSync()); 89 final mdn = JSON.parse(mdnFile.readAsTextSync());
103 90
104 print('Cross-referencing dart:html...'); 91 print('Cross-referencing dart:html...');
105 HtmlDiff.initialize(); 92 HtmlDiff.initialize(libPath);
106 _diff = new HtmlDiff(printWarnings:false); 93 _diff = new HtmlDiff(printWarnings:false);
107 _diff.run(); 94 _diff.run();
108 95
109 // Process handwritten HTML documentation. 96 // Process handwritten HTML documentation.
110 world.reset();
111 world.getOrAddLibrary('${doc.scriptDir}/../../lib/html/doc/html.dartdoc');
112 world.process();
113 final htmldoc = new Htmldoc(); 97 final htmldoc = new Htmldoc();
114 htmldoc.document(); 98 htmldoc.documentLibraries(
99 <String>['${doc.scriptDir}/../../lib/html/doc/html.dartdoc'],
100 libPath);
115 print('Processing handwritten HTML documentation...'); 101 print('Processing handwritten HTML documentation...');
116 102
117 // Process libraries. 103 // Process libraries.
118 104
119 // Note, Frog has global internal state. We need to clear away the
120 // HTML documentation classes above first.
121 world.reset();
122
123 // Add all of the core libraries. 105 // Add all of the core libraries.
124 world.getOrAddLibrary('dart:core'); 106 var apidocLibraries = <String>[
125 world.getOrAddLibrary('dart:coreimpl'); 107 'dart:core',
126 world.getOrAddLibrary('dart:crypto'); 108 'dart:coreimpl',
127 world.getOrAddLibrary('dart:html'); 109 'dart:crypto',
128 world.getOrAddLibrary('dart:io'); 110 'dart:html',
129 world.getOrAddLibrary('dart:isolate'); 111 'dart:io',
130 world.getOrAddLibrary('dart:json'); 112 'dart:isolate',
131 world.getOrAddLibrary('${doc.scriptDir}/../../lib/math/math.dart'); 113 'dart:json',
132 world.getOrAddLibrary('${doc.scriptDir}/../../lib/unittest/unittest.dart'); 114 '${doc.scriptDir}/../../lib/math/math.dart',
133 world.getOrAddLibrary('${doc.scriptDir}/../../lib/i18n/intl.dart'); 115 '${doc.scriptDir}/../../lib/unittest/unittest.dart',
134 world.getOrAddLibrary('dart:uri'); 116 '${doc.scriptDir}/../../lib/i18n/intl.dart',
135 world.getOrAddLibrary('dart:utf'); 117 'dart:uri',
136 world.getOrAddLibrary('dart:web'); 118 'dart:utf',
137 world.process(); 119 'dart:web',
138 120 ];
139 print('Generating docs...'); 121 print('Generating docs...');
140 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache); 122 final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache);
123 // Select the libraries to include in the produced documentation:
124 apidoc.libraries = <String>[
125 'core',
126 'coreimpl',
127 'crypto',
128 'html',
129 'io',
130 'dart:isolate',
131 'json',
132 'math',
133 'unittest',
134 'intl',
135 'uri',
136 'utf',
137 'web',
138 ];
141 139
142 Futures.wait([scriptCompiled, copiedStatic, copiedApiDocStatic]).then((_) { 140 Futures.wait([copiedStatic, copiedApiDocStatic]).then((_) {
143 apidoc.document(); 141 apidoc.documentLibraries(apidocLibraries, libPath);
144 }); 142 });
145 } 143 }
146 144
147 /** 145 /**
148 * This class is purely here to scrape handwritten HTML documentation. 146 * This class is purely here to scrape handwritten HTML documentation.
149 * This scraped documentation will later be merged with the generated 147 * This scraped documentation will later be merged with the generated
150 * HTML library. 148 * HTML library.
151 */ 149 */
152 class Htmldoc extends doc.Dartdoc { 150 class Htmldoc extends doc.Dartdoc {
153 String libraryComment; 151 String libraryComment;
152
153 /**
154 * Map from qualified type names to comments.
155 */
154 Map<String, String> typeComments; 156 Map<String, String> typeComments;
155 Map<String, Map<String, String>> memberComments; 157
158 /**
159 * Map from qualified member names to comments.
160 */
161 Map<String, String> memberComments;
156 162
157 Htmldoc() { 163 Htmldoc() {
158 typeComments = new Map<String, String>(); 164 typeComments = new Map<String, String>();
159 memberComments = new Map<String, Map<String, String>>(); 165 memberComments = new Map<String, String>();
160 } 166 }
161 167
162 // Suppress any actual writing to file. This is only for analysis. 168 // Suppress any actual writing to file. This is only for analysis.
163 void endFile() { 169 void endFile() {
164 } 170 }
165 171
166 void write(String s) { 172 void write(String s) {
167 } 173 }
168 174
169 String getRecordedLibraryComment(Library library) { 175 String getRecordedLibraryComment(LibraryMirror library) {
170 if (library.name == 'html') { 176 if (library.simpleName() == 'html') {
171 return libraryComment; 177 return libraryComment;
172 } 178 }
173 return null; 179 return null;
174 } 180 }
175 181
176 String getRecordedTypeComment(Type type) { 182 String getRecordedTypeComment(TypeMirror type) {
177 if (type.library.name == 'html') { 183 if (typeComments.containsKey(type.qualifiedName())) {
178 if (typeComments.containsKey(type.name)) { 184 return typeComments[type.qualifiedName()];
179 return typeComments[type.name];
180 }
181 } 185 }
182 return null; 186 return null;
183 } 187 }
184 188
185 String getRecordedMemberComment(Member member) { 189 String getRecordedMemberComment(MemberMirror member) {
186 if (member.library.name == 'html') { 190 if (memberComments.containsKey(member.qualifiedName())) {
187 String typeName; 191 return memberComments[member.qualifiedName()];
188 if (member.declaringType != null) {
189 typeName = member.declaringType.name;
190 }
191 if (typeName == null) {
192 typeName = '';
193 }
194 if (memberComments.containsKey(typeName)) {
195 Map<String, String> memberMap = memberComments[typeName];
196 if (memberMap.containsKey(member.name)) {
197 return memberMap[member.name];
198 }
199 }
200 } 192 }
201 return null; 193 return null;
202 } 194 }
203 195
204 // These methods are subclassed and used for internal processing. 196 // These methods are subclassed and used for internal processing.
205 // Do not invoke outside of this class. 197 // Do not invoke outside of this class.
206 String getLibraryComment(Library library) { 198 String getLibraryComment(LibraryMirror library) {
207 String comment = super.getLibraryComment(library); 199 String comment = super.getLibraryComment(library);
208 libraryComment = comment; 200 libraryComment = comment;
209 return comment; 201 return comment;
210 } 202 }
211 203
212 String getTypeComment(Type type) { 204 String getTypeComment(TypeMirror type) {
213 String comment = super.getTypeComment(type); 205 String comment = super.getTypeComment(type);
214 recordTypeComment(type, comment); 206 recordTypeComment(type, comment);
215 return comment; 207 return comment;
216 } 208 }
217 209
218 String getMethodComment(MethodMember method) { 210 String getMethodComment(MethodMirror method) {
219 String comment = super.getMethodComment(method); 211 String comment = super.getMethodComment(method);
220 recordMemberComment(method, comment); 212 recordMemberComment(method, comment);
221 return comment; 213 return comment;
222 } 214 }
223 215
224 String getFieldComment(FieldMember field) { 216 String getFieldComment(FieldMirror field) {
225 String comment = super.getFieldComment(field); 217 String comment = super.getFieldComment(field);
226 recordMemberComment(field, comment); 218 recordMemberComment(field, comment);
227 return comment; 219 return comment;
228 } 220 }
229 221
230 void recordTypeComment(Type type, String comment) { 222 void recordTypeComment(TypeMirror type, String comment) {
231 if (comment != null && comment.contains('@domName')) { 223 if (comment != null && comment.contains('@domName')) {
232 // This is not a handwritten comment. 224 // This is not a handwritten comment.
233 return; 225 return;
234 } 226 }
235 typeComments[type.name] = comment; 227 typeComments[type.qualifiedName()] = comment;
236 } 228 }
237 229
238 void recordMemberComment(Member member, String comment) { 230 void recordMemberComment(MemberMirror member, String comment) {
239 if (comment != null && comment.contains('@domName')) { 231 if (comment != null && comment.contains('@domName')) {
240 // This is not a handwritten comment. 232 // This is not a handwritten comment.
241 return; 233 return;
242 } 234 }
243 String typeName = member.declaringType.name; 235 memberComments[member.qualifiedName()] = comment;
244 if (typeName == null)
245 typeName = '';
246 if (!memberComments.containsKey(typeName)) {
247 memberComments[typeName] = new Map<String, String>();
248 }
249 Map<String, String> memberMap = memberComments[typeName];
250 memberMap[member.name] = comment;
251 } 236 }
252 } 237 }
253 238
254 class Apidoc extends doc.Dartdoc { 239 class Apidoc extends doc.Dartdoc {
255 /** Big ball of JSON containing the scraped MDN documentation. */ 240 /** Big ball of JSON containing the scraped MDN documentation. */
256 final Map mdn; 241 final Map mdn;
257 242
258 final Htmldoc htmldoc; 243 final Htmldoc htmldoc;
259 244
260 static final disqusShortname = 'dartapidocs'; 245 static final disqusShortname = 'dartapidocs';
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 ga.type = "text/javascript"; ga.async = true; 330 ga.type = "text/javascript"; ga.async = true;
346 ga.src = ("https:" == document.location.protocol ? 331 ga.src = ("https:" == document.location.protocol ?
347 "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; 332 "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
348 var s = document.getElementsByTagName("script")[0]; 333 var s = document.getElementsByTagName("script")[0];
349 s.parentNode.insertBefore(ga, s); 334 s.parentNode.insertBefore(ga, s);
350 })(); 335 })();
351 </script> 336 </script>
352 '''); 337 ''');
353 } 338 }
354 339
355 void docIndexLibrary(Library library) { 340 void docIndexLibrary(LibraryMirror library) {
356 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't 341 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't
357 // want it in the docs. 342 // want it in the docs.
358 if (library.name == 'dart:nativewrappers') return; 343 if (library.simpleName() == 'dart:nativewrappers') return;
359 super.docIndexLibrary(library); 344 super.docIndexLibrary(library);
360 } 345 }
361 346
362 void docLibraryNavigationJson(Library library, Map libraries) { 347 void docLibraryNavigationJson(LibraryMirror library, Map libraryMap) {
363 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't 348 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't
364 // want it in the docs. 349 // want it in the docs.
365 if (library.name == 'dart:nativewrappers') return; 350 if (library.simpleName() == 'dart:nativewrappers') return;
366 super.docLibraryNavigationJson(library, libraries); 351 super.docLibraryNavigationJson(library, libraryMap);
367 } 352 }
368 353
369 void docLibrary(Library library) { 354 void docLibrary(LibraryMirror library) {
370 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't 355 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't
371 // want it in the docs. 356 // want it in the docs.
372 if (library.name == 'dart:nativewrappers') return; 357 if (library.simpleName() == 'dart:nativewrappers') return;
373 super.docLibrary(library); 358 super.docLibrary(library);
374 } 359 }
375 360
376 /** Override definition from parent class to strip out annotation tags. */ 361 /** Override definition from parent class to strip out annotation tags. */
377 String commentToHtml(String comment) { 362 String commentToHtml(String comment) {
378 return super.commentToHtml( 363 return super.commentToHtml(
379 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); 364 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), ''));
380 } 365 }
381 366
382 String getLibraryComment(Library library) { 367 String getLibraryComment(LibraryMirror library) {
383 if (library.name == 'html') { 368 if (library.simpleName() == 'html') {
384 return htmldoc.libraryComment; 369 return htmldoc.libraryComment;
385 } 370 }
386 return super.getLibraryComment(library); 371 return super.getLibraryComment(library);
387 } 372 }
388 373
389 String getTypeComment(Type type) { 374 String getTypeComment(TypeMirror type) {
390 return _mergeDocs( 375 return _mergeDocs(
391 includeMdnTypeComment(type), super.getTypeComment(type), 376 includeMdnTypeComment(type), super.getTypeComment(type),
392 htmldoc.getRecordedTypeComment(type)); 377 htmldoc.getRecordedTypeComment(type));
393 } 378 }
394 379
395 String getMethodComment(MethodMember method) { 380 String getMethodComment(MethodMirror method) {
396 return _mergeDocs( 381 return _mergeDocs(
397 includeMdnMemberComment(method), super.getMethodComment(method), 382 includeMdnMemberComment(method), super.getMethodComment(method),
398 htmldoc.getRecordedMemberComment(method)); 383 htmldoc.getRecordedMemberComment(method));
399 } 384 }
400 385
401 String getFieldComment(FieldMember field) { 386 String getFieldComment(FieldMirror field) {
402 return _mergeDocs( 387 return _mergeDocs(
403 includeMdnMemberComment(field), super.getFieldComment(field), 388 includeMdnMemberComment(field), super.getFieldComment(field),
404 htmldoc.getRecordedMemberComment(field)); 389 htmldoc.getRecordedMemberComment(field));
405 } 390 }
406 391
407 bool isNonEmpty(String string) => (string != null) && (string.trim() != ''); 392 bool isNonEmpty(String string) => (string != null) && (string.trim() != '');
408 393
409 String _mergeDocs(String mdnComment, String fileComment, 394 String _mergeDocs(String mdnComment, String fileComment,
410 String handWrittenComment) { 395 String handWrittenComment) {
411 // Prefer the hand-written comment first. 396 // Prefer the hand-written comment first.
(...skipping 12 matching lines...) Expand all
424 $mdnComment 409 $mdnComment
425 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> 410 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div>
426 </div> 411 </div>
427 '''; 412 ''';
428 } 413 }
429 414
430 // We got nothing! 415 // We got nothing!
431 return ''; 416 return '';
432 } 417 }
433 418
434 void docType(Type type) { 419 void docType(TypeMirror type) {
435 // Track whether we've inserted MDN content into this page. 420 // Track whether we've inserted MDN content into this page.
436 mdnUrl = null; 421 mdnUrl = null;
437 422
438 super.docType(type); 423 super.docType(type);
439 } 424 }
440 425
441 void writeTypeFooter() { 426 void writeTypeFooter() {
442 if (mdnUrl != null) { 427 if (mdnUrl != null) {
443 final MOZ = 'http://www.mozilla.org/'; 428 final MOZ = 'http://www.mozilla.org/';
444 final MDN = 'https://developer.mozilla.org'; 429 final MDN = 'https://developer.mozilla.org';
(...skipping 15 matching lines...) Expand all
460 <a href="$MDN">The Mozilla Developer Network</a>. 445 <a href="$MDN">The Mozilla Developer Network</a>.
461 </p> 446 </p>
462 '''); 447 ''');
463 } 448 }
464 } 449 }
465 450
466 /** 451 /**
467 * Gets the MDN-scraped docs for [type], or `null` if this type isn't 452 * Gets the MDN-scraped docs for [type], or `null` if this type isn't
468 * scraped from MDN. 453 * scraped from MDN.
469 */ 454 */
470 includeMdnTypeComment(Type type) { 455 includeMdnTypeComment(TypeMirror type) {
471 if (type.library.name == 'html') { 456 if (type.library().simpleName() == 'html') {
472 // If it's an HTML type, try to map it to a base DOM type so we can find 457 // If it's an HTML type, try to map it to a base DOM type so we can find
473 // the MDN docs. 458 // the MDN docs.
474 final domTypes = _diff.htmlTypesToDom[type]; 459 final domTypes = _diff.htmlTypesToDom[type.qualifiedName()];
475 460
476 // Couldn't find a DOM type. 461 // Couldn't find a DOM type.
477 if ((domTypes == null) || (domTypes.length != 1)) return null; 462 if ((domTypes == null) || (domTypes.length != 1)) return null;
478 463
479 // Use the corresponding DOM type when searching MDN. 464 // Use the corresponding DOM type when searching MDN.
480 // TODO(rnystrom): Shame there isn't a simpler way to get the one item 465 // TODO(rnystrom): Shame there isn't a simpler way to get the one item
481 // out of a singleton Set. 466 // out of a singleton Set.
482 type = domTypes.iterator().next(); 467 type = domTypes.iterator().next();
483 } else if (type.library.name != 'dom') { 468 } else if (type.library().simpleName() != 'dom') {
484 // Not a DOM type. 469 // Not a DOM type.
485 return null; 470 return null;
486 } 471 }
487 472
488 final mdnType = mdn[type.name]; 473 final mdnType = mdn[type.simpleName()];
489 if (mdnType == null) return null; 474 if (mdnType == null) return null;
490 if (mdnType['skipped'] != null) return null; 475 if (mdnType['skipped'] != null) return null;
491 476
492 // Remember which MDN page we're using so we can attribute it. 477 // Remember which MDN page we're using so we can attribute it.
493 mdnUrl = mdnType['srcUrl']; 478 mdnUrl = mdnType['srcUrl'];
494 return mdnType['summary']; 479 return mdnType['summary'];
495 } 480 }
496 481
497 /** 482 /**
498 * Gets the MDN-scraped docs for [member], or `null` if this type isn't 483 * Gets the MDN-scraped docs for [member], or `null` if this type isn't
499 * scraped from MDN. 484 * scraped from MDN.
500 */ 485 */
501 includeMdnMemberComment(Member member) { 486 includeMdnMemberComment(MemberMirror member) {
502 if (member.library.name == 'html') { 487 var library = findLibrary(member);
488 if (library.simpleName() == 'html') {
503 // If it's an HTML type, try to map it to a base DOM type so we can find 489 // If it's an HTML type, try to map it to a base DOM type so we can find
504 // the MDN docs. 490 // the MDN docs.
505 final domMembers = _diff.htmlToDom[member]; 491 final domMembers = _diff.htmlToDom[member];
506 492
507 // Couldn't find a DOM type. 493 // Couldn't find a DOM type.
508 if ((domMembers == null) || (domMembers.length != 1)) return null; 494 if ((domMembers == null) || (domMembers.length != 1)) return null;
509 495
510 // Use the corresponding DOM member when searching MDN. 496 // Use the corresponding DOM member when searching MDN.
511 // TODO(rnystrom): Shame there isn't a simpler way to get the one item 497 // TODO(rnystrom): Shame there isn't a simpler way to get the one item
512 // out of a singleton Set. 498 // out of a singleton Set.
513 member = domMembers.iterator().next(); 499 member = domMembers.iterator().next();
514 } else if (member.library.name != 'dom') { 500 } else if (library.simpleName() != 'dom') {
515 // Not a DOM type. 501 // Not a DOM type.
516 return null; 502 return null;
517 } 503 }
518 504
519 // Ignore top-level functions. 505 // Ignore top-level functions.
520 if (member.declaringType.isTop) return null; 506 if (member.isTopLevel) return null;
521 507
522 final mdnType = mdn[member.declaringType.name]; 508 final mdnType = mdn[member.surroundingDeclaration().simpleName()];
523 if (mdnType == null) return null; 509 if (mdnType == null) return null;
524 var nameToFind = member.name; 510 var nameToFind = member.simpleName();
525 if (nameToFind.startsWith(GET_PREFIX)) { 511 if (nameToFind.startsWith(GET_PREFIX)) {
526 nameToFind = nameToFind.substring(GET_PREFIX.length); 512 nameToFind = nameToFind.substring(GET_PREFIX.length);
527 } 513 }
528 var mdnMember = null; 514 var mdnMember = null;
529 for (final candidateMember in mdnType['members']) { 515 for (final candidateMember in mdnType['members']) {
530 if (candidateMember['name'] == nameToFind) { 516 if (candidateMember['name'] == nameToFind) {
531 mdnMember = candidateMember; 517 mdnMember = candidateMember;
532 break; 518 break;
533 } 519 }
534 } 520 }
535 521
536 if (mdnMember == null) return null; 522 if (mdnMember == null) return null;
537 523
538 // Remember which MDN page we're using so we can attribute it. 524 // Remember which MDN page we're using so we can attribute it.
539 mdnUrl = mdnType['srcUrl']; 525 mdnUrl = mdnType['srcUrl'];
540 return mdnMember['help']; 526 return mdnMember['help'];
541 } 527 }
542 528
543 /** 529 /**
544 * Returns a link to [member], relative to a type page that may be in a 530 * Returns a link to [member], relative to a type page that may be in a
545 * different library than [member]. 531 * different library than [member].
546 */ 532 */
547 String _linkMember(Member member) { 533 String _linkMember(MemberMirror member) {
548 final typeName = member.declaringType.name; 534 final typeName = member.surroundingDeclaration().simpleName();
549 var memberName = '$typeName.${member.name}'; 535 var memberName = '$typeName.${member.simpleName()}';
550 if (member.isConstructor || member.isFactory) { 536 if (member.isConstructor || member.isFactory) {
551 final separator = member.constructorName == '' ? '' : '.'; 537 final separator = member.constructorName == '' ? '' : '.';
552 memberName = 'new $typeName$separator${member.constructorName}'; 538 memberName = 'new $typeName$separator${member.constructorName}';
553 } else if (member.name.startsWith(GET_PREFIX)) {
554 memberName = '$typeName.${member.name.substring(GET_PREFIX.length)}';
555 } 539 }
556 540
557 return a(memberUrl(member), memberName); 541 return a(memberUrl(member), memberName);
558 } 542 }
559 } 543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698