forked from therecipe/qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
variable.go
executable file
·165 lines (139 loc) · 3.86 KB
/
variable.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package parser
import (
"fmt"
"strings"
)
type Variable struct {
Name string `xml:"name,attr"`
Fullname string `xml:"fullname,attr"`
Href string `xml:"href,attr"`
Status string `xml:"status,attr"`
Access string `xml:"access,attr"`
Filepath string `xml:"filepath,attr"`
Static bool `xml:"static,attr"`
Output string `xml:"type,attr"`
Brief string `xml:"brief,attr"`
Getter []struct{} `xml:"getter"`
Setter []struct{} `xml:"setter"`
}
func (v *Variable) Class() (*Class, bool) {
var class, ok = State.ClassMap[v.ClassName()]
return class, ok
}
func (v *Variable) ClassName() string {
var s = strings.Split(v.Fullname, "::")
if len(s) == 3 {
return s[1]
}
return s[0]
}
func (v *Variable) varToFunc() []*Function {
var funcs = make([]*Function, 0)
var class, ok = v.Class()
if !ok || class.HasFunctionWithName(v.Name) {
return funcs
}
funcs = append(funcs, &Function{
Name: v.Name,
Fullname: v.Fullname,
Href: v.Href,
Status: v.Status,
Access: v.Access,
Filepath: v.Filepath,
Static: v.Static,
Output: v.Output,
Meta: GETTER,
Brief: v.Brief,
})
if strings.Contains(v.Output, "const") {
return funcs
}
funcs = append(funcs, &Function{
Name: fmt.Sprintf("set%v", strings.Title(v.Name)),
Fullname: fmt.Sprintf("%v::set%v", v.ClassName(), strings.Title(v.Name)),
Href: v.Href,
Status: v.Status,
Access: v.Access,
Filepath: v.Filepath,
Static: v.Static,
Output: "void",
Meta: SETTER,
Parameters: []*Parameter{{Value: v.Output}},
TmpName: v.Name,
Brief: v.Brief,
})
return funcs
}
func (v *Variable) propToFunc(c *Class) []*Function {
var funcs = make([]*Function, 0)
if len(v.Getter) != 0 {
return funcs
}
if !(c.HasFunctionWithName(v.Name) ||
c.HasFunctionWithName(fmt.Sprintf("is%v", strings.Title(v.Name))) ||
c.HasFunctionWithName(fmt.Sprintf("has%v", strings.Title(v.Name)))) {
var tmpF = &Function{
Name: v.Name,
Fullname: v.Fullname,
Href: v.Href,
Status: v.Status,
Access: v.Access,
Filepath: v.Filepath,
Static: v.Static,
Output: v.Output,
Meta: PLAIN,
Signature: "()",
}
if tmpF.Output == "bool" {
tmpF.Name = fmt.Sprintf("is%v", strings.Title(tmpF.Name))
tmpF.Fullname = fmt.Sprintf("%v::%v", tmpF.ClassName(), tmpF.Name)
}
funcs = append(funcs, tmpF)
}
if len(v.Setter) != 0 || c.HasFunctionWithName(fmt.Sprintf("set%v", strings.Title(v.Name))) {
return funcs
}
funcs = append(funcs, &Function{
Name: fmt.Sprintf("set%v", strings.Title(v.Name)),
Fullname: fmt.Sprintf("%v::set%v", v.ClassName(), strings.Title(v.Name)),
Href: v.Href,
Status: v.Status,
Access: v.Access,
Filepath: v.Filepath,
Static: v.Static,
Output: "void",
Meta: PLAIN,
Parameters: []*Parameter{{Name: v.Name, Value: v.Output}},
Signature: "()",
})
if c.Module == MOC {
funcs = append(funcs, &Function{
Name: fmt.Sprintf("%vChanged", v.Name),
Fullname: fmt.Sprintf("%v::%vChanged", v.ClassName(), v.Name),
Status: v.Status,
Access: v.Access,
Output: "void",
Meta: SIGNAL,
Parameters: []*Parameter{{Name: v.Name, Value: v.Output}},
Signature: "()",
})
}
//add all overloaded property functions from base classes
//TODO: move rest into seperate function, as this func is called multiple times
for _, bc := range c.GetAllBases() {
var bclass, ok = State.ClassMap[bc]
if !ok {
continue
}
for _, bcf := range bclass.Functions {
if bcf.Name != fmt.Sprintf("set%v", strings.Title(v.Name)) || !bcf.Overload {
continue
}
var tmpF = *bcf
tmpF.Name = fmt.Sprintf("set%v", strings.Title(v.Name))
tmpF.Fullname = fmt.Sprintf("%v::%v", v.ClassName(), tmpF.Name)
funcs = append(funcs, &tmpF)
}
}
return funcs
}