当前位置: 首页>>代码示例>>Golang>>正文


Golang ImportSpec.Pos方法代码示例

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


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

示例1: LookupImport

func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec) {
	fpath, err := strconv.Unquote(is.Path.Value)
	if err != nil {
		return
	}
	fbase := fpath
	pos := strings.LastIndexAny(fpath, "./-\\")
	if pos != -1 {
		fbase = fpath[pos+1:]
	}
	fid := fpath + "." + fbase
	//kind := ObjPkgName
	//fmt.Println(kind, true)

	if typeFindDef {
		fmt.Println(w.fset.Position(is.Pos()))
	}
	if typeFindInfo {
		fmt.Println("package", fpath)
	}
	if !typeFindUse {
		return
	}
	var usages []int
	for id, obj := range pkgInfo.Uses {
		if obj != nil && obj.Id() == fid { //!= nil && cursorObj.Pos() == obj.Pos() {
			usages = append(usages, int(id.Pos()))
		}
	}
	(sort.IntSlice(usages)).Sort()
	for _, pos := range usages {
		fmt.Println(w.fset.Position(token.Pos(pos)))
	}
}
开发者ID:RavenZZ,项目名称:liteide,代码行数:34,代码来源:type.go

示例2: UnusedImport

func (p *patchUnused) UnusedImport(imp *ast.ImportSpec) {
	if imp.Name != nil {
		p.patches = append(p.patches, patch.Replace(imp.Name, "_"))
	} else {
		p.patches = append(p.patches, patch.Insert(imp.Pos(), "_ "))
	}
}
开发者ID:soniah,项目名称:gosloppy,代码行数:7,代码来源:gosloppy.go

示例3: LookupImport

func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec) {
	fpath, err := strconv.Unquote(is.Path.Value)
	if err != nil {
		return
	}

	if typesFindDef {
		fmt.Println(w.fset.Position(is.Pos()))
	}

	fbase := fpath
	pos := strings.LastIndexAny(fpath, "./-\\")
	if pos != -1 {
		fbase = fpath[pos+1:]
	}

	var fname string
	if is.Name != nil {
		fname = is.Name.Name
	} else {
		fname = fbase
	}

	if typesFindInfo {
		if fname == fpath {
			fmt.Printf("package %s\n", fname)
		} else {
			fmt.Printf("package %s (\"%s\")\n", fname, fpath)
		}
	}

	if !typesFindUse {
		return
	}

	path := pkg.Path()

	if strings.Contains(path, "vendor/") {
		path = strings.Split(path, "vendor/")[1]
	}

	fid := path + "." + fname

	var usages []int
	for id, obj := range pkgInfo.Uses {
		if obj != nil && obj.Id() == fid { //!= nil && cursorObj.Pos() == obj.Pos() {
			usages = append(usages, int(id.Pos()))
		}
	}

	(sort.IntSlice(usages)).Sort()
	for _, pos := range usages {
		fmt.Println(w.fset.Position(token.Pos(pos)))
	}
}
开发者ID:donseba,项目名称:gotools,代码行数:55,代码来源:types.go

示例4: foundImport

func (ps *ProjectStats) foundImport(fs *token.FileSet, i *ast.ImportSpec, path string) error {
	importPath, err := strconv.Unquote(i.Path.Value)
	if err != nil {
		return err
	}
	ref := fs.Position(i.Pos())
	_, found := ps.ImportStatsByPath[importPath]
	if found {
		ps.ImportStatsByPath[importPath].ReferencePositions = append(ps.ImportStatsByPath[importPath].ReferencePositions, ref)
	} else {
		ps.ImportStatsByPath[importPath] = NewImportStats(importPath, ref)
	}
	return nil
}
开发者ID:johnt337,项目名称:gopack,代码行数:14,代码来源:stats.go

示例5: LookupImport

func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec) []*Doc {
	fpath, err := strconv.Unquote(is.Path.Value)
	if err != nil {
		return []*Doc{}
	}

	ret := []*Doc{}

	if w.findDef {
		fpos := w.fset.Position(is.Pos())
		ret = append(ret, &Doc{
			Pkg:  pkg.Name(),
			Src:  "",
			Name: is.Name.Name,
			Kind: "package",
			Fn:   fpos.Filename,
			Row:  fpos.Line - 1,
			Col:  fpos.Column - 1,
		})
		fmt.Println(fpos)
	}

	fbase := fpath
	pos := strings.LastIndexAny(fpath, "./-\\")
	if pos != -1 {
		fbase = fpath[pos+1:]
	}

	var fname string
	if is.Name != nil {
		fname = is.Name.Name
	} else {
		fname = fbase
	}

	if w.findInfo {
		if fname == fpath {
			fmt.Printf("package %s\n", fname)
		} else {
			fmt.Printf("package %s (\"%s\")\n", fname, fpath)
		}
	}

	if !w.findUse {
		return ret
	}

	fid := pkg.Path() + "." + fname
	var usages []int
	for id, obj := range pkgInfo.Uses {
		if obj != nil && obj.Id() == fid { //!= nil && cursorObj.Pos() == obj.Pos() {
			usages = append(usages, int(id.Pos()))
		}
	}
	(sort.IntSlice(usages)).Sort()
	for _, pos := range usages {
		fpos := w.fset.Position(token.Pos(pos))
		ret = append(ret, &Doc{
			Pkg:  pkg.Name(),
			Src:  "",
			Name: fname,
			Kind: "package",
			Fn:   fpos.Filename,
			Row:  fpos.Line - 1,
			Col:  fpos.Column - 1,
		})
		if typeVerbose {
			log.Println(fpos)
		}
	}

	return ret
}
开发者ID:nuance,项目名称:GoSublime,代码行数:73,代码来源:m_doc_types.go


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