buildProjectedType builds projected type for the given user type. viewspkg is the name of the views package
(projected, att *expr.AttributeExpr, viewspkg string, scope, viewScope *codegen.NameScope)
| 1924 | // |
| 1925 | // viewspkg is the name of the views package |
| 1926 | func buildProjectedType(projected, att *expr.AttributeExpr, viewspkg string, scope, viewScope *codegen.NameScope) *ProjectedTypeData { |
| 1927 | var ( |
| 1928 | projections []*InitData |
| 1929 | typeInits []*InitData |
| 1930 | views []*ViewData |
| 1931 | |
| 1932 | varname = viewScope.GoTypeName(projected) |
| 1933 | pt = projected.Type.(expr.UserType) |
| 1934 | ) |
| 1935 | if _, isrt := pt.(*expr.ResultTypeExpr); isrt { |
| 1936 | typeInits = buildTypeInits(projected, att, viewspkg, scope, viewScope) |
| 1937 | projections = buildProjections(projected, att, viewspkg, scope, viewScope) |
| 1938 | views = buildViews(att.Type.(*expr.ResultTypeExpr), viewScope) |
| 1939 | } |
| 1940 | validations := buildValidations(projected, viewScope) |
| 1941 | removeMeta(projected) |
| 1942 | return &ProjectedTypeData{ |
| 1943 | UserTypeData: &UserTypeData{ |
| 1944 | Name: varname, |
| 1945 | Description: fmt.Sprintf("%s is a type that runs validations on a projected type.", varname), |
| 1946 | VarName: varname, |
| 1947 | Def: viewScope.GoTypeDef(pt.Attribute(), true, true), |
| 1948 | Ref: viewScope.GoTypeRef(projected), |
| 1949 | Type: pt, |
| 1950 | }, |
| 1951 | Projections: projections, |
| 1952 | TypeInits: typeInits, |
| 1953 | Validations: validations, |
| 1954 | ViewsPkg: viewspkg, |
| 1955 | Views: views, |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | // buildViews builds the view data for all the views in the given result type. |
| 1960 | func buildViews(rt *expr.ResultTypeExpr, viewScope *codegen.NameScope) []*ViewData { |
no test coverage detected