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

Unified Diff: sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart

Issue 11726005: Dartdoc comments retrieved as metadata through dart2js mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 12 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart
diff --git a/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart b/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart
index cede225be99a109917dbbcaa04c9047e58434ebd..3eeb36b0f941409646506034f03fad9a22b06239 100644
--- a/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart
+++ b/sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util.dart
@@ -113,3 +113,49 @@ class HierarchyIterator implements Iterator<ClassMirror> {
bool get hasNext => !queue.isEmpty || object != null;
}
+
+final RegExp _singleLineCommentStart = new RegExp(r'^///? ?(.*)');
+final RegExp _multiLineCommentStartEnd =
+ new RegExp(r'^/\*\*? ?([\s\S]*)\*/$', multiLine: true);
+final RegExp _multiLineCommentLineStart = new RegExp(r'^[ \t]*\* ?(.*)');
+
+/**
+ * Pulls the raw text out of a comment (i.e. removes the comment
+ * characters).
+ */
+String stripComment(String comment) {
+ Match match = _singleLineCommentStart.firstMatch(comment);
+ if (match != null) {
+ return match[1];
+ }
+ match = _multiLineCommentStartEnd.firstMatch(comment);
+ if (match != null) {
+ comment = match[1];
+ bool first = true;
+ var sb = new StringBuffer();
+ Iterator<String> lines = comment.split('\n').iterator();
+ while (lines.hasNext) {
ahe 2013/01/08 11:59:43 lines.moveNext()
Johnni Winther 2013/01/08 13:39:46 Changed to use List and index.
+ String line = lines.next();
+ if (first) {
+ sb.add(line); // Add the first line unprocessed.
+ first = false;
+ continue;
+ }
+ sb.add('\n');
+ match = _multiLineCommentLineStart.firstMatch(line);
+ if (match != null) {
+ sb.add(match[1]);
+ } else if (lines.hasNext || !line.trim().isEmpty) {
ahe 2013/01/08 11:59:43 This wont work with the new iterators :-(
Johnni Winther 2013/01/08 13:39:46 Refactored.
+ // Do not add the last line if it only contains white space.
+ // This interprets cases like
+ // /*
+ // * Foo
+ // */
+ // as "\nFoo\n" and not as "\nFoo\n ".
+ sb.add(line);
+ }
+ }
+ return sb.toString();
+ }
+ throw new ArgumentError('Invalid comment $comment');
+}

Powered by Google App Engine
This is Rietveld 408576698