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


Golang GenDecl.Methods方法代码示例

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


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

示例1: clone

// TODO(bradfitz): delete this function (and whole file) once
// http://golang.org/issue/4380 is fixed.
func clone(i interface{}) (cloned interface{}) {
	if debugClone {
		defer func() {
			if !reflect.DeepEqual(i, cloned) {
				log.Printf("cloned %T doesn't match: in=%#v out=%#v", i, i, cloned)
			}
		}()
	}
	switch v := i.(type) {
	case nil:
		return nil
	case *ast.File:
		o := &ast.File{
			Doc:      v.Doc, // shallow
			Package:  v.Package,
			Comments: v.Comments, // shallow
			Name:     v.Name,
			Scope:    v.Scope,
		}
		for _, x := range v.Decls {
			o.Decls = append(o.Decls, clone(x).(ast.Decl))
		}
		for _, x := range v.Imports {
			o.Imports = append(o.Imports, clone(x).(*ast.ImportSpec))
		}
		for _, x := range v.Unresolved {
			o.Unresolved = append(o.Unresolved, x)
		}
		return o
	case *ast.GenDecl:
		o := new(ast.GenDecl)
		*o = *v
		o.Specs = nil
		for _, x := range v.Specs {
			o.Specs = append(o.Specs, clone(x).(ast.Spec))
		}
		return o
	case *ast.TypeSpec:
		o := new(ast.TypeSpec)
		*o = *v
		o.Type = cloneExpr(v.Type)
		return o
	case *ast.InterfaceType:
		o := new(ast.InterfaceType)
		*o = *v
		o.Methods = clone(v.Methods).(*ast.FieldList)
		return o
	case *ast.FieldList:
		if v == nil {
			return v
		}
		o := new(ast.FieldList)
		*o = *v
		o.List = nil
		for _, x := range v.List {
			o.List = append(o.List, clone(x).(*ast.Field))
		}
		return o
	case *ast.Field:
		o := &ast.Field{
			Doc:     v.Doc, // shallow
			Type:    cloneExpr(v.Type),
			Tag:     clone(v.Tag).(*ast.BasicLit),
			Comment: v.Comment, // shallow
		}
		for _, x := range v.Names {
			o.Names = append(o.Names, clone(x).(*ast.Ident))
		}
		return o
	case *ast.FuncType:
		if v == nil {
			return v
		}
		return &ast.FuncType{
			Func:    v.Func,
			Params:  clone(v.Params).(*ast.FieldList),
			Results: clone(v.Results).(*ast.FieldList),
		}
	case *ast.FuncDecl:
		if v == nil {
			return v
		}
		return &ast.FuncDecl{
			Recv: clone(v.Recv).(*ast.FieldList),
			Name: v.Name,
			Type: clone(v.Type).(*ast.FuncType),
			Body: v.Body, // shallow
		}
	case *ast.ValueSpec:
		if v == nil {
			return v
		}
		o := &ast.ValueSpec{
			Type: cloneExpr(v.Type),
		}
		for _, x := range v.Names {
			o.Names = append(o.Names, x)
		}
//.........这里部分代码省略.........
开发者ID:qunhu,项目名称:go_src_comment,代码行数:101,代码来源:clone.go


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