forked from percolate/charlatan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethod.go
113 lines (99 loc) · 2.83 KB
/
method.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
package main
import "strings"
// Method represents a method in an interface's method set
type Method struct {
Interface string
Name string
Parameters []*Identifier
Results []*Identifier
parametersDeclaration string
resultsDeclaration string
parametersCall string
resultsCall string
parametersSignature string
resultsSignature string
}
// ParametersDeclaration returns the formal declaration syntax for the method's parameters
func (m *Method) ParametersDeclaration() string {
if len(m.Parameters) == 0 {
return ""
}
if m.parametersDeclaration == "" {
idents := make([]string, len(m.Parameters))
for i, ident := range m.Parameters {
idents[i] = ident.ParameterFormat()
}
m.parametersDeclaration = strings.Join(idents, ", ")
}
return m.parametersDeclaration
}
// ResultsDeclaration returns the formal declaration syntax for the method's results
func (m *Method) ResultsDeclaration() string {
if len(m.Results) == 0 {
return ""
}
if m.resultsDeclaration == "" {
idents := make([]string, len(m.Results))
for i, ident := range m.Results {
idents[i] = ident.ParameterFormat()
}
m.resultsDeclaration = strings.Join(idents, ", ")
}
return m.resultsDeclaration
}
// ParametersReference returns the sytax to reference the method's parameters
func (m *Method) ParametersReference() string {
if len(m.Parameters) == 0 {
return ""
}
if m.parametersCall == "" {
idents := make([]string, len(m.Parameters))
for i, ident := range m.Parameters {
idents[i] = ident.ReferenceFormat()
}
m.parametersCall = strings.Join(idents, ", ")
}
return m.parametersCall
}
// ResultsReference returns the syntax to reference the method's results
func (m *Method) ResultsReference() string {
if len(m.Results) == 0 {
return ""
}
if m.resultsCall == "" {
idents := make([]string, len(m.Results))
for i, ident := range m.Results {
idents[i] = ident.ReferenceFormat()
}
m.resultsCall = strings.Join(idents, ", ")
}
return m.resultsCall
}
// ParametersSignature returns the type declaration syntax for the methods parameters
func (m *Method) ParametersSignature() string {
if len(m.Parameters) == 0 {
return ""
}
if m.parametersSignature == "" {
idents := make([]string, len(m.Parameters))
for i, ident := range m.Parameters {
idents[i] = ident.Signature()
}
m.parametersSignature = strings.Join(idents, ", ")
}
return m.parametersSignature
}
// ResultsSignature returns the type declaration syntax for the methods results
func (m *Method) ResultsSignature() string {
if len(m.Results) == 0 {
return ""
}
if m.resultsSignature == "" {
idents := make([]string, len(m.Results))
for i, ident := range m.Results {
idents[i] = ident.Signature()
}
m.resultsSignature = strings.Join(idents, ", ")
}
return m.resultsSignature
}