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


Golang Node.End方法代码示例

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


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

示例1: normalizeNodePos

// normalizeNodePos resets all position information of node and its descendants.
func normalizeNodePos(node ast.Node) {
	ast.Inspect(node, func(node ast.Node) bool {
		if node == nil {
			return true
		}

		if node.Pos() == token.NoPos && node.End() == token.NoPos {
			return true
		}

		pv := reflect.ValueOf(node)
		if pv.Kind() != reflect.Ptr {
			return true
		}

		v := pv.Elem()
		if v.Kind() != reflect.Struct {
			return true
		}

		for i := 0; i < v.NumField(); i++ {
			f := v.Field(i)
			ft := f.Type()
			if f.CanSet() && ft.PkgPath() == "go/token" && ft.Name() == "Pos" && f.Int() != 0 {
				f.SetInt(1)
			}
		}

		return true
	})
}
开发者ID:gopherds,项目名称:gophernotes,代码行数:32,代码来源:node.go

示例2: NewIssue

func NewIssue(ctx *Context, node ast.Node, desc string, severity Score, confidence Score) *Issue {
	var code string
	fobj := ctx.FileSet.File(node.Pos())
	name := fobj.Name()
	line := fobj.Line(node.Pos())

	if file, err := os.Open(fobj.Name()); err == nil {
		defer file.Close()
		s := (int64)(fobj.Position(node.Pos()).Offset) // Go bug, should be int64
		e := (int64)(fobj.Position(node.End()).Offset) // Go bug, should be int64
		code, err = codeSnippet(file, s, e, node)
		if err != nil {
			code = err.Error()
		}
	}

	return &Issue{
		File:       name,
		Line:       line,
		What:       desc,
		Confidence: confidence,
		Severity:   severity,
		Code:       code,
	}
}
开发者ID:vmware,项目名称:vic,代码行数:25,代码来源:issue.go

示例3: getSourceString

func getSourceString(node ast.Node, fset *token.FileSet) string {
	p1 := fset.Position(node.Pos())
	p2 := fset.Position(node.End())

	b := getFileBytes(p1.Filename)
	return string(b[p1.Offset:p2.Offset])
}
开发者ID:serussell,项目名称:gen,代码行数:7,代码来源:main.go

示例4: Visit

func (v *funcVisitor) Visit(n ast.Node) ast.Visitor {
	switch n := n.(type) {
	case *ast.FuncDecl:
		// Function name is prepended with "T." if there is a receiver, where
		// T is the type of the receiver, dereferenced if it is a pointer.
		name := n.Name.Name
		if n.Recv != nil {
			field := n.Recv.List[0]
			switch recv := field.Type.(type) {
			case *ast.StarExpr:
				name = recv.X.(*ast.Ident).Name + "." + name
			case *ast.Ident:
				name = recv.Name + "." + name
			}
		}
		start, end := v.fset.Position(n.Pos()), v.fset.Position(n.End())
		f := v.pkg.RegisterFunction(name, start.Filename, start.Offset, end.Offset)
		v.state.functions = append(v.state.functions, f)
		sv := &stmtVisitor{v.state}
		if n.Body != nil {
			sv.VisitStmt(n.Body)
		}
		// TODO function coverage (insert "function.Enter", "function.Leave").

		// TODO come up with naming scheme for function literals.
		// case *ast.FuncLit:
	}
	return v
}
开发者ID:fiber,项目名称:gocov,代码行数:29,代码来源:instrument.go

示例5: Visit

func (this DepthWalker) Visit(node ast.Node) ast.Visitor {
	if node == nil {
		return this + 1
	}

	buffer := ""
	for i := 0; i < int(this); i++ {
		buffer += " "
	}

	fmt.Printf("%sPos: %d %s\n", buffer, node.Pos(), AllSources.Position(node.Pos()))
	fmt.Printf("%sEnd: %d %s\n", buffer, node.End(), AllSources.Position(node.End()))
	fmt.Printf("%s%T\n", buffer, node)
	fmt.Printf("%s%v\n", buffer, node)
	if e, ok := node.(ast.Expr); ok {
		obj, typ := types.ExprType(e, LocalImporter)
		fmt.Printf("%s%v\n", buffer, obj)
		fmt.Printf("%s%v\n", buffer, typ)
	}
	fmt.Println()

	switch n := node.(type) {

	}

	return this + 1
}
开发者ID:newblue,项目名称:gorf,代码行数:27,代码来源:dscan.go

示例6: Visit

