本文整理汇总了Golang中go/ast.FuncDecl.End方法的典型用法代码示例。如果您正苦于以下问题:Golang FuncDecl.End方法的具体用法?Golang FuncDecl.End怎么用?Golang FuncDecl.End使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.FuncDecl
的用法示例。
在下文中一共展示了FuncDecl.End方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: method
func (v *fileVisitor) method(n *ast.FuncDecl) *Method {
method := &Method{Name: n.Name.Name}
method.Lines = []*Line{}
start := v.fset.Position(n.Pos())
end := v.fset.Position(n.End())
startLine := start.Line
startCol := start.Column
endLine := end.Line
endCol := end.Column
// The blocks are sorted, so we can stop counting as soon as we reach the end of the relevant block.
for _, b := range v.profile.Blocks {
if b.StartLine > endLine || (b.StartLine == endLine && b.StartCol >= endCol) {
// Past the end of the function.
break
}
if b.EndLine < startLine || (b.EndLine == startLine && b.EndCol <= startCol) {
// Before the beginning of the function
continue
}
for i := b.StartLine; i <= b.EndLine; i++ {
method.Lines = append(method.Lines, &Line{Number: i, Hits: int64(b.Count)})
}
}
return method
}
示例2: processFunction
func processFunction(funcDecl *ast.FuncDecl) {
m := function{}
m.bodyStart = fset.Position(funcDecl.Pos()).Line
m.bodyEnd = fset.Position(funcDecl.End()).Line
m.variables = getFunctionVariables(funcDecl)
addFoundFunctions(m)
}
示例3: checkFunctionLine
func (f *file) checkFunctionLine(funcDecl *ast.FuncDecl) {
lineLimit := f.config.FunctionLine
if lineLimit <= 0 {
return
}
start := f.fset.Position(funcDecl.Pos())
startLine := start.Line
endLine := f.fset.Position(funcDecl.End()).Line
lineCount := endLine - startLine
if lineCount > lineLimit {
problem := genFuncLineProblem(funcDecl.Name.Name, lineCount, lineLimit, start)
f.problems = append(f.problems, problem)
}
}
示例4: exampleOutput
func exampleOutput(fun *ast.FuncDecl, comments []*ast.CommentGroup) string {
// find the last comment in the function
var last *ast.CommentGroup
for _, cg := range comments {
if cg.Pos() < fun.Pos() {
continue
}
if cg.End() > fun.End() {
break
}
last = cg
}
if last != nil {
// test that it begins with the correct prefix
text := last.Text()
if loc := outputPrefix.FindStringIndex(text); loc != nil {
return strings.TrimSpace(text[loc[1]:])
}
}
return "" // no suitable comment found
}