Debian Codegraph @

examples/defaulter-gen/output_tests/marker/zz_generated.go

raw
1 //go:build !ignore_autogenerated
2 // +build !ignore_autogenerated
3
4 /*
5 Copyright The Kubernetes Authors.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 */
19
20 // Code generated by defaulter-gen. DO NOT EDIT.
21
22 package marker
23
24 import (
25 "encoding/json"
26
27 runtime "k8s.io/apimachinery/pkg/runtime"
28 external "k8s.io/gengo/examples/defaulter-gen/output_tests/marker/external"
29 externalexternal "k8s.io/gengo/examples/defaulter-gen/output_tests/marker/external/external"
30 external2 "k8s.io/gengo/examples/defaulter-gen/output_tests/marker/external2"
31 )
32
33 // RegisterDefaults adds defaulters functions to the given scheme.
34 // Public to allow building arbitrary schemes.
35 // All generated defaulters are covering - they call all nested defaulters.
36 func RegisterDefaults(scheme *runtime.Scheme) error {
37 scheme.AddTypeDefaultingFunc(&Defaulted{}, func(obj interface{}) { SetObjectDefaults_Defaulted(obj.(*Defaulted)) })
38 scheme.AddTypeDefaultingFunc(&DefaultedOmitempty{}, func(obj interface{}) { SetObjectDefaults_DefaultedOmitempty(obj.(*DefaultedOmitempty)) })
39 scheme.AddTypeDefaultingFunc(&DefaultedWithFunction{}, func(obj interface{}) { SetObjectDefaults_DefaultedWithFunction(obj.(*DefaultedWithFunction)) })
40 scheme.AddTypeDefaultingFunc(&DefaultedWithReference{}, func(obj interface{}) { SetObjectDefaults_DefaultedWithReference(obj.(*DefaultedWithReference)) })
41 return nil
42 }
43
44 func SetObjectDefaults_Defaulted(in *Defaulted) {
45 if in.StringDefault == "" {
46 in.StringDefault = "bar"
47 }
48 if in.StringPointer == nil {
49 var ptrVar1 string = "default"
50 in.StringPointer = &ptrVar1
51 }
52 if in.Int64 == nil {
53 var ptrVar1 int64 = 64
54 in.Int64 = &ptrVar1
55 }
56 if in.Int32 == nil {
57 var ptrVar1 int32 = 32
58 in.Int32 = &ptrVar1
59 }
60 if in.IntDefault == 0 {
61 in.IntDefault = 1
62 }
63 if in.FloatDefault == 0 {
64 in.FloatDefault = 0.5
65 }
66 if in.List == nil {
67 if err := json.Unmarshal([]byte(`["foo", "bar"]`), &in.List); err != nil {
68 panic(err)
69 }
70 }
71 for i := range in.List {
72 if in.List[i] == nil {
73 var ptrVar1 string = "apple"
74 in.List[i] = &ptrVar1
75 }
76 }
77 if in.Sub == nil {
78 if err := json.Unmarshal([]byte(`{"s": "foo", "i": 5}`), &in.Sub); err != nil {
79 panic(err)
80 }
81 }
82 if in.Sub != nil {
83 if in.Sub.I == 0 {
84 in.Sub.I = 1
85 }
86 }
87 if in.StructList == nil {
88 if err := json.Unmarshal([]byte(`[{"s": "foo1", "i": 1}, {"s": "foo2"}]`), &in.StructList); err != nil {
89 panic(err)
90 }
91 }
92 for i := range in.StructList {
93 a := &in.StructList[i]
94 if a.I == 0 {
95 a.I = 1
96 }
97 }
98 if in.PtrStructList == nil {
99 if err := json.Unmarshal([]byte(`[{"s": "foo1", "i": 1}, {"s": "foo2"}]`), &in.PtrStructList); err != nil {
100 panic(err)
101 }
102 }
103 for i := range in.PtrStructList {
104 a := in.PtrStructList[i]
105 if a != nil {
106 if a.I == 0 {
107 a.I = 1
108 }
109 }
110 }
111 if in.StringList == nil {
112 if err := json.Unmarshal([]byte(`["foo"]`), &in.StringList); err != nil {
113 panic(err)
114 }
115 }
116 if in.OtherSub.I == 0 {
117 in.OtherSub.I = 1
118 }
119 if in.Map == nil {
120 if err := json.Unmarshal([]byte(`{"foo": "bar"}`), &in.Map); err != nil {
121 panic(err)
122 }
123 }
124 for i_Map := range in.Map {
125 if in.Map[i_Map] == nil {
126 var ptrVar1 string = "apple"
127 in.Map[i_Map] = &ptrVar1
128 }
129 }
130 if in.StructMap == nil {
131 if err := json.Unmarshal([]byte(`{"foo": {"S": "string", "I": 1}}`), &in.StructMap); err != nil {
132 panic(err)
133 }
134 }
135 if in.PtrStructMap == nil {
136 if err := json.Unmarshal([]byte(`{"foo": {"S": "string", "I": 1}}`), &in.PtrStructMap); err != nil {
137 panic(err)
138 }
139 }
140 if in.AliasPtr == nil {
141 var ptrVar1 string = "banana"
142 in.AliasPtr = &ptrVar1
143 }
144 }
145
146 func SetObjectDefaults_DefaultedOmitempty(in *DefaultedOmitempty) {
147 if in.StringDefault == "" {
148 in.StringDefault = "bar"
149 }
150 if in.StringPointer == nil {
151 var ptrVar1 string = "default"
152 in.StringPointer = &ptrVar1
153 }
154 if in.Int64 == nil {
155 var ptrVar1 int64 = 64
156 in.Int64 = &ptrVar1
157 }
158 if in.Int32 == nil {
159 var ptrVar1 int32 = 32
160 in.Int32 = &ptrVar1
161 }
162 if in.IntDefault == 0 {
163 in.IntDefault = 1
164 }
165 if in.FloatDefault == 0 {
166 in.FloatDefault = 0.5
167 }
168 if in.List == nil {
169 if err := json.Unmarshal([]byte(`["foo", "bar"]`), &in.List); err != nil {
170 panic(err)
171 }
172 }
173 for i := range in.List {
174 if in.List[i] == nil {
175 var ptrVar1 string = "apple"
176 in.List[i] = &ptrVar1
177 }
178 }
179 if in.Sub == nil {
180 if err := json.Unmarshal([]byte(`{"s": "foo", "i": 5}`), &in.Sub); err != nil {
181 panic(err)
182 }
183 }
184 if in.Sub != nil {
185 if in.Sub.I == 0 {
186 in.Sub.I = 1
187 }
188 }
189 if in.StructList == nil {
190 if err := json.Unmarshal([]byte(`[{"s": "foo1", "i": 1}, {"s": "foo2"}]`), &in.StructList); err != nil {
191 panic(err)
192 }
193 }
194 for i := range in.StructList {
195 a := &in.StructList[i]
196 if a.I == 0 {
197 a.I = 1
198 }
199 }
200 if in.PtrStructList == nil {
201 if err := json.Unmarshal([]byte(`[{"s": "foo1", "i": 1}, {"s": "foo2"}]`), &in.PtrStructList); err != nil {
202 panic(err)
203 }
204 }
205 for i := range in.PtrStructList {
206 a := in.PtrStructList[i]
207 if a != nil {
208 if a.I == 0 {
209 a.I = 1
210 }
211 }
212 }
213 if in.StringList == nil {
214 if err := json.Unmarshal([]byte(`["foo"]`), &in.StringList); err != nil {
215 panic(err)
216 }
217 }
218 if in.OtherSub.I == 0 {
219 in.OtherSub.I = 1
220 }
221 if in.Map == nil {
222 if err := json.Unmarshal([]byte(`{"foo": "bar"}`), &in.Map); err != nil {
223 panic(err)
224 }
225 }
226 for i_Map := range in.Map {
227 if in.Map[i_Map] == nil {
228 var ptrVar1 string = "apple"
229 in.Map[i_Map] = &ptrVar1
230 }
231 }
232 if in.StructMap == nil {
233 if err := json.Unmarshal([]byte(`{"foo": {"S": "string", "I": 1}}`), &in.StructMap); err != nil {
234 panic(err)
235 }
236 }
237 if in.PtrStructMap == nil {
238 if err := json.Unmarshal([]byte(`{"foo": {"S": "string", "I": 1}}`), &in.PtrStructMap); err != nil {
239 panic(err)
240 }
241 }
242 if in.AliasPtr == nil {
243 var ptrVar1 string = "banana"
244 in.AliasPtr = &ptrVar1
245 }
246 }
247
248 func SetObjectDefaults_DefaultedWithFunction(in *DefaultedWithFunction) {
249 SetDefaults_DefaultedWithFunction(in)
250 if in.S1 == "" {
251 in.S1 = "default_marker"
252 }
253 if in.S2 == "" {
254 in.S2 = "default_marker"
255 }
256 }
257
258 func SetObjectDefaults_DefaultedWithReference(in *DefaultedWithReference) {
259 if in.AliasConvertDefaultPointer == nil {
260 ptrVar1 := DefaultedValueItem(SomeValue)
261 in.AliasConvertDefaultPointer = &ptrVar1
262 }
263 if in.PointerAliasDefault == nil {
264 var ptrVar1 string = "apple"
265 in.PointerAliasDefault = &ptrVar1
266 }
267 if in.AliasPointerInside == nil {
268 ptrVar1 := string(SomeDefault)
269 in.AliasPointerInside = &ptrVar1
270 }
271 if in.AliasOverride == nil {
272 ptrVar1 := string(SomeDefault)
273 in.AliasOverride = &ptrVar1
274 }
275 if in.AliasPointerDefault == nil {
276 ptrVar1 := DefaultedValueItem(SomeValue)
277 in.AliasPointerDefault = &ptrVar1
278 }
279 if in.AliasNonPointer == "" {
280 in.AliasNonPointer = ValueItem(SomeValue)
281 }
282 if in.AliasPointer == nil {
283 ptrVar1 := ValueItem(SomeValue)
284 in.AliasPointer = &ptrVar1
285 }
286 if in.SymbolReference == "" {
287 in.SymbolReference = string(SomeDefault)
288 }
289 if in.SameNamePackageSymbolReference1 == "" {
290 in.SameNamePackageSymbolReference1 = string(external.AConstant)
291 }
292 if in.SameNamePackageSymbolReference2 == "" {
293 in.SameNamePackageSymbolReference2 = string(externalexternal.AnotherConstant)
294 }
295 if in.PointerConversion == nil {
296 ptrVar9 := string(SomeValue)
297 ptrVar8 := &ptrVar9
298 ptrVar7 := (*B1)(&ptrVar8)
299 ptrVar6 := (*B2)(&ptrVar7)
300 ptrVar5 := &ptrVar6
301 ptrVar4 := &ptrVar5
302 ptrVar3 := &ptrVar4
303 ptrVar2 := (*B3)(&ptrVar3)
304 ptrVar1 := &ptrVar2
305 in.PointerConversion = (*B4)(&ptrVar1)
306 }
307 if in.PointerConversionValue == nil {
308 ptrVar8 := string(SomeValue)
309 ptrVar7 := &ptrVar8
310 ptrVar6 := (*B1)(&ptrVar7)
311 ptrVar5 := (*B2)(&ptrVar6)
312 ptrVar4 := &ptrVar5
313 ptrVar3 := &ptrVar4
314 ptrVar2 := &ptrVar3
315 ptrVar1 := (*B3)(&ptrVar2)
316 in.PointerConversionValue = &ptrVar1
317 }
318 if in.FullyQualifiedLocalSymbol == "" {
319 in.FullyQualifiedLocalSymbol = string(SomeValue)
320 }
321 if in.ImportFromAliasCast == nil {
322 ptrVar1 := external2.String(SomeValue)
323 in.ImportFromAliasCast = &ptrVar1
324 }
325 }