TaggedAttribute returns the name of the child attribute of a with the given tag if a is an object.
(a *AttributeExpr, tag string)
| 166 | // TaggedAttribute returns the name of the child attribute of a with the given |
| 167 | // tag if a is an object. |
| 168 | func TaggedAttribute(a *AttributeExpr, tag string) string { |
| 169 | obj := AsObject(a.Type) |
| 170 | if obj == nil { |
| 171 | return "" |
| 172 | } |
| 173 | for _, at := range *obj { |
| 174 | if _, ok := at.Attribute.Meta[tag]; ok { |
| 175 | return at.Name |
| 176 | } |
| 177 | } |
| 178 | for _, b := range a.Bases { |
| 179 | at := &AttributeExpr{Type: b} |
| 180 | if ut, ok := b.(UserType); ok { |
| 181 | at = ut.Attribute() |
| 182 | } |
| 183 | if n := TaggedAttribute(at, tag); n != "" { |
| 184 | return n |
| 185 | } |
| 186 | } |
| 187 | return "" |
| 188 | } |
| 189 | |
| 190 | // walkAttribute iterates over the given attribute, its bases and references |
| 191 | // (if any). It calls the given function giving each attribute as it iterates. |