transformAttribute returns the code to transform source attribute to target attribute. It returns an error if source and target are not compatible for transformation.
(source, target *expr.AttributeExpr, sourceVar, targetVar string, newVar bool, ta *TransformAttrs)
| 77 | // attribute. It returns an error if source and target are not compatible for |
| 78 | // transformation. |
| 79 | func transformAttribute(source, target *expr.AttributeExpr, sourceVar, targetVar string, newVar bool, ta *TransformAttrs) (code string, err error) { |
| 80 | if err = IsCompatible(source.Type, target.Type, sourceVar, targetVar); err != nil { |
| 81 | return |
| 82 | } |
| 83 | switch { |
| 84 | case expr.IsArray(source.Type): |
| 85 | code, err = transformArray(expr.AsArray(source.Type), expr.AsArray(target.Type), sourceVar, targetVar, newVar, ta) |
| 86 | case expr.IsMap(source.Type): |
| 87 | code, err = transformMap(expr.AsMap(source.Type), expr.AsMap(target.Type), sourceVar, targetVar, newVar, ta) |
| 88 | case expr.IsUnion(source.Type): |
| 89 | code, err = transformUnion(source, target, sourceVar, targetVar, newVar, ta) |
| 90 | case expr.IsObject(source.Type): |
| 91 | code, err = transformObject(source, target, sourceVar, targetVar, newVar, ta) |
| 92 | default: |
| 93 | code, err = transformPrimitive(source, target, sourceVar, targetVar, newVar, ta) |
| 94 | } |
| 95 | return |
| 96 | } |
| 97 | |
| 98 | // transformPrimitive returns the code to transform source primtive type to |
| 99 | // target primitive type. It returns an error if source and target are not |
no test coverage detected