Index: sdk/lib/_internal/dartdoc/lib/dartdoc.dart |
diff --git a/sdk/lib/_internal/dartdoc/lib/dartdoc.dart b/sdk/lib/_internal/dartdoc/lib/dartdoc.dart |
index 44c7d6934606b2bf8e9b46e9e83e718603216aaa..450cb0cfc49db0c7c2f0a75bb51db3e0001da8c0 100644 |
--- a/sdk/lib/_internal/dartdoc/lib/dartdoc.dart |
+++ b/sdk/lib/_internal/dartdoc/lib/dartdoc.dart |
@@ -222,8 +222,6 @@ class Dartdoc { |
*/ |
List<LibraryMirror> _sortedLibraries; |
- CommentMap _comments; |
- |
/** The library that we're currently generating docs for. */ |
LibraryMirror _currentLibrary; |
@@ -247,8 +245,7 @@ class Dartdoc { |
int get totalTypes => _totalTypes; |
int get totalMembers => _totalMembers; |
- Dartdoc() |
- : _comments = new CommentMap() { |
+ Dartdoc() { |
// Patch in support for [:...:]-style code to the markdown parser. |
// TODO(rnystrom): Markdown already has syntax for this. Phase this out? |
md.InlineParser.syntaxes.insertRange(0, 1, |
@@ -324,12 +321,14 @@ class Dartdoc { |
} |
void documentEntryPoint(Path entrypoint, Path libPath, Path pkgPath) { |
- final compilation = new Compilation(entrypoint, libPath, pkgPath); |
+ final compilation = new Compilation(entrypoint, libPath, pkgPath, |
+ <String>['--preserve-comments']); |
_document(compilation); |
} |
void documentLibraries(List<Path> libraryList, Path libPath, Path pkgPath) { |
- final compilation = new Compilation.library(libraryList, libPath, pkgPath); |
+ final compilation = new Compilation.library(libraryList, libPath, pkgPath, |
+ <String>['--preserve-comments']); |
_document(compilation); |
} |
@@ -361,7 +360,7 @@ class Dartdoc { |
startFile("apidoc.json"); |
var libraries = _sortedLibraries.map( |
- (lib) => new LibraryElement(lib.qualifiedName, lib, _comments)); |
+ (lib) => new LibraryElement(lib.qualifiedName, lib)); |
write(json_serializer.serialize(libraries)); |
endFile(); |
} |
@@ -1470,21 +1469,11 @@ class Dartdoc { |
DocComment createDocComment(String text, [ClassMirror inheritedFrom]) => |
new DocComment(text, inheritedFrom); |
- |
/** Get the doc comment associated with the given library. */ |
- DocComment getLibraryComment(LibraryMirror library) { |
- // Look for a comment for the entire library. |
- final comment = _comments.findLibrary(library.location); |
- if (comment == null) return null; |
- return createDocComment(comment); |
- } |
+ DocComment getLibraryComment(LibraryMirror library) => getComment(library); |
/** Get the doc comment associated with the given type. */ |
- DocComment getTypeComment(TypeMirror type) { |
- String comment = _comments.find(type.location); |
- if (comment == null) return null; |
- return createDocComment(comment); |
- } |
+ DocComment getTypeComment(TypeMirror type) => getComment(type); |
/** |
* Get the doc comment associated with the given member. |
@@ -1493,18 +1482,27 @@ class Dartdoc { |
* an inherited comment, favouring comments inherited from classes over |
* comments inherited from interfaces. |
*/ |
- DocComment getMemberComment(MemberMirror member) { |
- String comment = _comments.find(member.location); |
+ DocComment getMemberComment(MemberMirror member) => getComment(member); |
+ |
+ /** |
+ * Get the doc comment associated with the given declaration. |
+ * |
+ * If no comment was found on a member, the hierarchy is traversed to find |
+ * an inherited comment, favouring comments inherited from classes over |
+ * comments inherited from interfaces. |
+ */ |
+ DocComment getComment(DeclarationMirror mirror) { |
+ String comment = computeComment(mirror); |
ClassMirror inheritedFrom = null; |
if (comment == null) { |
- if (member.owner is ClassMirror) { |
+ if (mirror.owner is ClassMirror) { |
var iterable = |
- new HierarchyIterable(member.owner, |
+ new HierarchyIterable(mirror.owner, |
includeType: false); |
for (ClassMirror type in iterable) { |
- var inheritedMember = type.members[member.simpleName]; |
+ var inheritedMember = type.members[mirror.simpleName]; |
if (inheritedMember is MemberMirror) { |
- comment = _comments.find(inheritedMember.location); |
+ comment = computeComment(inheritedMember); |
if (comment != null) { |
inheritedFrom = type; |
break; |
@@ -1871,6 +1869,29 @@ class InternalError { |
String toString() => "InternalError: '$message'"; |
} |
+ |
ahe
2013/01/03 13:04:09
Extra line.
Johnni Winther
2013/01/04 16:40:53
Done.
|
+/** |
+ * Computes the doc comment for the declaration mirror. |
+* |
+ * Multiple comments are concatenated with newlines in between. |
+ */ |
+String computeComment(DeclarationMirror mirror) { |
+ String text; |
+ for (InstanceMirror metadata in mirror.metadata) { |
+ if (metadata is CommentInstanceMirror) { |
+ CommentInstanceMirror comment = metadata; |
+ if (comment.isDocComment) { |
+ if (text == null) { |
+ text = comment.trimmedText; |
+ } else { |
+ text = '$text\n${comment.trimmedText}'; |
+ } |
+ } |
+ } |
+ } |
+ return text; |
+} |
+ |
class DocComment { |
final String text; |