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


Golang xrefs.Normalizer类代码示例

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


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

示例1: decorationToReference

func decorationToReference(norm *xrefs.Normalizer, d *srvpb.FileDecorations_Decoration) *xpb.DecorationsReply_Reference {
	return &xpb.DecorationsReply_Reference{
		SourceTicket: d.Anchor.Ticket,
		TargetTicket: d.TargetTicket,
		Kind:         d.Kind,
		AnchorStart:  norm.ByteOffset(d.Anchor.StartOffset),
		AnchorEnd:    norm.ByteOffset(d.Anchor.EndOffset),
	}
}
开发者ID:herberteuler,项目名称:kythe,代码行数:9,代码来源:xrefs.go

示例2: normalizeSpan

func normalizeSpan(norm *xrefs.Normalizer, startOffset, endOffset int32) (start, end *xpb.Location_Point, err error) {
	start = norm.ByteOffset(startOffset)
	end = norm.ByteOffset(endOffset)

	if start.ByteOffset != startOffset {
		err = fmt.Errorf("inconsistent start location; expected: %d; found; %d",
			startOffset, start.ByteOffset)
	} else if end.ByteOffset != endOffset {
		err = fmt.Errorf("inconsistent end location; expected: %d; found; %d",
			endOffset, end.ByteOffset)
	}
	return
}
开发者ID:bzz,项目名称:kythe,代码行数:13,代码来源:xrefs.go

示例3: expandAnchor

func expandAnchor(anchor *srvpb.RawAnchor, file *srvpb.File, norm *xrefs.Normalizer, kind string) (*srvpb.ExpandedAnchor, error) {
	sp := norm.ByteOffset(anchor.StartOffset)
	ep := norm.ByteOffset(anchor.EndOffset)
	txt, err := getText(sp, ep, file)
	if err != nil {
		return nil, fmt.Errorf("error getting anchor text: %v", err)
	}

	ssp := norm.ByteOffset(anchor.SnippetStart)
	sep := norm.ByteOffset(anchor.SnippetEnd)
	snippet, err := getText(ssp, sep, file)
	if err != nil {
		return nil, fmt.Errorf("error getting text for snippet: %v", err)
	}

	// fallback to a line-based snippet if the indexer did not provide its own snippet offsets
	if snippet == "" {
		ssp = &xpb.Location_Point{
			ByteOffset: sp.ByteOffset - sp.ColumnOffset,
			LineNumber: sp.LineNumber,
		}
		nextLine := norm.Point(&xpb.Location_Point{LineNumber: sp.LineNumber + 1})
		sep = &xpb.Location_Point{
			ByteOffset:   nextLine.ByteOffset - 1,
			LineNumber:   sp.LineNumber,
			ColumnOffset: sp.ColumnOffset + (nextLine.ByteOffset - sp.ByteOffset - 1),
		}
		snippet, err = getText(ssp, sep, file)
		if err != nil {
			return nil, fmt.Errorf("error getting text for line snippet: %v", err)
		}
	}

	return &srvpb.ExpandedAnchor{
		Ticket: anchor.Ticket,
		Kind:   kind,
		Parent: file.Ticket,

		Text: txt,
		Span: &cpb.Span{
			Start: p2p(sp),
			End:   p2p(ep),
		},

		Snippet: snippet,
		SnippetSpan: &cpb.Span{
			Start: p2p(ssp),
			End:   p2p(sep),
		},
	}, nil
}
开发者ID:jwatt,项目名称:kythe,代码行数:51,代码来源:assemble.go

示例4: scanReferences

