diff options
Diffstat (limited to 'codegen')
-rw-r--r-- | codegen/methods.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/codegen/methods.go b/codegen/methods.go index 007384f9b..ed8dba923 100644 --- a/codegen/methods.go +++ b/codegen/methods.go @@ -288,6 +288,12 @@ func (m Method) Declaration(receiver string) string { return fmt.Sprintf("func (%s %s) %s%s %s", receiverShort(receiver), receiver, m.Name, m.inStr(), m.outStr()) } +// DeclarationNamed creates a method declaration (without any body) for the given receiver +// with named return values. +func (m Method) DeclarationNamed(receiver string) string { + return fmt.Sprintf("func (%s %s) %s%s %s", receiverShort(receiver), receiver, m.Name, m.inStr(), m.outStrNamed()) +} + // Delegate creates a delegate call string. func (m Method) Delegate(receiver, delegate string) string { ret := "" @@ -336,6 +342,19 @@ func (m Method) outStr() string { return "(" + strings.Join(m.Out, ", ") + ")" } +func (m Method) outStrNamed() string { + if len(m.Out) == 0 { + return "" + } + + outs := make([]string, len(m.Out)) + for i := 0; i < len(outs); i++ { + outs[i] = fmt.Sprintf("o%d %s", i, m.Out[i]) + } + + return "(" + strings.Join(outs, ", ") + ")" +} + // Methods represents a list of methods for one or more interfaces. // The order matches the defined order in their source file(s). type Methods []Method |