-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_interface.go
47 lines (37 loc) · 961 Bytes
/
block_interface.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
46
47
package codegen
import (
"strings"
)
type interfaceBlock struct {
name string
funcs []*FuncDeclaration
}
// Interface creates a new interface declaration block
func (f *File) Interface(interfaceName string) *interfaceBlock {
i := newInterface(interfaceName)
f.append(i)
return i
}
// Funcs adds function declarations to the interface
func (i *interfaceBlock) Funcs(functions ...*FuncDeclaration) *interfaceBlock {
i.funcs = functions
return i
}
// AddFunc adds a new function declaration to the interface
func (i *interfaceBlock) AddFunc(function *FuncDeclaration) {
i.funcs = append(i.funcs, function)
}
func newInterface(name string) *interfaceBlock {
return &interfaceBlock{
name: name,
funcs: make([]*FuncDeclaration, 0),
}
}
func (i *interfaceBlock) write(sb *strings.Builder) {
writeNewLineF(sb, "type %s interface {", i.name)
for _, function := range i.funcs {
function.wr(sb)
newLine(sb)
}
writeByteNewLine(sb, '}')
}