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


Golang Service.Edges方法代码示例

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


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

示例1: getTagFields

func getTagFields(xs xrefs.Service, ticket string) ([]string, error) {
	reply, err := xs.Edges(ctx, &xpb.EdgesRequest{
		Ticket: []string{ticket},
		Kind:   []string{schema.ChildOfEdge, schema.ParamEdge},
		Filter: []string{schema.NodeKindFact, schema.SubkindFact, identifierFact},
	})
	if err != nil || len(reply.EdgeSet) == 0 {
		return nil, err
	}

	var fields []string

	nodes := xrefs.NodesMap(reply.Node)
	edges := xrefs.EdgesMap(reply.EdgeSet)

	switch string(nodes[ticket][schema.NodeKindFact]) + "|" + string(nodes[ticket][schema.SubkindFact]) {
	case schema.FunctionKind + "|":
		fields = append(fields, "f")
		fields = append(fields, "arity:"+strconv.Itoa(len(edges[ticket][schema.ParamEdge])))
	case schema.EnumKind + "|" + schema.EnumClassSubkind:
		fields = append(fields, "g")
	case schema.PackageKind + "|":
		fields = append(fields, "p")
	case schema.RecordKind + "|" + schema.ClassSubkind:
		fields = append(fields, "c")
	case schema.VariableKind + "|":
		fields = append(fields, "v")
	}

	for _, parent := range edges[ticket][schema.ChildOfEdge] {
		parentIdent := string(nodes[parent][identifierFact])
		if parentIdent == "" {
			continue
		}
		switch string(nodes[parent][schema.NodeKindFact]) + "|" + string(nodes[parent][schema.SubkindFact]) {
		case schema.FunctionKind + "|":
			fields = append(fields, "function:"+parentIdent)
		case schema.RecordKind + "|" + schema.ClassSubkind:
			fields = append(fields, "class:"+parentIdent)
		case schema.EnumKind + "|" + schema.EnumClassSubkind:
			fields = append(fields, "enum:"+parentIdent)
		}
	}

	return fields, nil
}
开发者ID:jwatt,项目名称:kythe,代码行数:46,代码来源:ktags.go

示例2: getTagFields

func getTagFields(xs xrefs.Service, ticket string) ([]string, error) {
	reply, err := xs.Edges(ctx, &gpb.EdgesRequest{
		Ticket: []string{ticket},
		Kind:   []string{edges.ChildOf, edges.Param},
		Filter: []string{facts.NodeKind, facts.Subkind, identifierFact},
	})
	if err != nil || len(reply.EdgeSets) == 0 {
		return nil, err
	}

	var fields []string

	nmap := xrefs.NodesMap(reply.Nodes)
	emap := xrefs.EdgesMap(reply.EdgeSets)

	switch string(nmap[ticket][facts.NodeKind]) + "|" + string(nmap[ticket][facts.Subkind]) {
	case nodes.Function + "|":
		fields = append(fields, "f")
		fields = append(fields, "arity:"+strconv.Itoa(len(emap[ticket][edges.Param])))
	case nodes.Enum + "|" + nodes.EnumClass:
		fields = append(fields, "g")
	case nodes.Package + "|":
		fields = append(fields, "p")
	case nodes.Record + "|" + nodes.Class:
		fields = append(fields, "c")
	case nodes.Variable + "|":
		fields = append(fields, "v")
	}

	for parent := range emap[ticket][edges.ChildOf] {
		parentIdent := string(nmap[parent][identifierFact])
		if parentIdent == "" {
			continue
		}
		switch string(nmap[parent][facts.NodeKind]) + "|" + string(nmap[parent][facts.Subkind]) {
		case nodes.Function + "|":
			fields = append(fields, "function:"+parentIdent)
		case nodes.Record + "|" + nodes.Class:
			fields = append(fields, "class:"+parentIdent)
		case nodes.Enum + "|" + nodes.EnumClass:
			fields = append(fields, "enum:"+parentIdent)
		}
	}

	return fields, nil
}
开发者ID:benjyw,项目名称:kythe,代码行数:46,代码来源:ktags.go

示例3:

			flag.BoolVar(&targetsOnly, "targets_only", false, "Only display edge targets")
			flag.StringVar(&edgeKinds, "kinds", "", "Comma-separated list of edge kinds to return (default returns all)")
			flag.StringVar(&pageToken, "page_token", "", "Edges page token")
			flag.IntVar(&pageSize, "page_size", 0, "Maximum number of edges returned (0 lets the service use a sensible default)")
		},
		func(flag *flag.FlagSet) error {
			req := &xpb.EdgesRequest{
				Ticket:    flag.Args(),
				PageToken: pageToken,
				PageSize:  int32(pageSize),
			}
			if edgeKinds != "" {
				req.Kind = strings.Split(edgeKinds, ",")
			}
			logRequest(req)
			reply, err := xs.Edges(ctx, req)
			if err != nil {
				return err
			}
			if reply.NextPageToken != "" {
				defer log.Printf("Next page token: %s", reply.NextPageToken)
			}
			if countOnly {
				return displayEdgeCounts(reply)
			} else if targetsOnly {
				return displayTargets(reply.EdgeSet)
			}
			return displayEdges(reply)
		})

	cmdXRefs = newCommand("xrefs", "[--definitions kind] [--references kind] [--documentation kind] [--related_nodes] [--page_token token] [--page_size num] <ticket>",
开发者ID:pedrokiefer,项目名称:kythe,代码行数:31,代码来源:kythe_commands.go


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