-
Notifications
You must be signed in to change notification settings - Fork 2
/
method.go
33 lines (29 loc) · 856 Bytes
/
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
package fake
import (
"fmt"
"go/ast"
"io"
)
func (f *ParsedInterface) WriteMethodParams(implFile io.Writer, params []*ast.Field) {
fmt.Fprintf(implFile, "(")
f.PrintAstFields(implFile, params, true)
fmt.Fprintf(implFile, ")")
}
func (f *ParsedInterface) WriteMethodResults(implFile io.Writer, results []*ast.Field) {
if len(results) == 0 {
return
}
fmt.Fprintf(implFile, " (")
f.PrintAstFields(implFile, results, false)
fmt.Fprintf(implFile, ") ")
}
func (f *ParsedInterface) PrintMethodHeader(file io.Writer, methodName string, field *ParsedField) {
fmt.Fprint(file, methodName)
funcType := field.Ref.Type.(*ast.FuncType)
if fields := funcType.Params; fields != nil {
field.Interface.WriteMethodParams(file, fields.List)
}
if fields := funcType.Results; fields != nil {
field.Interface.WriteMethodResults(file, fields.List)
}
}