1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 "honnef.co/go/tools/go/types/typeutil"
19 const source = `package P
26 func f(offset int32) (value byte, ok bool)
27 func g(rune) (uint8, bool)
30 // Parse and type-check the package.
31 fset := token.NewFileSet()
32 f, err := parser.ParseFile(fset, "P.go", source, 0)
36 pkg, err := new(types.Config).Check("P", fset, []*ast.File{f}, nil)
43 // Group names of package-level objects by their type.
44 var namesByType typeutil.Map // value is []string
45 for _, name := range scope.Names() {
46 T := scope.Lookup(name).Type()
48 names, _ := namesByType.At(T).([]string)
49 names = append(names, name)
50 namesByType.Set(T, names)
53 // Format, sort, and print the map entries.
55 namesByType.Iterate(func(T types.Type, names interface{}) {
56 lines = append(lines, fmt.Sprintf("%s %s", names, T))
59 for _, line := range lines {
65 // [f g] func(offset int32) (value byte, ok bool)
66 // [p q] untyped float