本文整理汇总了Golang中go/ast.TypeSpec.Doc方法的典型用法代码示例。如果您正苦于以下问题:Golang TypeSpec.Doc方法的具体用法?Golang TypeSpec.Doc怎么用?Golang TypeSpec.Doc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/ast.TypeSpec
的用法示例。
在下文中一共展示了TypeSpec.Doc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
}
}
}
示例2: 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))
}
}
示例3: 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
}
示例4: 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)
}
}
}
}