aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/tools/go/types/typeutil/callee.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-04-10 20:30:34 +0200
committerMichael Muré <batolettre@gmail.com>2019-04-10 20:30:34 +0200
commit0e53d2555e9a6ddc707f6c59497f30e182116c80 (patch)
tree7fa6cd92d87c8ac6a0fd486be9647b69975b7d21 /vendor/golang.org/x/tools/go/types/typeutil/callee.go
parent9722d7c9eca28b1710e50ac9075fd11d0db0606a (diff)
downloadgit-bug-0e53d2555e9a6ddc707f6c59497f30e182116c80.tar.gz
force a version of golang.org/x/tools due to an incompatibility with gqlgen
Diffstat (limited to 'vendor/golang.org/x/tools/go/types/typeutil/callee.go')
-rw-r--r--vendor/golang.org/x/tools/go/types/typeutil/callee.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/vendor/golang.org/x/tools/go/types/typeutil/callee.go b/vendor/golang.org/x/tools/go/types/typeutil/callee.go
new file mode 100644
index 00000000..38f596da
--- /dev/null
+++ b/vendor/golang.org/x/tools/go/types/typeutil/callee.go
@@ -0,0 +1,46 @@
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package typeutil
+
+import (
+ "go/ast"
+ "go/types"
+
+ "golang.org/x/tools/go/ast/astutil"
+)
+
+// Callee returns the named target of a function call, if any:
+// a function, method, builtin, or variable.
+func Callee(info *types.Info, call *ast.CallExpr) types.Object {
+ var obj types.Object
+ switch fun := astutil.Unparen(call.Fun).(type) {
+ case *ast.Ident:
+ obj = info.Uses[fun] // type, var, builtin, or declared func
+ case *ast.SelectorExpr:
+ if sel, ok := info.Selections[fun]; ok {
+ obj = sel.Obj() // method or field
+ } else {
+ obj = info.Uses[fun.Sel] // qualified identifier?
+ }
+ }
+ if _, ok := obj.(*types.TypeName); ok {
+ return nil // T(x) is a conversion, not a call
+ }
+ return obj
+}
+
+// StaticCallee returns the target (function or method) of a static
+// function call, if any. It returns nil for calls to builtins.
+func StaticCallee(info *types.Info, call *ast.CallExpr) *types.Func {
+ if f, ok := Callee(info, call).(*types.Func); ok && !interfaceMethod(f) {
+ return f
+ }
+ return nil
+}
+
+func interfaceMethod(f *types.Func) bool {
+ recv := f.Type().(*types.Signature).Recv()
+ return recv != nil && types.IsInterface(recv.Type())
+}