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

Method GetMetadata

parser/parser_test.go:2692–2738  ·  view source on GitHub ↗
(elem any)

Source from the content-addressed store, hash-verified

2690}
2691
2692func (k *kindAndIDAdorner) GetMetadata(elem any) string {
2693 switch e := elem.(type) {
2694 case ast.Expr:
2695 if macroCall, found := k.sourceInfo.GetMacroCall(e.ID()); found {
2696 return fmt.Sprintf("^#%d:%s#", e.ID(), macroCall.AsCall().FunctionName())
2697 }
2698 var valType string
2699 switch e.Kind() {
2700 case ast.CallKind:
2701 valType = "*expr.Expr_CallExpr"
2702 case ast.ComprehensionKind:
2703 valType = "*expr.Expr_ComprehensionExpr"
2704 case ast.IdentKind:
2705 valType = "*expr.Expr_IdentExpr"
2706 case ast.LiteralKind:
2707 lit := e.AsLiteral()
2708 switch lit.(type) {
2709 case types.Bool:
2710 valType = "*expr.Constant_BoolValue"
2711 case types.Bytes:
2712 valType = "*expr.Constant_BytesValue"
2713 case types.Double:
2714 valType = "*expr.Constant_DoubleValue"
2715 case types.Int:
2716 valType = "*expr.Constant_Int64Value"
2717 case types.Null:
2718 valType = "*expr.Constant_NullValue"
2719 case types.String:
2720 valType = "*expr.Constant_StringValue"
2721 case types.Uint:
2722 valType = "*expr.Constant_Uint64Value"
2723 default:
2724 valType = reflect.TypeOf(lit).String()
2725 }
2726 case ast.ListKind:
2727 valType = "*expr.Expr_ListExpr"
2728 case ast.MapKind, ast.StructKind:
2729 valType = "*expr.Expr_StructExpr"
2730 case ast.SelectKind:
2731 valType = "*expr.Expr_SelectExpr"
2732 }
2733 return fmt.Sprintf("^#%d:%s#", e.ID(), valType)
2734 case ast.EntryExpr:
2735 return fmt.Sprintf("^#%d:%s#", e.ID(), "*expr.Expr_CreateStruct_Entry")
2736 }
2737 return ""
2738}
2739
2740type locationAdorner struct {
2741 sourceInfo *ast.SourceInfo

Callers

nothing calls this directly

Calls 7

GetMacroCallMethod · 0.80
IDMethod · 0.65
FunctionNameMethod · 0.65
AsCallMethod · 0.65
KindMethod · 0.65
AsLiteralMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected