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


Golang TypeSpec.Doc方法代码示例

本文整理汇总了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)
		}
	}
}
开发者ID:funkygao,项目名称:govtil,代码行数:33,代码来源:reader.go

示例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))
	}
}
开发者ID:sreis,项目名称:go,代码行数:13,代码来源:pkg.go

示例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
}
开发者ID:nsf,项目名称:gortfm,代码行数:19,代码来源:doce.go

示例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)
			}
		}
	}
}
开发者ID:krasin,项目名称:go-deflate,代码行数:41,代码来源:reader.go


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