MCPcopy Create free account
hub / github.com/goadesign/goa / collectTypes

Function collectTypes

codegen/service/service_data.go:1021–1063  ·  view source on GitHub ↗

collectTypes recurses through the attribute to gather all user types and records them in userTypes.

(at *expr.AttributeExpr, scope *codegen.NameScope, seen map[string]struct{}, loc *codegen.Location)

Source from the content-addressed store, hash-verified

1019// collectTypes recurses through the attribute to gather all user types and
1020// records them in userTypes.
1021func collectTypes(at *expr.AttributeExpr, scope *codegen.NameScope, seen map[string]struct{}, loc *codegen.Location) (data []*UserTypeData) {
1022 if at == nil || at.Type == expr.Empty {
1023 return data
1024 }
1025 collect := func(at *expr.AttributeExpr, loc *codegen.Location) []*UserTypeData {
1026 return collectTypes(at, scope, seen, loc)
1027 }
1028 switch dt := at.Type.(type) {
1029 case expr.UserType:
1030 if _, ok := seen[dt.ID()]; ok {
1031 return nil
1032 }
1033 typeLoc := codegen.UserTypeLocation(dt)
1034 if typeLoc == nil {
1035 typeLoc = loc
1036 }
1037 data = append(data, &UserTypeData{
1038 Name: dt.Name(),
1039 VarName: scope.GoTypeName(at),
1040 Description: dt.Attribute().Description,
1041 Def: scope.GoTypeDef(dt.Attribute(), false, true),
1042 Ref: scope.GoTypeRef(at),
1043 Loc: typeLoc,
1044 Type: dt,
1045 })
1046 seen[dt.ID()] = struct{}{}
1047 data = append(data, collect(dt.Attribute(), typeLoc)...)
1048 case *expr.Object:
1049 for _, nat := range *dt {
1050 data = append(data, collect(nat.Attribute, loc)...)
1051 }
1052 case *expr.Array:
1053 data = append(data, collect(dt.ElemType, loc)...)
1054 case *expr.Map:
1055 data = append(data, collect(dt.KeyType, loc)...)
1056 data = append(data, collect(dt.ElemType, loc)...)
1057 case *expr.Union:
1058 for _, nat := range dt.Values {
1059 data = append(data, collect(nat.Attribute, loc)...)
1060 }
1061 }
1062 return data
1063}
1064
1065// collectUnionTypes traverses the attribute to gather all union sum-type
1066// definitions referenced by the service. It records each union by its hash to

Callers 1

analyzeMethod · 0.85

Calls 7

UserTypeLocationFunction · 0.92
GoTypeNameMethod · 0.80
GoTypeDefMethod · 0.80
GoTypeRefMethod · 0.80
IDMethod · 0.65
NameMethod · 0.65
AttributeMethod · 0.65

Tested by

no test coverage detected