func (d *DB) scanReferences(fileTicket string, norm *xrefs.Normalizer) ([]*xpb.DecorationsReply_Reference, error) {
	rs, err := d.Query("SELECT anchor_ticket, kind, target_ticket, start_offset, end_offset FROM Decorations WHERE file_ticket = $1 ORDER BY start_offset, end_offset;", fileTicket)
	if err != nil {
		return nil, fmt.Errorf("error retrieving decorations: %v", err)
	}
	defer closeRows(rs)

	var references []*xpb.DecorationsReply_Reference
	for rs.Next() {
		r := &xpb.DecorationsReply_Reference{
			AnchorStart: &xpb.Location_Point{},
			AnchorEnd:   &xpb.Location_Point{},
		}
		if err := rs.Scan(&r.SourceTicket, &r.Kind, &r.TargetTicket, &r.AnchorStart.ByteOffset, &r.AnchorEnd.ByteOffset); err != nil {
			return nil, fmt.Errorf("sql scan error: %v", err)
		}
		r.AnchorStart = norm.Point(r.AnchorStart)
		r.AnchorEnd = norm.Point(r.AnchorEnd)
		references = append(references, r)
	}

	return references, nil
}
开发者ID:bzz,项目名称:kythe,代码行数:23,代码来源:pq_xrefs.go

示例5: ExpandAnchor

// ExpandAnchor returns the ExpandedAnchor equivalent of the given RawAnchor
// where file (and its associated Normalizer) must be the anchor's parent file.
func ExpandAnchor(anchor *srvpb.RawAnchor, file *srvpb.File, norm *xrefs.Normalizer, kind string) (*srvpb.ExpandedAnchor, error) {
	if err := checkSpan(len(file.Text), anchor.StartOffset, anchor.EndOffset); err != nil {
		return nil, fmt.Errorf("invalid text offsets: %v", err)
	}

	sp := norm.ByteOffset(anchor.StartOffset)
	ep := norm.ByteOffset(anchor.EndOffset)
	txt, err := getText(sp, ep, file)
	if err != nil {
		return nil, fmt.Errorf("error getting anchor text: %v", err)
	}

	var snippet string
	var ssp, sep *xpb.Location_Point
	if anchor.SnippetStart != 0 || anchor.SnippetEnd != 0 {
		if err := checkSpan(len(file.Text), anchor.SnippetStart, anchor.SnippetEnd); err != nil {
			return nil, fmt.Errorf("invalid snippet offsets: %v", err)
		}

		ssp = norm.ByteOffset(anchor.SnippetStart)
		sep = norm.ByteOffset(anchor.SnippetEnd)
		snippet, err = getText(ssp, sep, file)
		if err != nil {
			return nil, fmt.Errorf("error getting text for snippet: %v", err)
		}
	} else {
		// fallback to a line-based snippet if the indexer did not provide its own snippet offsets
		ssp = &xpb.Location_Point{
			ByteOffset: sp.ByteOffset - sp.ColumnOffset,
			LineNumber: sp.LineNumber,
		}
		nextLine := norm.Point(&xpb.Location_Point{LineNumber: sp.LineNumber + 1})
		if nextLine.ByteOffset <= ssp.ByteOffset { // double-check ssp != EOF
			return nil, errors.New("anchor past EOF")
		}
		sep = &xpb.Location_Point{
			ByteOffset:   nextLine.ByteOffset - 1,
			LineNumber:   sp.LineNumber,
			ColumnOffset: sp.ColumnOffset + (nextLine.ByteOffset - sp.ByteOffset - 1),
		}
		snippet, err = getText(ssp, sep, file)
		if err != nil {
			return nil, fmt.Errorf("error getting text for line snippet: %v", err)
		}
	}

	return &srvpb.ExpandedAnchor{
		Ticket: anchor.Ticket,
		Kind:   kind,
		Parent: file.Ticket,

		Text: txt,
		Span: &cpb.Span{
			Start: p2p(sp),
			End:   p2p(ep),
		},

		Snippet: snippet,
		SnippetSpan: &cpb.Span{
			Start: p2p(ssp),
			End:   p2p(sep),
		},
	}, nil
}
开发者ID:benjyw,项目名称:kythe,代码行数:66,代码来源:assemble.go


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