AddQualifier adds a qualifier to each possible attribute variant, and also creates a new namespaced variable from the qualified value. The algorithm for building the maybe attribute is as follows: 1. Create a maybe attribute from a simple identifier when it occurs in a parsed-only expression mb
(qual Qualifier)
| 497 | // |
| 498 | // If none of the attributes within the maybe resolves a value, the result is an error. |
| 499 | func (a *maybeAttribute) AddQualifier(qual Qualifier) (Attribute, error) { |
| 500 | str := "" |
| 501 | isStr := false |
| 502 | cq, isConst := qual.(ConstantQualifier) |
| 503 | if isConst { |
| 504 | str, isStr = cq.Value().Value().(string) |
| 505 | } |
| 506 | var augmentedNames []string |
| 507 | // First add the qualifier to all existing attributes in the oneof. |
| 508 | for _, attr := range a.attrs { |
| 509 | if isStr && len(attr.Qualifiers()) == 0 { |
| 510 | candidateVars := attr.CandidateVariableNames() |
| 511 | augmentedNames = make([]string, len(candidateVars)) |
| 512 | for i, name := range candidateVars { |
| 513 | augmentedNames[i] = fmt.Sprintf("%s.%s", name, str) |
| 514 | } |
| 515 | } |
| 516 | _, err := attr.AddQualifier(qual) |
| 517 | if err != nil { |
| 518 | return nil, err |
| 519 | } |
| 520 | } |
| 521 | // Next, ensure the most specific variable / type reference is searched first. |
| 522 | if len(augmentedNames) != 0 { |
| 523 | a.attrs = append([]NamespacedAttribute{a.fac.AbsoluteAttribute(qual.ID(), augmentedNames...)}, a.attrs...) |
| 524 | } |
| 525 | return a, nil |
| 526 | } |
| 527 | |
| 528 | // Qualify is an implementation of the Qualifier interface method. |
| 529 | func (a *maybeAttribute) Qualify(vars Activation, obj any) (any, error) { |
nothing calls this directly
no test coverage detected