mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:07:11 +00:00
Add the ability to link to members and constructors of other classes in Dartdoc.
The syntax is [Class.member] and [new Class], respectively. [new Class.namedConstructor] also works. Review URL: http://codereview.chromium.org//9146016 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@3217 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
1e27f4b30f
commit
70bbde3ead
4 changed files with 59 additions and 6 deletions
|
@ -794,8 +794,8 @@ class Dartdoc {
|
|||
return anchor;
|
||||
}
|
||||
|
||||
findMember(Type type) {
|
||||
final member = type.members[name];
|
||||
findMember(Type type, String memberName) {
|
||||
final member = type.members[memberName];
|
||||
if (member == null) return null;
|
||||
|
||||
// Special case: if the member we've resolved is a property (i.e. it wraps
|
||||
|
@ -821,21 +821,47 @@ 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 = (() {
|
||||
final match = new RegExp(@'new (\w+)(?:\.(\w+))?').firstMatch(name);
|
||||
if (match == null) return;
|
||||
final type = library.types[match[1]];
|
||||
if (type == null) return;
|
||||
final constructor = type.getConstructor(
|
||||
match[2] == null ? '' : match[2]);
|
||||
if (constructor == null) return;
|
||||
return makeLink(memberUrl(constructor));
|
||||
})();
|
||||
if (constructorLink != null) return constructorLink;
|
||||
|
||||
// See if it's a member of another type
|
||||
final foreignMemberLink = (() {
|
||||
final match = new RegExp(@'(\w+)\.(\w+)').firstMatch(name);
|
||||
if (match == null) return;
|
||||
final type = library.types[match[1]];
|
||||
if (type == null) return;
|
||||
final member = findMember(type, match[2]);
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -69,7 +69,12 @@ typeUrl(Type type) {
|
|||
}
|
||||
|
||||
/** Gets the URL for the documentation for [member]. */
|
||||
memberUrl(Member member) => '${typeUrl(member.declaringType)}#${member.name}';
|
||||
memberUrl(Member member) {
|
||||
final typeUrl = typeUrl(member.declaringType);
|
||||
if (!member.isConstructor) return '$typeUrl#${member.name}';
|
||||
if (member.constructorName == '') return '$typeUrl#new:${member.name}';
|
||||
return '$typeUrl#new:${member.name}.${member.constructorName}';
|
||||
}
|
||||
|
||||
/** Gets the anchor id for the document for [member]. */
|
||||
memberAnchor(Member member) => '${member.name}';
|
||||
|
|
|
@ -192,5 +192,25 @@ main() {
|
|||
type: klass, member: method))).
|
||||
equals('<code>unknownName</code>');
|
||||
});
|
||||
|
||||
test('to a member of another class', () {
|
||||
expect(render(doc.resolveNameReference('Class.method', library: dummy))).
|
||||
equals('<a class="crossref" href="../../dummy/Class.html#method">' +
|
||||
'Class.method</a>');
|
||||
});
|
||||
|
||||
test('to a constructor', () {
|
||||
expect(render(doc.resolveNameReference('new Class', library: dummy))).
|
||||
equals('<a class="crossref" href="../../dummy/Class.html#new:Class">' +
|
||||
'new Class</a>');
|
||||
});
|
||||
|
||||
test('to a named constructor', () {
|
||||
expect(render(doc.resolveNameReference('new Class.namedConstructor',
|
||||
library: dummy))).
|
||||
equals('<a class="crossref" ' +
|
||||
'href="../../dummy/Class.html#new:Class.namedConstructor">new ' +
|
||||
'Class.namedConstructor</a>');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
topLevelMethod() => null;
|
||||
|
||||
class Class {
|
||||
Class() => null;
|
||||
Class.namedConstructor() => null;
|
||||
method(param) => null;
|
||||
get getterOnly() => null;
|
||||
get getterAndSetter() => null;
|
||||
|
|
Loading…
Reference in a new issue