本文整理汇总了Golang中go/types.TypeName.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang TypeName.Type方法的具体用法?Golang TypeName.Type怎么用?Golang TypeName.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.TypeName
的用法示例。
在下文中一共展示了TypeName.Type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: genInterfaceInterface
func (g *ObjcGen) genInterfaceInterface(obj *types.TypeName, summary ifaceSummary, isProtocol bool) {
g.Printf("@interface %[1]s%[2]s : ", g.namePrefix, obj.Name())
if isErrorType(obj.Type()) {
g.Printf("NSError")
} else {
g.Printf("NSObject")
}
prots := []string{"goSeqRefInterface"}
if isProtocol {
prots = append(prots, fmt.Sprintf("%[1]s%[2]s", g.namePrefix, obj.Name()))
}
g.Printf(" <%s>", strings.Join(prots, ", "))
g.Printf(" {\n}\n")
g.Printf("@property(strong, readonly) id _ref;\n")
g.Printf("\n")
g.Printf("- (instancetype)initWithRef:(id)ref;\n")
for _, m := range summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(nil, m)
g.Printf("- %s;\n", s.asMethod(g))
}
g.Printf("@end\n")
}
示例2: genStructH
func (g *objcGen) genStructH(obj *types.TypeName, t *types.Struct) {
g.Printf("@interface %s%s : NSObject {\n", g.namePrefix, obj.Name())
g.Printf("}\n")
g.Printf("@property(strong, readonly) id _ref;\n")
g.Printf("\n")
g.Printf("- (id)initWithRef:(id)ref;\n")
// accessors to exported fields.
for _, f := range exportedFields(t) {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
continue
}
name, typ := f.Name(), g.objcFieldType(f.Type())
g.Printf("- (%s)%s;\n", typ, lowerFirst(name))
g.Printf("- (void)set%s:(%s)v;\n", name, typ)
}
// exported methods
for _, m := range exportedMethodSet(types.NewPointer(obj.Type())) {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(m)
g.Printf("- %s;\n", lowerFirst(s.asMethod(g)))
}
g.Printf("@end\n")
}
示例3: genInterfaceH
func (g *objcGen) genInterfaceH(obj *types.TypeName, t *types.Interface) {
g.Printf("@protocol %s%s\n", g.namePrefix, obj.Name())
for _, m := range exportedMethodSet(obj.Type()) {
s := g.funcSummary(m)
g.Printf("- %s;\n", s.asMethod(g))
}
g.Printf("@end\n")
}
示例4: genStructM
func (g *ObjcGen) genStructM(obj *types.TypeName, t *types.Struct) {
fields := exportedFields(t)
methods := exportedMethodSet(types.NewPointer(obj.Type()))
g.Printf("\n")
oinf := g.ostructs[obj]
g.Printf("@implementation %s%s {\n", g.namePrefix, obj.Name())
g.Printf("}\n\n")
g.Printf("- (id)initWithRef:(id)ref {\n")
g.Indent()
g.Printf("self = [super init];\n")
g.Printf("if (self) { __ref = ref; }\n")
g.Printf("return self;\n")
g.Outdent()
g.Printf("}\n\n")
if oinf != nil {
g.Printf("- (id)init {\n")
g.Indent()
g.Printf("self = [super init];\n")
g.Printf("if (self) {\n")
g.Indent()
g.Printf("__ref = go_seq_from_refnum(new_%s_%s());\n", g.pkgPrefix, obj.Name())
g.Outdent()
g.Printf("}\n")
g.Printf("return self;\n")
g.Outdent()
g.Printf("}\n\n")
}
for _, f := range fields {
if !g.isSupported(f.Type()) {
g.Printf("// skipped unsupported field %s with type %T\n\n", f.Name(), f)
continue
}
g.genGetter(obj.Name(), f)
g.genSetter(obj.Name(), f)
}
for _, m := range methods {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(g.ostructs[obj], m)
g.Printf("- %s {\n", s.asMethod(g))
g.Indent()
g.genFunc(s, obj.Name())
g.Outdent()
g.Printf("}\n\n")
}
g.Printf("@end\n\n")
}
示例5: newStruct
func newStruct(p *Package, obj *types.TypeName) (Struct, error) {
sym := p.syms.symtype(obj.Type())
if sym == nil {
panic(fmt.Errorf("no such object [%s] in symbols table", obj.Id()))
}
sym.doc = p.getDoc("", obj)
s := Struct{
pkg: p,
sym: sym,
obj: obj,
}
return s, nil
}
示例6: genStruct
func (g *goGen) genStruct(obj *types.TypeName, T *types.Struct) {
fields := exportedFields(T)
methods := exportedMethodSet(types.NewPointer(obj.Type()))
for _, f := range fields {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
continue
}
g.Printf("//export proxy%s_%s_%s_Set\n", g.pkgPrefix, obj.Name(), f.Name())
g.Printf("func proxy%s_%s_%s_Set(refnum C.int32_t, v C.%s) {\n", g.pkgPrefix, obj.Name(), f.Name(), g.cgoType(f.Type()))
g.Indent()
g.Printf("ref := _seq.FromRefNum(int32(refnum))\n")
g.genRead("_v", "v", f.Type(), modeRetained)
g.Printf("ref.Get().(*%s%s).%s = _v\n", g.pkgName(g.Pkg), obj.Name(), f.Name())
g.Outdent()
g.Printf("}\n\n")
g.Printf("//export proxy%s_%s_%s_Get\n", g.pkgPrefix, obj.Name(), f.Name())
g.Printf("func proxy%s_%s_%s_Get(refnum C.int32_t) C.%s {\n", g.pkgPrefix, obj.Name(), f.Name(), g.cgoType(f.Type()))
g.Indent()
g.Printf("ref := _seq.FromRefNum(int32(refnum))\n")
g.Printf("v := ref.Get().(*%s%s).%s\n", g.pkgName(g.Pkg), obj.Name(), f.Name())
g.genWrite("_v", "v", f.Type(), modeRetained)
g.Printf("return _v\n")
g.Outdent()
g.Printf("}\n\n")
}
for _, m := range methods {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
g.genFuncSignature(m, obj.Name())
g.Indent()
g.Printf("ref := _seq.FromRefNum(int32(refnum))\n")
g.Printf("v := ref.Get().(*%s%s)\n", g.pkgName(g.Pkg), obj.Name())
g.genFuncBody(m, "v.")
g.Outdent()
g.Printf("}\n\n")
}
// Export constructor for ObjC and Java default no-arg constructors
g.Printf("//export new_%s_%s\n", g.Pkg.Name(), obj.Name())
g.Printf("func new_%s_%s() C.int32_t {\n", g.Pkg.Name(), obj.Name())
g.Indent()
g.Printf("return C.int32_t(_seq.ToRefNum(new(%s%s)))\n", g.pkgName(g.Pkg), obj.Name())
g.Outdent()
g.Printf("}\n")
}
示例7: convertTypeName
func (c *converter) convertTypeName(v *gotypes.TypeName) *types.TypeName {
if v == nil {
return nil
}
if v, ok := c.converted[v]; ok {
return v.(*types.TypeName)
}
// This part is a bit tricky. gcimport calls NewTypeName with a nil typ
// argument, and then calls NewNamed on the resulting *TypeName, which
// sets its typ to a *Named referring to itself. So if we get a *TypeName
// whose Type() is a *Named whose Obj() is the same *TypeName, we know it
// was constructed this way, so we do the same. Otherwise we get into a
// infinite recursion converting the *TypeName's type.
var typ types.Type
if named, ok := v.Type().(*gotypes.Named); !ok || named.Obj() != v {
typ = c.convertType(v.Type())
}
ret := types.NewTypeName(
token.Pos(v.Pos()),
c.convertPackage(v.Pkg()),
v.Name(),
typ,
)
c.converted[v] = ret
named := types.NewNamed(ret, c.convertType(v.Type().Underlying()), nil)
c.converted[v.Type()] = named
return ret
}
示例8: genStructH
func (g *ObjcGen) genStructH(obj *types.TypeName, t *types.Struct) {
g.Printf("@interface %s%s : ", g.namePrefix, obj.Name())
oinf := g.ostructs[obj]
if oinf != nil {
var prots []string
for _, sup := range oinf.supers {
if !sup.Protocol {
g.Printf(sup.Name)
} else {
prots = append(prots, sup.Name)
}
}
if len(prots) > 0 {
g.Printf(" <%s>", strings.Join(prots, ", "))
}
} else {
g.Printf("NSObject <goSeqRefInterface>")
}
g.Printf(" {\n")
g.Printf("}\n")
g.Printf("@property(strong, readonly) id _ref;\n")
g.Printf("\n")
g.Printf("- (id)initWithRef:(id)ref;\n")
if oinf != nil {
g.Printf("- (id)init;\n")
}
// accessors to exported fields.
for _, f := range exportedFields(t) {
if t := f.Type(); !g.isSupported(t) {
g.Printf("// skipped field %s.%s with unsupported type: %T\n\n", obj.Name(), f.Name(), t)
continue
}
name, typ := f.Name(), g.objcFieldType(f.Type())
g.Printf("- (%s)%s;\n", typ, objcNameReplacer(lowerFirst(name)))
g.Printf("- (void)set%s:(%s)v;\n", name, typ)
}
// exported methods
for _, m := range exportedMethodSet(types.NewPointer(obj.Type())) {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(g.ostructs[obj], m)
g.Printf("- %s;\n", objcNameReplacer(lowerFirst(s.asMethod(g))))
}
g.Printf("@end\n")
}
示例9: genFromRefnum
func (g *JavaGen) genFromRefnum(toName, fromName string, t types.Type, o *types.TypeName) {
oPkg := o.Pkg()
isJava := isJavaType(o.Type())
if !isErrorType(o.Type()) && !g.validPkg(oPkg) && !isJava {
g.errorf("type %s is defined in package %s, which is not bound", t, oPkg)
return
}
p := pkgPrefix(oPkg)
g.Printf("jobject %s = go_seq_from_refnum(env, %s, ", toName, fromName)
if isJava {
g.Printf("NULL, NULL")
} else {
g.Printf("proxy_class_%s_%s, proxy_class_%s_%s_cons", p, o.Name(), p, o.Name())
}
g.Printf(");\n")
}
示例10: methodsFor
// methodsFor returns the named type and corresponding methods if the type
// denoted by obj is not an interface and has methods. Otherwise it returns
// the zero value.
func methodsFor(obj *types.TypeName) (*types.Named, []*types.Selection) {
named, _ := obj.Type().(*types.Named)
if named == nil {
// A type name's type can also be the
// exported basic type unsafe.Pointer.
return nil, nil
}
if _, ok := named.Underlying().(*types.Interface); ok {
// ignore interfaces
return nil, nil
}
methods := combinedMethodSet(named)
if len(methods) == 0 {
return nil, nil
}
return named, methods
}
示例11: methodDocComment
func methodDocComment(prog *loader.Program, tname *types.TypeName, methodName string) (string, error) {
t := tname.Type()
if !types.IsInterface(t) {
// Use the pointer type to get as many methods as possible.
t = types.NewPointer(t)
}
mset := types.NewMethodSet(t)
sel := mset.Lookup(nil, methodName)
if sel == nil {
return "", errgo.Newf("cannot find method %v on %v", methodName, t)
}
obj := sel.Obj()
decl, err := findDecl(prog, obj.Pos())
if err != nil {
return "", errgo.Mask(err)
}
switch decl := decl.(type) {
case *ast.GenDecl:
if decl.Tok != token.TYPE {
return "", errgo.Newf("found non-type decl %#v", decl)
}
for _, spec := range decl.Specs {
tspec := spec.(*ast.TypeSpec)
it := tspec.Type.(*ast.InterfaceType)
for _, m := range it.Methods.List {
for _, id := range m.Names {
if id.Pos() == obj.Pos() {
return m.Doc.Text(), nil
}
}
}
}
return "", errgo.Newf("method definition not found in type")
case *ast.FuncDecl:
if decl.Name.Pos() != obj.Pos() {
return "", errgo.Newf("method definition not found (at %#v)", prog.Fset.Position(obj.Pos()))
}
return decl.Doc.Text(), nil
default:
return "", errgo.Newf("unexpected declaration %T found", decl)
}
}
示例12: genStructH
func (g *objcGen) genStructH(obj *types.TypeName, t *types.Struct) {
g.Printf("@interface %s%s : NSObject {\n", g.namePrefix, obj.Name())
g.Printf("}\n")
g.Printf("@property(strong, readonly) id _ref;\n")
g.Printf("\n")
g.Printf("- (id)initWithRef:(id)ref;\n")
// accessors to exported fields.
for _, f := range exportedFields(t) {
name, typ := f.Name(), g.objcFieldType(f.Type())
g.Printf("- (%s)%s;\n", typ, lowerFirst(name))
g.Printf("- (void)set%s:(%s)v;\n", name, typ)
}
// exported methods
for _, m := range exportedMethodSet(types.NewPointer(obj.Type())) {
s := g.funcSummary(m)
g.Printf("- %s;\n", lowerFirst(s.asMethod(g)))
}
g.Printf("@end\n")
}
示例13: genInterfaceM
func (g *ObjcGen) genInterfaceM(obj *types.TypeName, t *types.Interface) bool {
summary := makeIfaceSummary(t)
// @implementation Interface -- similar to what genStructM does.
g.Printf("@implementation %s%s {\n", g.namePrefix, obj.Name())
g.Printf("}\n")
g.Printf("\n")
g.Printf("- (instancetype)initWithRef:(id)ref {\n")
g.Indent()
if isErrorType(obj.Type()) {
g.Printf("if (self) {\n")
g.Printf(" __ref = ref;\n")
g.Printf(" self = [super initWithDomain:@\"go\" code:1 userInfo:@{NSLocalizedDescriptionKey: [self error]}];\n")
g.Printf("}\n")
} else {
g.Printf("self = [super init];\n")
g.Printf("if (self) { __ref = ref; }\n")
}
g.Printf("return self;\n")
g.Outdent()
g.Printf("}\n")
g.Printf("\n")
for _, m := range summary.callable {
if !g.isSigSupported(m.Type()) {
g.Printf("// skipped method %s.%s with unsupported parameter or return types\n\n", obj.Name(), m.Name())
continue
}
s := g.funcSummary(nil, m)
g.Printf("- %s {\n", s.asMethod(g))
g.Indent()
g.genFunc(s, obj.Name())
g.Outdent()
g.Printf("}\n\n")
}
g.Printf("@end\n")
g.Printf("\n")
return summary.implementable
}
示例14: genStructM
func (g *objcGen) genStructM(obj *types.TypeName, t *types.Struct) {
fields := exportedFields(t)
methods := exportedMethodSet(types.NewPointer(obj.Type()))
desc := fmt.Sprintf("_GO_%s_%s", g.pkgName, obj.Name())
g.Printf("#define %s_DESCRIPTOR_ \"go.%s.%s\"\n", desc, g.pkgName, obj.Name())
for i, f := range fields {
g.Printf("#define %s_FIELD_%s_GET_ (0x%x0f)\n", desc, f.Name(), i)
g.Printf("#define %s_FIELD_%s_SET_ (0x%x1f)\n", desc, f.Name(), i)
}
for i, m := range methods {
g.Printf("#define %s_%s_ (0x%x0c)\n", desc, m.Name(), i)
}
g.Printf("\n")
g.Printf("@implementation %s%s {\n", g.namePrefix, obj.Name())
g.Printf("}\n\n")
g.Printf("- (id)initWithRef:(id)ref {\n")
g.Indent()
g.Printf("self = [super init];\n")
g.Printf("if (self) { __ref = ref; }\n")
g.Printf("return self;\n")
g.Outdent()
g.Printf("}\n\n")
for _, f := range fields {
g.genGetter(desc, f)
g.genSetter(desc, f)
}
for _, m := range methods {
s := g.funcSummary(m)
g.Printf("- %s {\n", s.asMethod(g))
g.Indent()
g.genFunc(desc+"_DESCRIPTOR_", desc+"_"+m.Name()+"_", s, true)
g.Outdent()
g.Printf("}\n\n")
}
g.Printf("@end\n")
}
示例15: genInterface
func (g *javaGen) genInterface(o *types.TypeName) {
iface := o.Type().(*types.Named).Underlying().(*types.Interface)
summary := makeIfaceSummary(iface)
g.Printf("public interface %s extends go.Seq.Object {\n", o.Name())
g.Indent()
methodSigErr := false
for _, m := range summary.callable {
if err := g.funcSignature(m, false); err != nil {
methodSigErr = true
g.errorf("%v", err)
}
g.Printf(";\n\n")
}
if methodSigErr {
return // skip stub generation, more of the same errors
}
if summary.implementable {
g.genInterfaceStub(o, iface)
}
g.Printf(javaProxyPreamble, o.Name())
g.Indent()
for _, m := range summary.callable {
g.genFunc(m, true)
}
for i, m := range summary.callable {
g.Printf("static final int CALL_%s = 0x%x0a;\n", m.Name(), i+1)
}
g.Outdent()
g.Printf("}\n")
g.Outdent()
g.Printf("}\n\n")
}