-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstract.go
More file actions
49 lines (39 loc) · 957 Bytes
/
abstract.go
File metadata and controls
49 lines (39 loc) · 957 Bytes
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
package golang
import (
"fmt"
"go/ast"
"github.com/code-visible/golang/parsedtypes"
"github.com/code-visible/golang/utils"
)
type Abstract struct {
ID string `json:"id"`
Pos string `json:"pos"`
Name string `json:"name"`
File string `json:"file"`
Comment string `json:"comment"`
Fields []string `json:"fields"`
ident *ast.Ident
fields parsedtypes.Fields
file *File
}
func NewAbstract(ident *ast.Ident, strtTyp *ast.StructType, file *File) *Abstract {
a := &Abstract{
Name: ident.Name,
ident: ident,
fields: make(parsedtypes.Fields, 0, len(strtTyp.Fields.List)),
file: file,
}
for _, field := range strtTyp.Fields.List {
a.fields.Parse(field)
}
return a
}
func (a *Abstract) SetupID() {
a.ID = utils.Hash(a.LookupName())
}
func (a *Abstract) LookupName() string {
return fmt.Sprintf("%s:%s", a.file.LookupName(), a.Name)
}
func (a *Abstract) Complete() {
a.Fields = a.fields.List()
}