本文整理汇总了Golang中go/ast.TypeSpec类的典型用法代码示例。如果您正苦于以下问题:Golang TypeSpec类的具体用法?Golang TypeSpec怎么用?Golang TypeSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TypeSpec类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: oneLineTypeDecl
// oneLineTypeDecl prints a type declaration as a single line.
func (pkg *Package) oneLineTypeDecl(spec *ast.TypeSpec) {
spec.Doc = nil
spec.Comment = nil
switch spec.Type.(type) {
case *ast.InterfaceType:
pkg.Printf("type %s interface { ... }\n", spec.Name)
case *ast.StructType:
pkg.Printf("type %s struct { ... }\n", spec.Name)
default:
pkg.Printf("type %s %s\n", spec.Name, pkg.formatNode(spec.Type))
}
}
开发者ID:sreis,项目名称:go,代码行数:13,代码来源:pkg.go
示例2: readType
// readType processes a type declaration.
//
func (r *reader) readType(decl *ast.GenDecl, spec *ast.TypeSpec) {
typ := r.lookupType(spec.Name.Name)
if typ == nil {
return // no name or blank name - ignore the type
}
// A type should be added at most once, so typ.decl
// should be nil - if it is not, simply overwrite it.
typ.decl = decl
// compute documentation
doc := spec.Doc
spec.Doc = nil // doc consumed - remove from AST
if doc == nil {
// no doc associated with the spec, use the declaration doc, if any
doc = decl.Doc
}
decl.Doc = nil // doc consumed - remove from AST
typ.doc = doc.Text()
// record anonymous fields (they may contribute methods)
// (some fields may have been recorded already when filtering
// exports, but that's ok)
var list []*ast.Field
list, typ.isStruct = fields(spec.Type)
for _, field := range list {
if len(field.Names) == 0 {
r.recordAnonymousField(typ, field.Type)
}
}
}
开发者ID:funkygao,项目名称:govtil,代码行数:33,代码来源:reader.go
示例3: parseTypeDeclaration
// parseTypeDeclaration creates a tag for type declaration ts and for each
// field in case of a struct, or each method in case of an interface.
func (p *tagParser) parseTypeDeclaration(ts *ast.TypeSpec) {
tag := p.createTag(ts.Name.Name, ts.Pos(), Type)
tag.Fields[Access] = getAccess(tag.Name)
switch s := ts.Type.(type) {
case *ast.StructType:
tag.Fields[TypeField] = "struct"
p.parseStructFields(tag.Name, s)
p.types = append(p.types, tag.Name)
case *ast.InterfaceType:
tag.Fields[TypeField] = "interface"
tag.Type = Interface
p.parseInterfaceMethods(tag.Name, s)
default:
tag.Fields[TypeField] = getType(ts.Type, true)
}
p.tags = append(p.tags, tag)
}
开发者ID:ppalucki,项目名称:gotags,代码行数:22,代码来源:parser.go
示例4: newType
func newType(decl *ast.GenDecl, spec *ast.TypeSpec) *Type {
if !ast.IsExported(spec.Name.Name) {
return nil
}
t := new(Type)
if spec.Doc != nil {
t.Doc = doc.CommentText(spec.Doc)
spec.Doc = nil
} else {
// if spec has no docs, try pulling comment from decl
t.Doc = doc.CommentText(decl.Doc)
}
cleanUnexportedFields(spec.Type)
t.Name = spec.Name.Name
t.Decl = spec
return t
}
开发者ID:nsf,项目名称:gortfm,代码行数:19,代码来源:doce.go
示例5: readType
// readType processes a type declaration.
//
func (r *reader) readType(decl *ast.GenDecl, spec *ast.TypeSpec) {
typ := r.lookupType(spec.Name.Name)
if typ == nil {
return // no name or blank name - ignore the type
}
// A type should be added at most once, so info.decl
// should be nil - if it is not, simply overwrite it.
typ.decl = decl
// compute documentation
doc := spec.Doc
spec.Doc = nil // doc consumed - remove from AST
if doc == nil {
// no doc associated with the spec, use the declaration doc, if any
doc = decl.Doc
}
decl.Doc = nil // doc consumed - remove from AST
typ.doc = doc.Text()
// look for anonymous fields that might contribute methods
var list []*ast.Field
list, typ.isStruct = fields(spec.Type)
for _, field := range list {
if len(field.Names) == 0 {
// anonymous field - add corresponding field type to typ
n, imp := baseTypeName(field.Type)
if imp {
// imported type - we don't handle this case
// at the moment
return
}
if embedded := r.lookupType(n); embedded != nil {
_, ptr := field.Type.(*ast.StarExpr)
typ.addEmbeddedType(embedded, ptr)
}
}
}
}
开发者ID:krasin,项目名称:go-deflate,代码行数:41,代码来源:reader.go
注:本文中的go/ast.TypeSpec类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论