本文整理汇总了Golang中go/ast.FuncDecl.Doc方法的典型用法代码示例。如果您正苦于以下问题:Golang FuncDecl.Doc方法的具体用法?Golang FuncDecl.Doc怎么用?Golang FuncDecl.Doc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.FuncDecl
的用法示例。
在下文中一共展示了FuncDecl.Doc方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: set
// set creates the corresponding Func for f and adds it to mset.
// If there are multiple f's with the same name, set keeps the first
// one with documentation; conflicts are ignored.
//
func (mset methodSet) set(f *ast.FuncDecl) {
name := f.Name.Name
if g := mset[name]; g != nil && g.Doc != "" {
// A function with the same name has already been registered;
// since it has documentation, assume f is simply another
// implementation and ignore it. This does not happen if the
// caller is using go/build.ScanDir to determine the list of
// files implementing a package.
return
}
// function doesn't exist or has no documentation; use f
recv := ""
if f.Recv != nil {
var typ ast.Expr
// be careful in case of incorrect ASTs
if list := f.Recv.List; len(list) == 1 {
typ = list[0].Type
}
recv = recvString(typ)
}
mset[name] = &Func{
Doc: f.Doc.Text(),
Name: name,
Decl: f,
Recv: recv,
Orig: recv,
}
f.Doc = nil // doc consumed - remove from AST
}
示例2: newFunc
func newFunc(decl *ast.FuncDecl) *Func {
if !ast.IsExported(decl.Name.Name) {
return nil
}
f := new(Func)
f.Doc = doc.CommentText(decl.Doc)
decl.Doc = nil
f.Name = decl.Name.Name
if decl.Recv != nil {
f.Recv = recvAsString(decl.Recv.List[0].Type)
}
f.Decl = decl
decl.Body = nil // remove body
return f
}
示例3: oneLineFunc
// oneLineFunc prints a function declaration as a single line.
func (pkg *Package) oneLineFunc(decl *ast.FuncDecl) {
decl.Doc = nil
decl.Body = nil
pkg.emit("", decl)
}