• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang ast.IsExported函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中go/ast.IsExported函数的典型用法代码示例。如果您正苦于以下问题:Golang IsExported函数的具体用法?Golang IsExported怎么用?Golang IsExported使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了IsExported函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: doSpec

func doSpec(sk int, sv interface{}, dirpkg string) {
	//Printf("doSpec: %#v\n", sv)
	switch x := sv.(type) {
	case (*ast.ImportSpec):
		path := x.Path.Value
		path = path[1 : len(path)-1] // Omit initial & final <">
		name := path
		j := strings.LastIndex(name, "/")
		if j > 0 {
			name = name[j+1:]
		}
		if x.Name != nil {
			name = x.Name.Name
		}
		//Printf("ImportSpec: NAME %s PATH %s\n", name, path)
		Printf("@@ %s { IMPORT %s path: %s }\n", dirpkg, name, path)
	case (*ast.TypeSpec):
		name := x.Name.Name
		if !ast.IsExported(x.Name.Name) {
			return
		}
		Printf("@@ %s { TYPE %s type: %s }\n", dirpkg, name, typeStr(x.Type))
	case (*ast.ValueSpec):
		for _, nv := range x.Names {
			//Printf("    ValueSPEC [%d] %s : %s\n", nk, nv.Name, Cond(x.Type == nil, "nil", typeStr(x.Type)))
			if !ast.IsExported(nv.Name) {
				return
			}
			Printf("@@ %s { VALUE %s : %s }\n", dirpkg, nv.Name, Cond(x.Type == nil, "!", typeStr(x.Type)))
		}
	default:
		panic(Sprintf("doSpec: DEFAULT: %#v\n", x))
	}
}
开发者ID:strickyak,项目名称:pyrrhus,代码行数:34,代码来源:grok.go


示例2: assignMethodPaths

func (g *Grapher) assignMethodPaths(named *types.Named, prefix []string, pkgscope bool) {
	for i := 0; i < named.NumMethods(); i++ {
		m := named.Method(i)
		path := append(append([]string{}, prefix...), m.Name())
		g.paths[m] = path

		g.exported[m] = ast.IsExported(m.Name())
		g.pkgscope[m] = pkgscope

		if s := m.Scope(); s != nil {
			g.assignPaths(s, path, false)
		}
	}

	if iface, ok := named.Underlying().(*types.Interface); ok {
		for i := 0; i < iface.NumExplicitMethods(); i++ {
			m := iface.Method(i)
			path := append(append([]string{}, prefix...), m.Name())
			g.paths[m] = path

			g.exported[m] = ast.IsExported(m.Name())
			g.pkgscope[m] = pkgscope

			if s := m.Scope(); s != nil {
				g.assignPaths(s, path, false)
			}
		}
	}
}
开发者ID:ildarisaev,项目名称:srclib-go,代码行数:29,代码来源:scope.go


示例3: lintValueSpecDoc

