MCPcopy Create free account
hub / github.com/cel-expr/cel-go / AddQualifier

Method AddQualifier

interpreter/attributes.go:499–526  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

497//
498// If none of the attributes within the maybe resolves a value, the result is an error.
499func (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.
529func (a *maybeAttribute) Qualify(vars Activation, obj any) (any, error) {

Callers

nothing calls this directly

Calls 6

ValueMethod · 0.65
QualifiersMethod · 0.65
AddQualifierMethod · 0.65
AbsoluteAttributeMethod · 0.65
IDMethod · 0.65

Tested by

no test coverage detected