summaryrefslogtreecommitdiffstats
path: root/codegen
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-03-25 18:18:34 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-03-26 10:20:40 +0100
commit4dae52af680e6ff2c8cdeb4ce1f219330b27001c (patch)
treedb157b09fc15b25a07512581fbd80536fe8e18ee /codegen
parent794d4052b87c98943588b35e1cfecc06e6a0c7f2 (diff)
Avoid nilpointer on no File on Page
Fixes #5781
Diffstat (limited to 'codegen')
-rw-r--r--codegen/methods.go19
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