本文整理汇总了Golang中code/google/com/p/go/tools/go/types.Type.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang Type.Name方法的具体用法?Golang Type.Name怎么用?Golang Type.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/go/tools/go/types.Type
的用法示例。
在下文中一共展示了Type.Name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: writeType
func (w *Walker) writeType(buf *bytes.Buffer, typ types.Type) {
switch typ := typ.(type) {
case *types.Basic:
s := typ.Name()
switch typ.Kind() {
case types.UnsafePointer:
s = "unsafe.Pointer"
case types.UntypedBool:
s = "ideal-bool"
case types.UntypedInt:
s = "ideal-int"
case types.UntypedRune:
// "ideal-char" for compatibility with old tool
// TODO(gri) change to "ideal-rune"
s = "ideal-char"
case types.UntypedFloat:
s = "ideal-float"
case types.UntypedComplex:
s = "ideal-complex"
case types.UntypedString:
s = "ideal-string"
case types.UntypedNil:
panic("should never see untyped nil type")
default:
switch s {
case "byte":
s = "uint8"
case "rune":
s = "int32"
}
}
buf.WriteString(s)
case *types.Array:
fmt.Fprintf(buf, "[%d]", typ.Len())
w.writeType(buf, typ.Elem())
case *types.Slice:
buf.WriteString("[]")
w.writeType(buf, typ.Elem())
case *types.Struct:
buf.WriteString("struct")
case *types.Pointer:
buf.WriteByte('*')
w.writeType(buf, typ.Elem())
case *types.Tuple:
panic("should never see a tuple type")
case *types.Signature:
buf.WriteString("func")
w.writeSignature(buf, typ)
case *types.Interface:
buf.WriteString("interface{")
if typ.NumMethods() > 0 {
buf.WriteByte(' ')
buf.WriteString(strings.Join(sortedMethodNames(typ), ", "))
buf.WriteByte(' ')
}
buf.WriteString("}")
case *types.Map:
buf.WriteString("map[")
w.writeType(buf, typ.Key())
buf.WriteByte(']')
w.writeType(buf, typ.Elem())
case *types.Chan:
var s string
switch typ.Dir() {
case ast.SEND:
s = "chan<- "
case ast.RECV:
s = "<-chan "
default:
s = "chan "
}
buf.WriteString(s)
w.writeType(buf, typ.Elem())
case *types.Named:
obj := typ.Obj()
pkg := obj.Pkg()
if pkg != nil && pkg != w.current {
buf.WriteString(pkg.Name())
buf.WriteByte('.')
}
buf.WriteString(typ.Obj().Name())
default:
panic(fmt.Sprintf("unknown type %T", typ))
}
}