Skip to content

Commit 78a40c4

Browse files
committed
parse links for class methods as well
1 parent 4f5d20c commit 78a40c4

File tree

1 file changed

+43
-60
lines changed

1 file changed

+43
-60
lines changed

parser.go

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,6 @@ func classFromFile(filepath string) Class {
8888
if instanceMethods != nil {
8989
class.InstanceMethods = retrieveMethodsFromNode(fset, instanceMethods, allComments)
9090
}
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
11591
return class
11692
}
11793

@@ -175,53 +151,60 @@ func DirectInsertLinkToComment(text string, class_name string) string {
175151
return strings.Replace(text, class_name, class_link, -1)
176152
}
177153

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
184159
for _, each_class := range classes {
185160
text = InsertLinkToComment(text, each_class.Name)
186161
}
162+
methods[i].Comment = template.HTML(text)
187163

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)
192168
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)
208171
}
172+
param.Class = template.HTML(c)
173+
param.Description = template.HTML(d)
174+
methods[i].Params[j] = param
175+
}
209176

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)
221184
}
185+
r.Class = template.HTML(c)
186+
r.Description = template.HTML(d)
187+
methods[i].Returns[j] = r
188+
}
222189

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)
223203
}
224204

205+
class.InstanceMethods = insertClassLinksForMethods(class.InstanceMethods, classes)
206+
class.ClassMethods = insertClassLinksForMethods(class.ClassMethods, classes)
207+
225208
class.Comment = template.HTML(text)
226209
returned_classes = append(returned_classes, class)
227210
}

0 commit comments

Comments
 (0)