本文整理汇总了Golang中golang.org/x/tools/go/types.MethodSet类的典型用法代码示例。如果您正苦于以下问题:Golang MethodSet类的具体用法?Golang MethodSet怎么用?Golang MethodSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MethodSet类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: methodSet
func (f *File) methodSet(set *types.MethodSet) {
// Build the set of things we're looking for.
methods := make([]method, 0, set.Len())
docs := make([]string, set.Len())
for i := 0; i < set.Len(); i++ {
if ast.IsExported(set.At(i).Obj().Name()) {
m := method{
i,
set.At(i),
}
methods = append(methods, m)
}
}
if len(methods) == 0 {
return
}
// Collect the docs.
for _, file := range f.allFiles {
visitor := &methodVisitor{
File: file,
methods: methods,
docs: docs,
}
ast.Walk(visitor, file.file)
methods = visitor.methods
}
// Print them in order. The incoming method set is sorted by name.
for _, doc := range docs {
if doc != "" {
fmt.Print(doc)
}
}
}
开发者ID:kissthink,项目名称:ide_stub,代码行数:33,代码来源:doc.go
示例2: containsAllIdsOf
// containsAllIdsOf reports whether the method identifiers of T are a
// superset of those in U. If U belongs to an interface type, the
// result is equal to types.Assignable(T, U), but is cheaper to compute.
//
// TODO(gri): make this a method of *types.MethodSet.
//
func containsAllIdsOf(T, U *types.MethodSet) bool {
t, tlen := 0, T.Len()
u, ulen := 0, U.Len()
for t < tlen && u < ulen {
tMeth := T.At(t).Obj()
uMeth := U.At(u).Obj()
tId := tMeth.Id()
uId := uMeth.Id()
if tId > uId {
// U has a method T lacks: fail.
return false
}
if tId < uId {
// T has a method U lacks: ignore it.
t++
continue
}
// U and T both have a method of this Id. Check types.
if !types.Identical(tMeth.Type(), uMeth.Type()) {
return false // type mismatch
}
u++
t++
}
return u == ulen
}
开发者ID:Christeefym,项目名称:lantern,代码行数:32,代码来源:implements.go
示例3: uncommonBuild
func (l langType) uncommonBuild(i int, sizes types.Sizes, name string, t types.Type) string {
pkgPath := ""
tt := t
switch tt.(type) {
case *types.Pointer:
el, ok := tt.(*types.Pointer).Elem().(*types.Named)
if ok {
tt = el
}
}
switch tt.(type) {
case *types.Named:
obj := tt.(*types.Named).Obj()
if obj != nil {
pkg := obj.Pkg()
if pkg != nil {
pkgPath = pkg.Path()
}
}
}
var methods *types.MethodSet
numMethods := 0
methods = l.PogoComp().MethodSetFor(t)
numMethods = methods.Len()
if name != "" || numMethods > 0 {
ret := "Go_haxegoruntime_newPPtrTToUUncommonTType.callFromRT(0,\n"
ret += "\t\t/*name:*/ \"" + name + "\",\n"
ret += "\t\t/*pkgPath:*/ \"" + pkgPath + "\",\n"
ret += "\t\t/*methods:*/ "
meths := "Go_haxegoruntime_newMMethodSSlice.callFromRT(0)"
//_, isIF := t.Underlying().(*types.Interface)
//if !isIF {
for m := 0; m < numMethods; m++ {
sel := methods.At(m)
ssaFn := l.PogoComp().RootProgram().Method(sel)
if l.PogoComp().FnIsCalled(ssaFn) {
fn := "null"
fnToCall := "null"
var name, str, path string
fid, haveFn := l.hc.pte.At(sel.Obj().Type()).(int)
if haveFn {
fn = fmt.Sprintf("type%d()", fid)
}
name = sel.Obj().Name()
str = sel.String()
funcObj, ok := sel.Obj().(*types.Func)
if ok {
pn := "unknown"
if funcObj.Pkg() != nil {
pn = sel.Obj().Pkg().Name()
path = sel.Obj().Pkg().Path()
}
fnToCall = `Go_` + l.LangName(
pn+":"+sel.Recv().String(),
funcObj.Name())
}
// now write out the method information
meths = "Go_haxegoruntime_addMMethod.callFromRT(0," + meths + ",\n"
meths += fmt.Sprintf("\n\t\t\t/*name:*/ \"%s\", // %s\n", name, str)
rune1, _ := utf8.DecodeRune([]byte(name))
if unicode.IsUpper(rune1) {
path = ""
}
meths += fmt.Sprintf("\t\t\t/*pkgPath:*/ \"%s\",\n", path)
// TODO should the two lines below be different?
meths += fmt.Sprintf("\t\t\t/*mtyp:*/ %s,\n", fn)
meths += fmt.Sprintf("\t\t\t/*typ:*/ %s,\n", fn)
// add links to the functions ...
if l.hc.funcNamesUsed[fnToCall] {
fnToCall += ".call"
} else {
//println("DEBUG uncommonBuild function name not found: ", fnToCall)
fnToCall = "null /* " + fnToCall + " */ "
}
meths += "\t\t\t" + fnToCall + "," + fnToCall + ")"
}
}
//}
ret += meths
return ret + "\t)"
}
return "null"
}
开发者ID:jmptrader,项目名称:tardisgo,代码行数:87,代码来源:tgotypes.go
注:本文中的golang.org/x/tools/go/types.MethodSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论