Implement constructor returns parsing
This commit is contained in:
12
class.go
12
class.go
@@ -62,6 +62,7 @@ type (
|
||||
}
|
||||
Constructor struct {
|
||||
Params []Param
|
||||
Returns string
|
||||
Comment string
|
||||
}
|
||||
)
|
||||
@@ -89,6 +90,7 @@ func (c *Class) Write(root string, tmpl *template.Template) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating output file %v: %v", c.ClassName, err)
|
||||
}
|
||||
// spew.Dump(c)
|
||||
err = tmpl.Execute(outfile, c)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing output file %v: %v", c.ClassName, err)
|
||||
@@ -135,7 +137,7 @@ func ParseClass(file string) (*Class, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting constructor: %w", err)
|
||||
}
|
||||
constructor = constructor
|
||||
res.Constructors = append(res.Constructors, constructor)
|
||||
|
||||
// Doing div+div specifically skips only the constructor which is usually the first div
|
||||
// So the constructor would then be located at h1 + p + div OR h1 + div if there is no description (no p)
|
||||
@@ -200,7 +202,7 @@ func getConstructor(dataContainer *goquery.Selection) (Constructor, error) {
|
||||
types.Each(func(i int, s *goquery.Selection) {
|
||||
resConstructor.Params = append(resConstructor.Params, Param{
|
||||
Name: strings.TrimSpace(params.Eq(i).Text()),
|
||||
Type: strings.TrimSpace(types.Eq(i).Text()),
|
||||
Type: MapType(strings.TrimSpace(types.Eq(i).Text())),
|
||||
Comment: "",
|
||||
})
|
||||
})
|
||||
@@ -251,7 +253,11 @@ func getConstructor(dataContainer *goquery.Selection) (Constructor, error) {
|
||||
}
|
||||
}
|
||||
case 2:
|
||||
log.Printf("%#v", s.Text())
|
||||
cleaned := CleanUp(s.Text())
|
||||
if resConstructor.Returns != "" {
|
||||
resConstructor.Returns += "\n"
|
||||
}
|
||||
resConstructor.Returns = cleaned
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@@ -27,7 +27,8 @@
|
||||
{{- if ne .Comment ""}}
|
||||
---{{.Name}} ({{.Type}}) -> {{.Comment}}
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
{{- end}}{{if ne .Returns ""}}
|
||||
---Returns {{.Returns}}{{end}}
|
||||
---@overload fun({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param.Name}}: {{$param.Type}}{{end}}): {{$.ClassName}}{{- if ne .Comment ""}}
|
||||
---{{.Comment}}
|
||||
{{- end}}
|
||||
|
Reference in New Issue
Block a user