From bc2d553f77729092e04e832ff8108986286b553a Mon Sep 17 00:00:00 2001 From: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Date: Wed, 18 May 2022 18:20:03 -0300 Subject: [PATCH] chore: rename container.AutoGroupType to container.ManyPerContainerType (#11978) Co-authored-by: Marko --- container/container.go | 16 ++++++++-------- container/container_test.go | 24 ++++++++++++------------ container/group.go | 24 ++++++++++++------------ container/testdata/example.dot | 2 +- container/testdata/example_error.dot | 2 +- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/container/container.go b/container/container.go index 76df8bedfa9c..484419757f9d 100644 --- a/container/container.go +++ b/container/container.go @@ -82,18 +82,18 @@ func (c *container) getResolver(typ reflect.Type) (resolver, error) { } elemType := typ - if isAutoGroupSliceType(elemType) || isOnePerModuleMapType(elemType) { + if isManyPerContainerSliceType(elemType) || isOnePerModuleMapType(elemType) { elemType = elemType.Elem() } var typeGraphNode *graphviz.Node - if isAutoGroupType(elemType) { - c.logf("Registering resolver for auto-group type %v", elemType) + if isManyPerContainerType(elemType) { + c.logf("Registering resolver for many-per-container type %v", elemType) sliceType := reflect.SliceOf(elemType) typeGraphNode = c.typeGraphNode(sliceType) - typeGraphNode.SetComment("auto-group") + typeGraphNode.SetComment("many-per-container") r := &groupResolver{ typ: elemType, @@ -141,8 +141,8 @@ func (c *container) addNode(provider *ProviderDescriptor, key *moduleKey) (inter hasOwnModuleKeyParam = true } - if isAutoGroupType(typ) { - return nil, fmt.Errorf("auto-group type %v can't be used as an input parameter", typ) + if isManyPerContainerType(typ) { + return nil, fmt.Errorf("many-per-container type %v can't be used as an input parameter", typ) } else if isOnePerModuleType(typ) { return nil, fmt.Errorf("one-per-module type %v can't be used as an input parameter", typ) } @@ -184,8 +184,8 @@ func (c *container) addNode(provider *ProviderDescriptor, key *moduleKey) (inter typ, typ.Elem()) } - // auto-group slices of auto-group types - if isAutoGroupSliceType(typ) { + // many-per-container slices of many-per-container types + if isManyPerContainerSliceType(typ) { typ = typ.Elem() } diff --git a/container/container_test.go b/container/container_test.go index 23ce2e9fd841..8ead6b1caea6 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -40,7 +40,7 @@ type Command struct { Run func() } -func (Command) IsAutoGroupType() {} +func (Command) IsManyPerContainerType() {} func ProvideKVStoreKey(moduleKey container.ModuleKey) KVStoreKey { return KVStoreKey{name: moduleKey.Name()} @@ -401,19 +401,19 @@ func TestOnePerModule(t *testing.T) { ) } -type AutoGroupInt int +type ManyPerContainerInt int -func (AutoGroupInt) IsAutoGroupType() {} +func (ManyPerContainerInt) IsManyPerContainerType() {} -func TestAutoGroup(t *testing.T) { - var xs []AutoGroupInt +func TestManyPerContainer(t *testing.T) { + var xs []ManyPerContainerInt var sum string require.NoError(t, container.Build( container.Provide( - func() AutoGroupInt { return 4 }, - func() AutoGroupInt { return 9 }, - func(xs []AutoGroupInt) string { + func() ManyPerContainerInt { return 4 }, + func() ManyPerContainerInt { return 9 }, + func(xs []ManyPerContainerInt) string { sum := 0 for _, x := range xs { sum += int(x) @@ -426,15 +426,15 @@ func TestAutoGroup(t *testing.T) { ), ) require.Len(t, xs, 2) - require.Contains(t, xs, AutoGroupInt(4)) - require.Contains(t, xs, AutoGroupInt(9)) + require.Contains(t, xs, ManyPerContainerInt(4)) + require.Contains(t, xs, ManyPerContainerInt(9)) require.Equal(t, "13", sum) - var z AutoGroupInt + var z ManyPerContainerInt require.Error(t, container.Build( container.Provide( - func() AutoGroupInt { return 0 }, + func() ManyPerContainerInt { return 0 }, ), &z, ), diff --git a/container/group.go b/container/group.go index ab29a30b85c4..db3ee6029888 100644 --- a/container/group.go +++ b/container/group.go @@ -9,23 +9,23 @@ import ( "github.com/cosmos/cosmos-sdk/container/internal/graphviz" ) -// AutoGroupType marks a type which automatically gets grouped together. For an AutoGroupType T, +// ManyPerContainerType marks a type which automatically gets grouped together. For an ManyPerContainerType T, // T and []T can be declared as output parameters for providers as many times within the container // as desired. All of the provided values for T can be retrieved by declaring an // []T input parameter. -type AutoGroupType interface { - // IsAutoGroupType is a marker function which just indicates that this is a auto-group type. - IsAutoGroupType() +type ManyPerContainerType interface { + // IsManyPerContainerType is a marker function which just indicates that this is a many-per-container type. + IsManyPerContainerType() } -var autoGroupTypeType = reflect.TypeOf((*AutoGroupType)(nil)).Elem() +var manyPerContainerTypeType = reflect.TypeOf((*ManyPerContainerType)(nil)).Elem() -func isAutoGroupType(t reflect.Type) bool { - return t.Implements(autoGroupTypeType) +func isManyPerContainerType(t reflect.Type) bool { + return t.Implements(manyPerContainerTypeType) } -func isAutoGroupSliceType(typ reflect.Type) bool { - return typ.Kind() == reflect.Slice && isAutoGroupType(typ.Elem()) +func isManyPerContainerSliceType(typ reflect.Type) bool { + return typ.Kind() == reflect.Slice && isManyPerContainerType(typ.Elem()) } type groupResolver struct { @@ -43,12 +43,12 @@ type sliceGroupResolver struct { } func (g *groupResolver) describeLocation() string { - return fmt.Sprintf("auto-group type %v", g.typ) + return fmt.Sprintf("many-per-container type %v", g.typ) } func (g *sliceGroupResolver) resolve(c *container, _ *moduleKey, caller Location) (reflect.Value, error) { // Log - c.logf("Providing auto-group type slice %v to %s from:", g.sliceType, caller.Name()) + c.logf("Providing many-per-container type slice %v to %s from:", g.sliceType, caller.Name()) c.indentLogger() for _, node := range g.providers { c.logf(node.provider.Location.String()) @@ -81,7 +81,7 @@ func (g *sliceGroupResolver) resolve(c *container, _ *moduleKey, caller Location } func (g *groupResolver) resolve(_ *container, _ *moduleKey, _ Location) (reflect.Value, error) { - return reflect.Value{}, errors.Errorf("%v is an auto-group type and cannot be used as an input value, instead use %v", g.typ, g.sliceType) + return reflect.Value{}, errors.Errorf("%v is an many-per-container type and cannot be used as an input value, instead use %v", g.typ, g.sliceType) } func (g *groupResolver) addNode(n *simpleProvider, i int) error { diff --git a/container/testdata/example.dot b/container/testdata/example.dot index becdb39af35c..a9ba2413ac05 100644 --- a/container/testdata/example.dot +++ b/container/testdata/example.dot @@ -14,7 +14,7 @@ digraph "" { "github.com/cosmos/cosmos-sdk/container_test.ProvideKVStoreKey"[color="black", fontcolor="black", penwidth="1.5", shape="box"]; } - "[]github.com/cosmos/cosmos-sdk/container_test.Command"[color="lightgrey", comment="auto-group", fontcolor="dimgrey", penwidth="0.5"]; + "[]github.com/cosmos/cosmos-sdk/container_test.Command"[color="lightgrey", comment="many-per-container", fontcolor="dimgrey", penwidth="0.5"]; "github.com/cosmos/cosmos-sdk/container.ModuleKey"[color="black", fontcolor="black", penwidth="1.5"]; "github.com/cosmos/cosmos-sdk/container.OwnModuleKey"[color="lightgrey", fontcolor="dimgrey", penwidth="0.5"]; "github.com/cosmos/cosmos-sdk/container_test.KVStoreKey"[color="black", fontcolor="black", penwidth="1.5"]; diff --git a/container/testdata/example_error.dot b/container/testdata/example_error.dot index 277afae1d49b..089a413d71e2 100644 --- a/container/testdata/example_error.dot +++ b/container/testdata/example_error.dot @@ -14,7 +14,7 @@ digraph "" { "github.com/cosmos/cosmos-sdk/container_test.ProvideKVStoreKey"[color="black", fontcolor="black", penwidth="1.5", shape="box"]; } - "[]github.com/cosmos/cosmos-sdk/container_test.Command"[color="lightgrey", comment="auto-group", fontcolor="dimgrey", penwidth="0.5"]; + "[]github.com/cosmos/cosmos-sdk/container_test.Command"[color="lightgrey", comment="many-per-container", fontcolor="dimgrey", penwidth="0.5"]; "github.com/cosmos/cosmos-sdk/container.ModuleKey"[color="black", fontcolor="black", penwidth="1.5"]; "github.com/cosmos/cosmos-sdk/container.OwnModuleKey"[color="lightgrey", fontcolor="dimgrey", penwidth="0.5"]; "github.com/cosmos/cosmos-sdk/container_test.KVStoreKey"[color="black", fontcolor="black", penwidth="1.5"];