Debian Codegraph @

model/value_metadata.go

raw symbols SCIP
1 package model
2
3 // MetadataValue returns a metadata value.
4 func (v *Value) MetadataValue(key string) (any, bool) {
5 if v.Metadata == nil {
6 return nil, false
7 }
8 val, ok := v.Metadata[key]
9 return val, ok
10 }
11
12 // SetMetadataValue sets a metadata value.
13 func (v *Value) SetMetadataValue(key string, val any) {
14 if v.Metadata == nil {
15 v.Metadata = map[string]any{}
16 }
17 v.Metadata[key] = val
18 }
19
20 // IsSpread returns true if the value is a spread value.
21 // Spread values are used to represent the spread operator.
22 func (v *Value) IsSpread() bool {
23 if v == nil {
24 return false
25 }
26 val, ok := v.MetadataValue("spread")
27 if !ok {
28 return false
29 }
30 spread, ok := val.(bool)
31 return ok && spread
32 }
33
34 // MarkAsSpread marks the value as a spread value.
35 // Spread values are used to represent the spread operator.
36 func (v *Value) MarkAsSpread() {
37 v.SetMetadataValue("spread", true)
38 }
39
40 // IsBranch returns true if the value is a branched value.
41 func (v *Value) IsBranch() bool {
42 if v == nil {
43 return false
44 }
45 val, ok := v.MetadataValue("branch")
46 if !ok {
47 return false
48 }
49 branch, ok := val.(bool)
50 return ok && branch
51 }
52
53 // MarkAsBranch marks the value as a branch value.
54 func (v *Value) MarkAsBranch() {
55 v.SetMetadataValue("branch", true)
56 }
57
58 // IsIgnore returns true if value should be ignored.
59 func (v *Value) IsIgnore() bool {
60 if v == nil {
61 return false
62 }
63 val, ok := v.MetadataValue("ignore")
64 if !ok {
65 return false
66 }
67 ignore, ok := val.(bool)
68 return ok && ignore
69 }
70
71 // MarkAsIgnore marks the value to be ignored.
72 func (v *Value) MarkAsIgnore() {
73 v.SetMetadataValue("ignore", true)
74 }