本文整理汇总了Golang中go/types.Interface.NumMethods方法的典型用法代码示例。如果您正苦于以下问题:Golang Interface.NumMethods方法的具体用法?Golang Interface.NumMethods怎么用?Golang Interface.NumMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/types.Interface
的用法示例。
在下文中一共展示了Interface.NumMethods方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sortedMethodNames
func sortedMethodNames(typ *types.Interface) []string {
n := typ.NumMethods()
list := make([]string, n)
for i := range list {
list[i] = typ.Method(i).Name()
}
sort.Strings(list)
return list
}
示例2: iface
func (p *exporter) iface(t *types.Interface) {
// TODO(gri): enable importer to load embedded interfaces,
// then emit Embeddeds and ExplicitMethods separately here.
p.int(0)
n := t.NumMethods()
if trace && n > 0 {
p.tracef("methods {>\n")
defer p.tracef("<\n} ")
}
p.int(n)
for i := 0; i < n; i++ {
if trace && i > 0 {
p.tracef("\n")
}
p.method(t.Method(i))
}
}
示例3: implements
func implements(t types.Type, interfac *types.Interface, pkg *types.Package) bool {
if interfac == nil || t == nil || interfac.Empty() {
return false
}
if types.Implements(t, interfac) {
return true
}
//For some reason, interfaces that comes
//already built in (not from sources) are
//not working with types.Implements method
for i := 0; i < interfac.NumMethods(); i++ {
m := interfac.Method(i)
obj, _, _ := types.LookupFieldOrMethod(t, true, pkg, m.Name())
if obj == nil {
util.Debug("method %s not found in type %v", m.Name(), t)
return false
}
}
return true
}
示例4: genInterfaceStub
func (g *javaGen) genInterfaceStub(o *types.TypeName, m *types.Interface) {
g.Printf("public static abstract class Stub implements %s {\n", o.Name())
g.Indent()
g.Printf("static final String DESCRIPTOR = \"go.%s.%s\";\n\n", g.pkg.Name(), o.Name())
g.Printf("private final go.Seq.Ref ref;\n")
g.Printf("public Stub() {\n ref = go.Seq.createRef(this);\n}\n\n")
g.Printf("public go.Seq.Ref ref() { return ref; }\n\n")
g.Printf("public void call(int code, go.Seq in, go.Seq out) {\n")
g.Indent()
g.Printf("switch (code) {\n")
for i := 0; i < m.NumMethods(); i++ {
f := m.Method(i)
g.Printf("case Proxy.CALL_%s: {\n", f.Name())
g.Indent()
sig := f.Type().(*types.Signature)
params := sig.Params()
for i := 0; i < params.Len(); i++ {
p := sig.Params().At(i)
jt := g.javaType(p.Type())
g.Printf("%s param_%s;\n", jt, paramName(params, i))
g.genRead("param_"+paramName(params, i), "in", p.Type())
}
res := sig.Results()
var returnsError bool
var numRes = res.Len()
if (res.Len() == 1 && isErrorType(res.At(0).Type())) ||
(res.Len() == 2 && isErrorType(res.At(1).Type())) {
numRes -= 1
returnsError = true
}
if returnsError {
g.Printf("try {\n")
g.Indent()
}
if numRes > 0 {
g.Printf("%s result = ", g.javaType(res.At(0).Type()))
}
g.Printf("this.%s(", f.Name())
for i := 0; i < params.Len(); i++ {
if i > 0 {
g.Printf(", ")
}
g.Printf("param_%s", paramName(params, i))
}
g.Printf(");\n")
if numRes > 0 {
g.Printf("out.write%s;\n", seqWrite(res.At(0).Type(), "result"))
}
if returnsError {
g.Printf("out.writeString(null);\n")
g.Outdent()
g.Printf("} catch (Exception e) {\n")
g.Indent()
if numRes > 0 {
resTyp := res.At(0).Type()
g.Printf("%s result = %s;\n", g.javaType(resTyp), g.javaTypeDefault(resTyp))
g.Printf("out.write%s;\n", seqWrite(resTyp, "result"))
}
g.Printf("out.writeString(e.getMessage());\n")
g.Outdent()
g.Printf("}\n")
}
g.Printf("return;\n")
g.Outdent()
g.Printf("}\n")
}
g.Printf("default:\n throw new RuntimeException(\"unknown code: \"+ code);\n")
g.Printf("}\n")
g.Outdent()
g.Printf("}\n")
g.Outdent()
g.Printf("}\n\n")
}