Skip to content

Commit 9bb4b38

Browse files
Added DeepCommentHandler
1 parent 47a26dd commit 9bb4b38

File tree

7 files changed

+95
-18
lines changed

7 files changed

+95
-18
lines changed

examples/basic/src/flattened.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class flattenedClass
66
/**
77
* A member that accepts an option object defined inline.
88
*
9-
* @param value A value on the options object parameter.
10-
* @param anotherValue Another value on the options object parameter.
11-
* @param moreOptions A typed child object of the options object.
12-
* @param moreOptions.moreValues A value of the typed child object.
9+
* @param options.value A value on the options object parameter.
10+
* @param options.anotherValue Another value on the options object parameter.
11+
* @param options.moreOptions A typed child object of the options object.
12+
* @param options.moreOptions.moreValues A value of the typed child object.
1313
*/
1414
options:{
1515
value?:string;
@@ -22,15 +22,16 @@ class flattenedClass
2222
/**
2323
* A member that holds a callback that requires a typed function signature.
2424
*
25-
* @param param A parameter of the typed function callback.
26-
* @param optionalParam An optional parameter of the typed function callback.
25+
* @param callback.param A parameter of the typed function callback.
26+
* @param callback.optionalParam An optional parameter of the typed function callback.
2727
*/
2828
callback:(param:number, optionalParam?:string) => string;
2929

3030
/**
3131
* A member that holds an index signature.
3232
*
33-
* @param text A property of the index signature instance.
33+
* @param indexed.index The index property comment.
34+
* @param indexed.test A property of the index signature instance.
3435
*/
3536
indexed:{
3637
[index:number]:{name:string; value?:number;};
@@ -47,7 +48,7 @@ class flattenedClass
4748
* @param options.moreOptions A typed child object of the options object.
4849
* @param options.moreOptions.moreValues A value of the typed child object.
4950
*/
50-
construct(options:{
51+
constructor(options:{
5152
value?:string;
5253
anotherValue?:string;
5354
moreOptions?:{
@@ -88,8 +89,9 @@ function flattenedObject(options:{
8889
/**
8990
* A function that accepts an index signature parameter.
9091
*
91-
* @param indexed The index signature parameter.
92-
* @param indexed.text A property of the index signature instance.
92+
* @param indexed The index signature parameter.
93+
* @param indexed.index The index property comment.
94+
* @param indexed.test A property of the index signature instance.
9395
*/
9496
function flattenedIndexSignature(indexed:{
9597
[index:number]:{name:string; value?:number;};

examples/basic/src/functions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export function multipleSignatures(value:string):string;
6262
/**
6363
* This is the second signature a function with multiple signatures.
6464
*
65-
* @param value An object containing the name value.
65+
* @param value An object containing the name value.
66+
* @param value.name A value of the object.
6667
*/
6768
export function multipleSignatures(value:{name:string}):string;
6869

@@ -93,8 +94,10 @@ export function genericFunction<T>(value:T):T {
9394

9495
/**
9596
* This is a function that is extended by a module.
97+
*
98+
* @param arg An argument.
9699
*/
97-
export function moduleFunction() { }
100+
export function moduleFunction(arg:string):string { return ''; }
98101

99102

100103
/**

src/typedoc/factories/Dispatcher.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ module TypeDoc.Factories
285285
var parent = <Models.DeclarationReflection>state.parentState.reflection;
286286
var reflection = new Models.DeclarationReflection();
287287
reflection.name = (state.flattenedName ? state.flattenedName + '.' : '') + state.getName();
288+
reflection.originalName = state.declaration.name;
288289
reflection.parent = parent;
289290

290291
state.reflection = reflection;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module TypeDoc.Factories
2+
{
3+
/**
4+
* A handler that moves comments with dot syntax to their target.
5+
*/
6+
export class DeepCommentHandler extends BaseHandler
7+
{
8+
/**
9+
* Create a new CommentHandler instance.
10+
*
11+
* @param dispatcher The dispatcher this handler should be attached to.
12+
*/
13+
constructor(dispatcher:Dispatcher) {
14+
super(dispatcher);
15+
16+
dispatcher.on(Dispatcher.EVENT_DECLARATION, this.onDeclaration, this, -512);
17+
}
18+
19+
20+
/**
21+
* Triggered when the dispatcher starts processing a declaration.
22+
*
23+
* @param state The state that describes the current declaration and reflection.
24+
*/
25+
private onDeclaration(state:DeclarationState) {
26+
var reflection = state.reflection;
27+
if (reflection.comment) {
28+
return;
29+
}
30+
31+
function push(reflection:Models.DeclarationReflection) {
32+
var part = reflection.originalName;
33+
if (reflection.isSignature) {
34+
part = '';
35+
}
36+
37+
if (part && part != '') {
38+
name = (name == '' ? part : part + '.' + name);
39+
}
40+
}
41+
42+
var name = '';
43+
var target = <Models.DeclarationReflection>reflection.parent;
44+
push(reflection);
45+
46+
while (target instanceof Models.DeclarationReflection) {
47+
if (target.comment) {
48+
var tag = target.comment.getTag('param', name);
49+
if (tag) {
50+
target.comment.tags.splice(target.comment.tags.indexOf(tag), 1);
51+
reflection.comment = new Models.Comment('', tag.text);
52+
break;
53+
}
54+
}
55+
56+
target = <Models.DeclarationReflection>target.parent;
57+
}
58+
}
59+
}
60+
61+
62+
/**
63+
* Register this handler.
64+
*/
65+
Dispatcher.HANDLERS.push(DeepCommentHandler);
66+
}

src/typedoc/factories/handlers/FunctionTypeHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ module TypeDoc.Factories
1313
constructor(dispatcher:Dispatcher) {
1414
super(dispatcher);
1515

16-
dispatcher.on(Dispatcher.EVENT_DECLARATION, this.onDeclaration, this, -256);
16+
dispatcher.on(Dispatcher.EVENT_END_DECLARATION, this.onEndDeclaration, this);
1717
}
1818

1919

2020
/**
21-
* Triggered when the dispatcher processes a declaration.
21+
* Triggered when the dispatcher has finished processing a declaration.
2222
*
2323
* @param state The state that describes the current declaration and reflection.
2424
*/
25-
private onDeclaration(state:DeclarationState) {
25+
private onEndDeclaration(state:DeclarationState) {
2626
if (state.isSignature) {
2727
return;
2828
}

src/typedoc/factories/handlers/ObjectLiteralHandler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ module TypeDoc.Factories
1313
constructor(dispatcher:Dispatcher) {
1414
super(dispatcher);
1515

16-
dispatcher.on(Dispatcher.EVENT_DECLARATION, this.onDeclaration, this, 1024);
16+
dispatcher.on(Dispatcher.EVENT_END_DECLARATION, this.onEndDeclaration, this);
1717
}
1818

1919

2020
/**
21-
* Triggered when the dispatcher starts processing a declaration.
21+
* Triggered when the dispatcher has finished processing a declaration.
2222
*
2323
* @param state The state that describes the current declaration and reflection.
2424
*/
25-
private onDeclaration(state:DeclarationState) {
25+
private onEndDeclaration(state:DeclarationState) {
2626
var literal = ObjectLiteralHandler.getLiteralDeclaration(state.declaration);
2727
if (literal && literal.getChildDecls().length > 0) {
2828
if (state.kindOf(TypeScript.PullElementKind.Variable)) {

src/typedoc/models/reflections/BaseReflection.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ module TypeDoc.Models
5555
*/
5656
name:string = '';
5757

58+
/**
59+
* The original name of the TypeScript declaration.
60+
*/
61+
originalName:string;
62+
5863
/**
5964
* The parsed documentation comment attached to this reflection.
6065
*/

0 commit comments

Comments
 (0)