-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconstructor.go
41 lines (33 loc) · 888 Bytes
/
constructor.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
package generate
import (
"github.com/pekim/jennifer/jen"
)
type Constructor struct {
*Function
}
func (c *Constructor) init(ns *Namespace, record *Record) {
// Some constructors defined in gir files reference a subclass
// of their real type.
// Ensure that all constructors return a pointer to their
// record/class type.
c.ReturnValue.Type.CType = record.CType + "*"
c.ReturnValue.Type.Name = record.Name
c.Function.init(ns, nil, "")
c.GoName = record.GoName + MakeExportedGoName(c.Name)
c.Function.ctorRecord = record
if record.Version != "" && c.Version == "" {
c.Version = record.Version
}
}
func (c *Constructor) generate(g *jen.Group, version *Version) {
if !supportedByVersion(c, version) {
return
}
supported, reason := c.supported()
if !supported {
g.Commentf("Unsupported : %s", reason)
g.Line()
return
}
c.Function.generate(g, version)
}