/
struct.go
96 lines (78 loc) · 1.85 KB
/
struct.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
// Copyright 2017-2021 the LinuxBoot Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package analyze
import (
"fmt"
"github.com/xaionaro-go/gosrc"
)
type Struct struct {
gosrc.Struct
Parent *File
Fields []*Field
}
func (_struct Struct) ElementStructInfoField() *Field {
for _, field := range _struct.Fields {
if field.isElementStructInfo() {
return field
}
}
return nil
}
func (_struct Struct) ElementStructVersion() string {
field := _struct.ElementStructInfoField()
if field == nil {
return ""
}
id, _ := field.TagGet("version")
return id
}
func (_struct Struct) ElementStructID() string {
field := _struct.ElementStructInfoField()
if field == nil {
return ""
}
id, _ := field.TagGet("id")
return id
}
func (_struct Struct) IsElementsContainer() bool {
for _, field := range _struct.Fields {
if field.IsElement() {
return true
}
}
return false
}
func (_struct Struct) PrettyString() (string, error) {
result, err := getPrettyString(_struct.TypeSpec.Name, _struct.TypeSpec.Doc, _struct.TypeSpec.Comment, "PrettyString:")
if err != nil {
err = fmt.Errorf("unable to get PrettyString for '%s'", _struct.TypeSpec.Name.Name)
}
return result, err
}
func (_struct Struct) Methods() Funcs {
var result Funcs
for _, method := range _struct.AstTypeSpec.Methods() {
result = append(result, &Func{Func: *method})
}
return result
}
func (_struct Struct) HasOnRehash() bool {
return _struct.MethodByName("onRehash") != nil
}
func (_struct Struct) ElementStructInfoVar0() string {
f := _struct.ElementStructInfoField()
if f == nil {
return ""
}
r, _ := f.TagGet("var0")
return r
}
func (_struct Struct) ElementStructInfoVar1() string {
f := _struct.ElementStructInfoField()
if f == nil {
return ""
}
r, _ := f.TagGet("var1")
return r
}