fix parser for go 1.15 (#304)

* fix parser for go 1.15
This commit is contained in:
Alexandr Mayorskiy
2020-08-12 14:22:55 +03:00
committed by GitHub
parent 853c4976cc
commit f3f97e8f15
+27 -7
View File
@@ -26,16 +26,36 @@ type visitor struct {
name string
}
func (p *Parser) needType(comments string) (skip, explicit bool) {
for _, v := range strings.Split(comments, "\n") {
if strings.HasPrefix(v, structSkipComment) {
func (p *Parser) needType(comments *ast.CommentGroup) (skip, explicit bool) {
if comments == nil {
return
}
for _, v := range comments.List {
comment := v.Text
if len(comment) > 2 {
switch comment[1] {
case '/':
// -style comment (no newline at the end)
comment = comment[2:]
case '*':
/*-style comment */
comment = comment[2 : len(comment)-2]
}
}
comment = strings.TrimSpace(comment)
if strings.HasPrefix(comment, structSkipComment) {
return true, false
}
if strings.HasPrefix(v, structComment) {
if strings.HasPrefix(comment, structComment) {
return false, true
}
}
return false, false
return
}
func (v *visitor) Visit(n ast.Node) (w ast.Visitor) {
@@ -47,7 +67,7 @@ func (v *visitor) Visit(n ast.Node) (w ast.Visitor) {
return v
case *ast.GenDecl:
skip, explicit := v.needType(n.Doc.Text())
skip, explicit := v.needType(n.Doc)
if skip || explicit {
for _, nc := range n.Specs {
@@ -60,7 +80,7 @@ func (v *visitor) Visit(n ast.Node) (w ast.Visitor) {
return v
case *ast.TypeSpec:
skip, explicit := v.needType(n.Doc.Text())
skip, explicit := v.needType(n.Doc)
if skip {
return nil
}