mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
Track Func in Universe
This commit is contained in:
@@ -293,11 +293,14 @@ func (b *Builder) FindTypes() (types.Universe, error) {
|
||||
for _, n := range s.Names() {
|
||||
obj := s.Lookup(n)
|
||||
tn, ok := obj.(*tc.TypeName)
|
||||
if !ok {
|
||||
continue
|
||||
if ok {
|
||||
t := b.walkType(u, nil, tn.Type())
|
||||
t.CommentLines = b.priorCommentLines(obj.Pos())
|
||||
}
|
||||
tf, ok := obj.(*tc.Func)
|
||||
if ok {
|
||||
b.addFunc(u, nil, tf)
|
||||
}
|
||||
t := b.walkType(u, nil, tn.Type())
|
||||
t.CommentLines = b.priorCommentLines(obj.Pos())
|
||||
}
|
||||
for p := range b.importGraph[pkgName] {
|
||||
u.AddImports(pkgName, p)
|
||||
@@ -316,6 +319,12 @@ func (b *Builder) priorCommentLines(pos token.Pos) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func tcFuncNameToName(in string) types.Name {
|
||||
name := strings.TrimLeft(in, "func ")
|
||||
nameParts := strings.Split(name, "(")
|
||||
return tcNameToName(nameParts[0])
|
||||
}
|
||||
|
||||
func tcNameToName(in string) types.Name {
|
||||
// Detect anonymous type names. (These may have '.' characters because
|
||||
// embedded types may have packages, so we detect them specially.)
|
||||
@@ -495,3 +504,14 @@ func (b *Builder) walkType(u types.Universe, useName *types.Name, in tc.Type) *t
|
||||
return out
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Builder) addFunc(u types.Universe, useName *types.Name, in *tc.Func) *types.Type {
|
||||
name := tcFuncNameToName(in.String())
|
||||
if useName != nil {
|
||||
name = *useName
|
||||
}
|
||||
out := u.Get(name)
|
||||
out.Kind = types.Func
|
||||
out.Signature = b.convertSignature(u, in.Type().(*tc.Signature))
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user