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 * 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 Loading... | |
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 final bool scriptCompiled = 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 ]; |
Bob Nystrom
2012/07/09 16:59:55
Style nit: indent just +2, not +4 and don't indent
Johnni Winther
2012/07/12 08:51:39
Done.
| |
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 ]; | |
Bob Nystrom
2012/07/09 16:59:55
Ditto.
Johnni Winther
2012/07/12 08:51:39
Done.
| |
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 /** | |
Bob Nystrom
2012/07/09 16:59:55
Style nit. Can you put a blank line between doc co
Johnni Winther
2012/07/12 08:51:39
Done.
| |
153 * Map from qualified type names to comments. | |
154 */ | |
154 Map<String, String> typeComments; | 155 Map<String, String> typeComments; |
155 Map<String, Map<String, String>> memberComments; | 156 /** |
157 * Map from qualified member names to comments. | |
158 */ | |
159 Map<String, String> memberComments; | |
156 | 160 |
157 Htmldoc() { | 161 Htmldoc() { |
158 typeComments = new Map<String, String>(); | 162 typeComments = new Map<String, String>(); |
159 memberComments = new Map<String, Map<String, String>>(); | 163 memberComments = new Map<String, String>(); |
160 } | 164 } |
161 | 165 |
162 // Suppress any actual writing to file. This is only for analysis. | 166 // Suppress any actual writing to file. This is only for analysis. |
163 void endFile() { | 167 void endFile() { |
164 } | 168 } |
165 | 169 |
166 void write(String s) { | 170 void write(String s) { |
167 } | 171 } |
168 | 172 |
169 String getRecordedLibraryComment(Library library) { | 173 String getRecordedLibraryComment(LibraryMirror library) { |
170 if (library.name == 'html') { | 174 if (library.simpleName() == 'html') { |
171 return libraryComment; | 175 return libraryComment; |
172 } | 176 } |
173 return null; | 177 return null; |
174 } | 178 } |
175 | 179 |
176 String getRecordedTypeComment(Type type) { | 180 String getRecordedTypeComment(TypeMirror type) { |
177 if (type.library.name == 'html') { | 181 if (typeComments.containsKey(type.qualifiedName())) { |
178 if (typeComments.containsKey(type.name)) { | 182 return typeComments[type.qualifiedName()]; |
179 return typeComments[type.name]; | |
180 } | |
181 } | 183 } |
182 return null; | 184 return null; |
183 } | 185 } |
184 | 186 |
185 String getRecordedMemberComment(Member member) { | 187 String getRecordedMemberComment(MemberMirror member) { |
186 if (member.library.name == 'html') { | 188 if (memberComments.containsKey(member.qualifiedName())) { |
187 String typeName; | 189 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 } | 190 } |
201 return null; | 191 return null; |
202 } | 192 } |
203 | 193 |
204 // These methods are subclassed and used for internal processing. | 194 // These methods are subclassed and used for internal processing. |
205 // Do not invoke outside of this class. | 195 // Do not invoke outside of this class. |
206 String getLibraryComment(Library library) { | 196 String getLibraryComment(LibraryMirror library) { |
207 String comment = super.getLibraryComment(library); | 197 String comment = super.getLibraryComment(library); |
208 libraryComment = comment; | 198 libraryComment = comment; |
209 return comment; | 199 return comment; |
210 } | 200 } |
211 | 201 |
212 String getTypeComment(Type type) { | 202 String getTypeComment(TypeMirror type) { |
213 String comment = super.getTypeComment(type); | 203 String comment = super.getTypeComment(type); |
214 recordTypeComment(type, comment); | 204 recordTypeComment(type, comment); |
215 return comment; | 205 return comment; |
216 } | 206 } |
217 | 207 |
218 String getMethodComment(MethodMember method) { | 208 String getMethodComment(MethodMirror method) { |
219 String comment = super.getMethodComment(method); | 209 String comment = super.getMethodComment(method); |
220 recordMemberComment(method, comment); | 210 recordMemberComment(method, comment); |
221 return comment; | 211 return comment; |
222 } | 212 } |
223 | 213 |
224 String getFieldComment(FieldMember field) { | 214 String getFieldComment(FieldMirror field) { |
225 String comment = super.getFieldComment(field); | 215 String comment = super.getFieldComment(field); |
226 recordMemberComment(field, comment); | 216 recordMemberComment(field, comment); |
227 return comment; | 217 return comment; |
228 } | 218 } |
229 | 219 |
230 void recordTypeComment(Type type, String comment) { | 220 void recordTypeComment(TypeMirror type, String comment) { |
231 if (comment != null && comment.contains('@domName')) { | 221 if (comment != null && comment.contains('@domName')) { |
232 // This is not a handwritten comment. | 222 // This is not a handwritten comment. |
233 return; | 223 return; |
234 } | 224 } |
235 typeComments[type.name] = comment; | 225 typeComments[type.qualifiedName()] = comment; |
236 } | 226 } |
237 | 227 |
238 void recordMemberComment(Member member, String comment) { | 228 void recordMemberComment(MemberMirror member, String comment) { |
239 if (comment != null && comment.contains('@domName')) { | 229 if (comment != null && comment.contains('@domName')) { |
240 // This is not a handwritten comment. | 230 // This is not a handwritten comment. |
241 return; | 231 return; |
242 } | 232 } |
243 String typeName = member.declaringType.name; | 233 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 } | 234 } |
252 } | 235 } |
253 | 236 |
254 class Apidoc extends doc.Dartdoc { | 237 class Apidoc extends doc.Dartdoc { |
255 /** Big ball of JSON containing the scraped MDN documentation. */ | 238 /** Big ball of JSON containing the scraped MDN documentation. */ |
256 final Map mdn; | 239 final Map mdn; |
257 | 240 |
258 final Htmldoc htmldoc; | 241 final Htmldoc htmldoc; |
259 | 242 |
260 static final disqusShortname = 'dartapidocs'; | 243 static final disqusShortname = 'dartapidocs'; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 ga.type = "text/javascript"; ga.async = true; | 328 ga.type = "text/javascript"; ga.async = true; |
346 ga.src = ("https:" == document.location.protocol ? | 329 ga.src = ("https:" == document.location.protocol ? |
347 "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; | 330 "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; |
348 var s = document.getElementsByTagName("script")[0]; | 331 var s = document.getElementsByTagName("script")[0]; |
349 s.parentNode.insertBefore(ga, s); | 332 s.parentNode.insertBefore(ga, s); |
350 })(); | 333 })(); |
351 </script> | 334 </script> |
352 '''); | 335 '''); |
353 } | 336 } |
354 | 337 |
355 void docIndexLibrary(Library library) { | 338 void docIndexLibrary(LibraryMirror library) { |
356 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't | 339 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't |
357 // want it in the docs. | 340 // want it in the docs. |
358 if (library.name == 'dart:nativewrappers') return; | 341 if (library.simpleName() == 'dart:nativewrappers') return; |
359 super.docIndexLibrary(library); | 342 super.docIndexLibrary(library); |
360 } | 343 } |
361 | 344 |
362 void docLibraryNavigationJson(Library library, Map libraries) { | 345 void docLibraryNavigationJson(LibraryMirror library, Map libraryMap) { |
363 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't | 346 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't |
364 // want it in the docs. | 347 // want it in the docs. |
365 if (library.name == 'dart:nativewrappers') return; | 348 if (library.simpleName() == 'dart:nativewrappers') return; |
366 super.docLibraryNavigationJson(library, libraries); | 349 super.docLibraryNavigationJson(library, libraryMap); |
367 } | 350 } |
368 | 351 |
369 void docLibrary(Library library) { | 352 void docLibrary(LibraryMirror library) { |
370 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't | 353 // TODO(rnystrom): Hackish. The IO libraries reference this but we don't |
371 // want it in the docs. | 354 // want it in the docs. |
372 if (library.name == 'dart:nativewrappers') return; | 355 if (library.simpleName() == 'dart:nativewrappers') return; |
373 super.docLibrary(library); | 356 super.docLibrary(library); |
374 } | 357 } |
375 | 358 |
376 /** Override definition from parent class to strip out annotation tags. */ | 359 /** Override definition from parent class to strip out annotation tags. */ |
377 String commentToHtml(String comment) { | 360 String commentToHtml(String comment) { |
378 return super.commentToHtml( | 361 return super.commentToHtml( |
379 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); | 362 comment.replaceAll(const RegExp("@([a-zA-Z]+) ([^;]+)(?:;|\$)"), '')); |
380 } | 363 } |
381 | 364 |
382 String getLibraryComment(Library library) { | 365 String getLibraryComment(LibraryMirror library) { |
383 if (library.name == 'html') { | 366 if (library.simpleName() == 'html') { |
384 return htmldoc.libraryComment; | 367 return htmldoc.libraryComment; |
385 } | 368 } |
386 return super.getLibraryComment(library); | 369 return super.getLibraryComment(library); |
387 } | 370 } |
388 | 371 |
389 String getTypeComment(Type type) { | 372 String getTypeComment(TypeMirror type) { |
390 return _mergeDocs( | 373 return _mergeDocs( |
391 includeMdnTypeComment(type), super.getTypeComment(type), | 374 includeMdnTypeComment(type), super.getTypeComment(type), |
392 htmldoc.getRecordedTypeComment(type)); | 375 htmldoc.getRecordedTypeComment(type)); |
393 } | 376 } |
394 | 377 |
395 String getMethodComment(MethodMember method) { | 378 String getMethodComment(MethodMirror method) { |
396 return _mergeDocs( | 379 return _mergeDocs( |
397 includeMdnMemberComment(method), super.getMethodComment(method), | 380 includeMdnMemberComment(method), super.getMethodComment(method), |
398 htmldoc.getRecordedMemberComment(method)); | 381 htmldoc.getRecordedMemberComment(method)); |
399 } | 382 } |
400 | 383 |
401 String getFieldComment(FieldMember field) { | 384 String getFieldComment(FieldMirror field) { |
402 return _mergeDocs( | 385 return _mergeDocs( |
403 includeMdnMemberComment(field), super.getFieldComment(field), | 386 includeMdnMemberComment(field), super.getFieldComment(field), |
404 htmldoc.getRecordedMemberComment(field)); | 387 htmldoc.getRecordedMemberComment(field)); |
405 } | 388 } |
406 | 389 |
407 bool isNonEmpty(String string) => (string != null) && (string.trim() != ''); | 390 bool isNonEmpty(String string) => (string != null) && (string.trim() != ''); |
408 | 391 |
409 String _mergeDocs(String mdnComment, String fileComment, | 392 String _mergeDocs(String mdnComment, String fileComment, |
410 String handWrittenComment) { | 393 String handWrittenComment) { |
411 // Prefer the hand-written comment first. | 394 // Prefer the hand-written comment first. |
(...skipping 12 matching lines...) Expand all Loading... | |
424 $mdnComment | 407 $mdnComment |
425 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> | 408 <div class="mdn-note"><a href="$mdnUrl">from MDN</a></div> |
426 </div> | 409 </div> |
427 '''; | 410 '''; |
428 } | 411 } |
429 | 412 |
430 // We got nothing! | 413 // We got nothing! |
431 return ''; | 414 return ''; |
432 } | 415 } |
433 | 416 |
434 void docType(Type type) { | 417 void docType(TypeMirror type) { |
435 // Track whether we've inserted MDN content into this page. | 418 // Track whether we've inserted MDN content into this page. |
436 mdnUrl = null; | 419 mdnUrl = null; |
437 | 420 |
438 super.docType(type); | 421 super.docType(type); |
439 } | 422 } |
440 | 423 |
441 void writeTypeFooter() { | 424 void writeTypeFooter() { |
442 if (mdnUrl != null) { | 425 if (mdnUrl != null) { |
443 final MOZ = 'http://www.mozilla.org/'; | 426 final MOZ = 'http://www.mozilla.org/'; |
444 final MDN = 'https://developer.mozilla.org'; | 427 final MDN = 'https://developer.mozilla.org'; |
(...skipping 15 matching lines...) Expand all Loading... | |
460 <a href="$MDN">The Mozilla Developer Network</a>. | 443 <a href="$MDN">The Mozilla Developer Network</a>. |
461 </p> | 444 </p> |
462 '''); | 445 '''); |
463 } | 446 } |
464 } | 447 } |
465 | 448 |
466 /** | 449 /** |
467 * Gets the MDN-scraped docs for [type], or `null` if this type isn't | 450 * Gets the MDN-scraped docs for [type], or `null` if this type isn't |
468 * scraped from MDN. | 451 * scraped from MDN. |
469 */ | 452 */ |
470 includeMdnTypeComment(Type type) { | 453 includeMdnTypeComment(TypeMirror type) { |
471 if (type.library.name == 'html') { | 454 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 | 455 // If it's an HTML type, try to map it to a base DOM type so we can find |
473 // the MDN docs. | 456 // the MDN docs. |
474 final domTypes = _diff.htmlTypesToDom[type]; | 457 final domTypes = _diff.htmlTypesToDom[type.qualifiedName()]; |
475 | 458 |
476 // Couldn't find a DOM type. | 459 // Couldn't find a DOM type. |
477 if ((domTypes == null) || (domTypes.length != 1)) return null; | 460 if ((domTypes == null) || (domTypes.length != 1)) return null; |
478 | 461 |
479 // Use the corresponding DOM type when searching MDN. | 462 // Use the corresponding DOM type when searching MDN. |
480 // TODO(rnystrom): Shame there isn't a simpler way to get the one item | 463 // TODO(rnystrom): Shame there isn't a simpler way to get the one item |
481 // out of a singleton Set. | 464 // out of a singleton Set. |
482 type = domTypes.iterator().next(); | 465 type = domTypes.iterator().next(); |
483 } else if (type.library.name != 'dom') { | 466 } else if (type.library().simpleName() != 'dom') { |
484 // Not a DOM type. | 467 // Not a DOM type. |
485 return null; | 468 return null; |
486 } | 469 } |
487 | 470 |
488 final mdnType = mdn[type.name]; | 471 final mdnType = mdn[type.simpleName()]; |
489 if (mdnType == null) return null; | 472 if (mdnType == null) return null; |
490 if (mdnType['skipped'] != null) return null; | 473 if (mdnType['skipped'] != null) return null; |
491 | 474 |
492 // Remember which MDN page we're using so we can attribute it. | 475 // Remember which MDN page we're using so we can attribute it. |
493 mdnUrl = mdnType['srcUrl']; | 476 mdnUrl = mdnType['srcUrl']; |
494 return mdnType['summary']; | 477 return mdnType['summary']; |
495 } | 478 } |
496 | 479 |
497 /** | 480 /** |
498 * Gets the MDN-scraped docs for [member], or `null` if this type isn't | 481 * Gets the MDN-scraped docs for [member], or `null` if this type isn't |
499 * scraped from MDN. | 482 * scraped from MDN. |
500 */ | 483 */ |
501 includeMdnMemberComment(Member member) { | 484 includeMdnMemberComment(MemberMirror member) { |
502 if (member.library.name == 'html') { | 485 var library = findLibrary(member); |
486 if (library.simpleName() == 'html') { | |
503 // If it's an HTML type, try to map it to a base DOM type so we can find | 487 // If it's an HTML type, try to map it to a base DOM type so we can find |
504 // the MDN docs. | 488 // the MDN docs. |
505 final domMembers = _diff.htmlToDom[member]; | 489 final domMembers = _diff.htmlToDom[member]; |
506 | 490 |
507 // Couldn't find a DOM type. | 491 // Couldn't find a DOM type. |
508 if ((domMembers == null) || (domMembers.length != 1)) return null; | 492 if ((domMembers == null) || (domMembers.length != 1)) return null; |
509 | 493 |
510 // Use the corresponding DOM member when searching MDN. | 494 // Use the corresponding DOM member when searching MDN. |
511 // TODO(rnystrom): Shame there isn't a simpler way to get the one item | 495 // TODO(rnystrom): Shame there isn't a simpler way to get the one item |
512 // out of a singleton Set. | 496 // out of a singleton Set. |
513 member = domMembers.iterator().next(); | 497 member = domMembers.iterator().next(); |
514 } else if (member.library.name != 'dom') { | 498 } else if (library.simpleName() != 'dom') { |
515 // Not a DOM type. | 499 // Not a DOM type. |
516 return null; | 500 return null; |
517 } | 501 } |
518 | 502 |
519 // Ignore top-level functions. | 503 // Ignore top-level functions. |
520 if (member.declaringType.isTop) return null; | 504 if (member.isTopLevel) return null; |
521 | 505 |
522 final mdnType = mdn[member.declaringType.name]; | 506 final mdnType = mdn[member.surroundingDeclaration().simpleName()]; |
523 if (mdnType == null) return null; | 507 if (mdnType == null) return null; |
524 var nameToFind = member.name; | 508 var nameToFind = member.simpleName(); |
525 if (nameToFind.startsWith(GET_PREFIX)) { | 509 if (nameToFind.startsWith(GET_PREFIX)) { |
526 nameToFind = nameToFind.substring(GET_PREFIX.length); | 510 nameToFind = nameToFind.substring(GET_PREFIX.length); |
527 } | 511 } |
528 var mdnMember = null; | 512 var mdnMember = null; |
529 for (final candidateMember in mdnType['members']) { | 513 for (final candidateMember in mdnType['members']) { |
530 if (candidateMember['name'] == nameToFind) { | 514 if (candidateMember['name'] == nameToFind) { |
531 mdnMember = candidateMember; | 515 mdnMember = candidateMember; |
532 break; | 516 break; |
533 } | 517 } |
534 } | 518 } |
535 | 519 |
536 if (mdnMember == null) return null; | 520 if (mdnMember == null) return null; |
537 | 521 |
538 // Remember which MDN page we're using so we can attribute it. | 522 // Remember which MDN page we're using so we can attribute it. |
539 mdnUrl = mdnType['srcUrl']; | 523 mdnUrl = mdnType['srcUrl']; |
540 return mdnMember['help']; | 524 return mdnMember['help']; |
541 } | 525 } |
542 | 526 |
543 /** | 527 /** |
544 * Returns a link to [member], relative to a type page that may be in a | 528 * Returns a link to [member], relative to a type page that may be in a |
545 * different library than [member]. | 529 * different library than [member]. |
546 */ | 530 */ |
547 String _linkMember(Member member) { | 531 String _linkMember(MemberMirror member) { |
548 final typeName = member.declaringType.name; | 532 final typeName = member.surroundingDeclaration().simpleName(); |
549 var memberName = '$typeName.${member.name}'; | 533 var memberName = '$typeName.${member.simpleName()}'; |
550 if (member.isConstructor || member.isFactory) { | 534 if (member.isConstructor || member.isFactory) { |
551 final separator = member.constructorName == '' ? '' : '.'; | 535 final separator = member.constructorName == '' ? '' : '.'; |
552 memberName = 'new $typeName$separator${member.constructorName}'; | 536 memberName = 'new $typeName$separator${member.constructorName}'; |
553 } else if (member.name.startsWith(GET_PREFIX)) { | |
554 memberName = '$typeName.${member.name.substring(GET_PREFIX.length)}'; | |
555 } | 537 } |
556 | 538 |
557 return a(memberUrl(member), memberName); | 539 return a(memberUrl(member), memberName); |
558 } | 540 } |
559 } | 541 } |
OLD | NEW |