NewMappedAttributeExpr instantiates a mapped attribute expression for the given attribute. The type of att must be Object.
(att *AttributeExpr)
| 31 | // NewMappedAttributeExpr instantiates a mapped attribute expression for the |
| 32 | // given attribute. The type of att must be Object. |
| 33 | func NewMappedAttributeExpr(att *AttributeExpr) *MappedAttributeExpr { |
| 34 | if att == nil { |
| 35 | return NewEmptyMappedAttributeExpr() |
| 36 | } |
| 37 | if !IsObject(att.Type) { |
| 38 | panic("cannot create a mapped attribute with a non object attribute") // bug |
| 39 | } |
| 40 | var ( |
| 41 | nameMap = make(map[string]string) |
| 42 | reverseMap = make(map[string]string) |
| 43 | validation *ValidationExpr |
| 44 | ) |
| 45 | if att.Validation != nil { |
| 46 | validation = att.Validation.Dup() |
| 47 | } else if ut, ok := att.Type.(UserType); ok { |
| 48 | if val := ut.Attribute().Validation; val != nil { |
| 49 | validation = val.Dup() |
| 50 | } |
| 51 | } |
| 52 | attr := DupAtt(att) |
| 53 | attr.Validation = validation |
| 54 | ma := &MappedAttributeExpr{ |
| 55 | AttributeExpr: attr, |
| 56 | nameMap: nameMap, |
| 57 | reverseMap: reverseMap, |
| 58 | } |
| 59 | ma.Remap() |
| 60 | return ma |
| 61 | } |
| 62 | |
| 63 | // Remap recomputes the name mappings from the inner attribute. Use this if |
| 64 | // the underlying attribute is modified after the mapped attribute has been |
no test coverage detected