Find finds a child attribute with the given name in the attribute and its bases and references. If the parent attribute is not an object, it returns nil.
(name string)
| 586 | // its bases and references. If the parent attribute is not an object, it |
| 587 | // returns nil. |
| 588 | func (a *AttributeExpr) Find(name string) *AttributeExpr { |
| 589 | findAttrFn := func(typ DataType) *AttributeExpr { |
| 590 | switch t := typ.(type) { |
| 591 | case UserType: |
| 592 | return t.Attribute().Find(name) |
| 593 | case *Object: |
| 594 | if att := t.Attribute(name); att != nil { |
| 595 | return att |
| 596 | } |
| 597 | } |
| 598 | return nil |
| 599 | } |
| 600 | |
| 601 | if att := findAttrFn(a.Type); att != nil { |
| 602 | return att |
| 603 | } |
| 604 | for _, b := range a.Bases { |
| 605 | if att := findAttrFn(b); att != nil { |
| 606 | return att |
| 607 | } |
| 608 | } |
| 609 | for _, ref := range a.References { |
| 610 | if att := findAttrFn(ref); att != nil { |
| 611 | return att |
| 612 | } |
| 613 | } |
| 614 | return nil |
| 615 | } |
| 616 | |
| 617 | // Delete removes an attribute with the given name. It does nothing if the |
| 618 | // attribute expression is not an object type. |