func (visitor *astNodeVisitorForMultipleStatements) Visit(node ast.Node) (w ast.Visitor) {
	if node != nil {
		if visitor.context.fset.Position(node.Pos()).Line == visitor.context.selection.Begin.Line &&
			visitor.context.fset.Position(node.Pos()).Column == visitor.context.selection.Begin.Column &&
			!visitor.context.shouldRecord {
			// fmt.Println("Starting with node at pos", visitor.context.fset.Position(node.Pos()), "and end", visitor.context.fset.Position(node.End()))
			// ast.Print(visitor.context.fset, node)
			// fmt.Println(node.Pos(), node)
			// fmt.Println("Parent")
			// ast.Print(visitor.context.fset, visitor.parentNode)
			visitor.context.posParent = visitor.parentNode
			visitor.context.shouldRecord = true
		}
		if visitor.context.shouldRecord && visitor.context.posParent == visitor.parentNode {
			visitor.context.nodesToExtract = append(visitor.context.nodesToExtract, node)
		}
		if visitor.context.fset.Position(node.End()).Line == visitor.context.selection.End.Line &&
			visitor.context.fset.Position(node.End()).Column == visitor.context.selection.End.Column {
			// fmt.Println("Ending with node at pos", visitor.context.fset.Position(node.Pos()), "and end", visitor.context.fset.Position(node.End()))
			// ast.Print(visitor.context.fset, node)
			// fmt.Println("Parent")
			// ast.Print(visitor.context.fset, visitor.parentNode)
			visitor.context.endParent = visitor.parentNode
			visitor.context.shouldRecord = false
			return nil
		}
	}
	return &astNodeVisitorForMultipleStatements{
		parentNode: node,
		context:    visitor.context,
	}
}
开发者ID:petergtz,项目名称:goextract,代码行数:32,代码来源:statements.go

示例7: posLink_urlFunc

func posLink_urlFunc(node ast.Node, fset *token.FileSet) string {
	var relpath string
	var line int
	var low, high int // selection

	if p := node.Pos(); p.IsValid() {
		pos := fset.Position(p)
		relpath = pos.Filename
		line = pos.Line
		low = pos.Offset
	}
	if p := node.End(); p.IsValid() {
		high = fset.Position(p).Offset
	}

	var buf bytes.Buffer
	template.HTMLEscape(&buf, []byte(relpath))
	// selection ranges are of form "s=low:high"
	if low < high {
		fmt.Fprintf(&buf, "?s=%d:%d", low, high) // no need for URL escaping
		// if we have a selection, position the page
		// such that the selection is a bit below the top
		line -= 10
		if line < 1 {
			line = 1
		}
	}
	// line id's in html-printed source are of the
	// form "L%d" where %d stands for the line number
	if line > 0 {
		fmt.Fprintf(&buf, "#L%d", line) // no need for URL escaping
	}

	return buf.String()
}
开发者ID:tw4452852,项目名称:go-src,代码行数:35,代码来源:godoc.go

示例8: newIssueRangeFromNode

func (f *gofile) newIssueRangeFromNode(n ast.Node) *issueRange {
	s := f.Fset().Position(n.Pos())
	e := f.Fset().Position(n.End())
	return &issueRange{
		s,
		e,
	}
}
开发者ID:guycook,项目名称:tenets,代码行数:8,代码来源:file.go

示例9: addAnnoation

func (v *annotationVisitor) addAnnoation(n ast.Node, packageName string, name string) {
	pos := v.fset.Position(n.Pos())
	end := v.fset.Position(n.End())
	v.annotations = append(v.annotations, TypeAnnotation{
		pos.Offset - len(packageWrapper),
		end.Offset - len(packageWrapper),
		packageName,
		name})
}
开发者ID:goods,项目名称:thegoods,代码行数:9,代码来源:build.go

示例10: Visit

