From a083052bf637aadf878cb6271f81cd749f850b67 Mon Sep 17 00:00:00 2001 From: Sebastien Binet Date: Tue, 28 Jul 2015 14:35:59 +0200 Subject: [PATCH] bind/utils: helper to check wether a func is 'func String() string' --- bind/utils.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/bind/utils.go b/bind/utils.go index 47471f3..e524909 100644 --- a/bind/utils.go +++ b/bind/utils.go @@ -11,3 +11,35 @@ import ( func isErrorType(typ types.Type) bool { return typ == types.Universe.Lookup("error").Type() } + +func isStringer(obj types.Object) bool { + switch obj := obj.(type) { + case *types.Func: + if obj.Name() != "String" { + return false + } + sig, ok := obj.Type().(*types.Signature) + if !ok { + return false + } + if sig.Recv() == nil { + return false + } + if sig.Params().Len() != 0 { + return false + } + res := sig.Results() + if res.Len() != 1 { + return false + } + ret := res.At(0).Type() + if ret != types.Universe.Lookup("string").Type() { + return false + } + return true + default: + return false + } + + return false +}