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

Side by Side Diff: pkg/dartdoc/lib/dartdoc.dart

Issue 11339056: Cleanup run on DartDoc from Dart Editor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « pkg/dartdoc/lib/classify.dart ('k') | pkg/dartdoc/lib/markdown.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 * To generate docs for a library, run this script with the path to an 6 * To generate docs for a library, run this script with the path to an
7 * entrypoint .dart file, like: 7 * entrypoint .dart file, like:
8 * 8 *
9 * $ dart dartdoc.dart foo.dart 9 * $ dart dartdoc.dart foo.dart
10 * 10 *
11 * This will create a "docs" directory with the docs for your libraries. To 11 * This will create a "docs" directory with the docs for your libraries. To
12 * create these beautiful docs, dartdoc parses your library and every library 12 * create these beautiful docs, dartdoc parses your library and every library
13 * it imports (recursively). From each library, it parses all classes and 13 * it imports (recursively). From each library, it parses all classes and
14 * members, finds the associated doc comments and builds crosslinked docs from 14 * members, finds the associated doc comments and builds crosslinked docs from
15 * them. 15 * them.
16 */ 16 */
17 #library('dartdoc'); 17 library dartdoc;
18 18
19 #import('dart:io'); 19 import 'dart:io';
20 #import('dart:math'); 20 import 'dart:math';
21 #import('dart:uri'); 21 import 'dart:uri';
22 #import('dart:json'); 22 import 'dart:json';
23 23
24 // TODO(rnystrom): Use "package:" URL (#4968). 24 // TODO(rnystrom): Use "package:" URL (#4968).
25 #import('mirrors.dart'); 25 import 'mirrors.dart';
26 #import('mirrors_util.dart'); 26 import 'mirrors_util.dart';
27 #import('src/mirrors/dart2js_mirror.dart', prefix: 'dart2js'); 27 import 'src/mirrors/dart2js_mirror.dart' as dart2js;
28 #import('classify.dart'); 28 import 'classify.dart';
29 #import('markdown.dart', prefix: 'md'); 29 import 'markdown.dart' as md;
30 #import('../../../lib/compiler/implementation/scanner/scannerlib.dart', 30 import '../../../lib/compiler/implementation/scanner/scannerlib.dart' as dart2js ;
31 prefix: 'dart2js'); 31 import '../../../lib/_internal/libraries.dart';
32 #import('../../../lib/_internal/libraries.dart');
33 32
34 // TODO(rnystrom): Use "package:" URL (#4968). 33 // TODO(rnystrom): Use "package:" URL (#4968).
35 #source('src/dartdoc/comment_map.dart'); 34 part 'src/dartdoc/comment_map.dart';
36 #source('src/dartdoc/nav.dart'); 35 part 'src/dartdoc/nav.dart';
37 #source('src/dartdoc/utils.dart'); 36 part 'src/dartdoc/utils.dart';
38 37
39 /** 38 /**
40 * Generates completely static HTML containing everything you need to browse 39 * Generates completely static HTML containing everything you need to browse
41 * the docs. The only client side behavior is trivial stuff like syntax 40 * the docs. The only client side behavior is trivial stuff like syntax
42 * highlighting code. 41 * highlighting code.
43 */ 42 */
44 const MODE_STATIC = 0; 43 const MODE_STATIC = 0;
45 44
46 /** 45 /**
47 * Generated docs do not include baked HTML navigation. Instead, a single 46 * Generated docs do not include baked HTML navigation. Instead, a single
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 if (host is ClassMirror) { 1043 if (host is ClassMirror) {
1045 var iterable = new HierarchyIterable(host, includeType: true); 1044 var iterable = new HierarchyIterable(host, includeType: true);
1046 for (ClassMirror type in iterable) { 1045 for (ClassMirror type in iterable) {
1047 if (!host.isObject && !inheritFromObject && type.isObject) continue; 1046 if (!host.isObject && !inheritFromObject && type.isObject) continue;
1048 1047
1049 type.declaredMembers.forEach((_, MemberMirror member) { 1048 type.declaredMembers.forEach((_, MemberMirror member) {
1050 if (member.isStatic) return; 1049 if (member.isStatic) return;
1051 if (!showPrivate && member.isPrivate) return; 1050 if (!showPrivate && member.isPrivate) return;
1052 1051
1053 bool inherit = true; 1052 bool inherit = true;
1054 if (type !== host) { 1053 if (type != host) {
1055 if (member.isPrivate) { 1054 if (member.isPrivate) {
1056 // Don't inherit private members. 1055 // Don't inherit private members.
1057 inherit = false; 1056 inherit = false;
1058 } 1057 }
1059 if (member.isConstructor) { 1058 if (member.isConstructor) {
1060 // Don't inherit constructors. 1059 // Don't inherit constructors.
1061 inherit = false; 1060 inherit = false;
1062 } 1061 }
1063 } 1062 }
1064 if (!inherit) return; 1063 if (!inherit) return;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 assert(getter is MethodMirror); 1161 assert(getter is MethodMirror);
1163 docProperty(host, getter, null); 1162 docProperty(host, getter, null);
1164 } 1163 }
1165 } else if (getter == null) { 1164 } else if (getter == null) {
1166 // We only have a setter => Document as a method. 1165 // We only have a setter => Document as a method.
1167 assert(setter is MethodMirror); 1166 assert(setter is MethodMirror);
1168 docMethod(host, setter); 1167 docMethod(host, setter);
1169 } else { 1168 } else {
1170 DocComment getterComment = getMemberComment(getter); 1169 DocComment getterComment = getMemberComment(getter);
1171 DocComment setterComment = getMemberComment(setter); 1170 DocComment setterComment = getMemberComment(setter);
1172 if (getter.owner !== setter.owner || 1171 if (getter.owner != setter.owner ||
1173 getterComment != null && setterComment != null) { 1172 getterComment != null && setterComment != null) {
1174 // Both have comments or are not declared in the same class 1173 // Both have comments or are not declared in the same class
1175 // => Documents separately. 1174 // => Documents separately.
1176 if (getter is FieldMirror) { 1175 if (getter is FieldMirror) {
1177 // Document field as a getter (setter is inherited). 1176 // Document field as a getter (setter is inherited).
1178 docField(host, getter, asGetter: true); 1177 docField(host, getter, asGetter: true);
1179 } else { 1178 } else {
1180 docMethod(host, getter); 1179 docMethod(host, getter);
1181 } 1180 }
1182 if (setter is FieldMirror) { 1181 if (setter is FieldMirror) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 1415
1417 first = false; 1416 first = false;
1418 } 1417 }
1419 1418
1420 if (inOptionals) write(']'); 1419 if (inOptionals) write(']');
1421 write(')'); 1420 write(')');
1422 } 1421 }
1423 1422
1424 void docComment(ObjectMirror host, DocComment comment) { 1423 void docComment(ObjectMirror host, DocComment comment) {
1425 if (comment != null) { 1424 if (comment != null) {
1426 if (comment.inheritedFrom !== null) { 1425 if (comment.inheritedFrom != null) {
1427 writeln('<div class="inherited">'); 1426 writeln('<div class="inherited">');
1428 writeln(comment.html); 1427 writeln(comment.html);
1429 write('<div class="docs-inherited-from">docs inherited from '); 1428 write('<div class="docs-inherited-from">docs inherited from ');
1430 annotateType(host, comment.inheritedFrom); 1429 annotateType(host, comment.inheritedFrom);
1431 write('</div>'); 1430 write('</div>');
1432 writeln('</div>'); 1431 writeln('</div>');
1433 } else { 1432 } else {
1434 writeln(comment.html); 1433 writeln(comment.html);
1435 } 1434 }
1436 } 1435 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 1544
1546 /** Gets the anchor id for the document for [member]. */ 1545 /** Gets the anchor id for the document for [member]. */
1547 String memberAnchor(MemberMirror member) { 1546 String memberAnchor(MemberMirror member) {
1548 return member.simpleName; 1547 return member.simpleName;
1549 } 1548 }
1550 1549
1551 /** 1550 /**
1552 * Creates a hyperlink. Handles turning the [href] into an appropriate 1551 * Creates a hyperlink. Handles turning the [href] into an appropriate
1553 * relative path from the current file. 1552 * relative path from the current file.
1554 */ 1553 */
1555 String a(String href, String contents, [String css]) { 1554 String a(String href, String contents, {String css}) {
gram 2012/10/30 22:30:04 Why use a named parameter here? Usually you would
Andrei Mouravski 2012/10/31 15:08:00 Done.
1556 // Mark outgoing external links, mainly so we can style them. 1555 // Mark outgoing external links, mainly so we can style them.
1557 final rel = isAbsolute(href) ? ' ref="external"' : ''; 1556 final rel = isAbsolute(href) ? ' ref="external"' : '';
1558 final cssClass = css == null ? '' : ' class="$css"'; 1557 final cssClass = css == null ? '' : ' class="$css"';
1559 return '<a href="${relativePath(href)}"$cssClass$rel>$contents</a>'; 1558 return '<a href="${relativePath(href)}"$cssClass$rel>$contents</a>';
1560 } 1559 }
1561 1560
1562 /** 1561 /**
1563 * Writes a type annotation for the given type and (optional) parameter name. 1562 * Writes a type annotation for the given type and (optional) parameter name.
1564 */ 1563 */
1565 annotateType(ObjectMirror enclosingType, 1564 annotateType(ObjectMirror enclosingType,
1566 TypeMirror type, 1565 TypeMirror type,
1567 [String paramName = null]) { 1566 [String paramName = null]) {
1568 // Don't bother explicitly displaying Dynamic. 1567 // Don't bother explicitly displaying Dynamic.
1569 if (type.isDynamic) { 1568 if (type.isDynamic) {
1570 if (paramName !== null) write(paramName); 1569 if (paramName != null) write(paramName);
1571 return; 1570 return;
1572 } 1571 }
1573 1572
1574 // For parameters, handle non-typedefed function types. 1573 // For parameters, handle non-typedefed function types.
1575 if (paramName !== null && type is FunctionTypeMirror) { 1574 if (paramName != null && type is FunctionTypeMirror) {
1576 annotateType(enclosingType, type.returnType); 1575 annotateType(enclosingType, type.returnType);
1577 write(paramName); 1576 write(paramName);
1578 1577
1579 docParamList(enclosingType, type.parameters); 1578 docParamList(enclosingType, type.parameters);
1580 return; 1579 return;
1581 } 1580 }
1582 1581
1583 linkToType(enclosingType, type); 1582 linkToType(enclosingType, type);
1584 1583
1585 write(' '); 1584 write(' ');
1586 if (paramName !== null) write(paramName); 1585 if (paramName != null) write(paramName);
1587 } 1586 }
1588 1587
1589 /** Writes a link to a human-friendly string representation for a type. */ 1588 /** Writes a link to a human-friendly string representation for a type. */
1590 linkToType(ObjectMirror enclosingType, TypeMirror type) { 1589 linkToType(ObjectMirror enclosingType, TypeMirror type) {
1591 if (type.isVoid) { 1590 if (type.isVoid) {
1592 // Do not generate links for void. 1591 // Do not generate links for void.
1593 // TODO(johnniwinter): Generate span for specific style? 1592 // TODO(johnniwinter): Generate span for specific style?
1594 write('void'); 1593 write('void');
1595 return; 1594 return;
1596 } 1595 }
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 final ClassMirror inheritedFrom; 1856 final ClassMirror inheritedFrom;
1858 1857
1859 DocComment(this.text, [this.inheritedFrom = null]) { 1858 DocComment(this.text, [this.inheritedFrom = null]) {
1860 assert(text != null && !text.trim().isEmpty); 1859 assert(text != null && !text.trim().isEmpty);
1861 } 1860 }
1862 1861
1863 String get html => md.markdownToHtml(text); 1862 String get html => md.markdownToHtml(text);
1864 1863
1865 String toString() => text; 1864 String toString() => text;
1866 } 1865 }
OLDNEW
« no previous file with comments | « pkg/dartdoc/lib/classify.dart ('k') | pkg/dartdoc/lib/markdown.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698