func (v *funcVisitor) Visit(n ast.Node) ast.Visitor {
	var body *ast.BlockStmt

	switch n := n.(type) {
	case *ast.FuncDecl:
		// Function name is prepended with "T." if there is a receiver, where
		// T is the type of the receiver, dereferenced if it is a pointer.
		name := n.Name.Name
		if n.Recv != nil {
			field := n.Recv.List[0]
			switch recv := field.Type.(type) {
			case *ast.StarExpr:
				name = recv.X.(*ast.Ident).Name + "." + name
			case *ast.Ident:
				name = recv.Name + "." + name
			}
		}
		start, end := v.fset.Position(n.Pos()), v.fset.Position(n.End())
		f := v.pkg.RegisterFunction(name, start.Filename, start.Offset, end.Offset)
		v.state.functions = append(v.state.functions, f)
		body = n.Body

	case *ast.FuncLit:
		// Function literals defined within a function do not get a separate
		// *gocov.Function, rather their statements are counted in the
		// enclosing function.
		//
		// Function literals at the package scope are named "@<Position>",
		// where "<Position>" is the position of the beginning of the function
		// literal.
		start, end := v.fset.Position(n.Pos()), v.fset.Position(n.End())
		var enclosing *gocov.Function
		if len(v.functions) > 0 {
			lastfunc := v.functions[len(v.functions)-1]
			if start.Offset < lastfunc.End {
				enclosing = lastfunc
			}
		}
		if enclosing == nil {
			name := fmt.Sprintf("@%d:%d", start.Line, start.Column)
			f := v.pkg.RegisterFunction(name, start.Filename, start.Offset, end.Offset)
			v.state.functions = append(v.state.functions, f)
		}
		body = n.Body
	}

	if body != nil {
		// TODO function coverage (insert "function.Enter", "function.Leave").
		//
		// FIXME instrumentation no longer records statements in line order,
		// as function literals are processed after the body of a function.
		sv := &stmtVisitor{v.state}
		sv.VisitStmt(body)
	}

	return v
}
开发者ID:vube,项目名称:gocov,代码行数:57,代码来源:instrument.go

示例11: Visit

func (vis *findNodeVisitor) Visit(node ast.Node) (w ast.Visitor) {
	if node == nil || vis.result != nil {
		return nil
	}
	if utils.ComparePosWithinFile(vis.stPos, vis.fset.Position(node.Pos())) == 0 &&
		utils.ComparePosWithinFile(vis.endPos, vis.fset.Position(node.End())) == 0 {
		vis.result = node
		return nil
	}
	return vis
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:11,代码来源:findNodeVisitor.go

示例12: Visit

func (v *calltipVisitor) Visit(node ast.Node) (w ast.Visitor) {
	if node != nil {
		if x, ok := node.(*ast.CallExpr); ok {
			a := v.fset.Position(node.Pos())
			b := v.fset.Position(node.End())

			if (a.IsValid() && v.offset >= a.Offset) && (!b.IsValid() || v.offset <= b.Offset) {
				v.x = x
			}
		}
	}
	return v
}
开发者ID:rpontes,项目名称:sublime-text-2,代码行数:13,代码来源:m_gocode.go

示例13: Visit

func (v *Visitor) Visit(node ast.Node) (w ast.Visitor) {

	if node != nil {
		fmt.Println(fset.Position(node.Pos()))
		fmt.Println(fset.Position(node.End()))
		fmt.Println(reflect.TypeOf(node))
		if f := m[reflect.TypeOf(node)]; f != nil {
			f(node)
		}
	}

	return v
}
开发者ID:pcasaretto,项目名称:go-mutate,代码行数:13,代码来源:mutate.go

示例14: Span

// Span returns the 0-based offset range of the given AST node.
// The range is half-open, including the start position but excluding the end.
// If node == nil or lacks a valid start position, Span returns -1, -1.
// If the end position of node is invalid, start == end.
func (pi *PackageInfo) Span(node ast.Node) (start, end int) {
	if node == nil {
		return -1, -1
	} else if pos := node.Pos(); pos == token.NoPos {
		return -1, -1
	} else {
		start = pi.FileSet.Position(pos).Offset
		end = start
	}
	if pos := node.End(); pos != token.NoPos {
		end = pi.FileSet.Position(pos).Offset
	}
	return
}
开发者ID:benjyw,项目名称:kythe,代码行数:18,代码来源:indexer.go

示例15: Visit

// Visit finds f.node performing a search down the ast tree.
// It keeps the last block statement and statement seen for later use.
func (f *blockStmtFinder) Visit(node ast.Node) ast.Visitor {
	if node == nil || f.node.Pos() < node.Pos() || f.node.End() > node.End() {
		return nil // not here
	}
	switch n := node.(type) {
	case *ast.BlockStmt:
		f.block = n
	case ast.Stmt:
		f.stmt = n
	}
	if f.node.Pos() == node.Pos() && f.node.End() == node.End() {
		return nil // found
	}
	return f // keep looking
}
开发者ID:Harvey-OS,项目名称:go,代码行数:17,代码来源:httpresponse.go


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