Skip to content

Commit

Permalink
Merge pull request #19 from percolate/fix-formatting
Browse files Browse the repository at this point in the history
Fix formatting related to variadic types
  • Loading branch information
kevinbirch committed Apr 17, 2018
2 parents a789b0d + eb4f3b7 commit 4cd615c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.3
1.0.4
22 changes: 11 additions & 11 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func extractIdentifiersFromField(field *ast.Field, imports *ImportSet) ([]*Ident
return []*Identifier{
&Identifier{
Name: identSymGen.Next(),
valueType: identifierType,
ValueType: identifierType,
},
}, nil
}
Expand All @@ -125,7 +125,7 @@ func extractIdentifiersFromField(field *ast.Field, imports *ImportSet) ([]*Ident
for i, name := range field.Names {
identifiers[i] = &Identifier{
Name: name.Name,
valueType: identifierType,
ValueType: identifierType,
}
}

Expand Down Expand Up @@ -241,10 +241,10 @@ func (i *Interface) addMethodFromType(f *types.Func, imports *ImportSet) error {
}
if sig.Variadic() {
last := parameters[len(parameters)-1]
if avt, ok := last.valueType.(*Array); ok {
last.valueType = &Ellipsis{subType: avt.subType}
if avt, ok := last.ValueType.(*Array); ok {
last.ValueType = &Ellipsis{subType: avt.subType}
} else {
last.valueType = &Ellipsis{subType: last.valueType}
last.ValueType = &Ellipsis{subType: last.ValueType}
}
}
method.Parameters = append(method.Parameters, parameters...)
Expand Down Expand Up @@ -274,7 +274,7 @@ func extractIdentifiersFromTuple(tuple *types.Tuple, imports *ImportSet) ([]*Ide
}
ident := &Identifier{
Name: p.Name(),
valueType: identifierType,
ValueType: identifierType,
}
if "" == ident.Name {
ident.Name = identSymGen.Next()
Expand Down Expand Up @@ -462,7 +462,7 @@ func (m *Method) ResultsSignature() string {

type Identifier struct {
Name string
valueType Type
ValueType Type
titleCase string
parameterFormat string
referenceFormat string
Expand All @@ -479,31 +479,31 @@ func (i *Identifier) TitleCase() string {

func (i *Identifier) ParameterFormat() string {
if i.parameterFormat == "" {
i.parameterFormat = fmt.Sprintf("%s %s", i.Name, i.valueType.ParameterFormat())
i.parameterFormat = fmt.Sprintf("%s %s", i.Name, i.ValueType.ParameterFormat())
}

return i.parameterFormat
}

func (i *Identifier) ReferenceFormat() string {
if i.referenceFormat == "" {
i.referenceFormat = fmt.Sprintf("%s%s", i.Name, i.valueType.ReferenceFormat())
i.referenceFormat = fmt.Sprintf("%s%s", i.Name, i.ValueType.ReferenceFormat())
}

return i.referenceFormat
}

func (i *Identifier) FieldFormat() string {
if i.fieldFormat == "" {
i.fieldFormat = fmt.Sprintf("%s %s", i.TitleCase(), i.valueType.FieldFormat())
i.fieldFormat = fmt.Sprintf("%s %s", i.TitleCase(), i.ValueType.FieldFormat())
}

return i.fieldFormat
}

func (i *Identifier) Signature() string {
if i.signature == "" {
i.signature = i.valueType.ParameterFormat()
i.signature = i.ValueType.ParameterFormat()
}

return i.signature
Expand Down
4 changes: 2 additions & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type {{.Interface}}{{.Name}}Invocation struct {
{{if and .Parameters .Results}}
// New{{.Interface}}{{.Name}}Invocation creates a new instance of {{.Interface}}{{.Name}}Invocation
func New{{.Interface}}{{.Name}}Invocation({{.ParametersDeclaration}}, {{.ResultsDeclaration}}) *{{.Interface}}{{.Name}}Invocation {
func New{{.Interface}}{{.Name}}Invocation({{range .Parameters}}{{.Name}} {{.ValueType.FieldFormat}}, {{end}}{{.ResultsDeclaration}}) *{{.Interface}}{{.Name}}Invocation {
invocation := new({{.Interface}}{{.Name}}Invocation)
{{range .Parameters}} invocation.Parameters.{{.TitleCase}} = {{.Name}}
Expand Down Expand Up @@ -154,7 +154,7 @@ func (f *Fake{{.Name}}) Reset() {
return
}
}
return fallback{{$d}}()
}
}{{end}}{{end}}{{end}}{{end}}{{/* end if and .Parameters .Results */}}
Expand Down

0 comments on commit 4cd615c

Please sign in to comment.