// lintValueSpecDoc examines package-global variables and constants.
// It complains if they are not individually declared,
// or if they are not suitably documented in the right form (unless they are in a block that is commented).
func (f *file) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genDeclMissingComments map[*ast.GenDecl]bool) {
	kind := "var"
	if gd.Tok == token.CONST {
		kind = "const"
	}

	if len(vs.Names) > 1 {
		// Check that none are exported.
		for _, n := range vs.Names {
			if ast.IsExported(n.Name) {
				f.errorf(vs, 1, "exported %s %s should have its own declaration", kind, n.Name)
				return
			}
		}
	}

	// Only one name.
	name := vs.Names[0].Name
	if !ast.IsExported(name) {
		return
	}

	if vs.Doc == nil {
		if gd.Doc == nil && !genDeclMissingComments[gd] {
			f.errorf(vs, 1, "exported %s %s should have comment or be unexported", kind, name)
			genDeclMissingComments[gd] = true
		}
		return
	}
	prefix := name + " "
	if !strings.HasPrefix(vs.Doc.Text(), prefix) {
		f.errorf(vs.Doc, 1, `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
	}
}
开发者ID:bernerdschaefer,项目名称:lint,代码行数:37,代码来源:lint.go


示例4: checkInPackageBlock

// checkInPackageBlock performs safety checks for renames of
// func/var/const/type objects in the package block.
func (r *renamer) checkInPackageBlock(from types.Object) {
	// Check that there are no references to the name from another
	// package if the renaming would make it unexported.
	if ast.IsExported(from.Name()) && !ast.IsExported(r.to) {
		for pkg, info := range r.packages {
			if pkg == from.Pkg() {
				continue
			}
			if id := someUse(info, from); id != nil &&
				!r.checkExport(id, pkg, from) {
				break
			}
		}
	}

	info := r.packages[from.Pkg()]

	// Check that in the package block, "init" is a function, and never referenced.
	if r.to == "init" {
		kind := objectKind(from)
		if kind == "func" {
			// Reject if intra-package references to it exist.
			for id, obj := range info.Uses {
				if obj == from {
					r.errorf(from.Pos(),
						"renaming this func %q to %q would make it a package initializer",
						from.Name(), r.to)
					r.errorf(id.Pos(), "\tbut references to it exist")
					break
				}
			}
		} else {
			r.errorf(from.Pos(), "you cannot have a %s at package level named %q",
				kind, r.to)
		}
	}

	// Check for conflicts between package block and all file blocks.
	for _, f := range info.Files {
		fileScope := info.Info.Scopes[f]
		b, prev := fileScope.LookupParent(r.to, token.NoPos)
		if b == fileScope {
			r.errorf(from.Pos(), "renaming this %s %q to %q would conflict",
				objectKind(from), from.Name(), r.to)
			r.errorf(prev.Pos(), "\twith this %s",
				objectKind(prev))
			return // since checkInPackageBlock would report redundant errors
		}
	}

	// Check for conflicts in lexical scope.
	if from.Exported() {
		for _, info := range r.packages {
			r.checkInLexicalScope(from, info)
		}
	} else {
		r.checkInLexicalScope(from, info)
	}
}
开发者ID:ChloeTigre,项目名称:golang-tools,代码行数:61,代码来源:check.go


示例5: checkInPackageBlock

// checkInPackageBlock performs safety checks for renames of
// func/var/const/type objects in the package block.
func (r *Unexporter) checkInPackageBlock(objsToUpdate map[types.Object]string, from types.Object, to string) {
	// Check that there are no references to the name from another
	// package if the renaming would make it unexported.
	if ast.IsExported(from.Name()) && !ast.IsExported(to) {
		for pkg, info := range r.packages {
			if pkg == from.Pkg() {
				continue
			}
			if id := someUse(info, from); id != nil &&
				!r.checkExport(id, pkg, from, to) {
				break
			}
		}
	}

	info := r.packages[from.Pkg()]
	lexinfo := r.lexInfo(info)

	// Check that in the package block, "init" is a function, and never referenced.
	if to == "init" {
		kind := objectKind(from)
		if kind == "func" {
			// Reject if intra-package references to it exist.
			if refs := lexinfo.Refs[from]; len(refs) > 0 {
				r.warn(from,
					r.errorf(from.Pos(),
						"renaming this func %q to %q would make it a package initializer",
						from.Name(), to),
					r.errorf(refs[0].Id.Pos(), "\tbut references to it exist"))
			}
		} else {
			r.warn(from, r.errorf(from.Pos(), "you cannot have a %s at package level named %q",
				kind, to))
		}
	}

	// Check for conflicts between package block and all file blocks.
	for _, f := range info.Files {
		if prev, b := lexinfo.Blocks[f].Lookup(to); b == lexinfo.Blocks[f] {
			r.warn(from,
				r.errorf(from.Pos(), "renaming this %s %q to %q would conflict",
					objectKind(from), from.Name(), to),
				r.errorf(prev.Pos(), "\twith this %s",
					objectKind(prev)))
			return // since checkInPackageBlock would report redundant errors
		}
	}

	// Check for conflicts in lexical scope.
	if from.Exported() {
		for _, info := range r.packages {
			r.checkInLexicalScope(objsToUpdate, from, to, info)
		}
	} else {
		r.checkInLexicalScope(objsToUpdate, from, to, info)
	}
}
开发者ID:rakyll,项目名称:GCSolutions,代码行数:59,代码来源:check.go


示例6: FuncLink

func (p *Package) FuncLink(fn *ast.FuncDecl) string {
	recv := FuncReceiver(fn)
	if ast.IsExported(fn.Name.Name) && (recv == "" || ast.IsExported(recv)) {
		if recv != "" {
			return "#" + MethodId(recv, fn.Name.Name)
		}
		return "#" + FuncId(fn.Name.Name)
	}
	return p.ReversePos(fn)
}
开发者ID:rainycape,项目名称:gondola,代码行数:10,代码来源:package.go


示例7: interfaceMethods

// interfaceMethods returns the expanded list of exported methods for an interface.
// The boolean complete reports whether the list contains all methods (that is, the
// interface has no unexported methods).
// pkg is the complete package name ("net/http")
// iname is the interface name.
func (w *Walker) interfaceMethods(pkg, iname string) (methods []method, complete bool) {
	t, ok := w.interfaces[pkgSymbol{pkg, iname}]
	if !ok {
		log.Fatalf("failed to find interface %s.%s", pkg, iname)
	}

	complete = true
	for _, f := range t.Methods.List {
		typ := f.Type
		switch tv := typ.(type) {
		case *ast.FuncType:
			for _, mname := range f.Names {
				if ast.IsExported(mname.Name) {
					ft := typ.(*ast.FuncType)
					methods = append(methods, method{
						name: mname.Name,
						sig:  w.funcSigString(ft),
					})
				} else {
					complete = false
				}
			}
		case *ast.Ident:
			embedded := typ.(*ast.Ident).Name
			if embedded == "error" {
				methods = append(methods, method{
					name: "Error",
					sig:  "() string",
				})
				continue
			}
			if !ast.IsExported(embedded) {
				log.Fatalf("unexported embedded interface %q in exported interface %s.%s; confused",
					embedded, pkg, iname)
			}
			m, c := w.interfaceMethods(pkg, embedded)
			methods = append(methods, m...)
			complete = complete && c
		case *ast.SelectorExpr:
			lhs := w.nodeString(tv.X)
			rhs := w.nodeString(tv.Sel)
			fpkg, ok := w.selectorFullPkg[lhs]
			if !ok {
				log.Fatalf("can't resolve selector %q in interface %s.%s", lhs, pkg, iname)
			}
			m, c := w.interfaceMethods(fpkg, rhs)
			methods = append(methods, m...)
			complete = complete && c
		default:
			log.Fatalf("unknown type %T in interface field", typ)
		}
	}
	return
}
开发者ID:hfeeki,项目名称:go,代码行数:59,代码来源:goapi.go


示例8: Visit

func (v *annotationVisitor) Visit(n ast.Node) ast.Visitor {
	switch n := n.(type) {
	case *ast.TypeSpec:
		if n.Type != nil {
			ast.Walk(v, n.Type)
		}
		return nil
	case *ast.FuncDecl:
		if n.Recv != nil {
			ast.Walk(v, n.Recv)
		}
		if n.Type != nil {
			ast.Walk(v, n.Type)
		}
		return nil
	case *ast.Field:
		if n.Type != nil {
			ast.Walk(v, n.Type)
		}
		return nil
	case *ast.ValueSpec:
		if n.Type != nil {
			ast.Walk(v, n.Type)
		}
		return nil
	case *ast.FuncLit:
		if n.Type != nil {
			ast.Walk(v, n.Type)
		}
		return nil
	case *ast.CompositeLit:
		if n.Type != nil {
			ast.Walk(v, n.Type)
		}
		return nil
	case *ast.Ident:
		if !ast.IsExported(n.Name) {
			return nil
		}
		v.addAnnotation(n, "", n.Name)
		return nil
	case *ast.SelectorExpr:
		if !ast.IsExported(n.Sel.Name) {
			return nil
		}
		if i, ok := n.X.(*ast.Ident); ok {
			v.addAnnotation(n, i.Name, n.Sel.Name)
			return nil
		}
	}
	return v
}
开发者ID:viney,项目名称:gopkgdoc,代码行数:52,代码来源:builder.go


示例9: getGenSpecs

func getGenSpecs(opts *options, structArgs []*structArg) (genSpecs []*genSpec) {
	fset := token.NewFileSet()
	types := getAllTypes(fset)

	for _, structArg := range structArgs {
		g := newGenSpec(structArg.Pointer, structArg.Package, structArg.Name)
		genSpecs = append(genSpecs, g)
		key := joinName(structArg.Package, structArg.Name)
		typ, known := types[key]
		if known {
			g.Methods = getMethods(typ)
			s, err := getStructType(typ)
			if err == nil {
				fieldSpecs := getFieldSpecs(s, fset, opts)
				g.AddFieldSpecs(fieldSpecs)
			}
		} else {
			addError(fmt.Sprintf("%s is not a known struct type", key))
			g.Methods = getMethods(nil)
		}
		if opts.ExportedOnly {
			if ast.IsExported(structArg.Name) {
				notes = append(notes, fmt.Sprintf("the %s type is already exported; the -e[xported] flag is redundant (ignored)", structArg.Name))
			} else {
				addError(fmt.Sprintf("the %s type is not exported; the -e[xported] flag conflicts", structArg.Name))
			}
		}
	}
	if opts.All {
		for key, typ := range types {
			pkg, name := splitName(key)
			if !opts.ExportedOnly || ast.IsExported(name) {
				g := newGenSpec(opts.AllPointer, pkg, name)
				g.Methods = getMethods(typ)
				s, err := getStructType(typ)
				if err == nil {
					fieldSpecs := getFieldSpecs(s, fset, opts)
					g.AddFieldSpecs(fieldSpecs)
				}
				genSpecs = append(genSpecs, g)
			}
		}
	}

	for _, g := range genSpecs {
		g.DetermineImports()
	}

	return
}
开发者ID:GauntletWizard,项目名称:gen,代码行数:50,代码来源:main.go


示例10: lintValueSpecDoc

// lintValueSpecDoc examines package-global variables and constants.
// It complains if they are not individually declared,
// or if they are not suitably documented in the right form (unless they are in a block that is commented).
func (f *file) lintValueSpecDoc(vs *ast.ValueSpec, gd *ast.GenDecl, genDeclMissingComments map[*ast.GenDecl]bool) {
	kind := "var"
	if gd.Tok == token.CONST {
		kind = "const"
	}

	if len(vs.Names) > 1 {
		// Check that none are exported except for the first.
		for _, n := range vs.Names[1:] {
			if ast.IsExported(n.Name) {
				f.errorf(vs, 1, category("comments"), "exported %s %s should have its own declaration", kind, n.Name)
				return
			}
		}
	}

	// Only one name.
	name := vs.Names[0].Name
	if !ast.IsExported(name) {
		return
	}

	if vs.Doc == nil && gd.Doc == nil {
		if genDeclMissingComments[gd] {
			return
		}
		block := ""
		if kind == "const" && gd.Lparen.IsValid() {
			block = " (or a comment on this block)"
		}
		f.errorf(vs, 1, link(docCommentsLink), category("comments"), "exported %s %s should have comment%s or be unexported", kind, name, block)
		genDeclMissingComments[gd] = true
		return
	}
	// If this GenDecl has parens and a comment, we don't check its comment form.
	if gd.Lparen.IsValid() && gd.Doc != nil {
		return
	}
	// The relevant text to check will be on either vs.Doc or gd.Doc.
	// Use vs.Doc preferentially.
	doc := vs.Doc
	if doc == nil {
		doc = gd.Doc
	}
	prefix := name + " "
	if !strings.HasPrefix(doc.Text(), prefix) {
		f.errorf(doc, 1, link(docCommentsLink), category("comments"), `comment on exported %s %s should be of the form "%s..."`, kind, name, prefix)
	}
}
开发者ID:swadhin4,项目名称:lint,代码行数:52,代码来源:lint.go


示例11: astFieldListToDecls

func astFieldListToDecls(f *ast.FieldList, class int, flags int, scope *Scope) map[string]*Decl {
	count := 0
	for _, field := range f.List {
		count += len(field.Names)
	}

	if count == 0 {
		return nil
	}

	decls := make(map[string]*Decl, count)
	for _, field := range f.List {
		for _, name := range field.Names {
			if flags&DECL_FOREIGN != 0 && !ast.IsExported(name.Name()) {
				continue
			}
			d := new(Decl)
			d.Name = name.Name()
			d.Type = field.Type
			d.Class = int16(class)
			d.Flags = int16(flags)
			d.Children = astTypeToChildren(field.Type, flags, scope)
			d.Embedded = astTypeToEmbedded(field.Type)
			d.Scope = scope
			d.ValueIndex = -1
			d.init()
			decls[d.Name] = d
		}

		// add anonymous field as a child (type embedding)
		if class == DECL_VAR && field.Names == nil {
			tp := typePath(field.Type)
			if flags&DECL_FOREIGN != 0 && !ast.IsExported(tp.name) {
				continue
			}
			d := new(Decl)
			d.Name = tp.name
			d.Type = field.Type
			d.Class = int16(class)
			d.Flags = int16(flags)
			d.Scope = scope
			d.ValueIndex = -1
			d.init()
			decls[d.Name] = d
		}
	}
	return decls
}
开发者ID:kij,项目名称:gocode,代码行数:48,代码来源:decl.go


示例12: Get

// Get retrieves a single named value from the given builder.
// If the value has not been set, it returns (nil, false). Otherwise, it will
// return (value, true).
//
// If the named value was last set with Append or Extend, the returned value
// will be a slice. If the given Builder has been registered with Register or
// RegisterType and the given name is an exported field of the registered
// struct, the returned slice will have the same type as that field. Otherwise
// the slice will have type []interface{}. It will panic if the given name is a
// registered struct's exported field and the value set on the Builder is not
// assignable to the field.
func Get(builder interface{}, name string) (interface{}, bool) {
	val, ok := getBuilderMap(builder).Lookup(name)
	if !ok {
		return nil, false
	}

	list, isList := val.(ps.List)
	if isList {
		arrayType := anyArrayType

		if ast.IsExported(name) {
			structType := getBuilderStructType(reflect.TypeOf(builder))
			if structType != nil {
				field, ok := (*structType).FieldByName(name)
				if ok {
					arrayType = field.Type
				}
			}
		}

		val = listToSlice(list, arrayType).Interface()
	}

	return val, true
}
开发者ID:stellar,项目名称:bridge-server,代码行数:36,代码来源:builder.go


示例13: VisitFuncProtoDecl

func (c *compiler) VisitFuncProtoDecl(f *ast.FuncDecl) Value {
	var fn_type *types.Func
	fn_name := f.Name.String()

	exported := ast.IsExported(fn_name)
	if fn_name == "init" {
		// Make "init" functions anonymous.
		fn_name = ""
		// "init" functions aren't recorded by the parser, so f.Name.Obj is
		// not set.
		fn_type = &types.Func{ /* no params or result */ }
	} else {
		fn_type = f.Name.Obj.Type.(*types.Func)
		if c.module.Name == "main" && fn_name == "main" {
			exported = true
		} else {
			pkgname := c.pkgmap[f.Name.Obj]
			fn_name = pkgname + "." + fn_name
		}
	}

	llvm_fn_type := c.types.ToLLVM(fn_type).ElementType()
	fn := llvm.AddFunction(c.module.Module, fn_name, llvm_fn_type)
	if exported {
		fn.SetLinkage(llvm.ExternalLinkage)
	}

	result := c.NewLLVMValue(fn, fn_type)
	if f.Name.Obj != nil {
		f.Name.Obj.Data = result
		f.Name.Obj.Type = fn_type
	}
	return result
}
开发者ID:c0der007,项目名称:llgo,代码行数:34,代码来源:decl.go


示例14: AddVar

func (symbols *Symbols) AddVar(d *ast.ValueSpec) {
	for _, name := range d.Names {
		if ast.IsExported(name.Name) {
			symbols.varcons = append(symbols.varcons, name.Name)
		}
	}
}
开发者ID:nullr0ute,项目名称:gofed,代码行数:7,代码来源:getUsedSymbols.go


示例15: walkVar

func (w *Walker) walkVar(vs *ast.ValueSpec) {
	for i, ident := range vs.Names {
		if !ast.IsExported(ident.Name) {
			continue
		}

		typ := ""
		if vs.Type != nil {
			typ = w.nodeString(vs.Type)
		} else {
			if len(vs.Values) == 0 {
				log.Fatalf("no values for var %q", ident.Name)
			}
			if len(vs.Values) > 1 {
				log.Fatalf("more than 1 values in ValueSpec not handled, var %q", ident.Name)
			}
			var err error
			typ, err = w.varValueType(vs.Values[i])
			if err != nil {
				log.Fatalf("unknown type of variable %q, type %T, error = %v\ncode: %s",
					ident.Name, vs.Values[i], err, w.nodeString(vs.Values[i]))
			}
		}
		w.emitFeature(fmt.Sprintf("var %s %s", ident, typ))
	}
}
开发者ID:joninvski,项目名称:go,代码行数:26,代码来源:goapi.go


示例16: fillFunc

func fillFunc(node *ast.FuncDecl, src string, fnct *Function) bool {
	if node.Name != nil {
		if !ast.IsExported(node.Name.Name) {
			return false
		}
		fnct.Name = node.Name.Name
	} else {
		return false
	}

	if node.Doc != nil {
		fnct.Doc = node.Doc.Text()
	}
	if node.Type != nil {
		if node.Type.Params != nil {
			fnct.Args = src[node.Type.Params.Pos() : node.Type.Params.End()-2]
		}
		if node.Type.Results != nil {
			fnct.Type = src[node.Type.Results.Pos()-1 : node.Type.Results.End()]
		}
	}

	if node.Recv != nil && len(node.Recv.List) > 0 {
		expr := node.Recv.List[0].Type
		recv := GetExprName(expr)
		if recv != "" {
			fnct.Recv = recv
		}
	}
	return true
}
开发者ID:YouROK,项目名称:GoProjectManager,代码行数:31,代码来源:fileparse.go


示例17: Visit

func (v *ControllerVisitor) Visit(node ast.Node) ast.Visitor {
	if node == nil {
		return nil
	}

	switch x := node.(type) {
	case *ast.GenDecl:
		if x.Tok == token.IMPORT {
			for _, s := range x.Specs {
				if spec, ok := s.(*ast.ImportSpec); ok {
					p := spec.Path.Value
					v.imports[p[1:len(p)-1]] = true
				}
			}
			// I think this is ok... there's nothing deeper in an import than what we've already gotten, right?
			return nil
		}
	case *ast.FuncDecl:
		/*
			This assumes that a .controller file will export only functions we want to be actions...
			Maybe we should annotate actions somehow?
		*/
		if x.Type.Results.NumFields() != 0 {
			panic(fmt.Sprintf("Could not transform %s.%s: number of result fields is not 0.", v.controllerName, x.Name.Name))
		}
		if ast.IsExported(x.Name.Name) {
			transformAction(x)
			return &RenderFuncVisitor{}
		}
		return nil
	}

	return v
}
开发者ID:shunyata,项目名称:systic,代码行数:34,代码来源:visitors.go


示例18: lintUnexportedReturn

// lintUnexportedReturn examines exported function declarations.
// It complains if any return an unexported type.
func (f *file) lintUnexportedReturn() {
	f.walk(func(n ast.Node) bool {
		fn, ok := n.(*ast.FuncDecl)
		if !ok {
			return true
		}
		if fn.Type.Results == nil {
			return false
		}
		if !fn.Name.IsExported() {
			return false
		}
		thing := "func"
		if fn.Recv != nil && len(fn.Recv.List) > 0 {
			thing = "method"
			if !ast.IsExported(receiverType(fn)) {
				// Don't report exported methods of unexported types,
				// such as private implementations of sort.Interface.
				return false
			}
		}
		for _, ret := range fn.Type.Results.List {
			typ := f.pkg.typeOf(ret.Type)
			if exportedType(typ) {
				continue
			}
			f.errorf(ret.Type, 0.8, category("unexported-type-in-api"),
				"exported %s %s returns unexported type %s, which can be annoying to use",
				thing, fn.Name.Name, typ)
			break // only flag one
		}
		return false
	})
}
开发者ID:swadhin4,项目名称:lint,代码行数:36,代码来源:lint.go


示例19: def

// Objects with names containing blanks are internal and not entered into
// a scope. Objects with exported names are inserted in the unsafe package
// scope; other objects are inserted in the universe scope.
//
func def(obj Object) {
	name := obj.Name()
	if strings.Index(name, " ") >= 0 {
		return // nothing to do
	}
	// fix Obj link for named types
	if typ, ok := obj.Type().(*Named); ok {
		typ.obj = obj.(*TypeName)
	}
	// exported identifiers go into package unsafe
	scope := Universe
	if ast.IsExported(name) {
		scope = Unsafe.scope
		// set Pkg field
		switch obj := obj.(type) {
		case *TypeName:
			obj.pkg = Unsafe
		case *Func:
			obj.pkg = Unsafe
		default:
			unreachable()
		}
	}
	if scope.Insert(obj) != nil {
		panic("internal error: double declaration")
	}
}
开发者ID:pombredanne,项目名称:go.tools,代码行数:31,代码来源:universe.go


示例20: writeStub

func (fi *funcInfo) writeStub(out io.Writer) {
	fmt.Fprintf(out, "func ")
	if fi.IsMethod() {
		fmt.Fprintf(out, "(%s %s) ", fi.recv.name, fi.recv.expr)
	}
	if ast.IsExported(fi.name) {
		fmt.Fprintf(out, "_real_")
	}
	fmt.Fprintf(out, "%s(", fi.name)
	for i, param := range fi.params {
		if i > 0 {
			fmt.Fprintf(out, ", ")
		}
		n := strings.Join(param.names, ", ")
		fmt.Fprintf(out, "%s %s", n, param.expr)
	}
	fmt.Fprintf(out, ") ")
	if len(fi.results) > 0 {
		fmt.Fprintf(out, "(")
		for i, result := range fi.results {
			if i > 0 {
				fmt.Fprintf(out, ", ")
			}
			n := strings.Join(result.names, ", ")
			fmt.Fprintf(out, "%s %s", n, result.expr)
		}
		fmt.Fprintf(out, ") ")
	}
	fmt.Fprintf(out, "{\n")
	fmt.Fprintf(out, "\tpanic(\"This is only a stub!\")\n")
	fmt.Fprintf(out, "}\n")
	fmt.Fprintf(out, "\n")
}
开发者ID:nlailler,项目名称:withmock,代码行数:33,代码来源:mock.go



注:本文中的go/ast.IsExported函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ast.MergePackageFiles函数代码示例发布时间:2022-05-28
下一篇:
Golang ast.Inspect函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap