From b9615fb2aea9d6fd21d6cdd2e5228cec02d14faa Mon Sep 17 00:00:00 2001 From: Bevan Arps Date: Thu, 10 Jun 2021 15:08:03 +1200 Subject: [PATCH] Remove name fields --- .../conversions/hub_conversion_function.go | 8 +------- .../property_assignment_function.go | 20 +++++++------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/hack/generator/pkg/conversions/hub_conversion_function.go b/hack/generator/pkg/conversions/hub_conversion_function.go index e1b22326a4a..f87364c5d02 100644 --- a/hack/generator/pkg/conversions/hub_conversion_function.go +++ b/hack/generator/pkg/conversions/hub_conversion_function.go @@ -13,15 +13,11 @@ import ( "github.com/Azure/azure-service-operator/hack/generator/pkg/astbuilder" "github.com/Azure/azure-service-operator/hack/generator/pkg/astmodel" - "github.com/dave/dst" - "go/token" ) // HubConversionFunction implements conversions to/from our hub type // Existing PropertyAssignment functions are used to implement stepwise conversion type HubConversionFunction struct { - // name of this conversion function - name string // hub is the TypeName of the canonical hub type, the final target or original source for conversion hub astmodel.TypeName // direction specifies whether we are converting to the hub type, or from it @@ -45,7 +41,6 @@ func NewConversionToHubFunction( propertyFunctionName string, idFactory astmodel.IdentifierFactory) *HubConversionFunction { result := &HubConversionFunction{ - name: "ConvertTo", hub: hub, direction: ConvertTo, propertyFunctionName: propertyFunctionName, @@ -66,7 +61,6 @@ func NewConversionFromHubFunction( propertyFunctionName string, idFactory astmodel.IdentifierFactory) *HubConversionFunction { result := &HubConversionFunction{ - name: "ConvertFrom", hub: hub, direction: ConvertFrom, propertyFunctionName: propertyFunctionName, @@ -310,7 +304,7 @@ func (fn *HubConversionFunction) Equals(otherFn astmodel.Function) bool { } } - return fn.name == hcf.name && + return fn.Name() == hcf.Name() && fn.direction == hcf.direction && fn.hub.Equals(hcf.hub) } diff --git a/hack/generator/pkg/conversions/property_assignment_function.go b/hack/generator/pkg/conversions/property_assignment_function.go index 40197220174..38586121992 100644 --- a/hack/generator/pkg/conversions/property_assignment_function.go +++ b/hack/generator/pkg/conversions/property_assignment_function.go @@ -19,8 +19,6 @@ import ( // PropertyAssignmentFunction represents a function that assigns all the properties from one resource or object to // another. Performs a single step of the conversions required to/from the hub version. type PropertyAssignmentFunction struct { - // name of this conversion function - name string // otherDefinition is the type we are converting to (or from). This will be a type which is "closer" // to the hub storage type, making this a building block of the final conversion. otherDefinition astmodel.TypeDefinition @@ -55,7 +53,6 @@ func NewPropertyAssignmentFromFunction( conversionContext *PropertyConversionContext, ) (*PropertyAssignmentFunction, error) { result := &PropertyAssignmentFunction{ - name: nameOfPropertyAssignmentFunction(otherDefinition.Name(), ConvertFrom, idFactory), otherDefinition: otherDefinition, idFactory: idFactory, direction: ConvertFrom, @@ -63,12 +60,11 @@ func NewPropertyAssignmentFromFunction( knownLocals: astmodel.NewKnownLocalsSet(idFactory), } - result.name = nameOfPropertyAssignmentFunction(otherDefinition.Name(), ConvertFrom, idFactory) - result.conversionContext = conversionContext.WithFunctionName(result.name).WithKnownLocals(result.knownLocals) + result.conversionContext = conversionContext.WithFunctionName(result.Name()).WithKnownLocals(result.knownLocals) err := result.createConversions(receiver) if err != nil { - return nil, errors.Wrapf(err, "creating '%s()'", result.name) + return nil, errors.Wrapf(err, "creating '%s()'", result.Name()) } return result, nil @@ -82,7 +78,6 @@ func NewPropertyAssignmentToFunction( conversionContext *PropertyConversionContext, ) (*PropertyAssignmentFunction, error) { result := &PropertyAssignmentFunction{ - name: nameOfPropertyAssignmentFunction(otherDefinition.Name(), ConvertTo, idFactory), otherDefinition: otherDefinition, idFactory: idFactory, direction: ConvertTo, @@ -90,12 +85,11 @@ func NewPropertyAssignmentToFunction( knownLocals: astmodel.NewKnownLocalsSet(idFactory), } - result.name = nameOfPropertyAssignmentFunction(otherDefinition.Name(), ConvertTo, idFactory) - result.conversionContext = conversionContext.WithFunctionName(result.name).WithKnownLocals(result.knownLocals) + result.conversionContext = conversionContext.WithFunctionName(result.Name()).WithKnownLocals(result.knownLocals) err := result.createConversions(receiver) if err != nil { - return nil, errors.Wrapf(err, "creating '%s()'", result.name) + return nil, errors.Wrapf(err, "creating '%s()'", result.Name()) } return result, nil @@ -103,10 +97,10 @@ func NewPropertyAssignmentToFunction( // Name returns the name of this function func (fn *PropertyAssignmentFunction) Name() string { - return fn.name + return nameOfPropertyAssignmentFunction(fn.otherDefinition.Name(), fn.direction, fn.idFactory) } -// OtherType() returns the other type involved in the property assignments +// OtherType returns the other type involved in the property assignments func (fn *PropertyAssignmentFunction) OtherType() astmodel.TypeName { return fn.otherDefinition.Name() } @@ -132,7 +126,7 @@ func (fn *PropertyAssignmentFunction) References() astmodel.TypeNameSet { // Equals checks to see if the supplied function is the same as this one func (fn *PropertyAssignmentFunction) Equals(f astmodel.Function) bool { if other, ok := f.(*PropertyAssignmentFunction); ok { - if fn.name != other.name { + if fn.Name() != other.Name() { // Different name means not-equal return false }