@@ -88,30 +88,6 @@ func classFromFile(filepath string) Class {
88
88
if instanceMethods != nil {
89
89
class .InstanceMethods = retrieveMethodsFromNode (fset , instanceMethods , allComments )
90
90
}
91
- // allExpr := instanceMethods.Values[0].(*ast.CompositeLit).Elts
92
- // var attrs []ast.Expr
93
- // for _, expr := range allExpr {
94
- // attrs = expr.(*ast.CompositeLit).Elts
95
- // method := Method{}
96
- // // Attributes should only contain "Name" & "Fn" for now
97
- // for _, attr := range attrs {
98
- // thisExpr := attr.(*ast.KeyValueExpr)
99
- // name := thisExpr.Key.(*ast.Ident).Name
100
- // if name == "Name" {
101
- // method.FnName = strings.Replace(thisExpr.Value.(*ast.BasicLit).Value, "\"", "", -1)
102
- // method.FnLine = fset.Position(thisExpr.Key.(*ast.Ident).NamePos).Line
103
- // }
104
- // if name == "Fn" {
105
- // methodComments := allComments.findCommentFor(method.FnLine)
106
- // method.Params = methodComments.Params
107
- // method.Returns = methodComments.Returns
108
- // method.Comment = template.HTML(methodComments.Description)
109
- // }
110
- // }
111
- // allInstanceMethods = append(allInstanceMethods, method)
112
- // }
113
- //
114
- // class.InstanceMethods = allInstanceMethods
115
91
return class
116
92
}
117
93
@@ -175,53 +151,60 @@ func DirectInsertLinkToComment(text string, class_name string) string {
175
151
return strings .Replace (text , class_name , class_link , - 1 )
176
152
}
177
153
178
- func InsertClassLinks (classes Classes ) Classes {
179
- var returned_classes Classes
180
- // loop classes
181
- for _ , class := range classes {
182
- text := string (class .Comment )
183
- // insert link to class comment
154
+ func insertClassLinksForMethods (methods Methods , classes Classes ) Methods {
155
+ // loop methods in a class
156
+ for i , method := range methods {
157
+ text := string (method .Comment )
158
+ // insert link to method comment
184
159
for _ , each_class := range classes {
185
160
text = InsertLinkToComment (text , each_class .Name )
186
161
}
162
+ methods [i ].Comment = template .HTML (text )
187
163
188
- // loop methods in a class
189
- for i , method := range class . InstanceMethods {
190
- text := string (method . Comment )
191
- // insert link to method comment
164
+ // insert link to params
165
+ for j , param := range method . Params {
166
+ c := string (param . Class )
167
+ d := string ( param . Description )
192
168
for _ , each_class := range classes {
193
- text = InsertLinkToComment (text , each_class .Name )
194
- }
195
- class .InstanceMethods [i ].Comment = template .HTML (text )
196
-
197
- // insert link to params
198
- for j , param := range method .Params {
199
- c := string (param .Class )
200
- d := string (param .Description )
201
- for _ , each_class := range classes {
202
- c = DirectInsertLinkToComment (c , each_class .Name )
203
- d = DirectInsertLinkToComment (d , each_class .Name )
204
- }
205
- param .Class = template .HTML (c )
206
- param .Description = template .HTML (d )
207
- class .InstanceMethods [i ].Params [j ] = param
169
+ c = DirectInsertLinkToComment (c , each_class .Name )
170
+ d = DirectInsertLinkToComment (d , each_class .Name )
208
171
}
172
+ param .Class = template .HTML (c )
173
+ param .Description = template .HTML (d )
174
+ methods [i ].Params [j ] = param
175
+ }
209
176
210
- // insert link to returns
211
- for j , r := range method .Returns {
212
- c := string (r .Class )
213
- d := string (r .Description )
214
- for _ , each_class := range classes {
215
- c = DirectInsertLinkToComment (c , each_class .Name )
216
- d = DirectInsertLinkToComment (d , each_class .Name )
217
- }
218
- r .Class = template .HTML (c )
219
- r .Description = template .HTML (d )
220
- class .InstanceMethods [i ].Returns [j ] = r
177
+ // insert link to returns
178
+ for j , r := range method .Returns {
179
+ c := string (r .Class )
180
+ d := string (r .Description )
181
+ for _ , each_class := range classes {
182
+ c = DirectInsertLinkToComment (c , each_class .Name )
183
+ d = DirectInsertLinkToComment (d , each_class .Name )
221
184
}
185
+ r .Class = template .HTML (c )
186
+ r .Description = template .HTML (d )
187
+ methods [i ].Returns [j ] = r
188
+ }
222
189
190
+ }
191
+
192
+ return methods
193
+ }
194
+
195
+ func InsertClassLinks (classes Classes ) Classes {
196
+ var returned_classes Classes
197
+ // loop classes
198
+ for _ , class := range classes {
199
+ text := string (class .Comment )
200
+ // insert link to class comment
201
+ for _ , each_class := range classes {
202
+ text = InsertLinkToComment (text , each_class .Name )
223
203
}
224
204
205
+ class .InstanceMethods = insertClassLinksForMethods (class .InstanceMethods , classes )
206
+ class .ClassMethods = insertClassLinksForMethods (class .ClassMethods , classes )
207
+
225
208
class .Comment = template .HTML (text )
226
209
returned_classes = append (returned_classes , class )
227
210
}
0 commit comments