-
Notifications
You must be signed in to change notification settings - Fork 0
/
declarations.go
61 lines (51 loc) · 1.16 KB
/
declarations.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
package gopkg
import (
"reflect"
)
type DeclFunc struct {
Name string
Import string
Receiver FuncReceiver
Args []DeclVar
VariadicLastArg bool
ReturnArgs []DeclVar
BodyTmpl string
BodyData any
DocString string
}
type FuncReceiver struct {
VarName string
TypeName string
IsPointer bool
}
type DeclType struct {
Name string
Import string
Type Type
DocString string
}
type DeclVar struct {
Type
Name string
Import string
// LiteralValue is the value of the literal assigned to this variable declaration
// (if one was assigned - otherwise it will be empty)
//
// e.g. for `var MyVar int = 123`, LiteralValue will be `123`
LiteralValue string
// StructTag holds the tags for a struct field if this DeclVar represents a
// field within a struct.
// If this DeclVar is not within a struct then it is not used.
StructTag reflect.StructTag
DocString string
}
func (d DeclFunc) RequiredImports() map[string]bool {
ret := make(map[string]bool)
for _, arg := range d.Args {
ret = union(ret, arg.RequiredImports())
}
for _, retArg := range d.ReturnArgs {
ret = union(ret, retArg.RequiredImports())
}
return ret
}