Skip to content

Commit

Permalink
Remove name fields
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek committed Jun 14, 2021
1 parent 1bc8ba0 commit b9615fb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
8 changes: 1 addition & 7 deletions hack/generator/pkg/conversions/hub_conversion_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,7 +41,6 @@ func NewConversionToHubFunction(
propertyFunctionName string,
idFactory astmodel.IdentifierFactory) *HubConversionFunction {
result := &HubConversionFunction{
name: "ConvertTo",
hub: hub,
direction: ConvertTo,
propertyFunctionName: propertyFunctionName,
Expand All @@ -66,7 +61,6 @@ func NewConversionFromHubFunction(
propertyFunctionName string,
idFactory astmodel.IdentifierFactory) *HubConversionFunction {
result := &HubConversionFunction{
name: "ConvertFrom",
hub: hub,
direction: ConvertFrom,
propertyFunctionName: propertyFunctionName,
Expand Down Expand Up @@ -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)
}
20 changes: 7 additions & 13 deletions hack/generator/pkg/conversions/property_assignment_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -55,20 +53,18 @@ func NewPropertyAssignmentFromFunction(
conversionContext *PropertyConversionContext,
) (*PropertyAssignmentFunction, error) {
result := &PropertyAssignmentFunction{
name: nameOfPropertyAssignmentFunction(otherDefinition.Name(), ConvertFrom, idFactory),
otherDefinition: otherDefinition,
idFactory: idFactory,
direction: ConvertFrom,
conversions: make(map[string]StoragePropertyConversion),
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
Expand All @@ -82,31 +78,29 @@ func NewPropertyAssignmentToFunction(
conversionContext *PropertyConversionContext,
) (*PropertyAssignmentFunction, error) {
result := &PropertyAssignmentFunction{
name: nameOfPropertyAssignmentFunction(otherDefinition.Name(), ConvertTo, idFactory),
otherDefinition: otherDefinition,
idFactory: idFactory,
direction: ConvertTo,
conversions: make(map[string]StoragePropertyConversion),
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
}

// 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()
}
Expand All @@ -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
}
Expand Down

0 comments on commit b9615fb

Please sign in to comment.