mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
+27
-7
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user