Merge merges other's attributes into a overriding attributes of a with attributes of other with identical names. This only applies to attributes of type Object and Merge panics if the argument or the target is not of type Object.
(other *AttributeExpr)
| 389 | // This only applies to attributes of type Object and Merge panics if the |
| 390 | // argument or the target is not of type Object. |
| 391 | func (a *AttributeExpr) Merge(other *AttributeExpr) { |
| 392 | if other == nil { |
| 393 | return |
| 394 | } |
| 395 | left := AsObject(a.Type) |
| 396 | right := AsObject(other.Type) |
| 397 | if left == nil || right == nil { |
| 398 | panic("cannot merge non object attributes") // bug |
| 399 | } |
| 400 | if a.Type == Empty && len(*right) > 0 { |
| 401 | a.Type = &Object{} |
| 402 | left = AsObject(a.Type) |
| 403 | } |
| 404 | if other.Validation != nil { |
| 405 | if a.Validation == nil { |
| 406 | a.Validation = other.Validation.Dup() |
| 407 | } else { |
| 408 | a.Validation.Merge(other.Validation) |
| 409 | } |
| 410 | } |
| 411 | for _, nat := range *right { |
| 412 | left.Set(nat.Name, nat.Attribute) |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // Inherit merges the properties of existing target type attributes with the |
| 417 | // argument's. The algorithm is recursive so that child attributes are also |