-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_method.go
45 lines (36 loc) · 944 Bytes
/
block_method.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package codegen
import "strings"
type methodBlock struct {
this *thisDecl
*funcBlock
}
// Method creates a new method block
func (f *File) Method(this *thisDecl, name string) *methodBlock {
method := newMethod(this, name)
f.append(method)
return method
}
// Params appends method parameters
func (m *methodBlock) Params(params ...*ParamDecl) *methodBlock {
m.funcBlock.Params(params...)
return m
}
// ReturnTypes appends function return parameters
func (m *methodBlock) ReturnTypes(returnTypes ...*TypeDecl) *methodBlock {
m.funcBlock.ReturnTypes(returnTypes...)
return m
}
func newMethod(this *thisDecl, name string) *methodBlock {
return &methodBlock{
this: this,
funcBlock: newFunc(name),
}
}
func (m *methodBlock) write(sb *strings.Builder) {
sb.WriteString("func (")
m.this.wr(sb)
writeF(sb, ") %s", m.name)
writeParams(sb, m.params)
writeReturnTypes(sb, m.retTypes)
writeStmtsBlock(sb, m.stmts, true)
}