mirror of https://github.com/k3s-io/k3s
Track Func in Universe
parent
07664a6104
commit
75cf28b7df
|
@ -293,11 +293,14 @@ func (b *Builder) FindTypes() (types.Universe, error) {
|
||||||
for _, n := range s.Names() {
|
for _, n := range s.Names() {
|
||||||
obj := s.Lookup(n)
|
obj := s.Lookup(n)
|
||||||
tn, ok := obj.(*tc.TypeName)
|
tn, ok := obj.(*tc.TypeName)
|
||||||
if !ok {
|
if ok {
|
||||||
continue
|
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] {
|
for p := range b.importGraph[pkgName] {
|
||||||
u.AddImports(pkgName, p)
|
u.AddImports(pkgName, p)
|
||||||
|
@ -316,6 +319,12 @@ func (b *Builder) priorCommentLines(pos token.Pos) string {
|
||||||
return ""
|
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 {
|
func tcNameToName(in string) types.Name {
|
||||||
// Detect anonymous type names. (These may have '.' characters because
|
// Detect anonymous type names. (These may have '.' characters because
|
||||||
// embedded types may have packages, so we detect them specially.)
|
// 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
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -70,6 +70,9 @@ type Object struct {
|
||||||
common.Object
|
common.Object
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AFunc(obj1 common.Object, obj2 Object) Frobber {
|
||||||
|
}
|
||||||
|
|
||||||
`,
|
`,
|
||||||
"base/common/proto/common.go": `
|
"base/common/proto/common.go": `
|
||||||
package common
|
package common
|
||||||
|
@ -88,11 +91,16 @@ package o
|
||||||
}
|
}
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{range $t := .}}{{if eq $t.Kind "Struct"}}{{template "Struct" $t}}{{end}}{{end}}`
|
{{define "Func"}}{{$s := .Signature}}func {{Raw .}}( {{range $s.Parameters}}{{Raw .}} {{end}}) {{range $s.Results}}{{Raw .}} {{end}}{}
|
||||||
|
|
||||||
|
{{end}}
|
||||||
|
{{range $t := .}}{{if eq $t.Kind "Struct"}}{{template "Struct" $t}}{{end}}{{end}}
|
||||||
|
{{range $t := .}}{{if eq $t.Kind "Func"}}{{template "Func" $t}}{{end}}{{end}}`
|
||||||
|
|
||||||
var expect = `
|
var expect = `
|
||||||
package o
|
package o
|
||||||
|
|
||||||
|
|
||||||
type CommonObject interface {
|
type CommonObject interface {
|
||||||
ID() Int64
|
ID() Int64
|
||||||
SetID(Int64)
|
SetID(Int64)
|
||||||
|
@ -119,8 +127,12 @@ type FooObject interface {
|
||||||
CommonObject
|
CommonObject
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func proto.AFunc( proto.Object proto.Object ) proto.Frobber {}
|
||||||
|
|
||||||
`
|
`
|
||||||
testNamer := namer.NewPublicNamer(1, "proto")
|
testNamer := namer.NewPublicNamer(1, "proto")
|
||||||
|
rawNamer := namer.NewRawNamer("o", nil)
|
||||||
_, u, o := construct(t, testFiles, testNamer)
|
_, u, o := construct(t, testFiles, testNamer)
|
||||||
t.Logf("\n%v\n\n", o)
|
t.Logf("\n%v\n\n", o)
|
||||||
tmpl := template.Must(
|
tmpl := template.Must(
|
||||||
|
@ -128,6 +140,7 @@ type FooObject interface {
|
||||||
Funcs(
|
Funcs(
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
"Name": testNamer.Name,
|
"Name": testNamer.Name,
|
||||||
|
"Raw": rawNamer.Name,
|
||||||
}).
|
}).
|
||||||
Parse(tmplText),
|
Parse(tmplText),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue