本文整理汇总了Golang中go/ast.Field.Names方法的典型用法代码示例。如果您正苦于以下问题:Golang Field.Names方法的具体用法?Golang Field.Names怎么用?Golang Field.Names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.Field
的用法示例。
在下文中一共展示了Field.Names方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseParamDecl
func (p *parser) parseParamDecl(n *parse.Node, scope *ast.Scope) *ast.Field {
field := ast.Field{}
if n.Child(0).Is(type_) {
field.Type = p.parseType(n.Child(0))
} else {
field.Names = p.parseIdentList(n.Child(0))
if n.Child(1).Is(type_) {
field.Type = p.parseType(n.Child(1))
} else {
// TODO ...
field.Type = p.parseType(n.Child(2))
}
}
p.declare(field, nil, scope, ast.Var, field.Names...)
if field.Type != nil {
p.resolve(field.Type)
}
return &field
}
示例2: Struct
// Struct creates a struct{} expression. The arguments are a series
// of name/type/tag tuples. Name must be of type *ast.Ident, type
// must be of type ast.Expr, and tag must be of type *ast.BasicLit,
// The number of arguments must be a multiple of 3, or a run-time
// panic will occur.
func Struct(args ...ast.Expr) *ast.StructType {
fields := new(ast.FieldList)
if len(args)%3 != 0 {
panic("Number of args to FieldList must be a multiple of 3, got " + strconv.Itoa(len(args)))
}
for i := 0; i < len(args); i += 3 {
var field ast.Field
name, typ, tag := args[i], args[i+1], args[i+2]
if name != nil {
field.Names = []*ast.Ident{name.(*ast.Ident)}
}
if typ != nil {
field.Type = typ
}
if tag != nil {
field.Tag = tag.(*ast.BasicLit)
}
fields.List = append(fields.List, &field)
}
return &ast.StructType{Fields: fields}
}
示例3: mockField
func mockField(idx int, f *ast.Field) *ast.Field {
if f.Names == nil {
if idx < 0 {
return f
}
// Edit the field directly to ensure the same name is used in the mock
// struct.
f.Names = []*ast.Ident{{Name: fmt.Sprintf(inputFmt, idx)}}
return f
}
// Here, we want a copy, so that we can use altered names without affecting
// field names in the mock struct.
newField := &ast.Field{Type: f.Type}
for _, n := range f.Names {
name := n.Name
if name == receiverName {
name += "_"
}
newField.Names = append(newField.Names, &ast.Ident{Name: name})
}
return newField
}