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

Unified Diff: utils/dartdoc/dartdoc.dart

Issue 9146016: Add the ability to link to members and constructors of other classes in Dartdoc. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | utils/dartdoc/files.dart » ('j') | utils/dartdoc/test/dartdoc_tests.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/dartdoc/dartdoc.dart
diff --git a/utils/dartdoc/dartdoc.dart b/utils/dartdoc/dartdoc.dart
index 4e0f7a6f2cddf29311041df15562cc39ddec25f8..2c52a74b1b41884d6dc422434c6bbc44149e5f61 100644
--- a/utils/dartdoc/dartdoc.dart
+++ b/utils/dartdoc/dartdoc.dart
@@ -791,7 +791,7 @@ class Dartdoc {
return anchor;
}
- findMember(Type type) {
+ findMember(Type type, String name) {
Bob Nystrom 2012/01/10 00:40:41 Shadowing name here, makes this already-confusing
nweiz 2012/01/10 01:51:55 Done.
final member = type.members[name];
if (member == null) return null;
@@ -818,21 +818,48 @@ class Dartdoc {
// See if it's another member of the current type.
if (type != null) {
- final member = findMember(type);
+ final member = findMember(type, name);
if (member != null) {
return makeLink(memberUrl(member));
}
}
- // See if it's another type in the current library.
+ // See if it's another type or a member of another type in the current
+ // library.
if (library != null) {
+ // See if it's a constructor
+ final constructorLink = (() {
+ if (!name.startsWith('new ')) return;
+ final classAndName = name.substring(4).split('.');
Bob Nystrom 2012/01/10 00:40:41 I think a regex would be simpler here: 'new (\w+).
nweiz 2012/01/10 01:51:55 Done.
+ if (classAndName.length > 2) return;
+ final type = library.types[classAndName[0]];
+ if (type == null) return;
+ final constructor = type.getConstructor(
+ classAndName.length == 2 ? classAndName[1] : '');
+ if (constructor == null) return;
+ return makeLink(memberUrl(constructor));
+ })();
Bob Nystrom 2012/01/10 00:40:41 This is clever, but perverse. :) If using a regex
nweiz 2012/01/10 01:51:55 I had this as a local named function before this,
+ if (constructorLink != null) return constructorLink;
+
+ // See if it's a member of another type
+ final foreignMemberLink = (() {
+ final nameAndMember = name.split('.');
+ if (nameAndMember.length != 2) return;
+ final type = library.types[nameAndMember[0]];
+ if (type == null) return;
+ final member = findMember(type, nameAndMember[1]);
+ if (member == null) return;
+ return makeLink(memberUrl(member));
+ })();
+ if (foreignMemberLink != null) return foreignMemberLink;
+
final type = library.types[name];
if (type != null) {
return makeLink(typeUrl(type));
}
// See if it's a top-level member in the current library.
- final member = findMember(library.topType);
+ final member = findMember(library.topType, name);
if (member != null) {
return makeLink(memberUrl(member));
}
« no previous file with comments | « no previous file | utils/dartdoc/files.dart » ('j') | utils/dartdoc/test/dartdoc_tests.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698