-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_type.go
51 lines (41 loc) · 1011 Bytes
/
block_type.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
48
49
50
51
package codegen
import (
"strings"
)
type typeBlock struct {
name string
baseType *nameHelper
}
// Type creates a new type block
func (f *File) Type(typeName, baseType string) *typeBlock {
t := newType(typeName, "", baseType)
f.append(t)
return t
}
// Type creates a new type block with a package alias
func (f *File) QualType(typeName, alias, baseType string) *typeBlock {
t := newType(typeName, alias, baseType)
f.append(t)
return t
}
// Pointer turns the base type to the poiter type
func (t *typeBlock) Pointer() *typeBlock {
t.SetIsPointer(true)
return t
}
// SetIsPointer sets whether or not a type is a pointer
func (t *typeBlock) SetIsPointer(isPointer bool) *typeBlock {
t.baseType.setIsPointer(isPointer)
return t
}
func newType(name, alias, baseType string) *typeBlock {
return &typeBlock{
name: name,
baseType: newNameHelper(alias, baseType),
}
}
func (t *typeBlock) write(sb *strings.Builder) {
writeF(sb, "type %s ", t.name)
t.baseType.wr(sb)
newLine(sb)
}