Esempio n. 1
0
// 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
}
Esempio n. 2
0
File: doce.go Progetto: nsf/gortfm
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
}
Esempio n. 3
0
File: pkg.go Progetto: sreis/go
// 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)
}