x/tools: modernize interface{} -> any
Produced with a patched version of modernize containing only the efaceany pass: $ go run ./gopls/internal/analysis/modernize/cmd/modernize/main.go -test -fix ./... ./gopls/... This is very safe and forms the bulk of the modernize diff, isolating the other changes for ease of review. Change-Id: Iec9352bac5a639a5c03368427531c7842c6e9ad0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/650759 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
a462ac68ac
commit
47e1b0be9d
8 changed files with 46 additions and 46 deletions
|
|
@ -260,7 +260,7 @@ func newConnection(bindCtx context.Context, rwc io.ReadWriteCloser, binder Binde
|
|||
// Notify invokes the target method but does not wait for a response.
|
||||
// The params will be marshaled to JSON before sending over the wire, and will
|
||||
// be handed to the method invoked.
|
||||
func (c *Connection) Notify(ctx context.Context, method string, params interface{}) (err error) {
|
||||
func (c *Connection) Notify(ctx context.Context, method string, params any) (err error) {
|
||||
ctx, done := event.Start(ctx, method,
|
||||
jsonrpc2.Method.Of(method),
|
||||
jsonrpc2.RPCDirection.Of(jsonrpc2.Outbound),
|
||||
|
|
@ -309,7 +309,7 @@ func (c *Connection) Notify(ctx context.Context, method string, params interface
|
|||
// be handed to the method invoked.
|
||||
// You do not have to wait for the response, it can just be ignored if not needed.
|
||||
// If sending the call failed, the response will be ready and have the error in it.
|
||||
func (c *Connection) Call(ctx context.Context, method string, params interface{}) *AsyncCall {
|
||||
func (c *Connection) Call(ctx context.Context, method string, params any) *AsyncCall {
|
||||
// Generate a new request identifier.
|
||||
id := Int64ID(atomic.AddInt64(&c.seq, 1))
|
||||
ctx, endSpan := event.Start(ctx, method,
|
||||
|
|
@ -410,7 +410,7 @@ func (ac *AsyncCall) retire(response *Response) {
|
|||
|
||||
// Await waits for (and decodes) the results of a Call.
|
||||
// The response will be unmarshaled from JSON into the result.
|
||||
func (ac *AsyncCall) Await(ctx context.Context, result interface{}) error {
|
||||
func (ac *AsyncCall) Await(ctx context.Context, result any) error {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
|
|
@ -429,7 +429,7 @@ func (ac *AsyncCall) Await(ctx context.Context, result interface{}) error {
|
|||
//
|
||||
// Respond must be called exactly once for any message for which a handler
|
||||
// returns ErrAsyncResponse. It must not be called for any other message.
|
||||
func (c *Connection) Respond(id ID, result interface{}, err error) error {
|
||||
func (c *Connection) Respond(id ID, result any, err error) error {
|
||||
var req *incomingRequest
|
||||
c.updateInFlight(func(s *inFlightState) {
|
||||
req = s.incomingByID[id]
|
||||
|
|
@ -678,7 +678,7 @@ func (c *Connection) handleAsync() {
|
|||
}
|
||||
|
||||
// processResult processes the result of a request and, if appropriate, sends a response.
|
||||
func (c *Connection) processResult(from interface{}, req *incomingRequest, result interface{}, err error) error {
|
||||
func (c *Connection) processResult(from any, req *incomingRequest, result any, err error) error {
|
||||
switch err {
|
||||
case ErrAsyncResponse:
|
||||
if !req.IsCall() {
|
||||
|
|
@ -781,7 +781,7 @@ func (c *Connection) write(ctx context.Context, msg Message) error {
|
|||
// internalErrorf reports an internal error. By default it panics, but if
|
||||
// c.onInternalError is non-nil it instead calls that and returns an error
|
||||
// wrapping ErrInternal.
|
||||
func (c *Connection) internalErrorf(format string, args ...interface{}) error {
|
||||
func (c *Connection) internalErrorf(format string, args ...any) error {
|
||||
err := fmt.Errorf(format, args...)
|
||||
if c.onInternalError == nil {
|
||||
panic("jsonrpc2: " + err.Error())
|
||||
|
|
@ -803,7 +803,7 @@ func labelStatus(ctx context.Context, err error) {
|
|||
// notDone is a context.Context wrapper that returns a nil Done channel.
|
||||
type notDone struct{ ctx context.Context }
|
||||
|
||||
func (ic notDone) Value(key interface{}) interface{} {
|
||||
func (ic notDone) Value(key any) any {
|
||||
return ic.ctx.Value(key)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ type Preempter interface {
|
|||
// Otherwise, the result and error are processed as if returned by Handle.
|
||||
//
|
||||
// Preempt must not block. (The Context passed to it is for Values only.)
|
||||
Preempt(ctx context.Context, req *Request) (result interface{}, err error)
|
||||
Preempt(ctx context.Context, req *Request) (result any, err error)
|
||||
}
|
||||
|
||||
// A PreempterFunc implements the Preempter interface for a standalone Preempt function.
|
||||
type PreempterFunc func(ctx context.Context, req *Request) (interface{}, error)
|
||||
type PreempterFunc func(ctx context.Context, req *Request) (any, error)
|
||||
|
||||
func (f PreempterFunc) Preempt(ctx context.Context, req *Request) (interface{}, error) {
|
||||
func (f PreempterFunc) Preempt(ctx context.Context, req *Request) (any, error) {
|
||||
return f(ctx, req)
|
||||
}
|
||||
|
||||
|
|
@ -71,23 +71,23 @@ type Handler interface {
|
|||
// connection is broken or the request is canceled or completed.
|
||||
// (If Handle returns ErrAsyncResponse, ctx will remain uncanceled
|
||||
// until either Cancel or Respond is called for the request's ID.)
|
||||
Handle(ctx context.Context, req *Request) (result interface{}, err error)
|
||||
Handle(ctx context.Context, req *Request) (result any, err error)
|
||||
}
|
||||
|
||||
type defaultHandler struct{}
|
||||
|
||||
func (defaultHandler) Preempt(context.Context, *Request) (interface{}, error) {
|
||||
func (defaultHandler) Preempt(context.Context, *Request) (any, error) {
|
||||
return nil, ErrNotHandled
|
||||
}
|
||||
|
||||
func (defaultHandler) Handle(context.Context, *Request) (interface{}, error) {
|
||||
func (defaultHandler) Handle(context.Context, *Request) (any, error) {
|
||||
return nil, ErrNotHandled
|
||||
}
|
||||
|
||||
// A HandlerFunc implements the Handler interface for a standalone Handle function.
|
||||
type HandlerFunc func(ctx context.Context, req *Request) (interface{}, error)
|
||||
type HandlerFunc func(ctx context.Context, req *Request) (any, error)
|
||||
|
||||
func (f HandlerFunc) Handle(ctx context.Context, req *Request) (interface{}, error) {
|
||||
func (f HandlerFunc) Handle(ctx context.Context, req *Request) (any, error) {
|
||||
return f(ctx, req)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -87,24 +87,24 @@ type invoker interface {
|
|||
|
||||
type notify struct {
|
||||
method string
|
||||
params interface{}
|
||||
params any
|
||||
}
|
||||
|
||||
type call struct {
|
||||
method string
|
||||
params interface{}
|
||||
expect interface{}
|
||||
params any
|
||||
expect any
|
||||
}
|
||||
|
||||
type async struct {
|
||||
name string
|
||||
method string
|
||||
params interface{}
|
||||
params any
|
||||
}
|
||||
|
||||
type collect struct {
|
||||
name string
|
||||
expect interface{}
|
||||
expect any
|
||||
fails bool
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ func (test call) Invoke(t *testing.T, ctx context.Context, h *handler) {
|
|||
|
||||
func (test echo) Invoke(t *testing.T, ctx context.Context, h *handler) {
|
||||
results := newResults(test.expect)
|
||||
if err := h.conn.Call(ctx, "echo", []interface{}{test.method, test.params}).Await(ctx, results); err != nil {
|
||||
if err := h.conn.Call(ctx, "echo", []any{test.method, test.params}).Await(ctx, results); err != nil {
|
||||
t.Fatalf("%v:Echo failed: %v", test.method, err)
|
||||
}
|
||||
verifyResults(t, test.method, results, test.expect)
|
||||
|
|
@ -221,10 +221,10 @@ func (test sequence) Invoke(t *testing.T, ctx context.Context, h *handler) {
|
|||
}
|
||||
|
||||
// newResults makes a new empty copy of the expected type to put the results into
|
||||
func newResults(expect interface{}) interface{} {
|
||||
func newResults(expect any) any {
|
||||
switch e := expect.(type) {
|
||||
case []interface{}:
|
||||
var r []interface{}
|
||||
case []any:
|
||||
var r []any
|
||||
for _, v := range e {
|
||||
r = append(r, reflect.New(reflect.TypeOf(v)).Interface())
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ func newResults(expect interface{}) interface{} {
|
|||
}
|
||||
|
||||
// verifyResults compares the results to the expected values
|
||||
func verifyResults(t *testing.T, method string, results interface{}, expect interface{}) {
|
||||
func verifyResults(t *testing.T, method string, results any, expect any) {
|
||||
if expect == nil {
|
||||
if results != nil {
|
||||
t.Errorf("%v:Got results %+v where none expected", method, expect)
|
||||
|
|
@ -278,7 +278,7 @@ func (h *handler) waiter(name string) chan struct{} {
|
|||
return waiter
|
||||
}
|
||||
|
||||
func (h *handler) Preempt(ctx context.Context, req *jsonrpc2.Request) (interface{}, error) {
|
||||
func (h *handler) Preempt(ctx context.Context, req *jsonrpc2.Request) (any, error) {
|
||||
switch req.Method {
|
||||
case "unblock":
|
||||
var name string
|
||||
|
|
@ -304,7 +304,7 @@ func (h *handler) Preempt(ctx context.Context, req *jsonrpc2.Request) (interface
|
|||
}
|
||||
}
|
||||
|
||||
func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{}, error) {
|
||||
func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (any, error) {
|
||||
switch req.Method {
|
||||
case "no_args":
|
||||
if len(req.Params) > 0 {
|
||||
|
|
@ -349,11 +349,11 @@ func (h *handler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{
|
|||
}
|
||||
return path.Join(v...), nil
|
||||
case "echo":
|
||||
var v []interface{}
|
||||
var v []any
|
||||
if err := json.Unmarshal(req.Params, &v); err != nil {
|
||||
return nil, fmt.Errorf("%w: %s", jsonrpc2.ErrParse, err)
|
||||
}
|
||||
var result interface{}
|
||||
var result any
|
||||
err := h.conn.Call(ctx, v[0].(string), v[1]).Await(ctx, &result)
|
||||
return result, err
|
||||
case "wait":
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import (
|
|||
|
||||
// ID is a Request identifier.
|
||||
type ID struct {
|
||||
value interface{}
|
||||
value any
|
||||
}
|
||||
|
||||
// Message is the interface to all jsonrpc2 message types.
|
||||
|
|
@ -59,18 +59,18 @@ func Int64ID(i int64) ID { return ID{value: i} }
|
|||
func (id ID) IsValid() bool { return id.value != nil }
|
||||
|
||||
// Raw returns the underlying value of the ID.
|
||||
func (id ID) Raw() interface{} { return id.value }
|
||||
func (id ID) Raw() any { return id.value }
|
||||
|
||||
// NewNotification constructs a new Notification message for the supplied
|
||||
// method and parameters.
|
||||
func NewNotification(method string, params interface{}) (*Request, error) {
|
||||
func NewNotification(method string, params any) (*Request, error) {
|
||||
p, merr := marshalToRaw(params)
|
||||
return &Request{Method: method, Params: p}, merr
|
||||
}
|
||||
|
||||
// NewCall constructs a new Call message for the supplied ID, method and
|
||||
// parameters.
|
||||
func NewCall(id ID, method string, params interface{}) (*Request, error) {
|
||||
func NewCall(id ID, method string, params any) (*Request, error) {
|
||||
p, merr := marshalToRaw(params)
|
||||
return &Request{ID: id, Method: method, Params: p}, merr
|
||||
}
|
||||
|
|
@ -85,7 +85,7 @@ func (msg *Request) marshal(to *wireCombined) {
|
|||
|
||||
// NewResponse constructs a new Response message that is a reply to the
|
||||
// supplied. If err is set result may be ignored.
|
||||
func NewResponse(id ID, result interface{}, rerr error) (*Response, error) {
|
||||
func NewResponse(id ID, result any, rerr error) (*Response, error) {
|
||||
r, merr := marshalToRaw(result)
|
||||
return &Response{ID: id, Result: r, Error: rerr}, merr
|
||||
}
|
||||
|
|
@ -169,7 +169,7 @@ func DecodeMessage(data []byte) (Message, error) {
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
func marshalToRaw(obj interface{}) (json.RawMessage, error) {
|
||||
func marshalToRaw(obj any) (json.RawMessage, error) {
|
||||
if obj == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ type msg struct {
|
|||
|
||||
type fakeHandler struct{}
|
||||
|
||||
func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (interface{}, error) {
|
||||
func (fakeHandler) Handle(ctx context.Context, req *jsonrpc2.Request) (any, error) {
|
||||
switch req.Method {
|
||||
case "ping":
|
||||
return &msg{"pong"}, nil
|
||||
|
|
@ -296,7 +296,7 @@ func TestCloseCallRace(t *testing.T) {
|
|||
pokec := make(chan *jsonrpc2.AsyncCall, 1)
|
||||
|
||||
s := jsonrpc2.NewServer(ctx, listener, jsonrpc2.BinderFunc(func(_ context.Context, srvConn *jsonrpc2.Connection) jsonrpc2.ConnectionOptions {
|
||||
h := jsonrpc2.HandlerFunc(func(ctx context.Context, _ *jsonrpc2.Request) (interface{}, error) {
|
||||
h := jsonrpc2.HandlerFunc(func(ctx context.Context, _ *jsonrpc2.Request) (any, error) {
|
||||
// Start a concurrent call from the server to the client.
|
||||
// The point of this test is to ensure this doesn't deadlock
|
||||
// if the client shuts down the connection concurrently.
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ const wireVersion = "2.0"
|
|||
// We can decode this and then work out which it is.
|
||||
type wireCombined struct {
|
||||
VersionTag string `json:"jsonrpc"`
|
||||
ID interface{} `json:"id,omitempty"`
|
||||
ID any `json:"id,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Params json.RawMessage `json:"params,omitempty"`
|
||||
Result json.RawMessage `json:"result,omitempty"`
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func TestWireMessage(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func newNotification(method string, params interface{}) jsonrpc2.Message {
|
||||
func newNotification(method string, params any) jsonrpc2.Message {
|
||||
msg, err := jsonrpc2.NewNotification(method, params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -71,7 +71,7 @@ func newNotification(method string, params interface{}) jsonrpc2.Message {
|
|||
return msg
|
||||
}
|
||||
|
||||
func newID(id interface{}) jsonrpc2.ID {
|
||||
func newID(id any) jsonrpc2.ID {
|
||||
switch v := id.(type) {
|
||||
case nil:
|
||||
return jsonrpc2.ID{}
|
||||
|
|
@ -86,7 +86,7 @@ func newID(id interface{}) jsonrpc2.ID {
|
|||
}
|
||||
}
|
||||
|
||||
func newCall(id interface{}, method string, params interface{}) jsonrpc2.Message {
|
||||
func newCall(id any, method string, params any) jsonrpc2.Message {
|
||||
msg, err := jsonrpc2.NewCall(newID(id), method, params)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -94,7 +94,7 @@ func newCall(id interface{}, method string, params interface{}) jsonrpc2.Message
|
|||
return msg
|
||||
}
|
||||
|
||||
func newResponse(id interface{}, result interface{}, rerr error) jsonrpc2.Message {
|
||||
func newResponse(id any, result any, rerr error) jsonrpc2.Message {
|
||||
msg, err := jsonrpc2.NewResponse(newID(id), result, rerr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ func Detach(ctx context.Context) context.Context { return detachedContext{ctx} }
|
|||
|
||||
type detachedContext struct{ parent context.Context }
|
||||
|
||||
func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false }
|
||||
func (v detachedContext) Done() <-chan struct{} { return nil }
|
||||
func (v detachedContext) Err() error { return nil }
|
||||
func (v detachedContext) Value(key interface{}) interface{} { return v.parent.Value(key) }
|
||||
func (v detachedContext) Deadline() (time.Time, bool) { return time.Time{}, false }
|
||||
func (v detachedContext) Done() <-chan struct{} { return nil }
|
||||
func (v detachedContext) Err() error { return nil }
|
||||
func (v detachedContext) Value(key any) any { return v.parent.Value(key) }
|
||||
|
|
|
|||
Loading…
Reference in a new issue