-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_structProp.go
54 lines (44 loc) · 1.28 KB
/
block_structProp.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
52
53
54
package codegen
import "strings"
type PropertyDecl struct {
name string
typeName *nameHelper
}
// Property creates a new property declaration
func Property(propertyName, typeName string) *PropertyDecl {
return &PropertyDecl{
name: propertyName,
typeName: newNameHelper("", typeName),
}
}
// QualProperty creates a new property declaration with a package alias
func QualProperty(propertyName, alias, typeName string) *PropertyDecl {
return &PropertyDecl{
name: propertyName,
typeName: newNameHelper(alias, typeName),
}
}
// EmbeddedProp crates a new embedded property
func EmbeddedProperty(typeName string) *PropertyDecl {
return Property("", typeName)
}
// QualEmbeddedProperty creates a new embedded property with a package alias
func QualEmbeddedProperty(alias, typeName string) *PropertyDecl {
return QualProperty("", alias, typeName)
}
// Pointer turns the property into a pointer type
func (p *PropertyDecl) Pointer() *PropertyDecl {
p.SetIsPointer(true)
return p
}
// SetIsPointer sets whether or not a property is a pointer
func (p *PropertyDecl) SetIsPointer(isPointer bool) *PropertyDecl {
p.typeName.setIsPointer(isPointer)
return p
}
func (p *PropertyDecl) wr(sb *strings.Builder) {
if len(p.name) != 0 {
writeF(sb, "%s ", p.name)
}
p.typeName.wr(sb)
}