Repository navigation
Expand file tree
/
Copy pathbuilders_dispatch.go
More file actions
59 lines (52 loc) · 1.49 KB
/
Copy pathbuilders_dispatch.go
File metadata and controls
59 lines (52 loc) · 1.49 KB
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
package uir
// DispatchCallBuilder provides fluent API for building DispatchCallStmt
type DispatchCallBuilder struct {
DispatchCallStmt
}
// NewDispatchCall starts a call to method, the declared target, whose
// implementation is chosen at run time among the candidates added to it.
func NewDispatchCall(method string, id ...Identifier) *DispatchCallBuilder {
nodeRef := Identifier{}
if len(id) > 0 {
nodeRef = id[0]
}
nodeRef.Method = method
return &DispatchCallBuilder{
DispatchCallStmt: DispatchCallStmt{
methodBase: methodBase{
statementBase: statementBase{Type: ASTStatementTypeDispatchCall},
Method: NewRef(nodeRef),
},
},
}
}
func (b *DispatchCallBuilder) WithCandidate(node Node) *DispatchCallBuilder {
b.Candidates = append(b.Candidates, node)
return b
}
func (b *DispatchCallBuilder) WithReceiver(expr ExprStmt) *DispatchCallBuilder {
b.Receiver = &expr
return b
}
func (b *DispatchCallBuilder) WithArgument(name string, value ExprStmt) *DispatchCallBuilder {
b.Arguments = append(b.Arguments, struct {
Name *string `json:"name,omitempty"`
Value ExprStmt `json:"value,omitempty"`
}{
Name: &name,
Value: value,
})
return b
}
func (b *DispatchCallBuilder) WithPositionalArg(value ExprStmt) *DispatchCallBuilder {
b.Arguments = append(b.Arguments, struct {
Name *string `json:"name,omitempty"`
Value ExprStmt `json:"value,omitempty"`
}{
Value: value,
})
return b
}
func (b *DispatchCallBuilder) Build() DispatchCallStmt {
return b.DispatchCallStmt
}