MCPcopy Create free account
hub / github.com/devfile/api / cleanupValues

Function cleanupValues

pkg/apis/workspaces/v1alpha2/union_implementation.go:97–119  ·  view source on GitHub ↗
(union Union, visitorType reflect.Type)

Source from the content-addressed store, hash-verified

95}
96
97func cleanupValues(union Union, visitorType reflect.Type) error {
98 unionValue := reflect.ValueOf(union)
99
100 if union.discriminator() == nil {
101 return errors.New("Discriminator should not be 'nil' in union: " + unionValue.Type().Name())
102 }
103
104 if *union.discriminator() == "" {
105 // Nothing to do
106 return errors.New("Values cannot be cleaned up without a discriminator in union: " + unionValue.Type().Name())
107 }
108
109 for i := 0; i < visitorType.NumField(); i++ {
110 unionMemberToRead := visitorType.Field(i).Name
111 unionMember := unionValue.Elem().FieldByName(unionMemberToRead)
112 if !unionMember.IsZero() {
113 if unionMemberToRead != *union.discriminator() {
114 unionMember.Set(reflect.Zero(unionMember.Type()))
115 }
116 }
117 }
118 return nil
119}

Callers 1

normalizeUnionFunction · 0.70

Calls 2

NameMethod · 0.80
discriminatorMethod · 0.65

Tested by

no test coverage detected