示例#1
0
文件: godef.go 项目: gonotes/godef
func done(obj *ast.Object, typ types.Type) {
	defer os.Exit(0)
	if *pflag {
		for o := obj; o != nil; o = o.Next {
			pos := types.FileSet.Position(types.DeclPos(o))
			fmt.Printf("%v\n", pos)
		}
	} else {
		pos := types.FileSet.Position(types.DeclPos(obj))
		fmt.Printf("%v\n", pos)
	}
	if typ.Kind == ast.Bad || !*tflag {
		return
	}
	fmt.Printf("%s\n", strings.Replace(typeStr(obj, typ), "\n", "\n\t", -1))
	if *aflag || *Aflag {
		var m orderedObjects
		for obj := range typ.Iter() {
			m = append(m, obj)
		}
		sort.Sort(m)
		for _, obj := range m {
			// Ignore unexported members unless Aflag is set.
			if !*Aflag && (typ.Pkg != "" || !ast.IsExported(obj.Name)) {
				continue
			}
			id := ast.NewIdent(obj.Name)
			id.Obj = obj
			_, mt := types.ExprType(id, types.DefaultImporter, types.FileSet)
			fmt.Printf("\t%s\n", strings.Replace(typeStr(obj, mt), "\n", "\n\t\t", -1))
			fmt.Printf("\t\t%v\n", types.FileSet.Position(types.DeclPos(obj)))
		}
	}
}