Skip to content

Commit

Permalink
add embedding support
Browse files Browse the repository at this point in the history
  • Loading branch information
vektah committed Mar 17, 2018
1 parent 0980df0 commit 9d71071
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions codegen/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,42 @@ func findMethod(typ *types.Named, name string) *types.Func {
return method
}
}

if s, ok := typ.Underlying().(*types.Struct); ok {
for i := 0; i < s.NumFields(); i++ {
field := s.Field(i)
if !field.Anonymous() {
continue
}

if named, ok := field.Type().(*types.Named); ok {
if f := findMethod(named, name); f != nil {
return f
}
}
}
}

return nil
}

func findField(typ *types.Struct, name string) *types.Var {
for i := 0; i < typ.NumFields(); i++ {
field := typ.Field(i)
if field.Anonymous() {
if named, ok := field.Type().(*types.Struct); ok {
if f := findField(named, name); f != nil {
return f
}
}

if named, ok := field.Type().Underlying().(*types.Struct); ok {
if f := findField(named, name); f != nil {
return f
}
}
}

if !field.Exported() {
continue
}
Expand Down

0 comments on commit 9d71071

Please sign in to comment.