本文整理匯總了Golang中rsc/io/grind/grinder.EditBuffer.CopyLine方法的典型用法代碼示例。如果您正苦於以下問題:Golang EditBuffer.CopyLine方法的具體用法?Golang EditBuffer.CopyLine怎麽用?Golang EditBuffer.CopyLine使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsc/io/grind/grinder.EditBuffer
的用法示例。
在下文中一共展示了EditBuffer.CopyLine方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: grindFunc
func grindFunc(ctxt *grinder.Context, pkg *grinder.Package, edit *grinder.EditBuffer, fn *ast.FuncDecl) {
vars := analyzeFunc(pkg, edit, fn.Body)
// fmt.Printf("%s", vardecl.PrintVars(conf.Fset, vars))
for _, v := range vars {
spec := v.Decl.Decl.(*ast.GenDecl).Specs[0].(*ast.ValueSpec)
if len(spec.Names) > 1 {
// TODO: Handle decls with multiple variables
continue
}
if pkg.FileSet.Position(v.Decl.Pos()).Line != pkg.FileSet.Position(v.Decl.End()).Line {
// Declaration spans line. Maybe not great to move or duplicate?
continue
}
keepDecl := false
for _, d := range v.Defs {
if d.Init == v.Decl {
keepDecl = true
continue
}
switch x := d.Init.(type) {
default:
panic("unexpected init")
case *ast.EmptyStmt:
edit.CopyLine(v.Decl.Pos(), v.Decl.End(), x.Semicolon)
case *ast.AssignStmt:
edit.Insert(x.TokPos, ":")
if !hasType(pkg, fn, edit, x.Rhs[0], x.Lhs[0]) {
typ := edit.TextAt(spec.Type.Pos(), spec.Type.End())
if strings.Contains(typ, " ") || typ == "interface{}" || typ == "struct{}" || strings.HasPrefix(typ, "*") {
typ = "(" + typ + ")"
}
edit.Insert(x.Rhs[0].Pos(), typ+"(")
edit.Insert(x.Rhs[0].End(), ")")
}
}
}
if !keepDecl {
edit.DeleteLine(v.Decl.Pos(), v.Decl.End())
}
}
if edit.NumEdits() == 0 {
initToDecl(ctxt, pkg, edit, fn)
}
}