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


Golang SourceUnit.Files方法代码示例

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


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

示例1: addSourceUnitFiles

func addSourceUnitFiles(u *unit.SourceUnit, file string) {
	for _, f := range u.Files {
		if f == file {
			return
		}
	}
	u.Files = append(u.Files, file)
}
开发者ID:ildarisaev,项目名称:srclib,代码行数:8,代码来源:bench_test.go

示例2: addSourceUnitFilesFromData

func addSourceUnitFilesFromData(u *unit.SourceUnit, data *graph.Output) {
	files := map[string]struct{}{}
	for _, def := range data.Defs {
		files[def.File] = struct{}{}
	}
	for _, ref := range data.Refs {
		files[ref.File] = struct{}{}
	}
	for f := range files {
		u.Files = append(u.Files, f)
	}
	sort.Strings(u.Files)
}
开发者ID:ildarisaev,项目名称:srclib,代码行数:13,代码来源:bench_test.go

示例3: genUnit

func (c *SimpleRepoCmd) genUnit(ut *unit.SourceUnit) error {
	defs := make([]*graph.Def, 0)
	refs := make([]*graph.Ref, 0)
	docs := make([]*graph.Doc, 0)

	for _, filename := range hierarchicalNames("dir", "file", ut.Name, c.NFiles) {
		ut.Files = append(ut.Files, filename)
		fileDefs, fileRefs, fileDocs, err := c.genFile(ut, filename)
		if err != nil {
			return err
		}
		defs, refs, docs = append(defs, fileDefs...), append(refs, fileRefs...), append(docs, fileDocs...)
	}

	if !c.GenSource {
		gr := graph.Output{Defs: defs, Refs: refs, Docs: docs}
		deps := make([]*dep.Resolution, 0)
		if err := writeSrclibCache(ut, &gr, deps); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:xuy,项目名称:srclib,代码行数:24,代码来源:simple.go

示例4: genDefsFile

func (c *URefsRepoCmd) genDefsFile(ut *unit.SourceUnit, filename string) (defs []*graph.Def, defRefs []*graph.Ref, err error) {
	filename = filepath.Join(ut.Name, filename)
	ut.Files = append(ut.Files, filename)

	offset := 0
	defName := "foo"

	var sourceFile *os.File
	if c.GenSource {
		err := os.MkdirAll(filepath.Dir(filename), 0700)
		if err != nil {
			return nil, nil, err
		}
		file, err := os.Create(filename)
		if err != nil {
			return nil, nil, err
		}
		sourceFile = file
	}

	for i := 0; i < c.NDefs; i++ {
		def := &graph.Def{
			DefKey: graph.DefKey{
				Repo:     ut.Repo,
				CommitID: ut.CommitID,
				UnitType: ut.Type,
				Unit:     ut.Name,
				Path:     filepath.ToSlash(filepath.Join(filename, fmt.Sprintf("method_%d", i))),
			},
			Name:     defName,
			Exported: true,
			File:     filename,
			DefStart: uint32(offset),
			DefEnd:   uint32(offset + len(defName) - 1),
		}
		if sourceFile != nil {
			_, err := sourceFile.WriteString(def.Name + "\n")
			if err != nil {
				return nil, nil, err
			}
		}
		offset += len(defName) + 1
		defs = append(defs, def)

		defRef := &graph.Ref{
			DefRepo:     def.Repo,
			DefUnitType: def.UnitType,
			DefUnit:     def.Unit,
			DefPath:     def.Path,
			Repo:        def.Repo,
			CommitID:    def.CommitID,
			UnitType:    def.UnitType,
			Unit:        def.Unit,
			Def:         true,
			File:        def.File,
			Start:       def.DefStart,
			End:         def.DefEnd,
		}
		defRefs = append(defRefs, defRef)
	}

	// Close source file
	if sourceFile != nil {
		sourceFile.WriteString("\n")
		sourceFile.Close()
	}

	return defs, defRefs, nil
}
开发者ID:jpoler,项目名称:srclib,代码行数:69,代码来源:urefs.go


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