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

Function visitUnion

pkg/apis/workspaces/v1alpha2/union_implementation.go:24–50  ·  view source on GitHub ↗
(union interface{}, visitor interface{})

Source from the content-addressed store, hash-verified

22)
23
24func visitUnion(union interface{}, visitor interface{}) (err error) {
25 visitorValue := reflect.ValueOf(visitor)
26 unionValue := reflect.ValueOf(union)
27 oneMemberPresent := false
28 typeOfVisitor := visitorValue.Type()
29 for i := 0; i < visitorValue.NumField(); i++ {
30 unionMemberToRead := typeOfVisitor.Field(i).Name
31 unionMember := unionValue.FieldByName(unionMemberToRead)
32 if !unionMember.IsZero() {
33 if oneMemberPresent {
34 err = errors.New("Only one element should be set in union: " + unionValue.Type().Name())
35 return
36 }
37 oneMemberPresent = true
38 visitorFunction := visitorValue.Field(i)
39 if visitorFunction.IsNil() {
40 return
41 }
42 results := visitorFunction.Call([]reflect.Value{unionMember})
43 if !results[0].IsNil() {
44 err = results[0].Interface().(error)
45 }
46 return
47 }
48 }
49 return
50}
51
52func simplifyUnion(union Union, visitorType reflect.Type) {
53 _ = normalizeUnion(union, visitorType)

Callers 15

VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70
VisitMethod · 0.70

Calls 1

NameMethod · 0.80

Tested by

no test coverage detected