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

Method GetMetadata

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

Source from the content-addressed store, hash-verified

2117}
2118
2119func (k *kindAndIDAdorner) GetMetadata(elem any) string {
2120 switch e := elem.(type) {
2121 case ast.Expr:
2122 if macroCall, found := k.sourceInfo.GetMacroCall(e.ID()); found {
2123 return fmt.Sprintf("^#%d:%s#", e.ID(), macroCall.AsCall().FunctionName())
2124 }
2125 var valType string
2126 switch e.Kind() {
2127 case ast.CallKind:
2128 valType = "*expr.Expr_CallExpr"
2129 case ast.ComprehensionKind:
2130 valType = "*expr.Expr_ComprehensionExpr"
2131 case ast.IdentKind:
2132 valType = "*expr.Expr_IdentExpr"
2133 case ast.LiteralKind:
2134 lit := e.AsLiteral()
2135 switch lit.(type) {
2136 case types.Bool:
2137 valType = "*expr.Constant_BoolValue"
2138 case types.Bytes:
2139 valType = "*expr.Constant_BytesValue"
2140 case types.Double:
2141 valType = "*expr.Constant_DoubleValue"
2142 case types.Int:
2143 valType = "*expr.Constant_Int64Value"
2144 case types.Null:
2145 valType = "*expr.Constant_NullValue"
2146 case types.String:
2147 valType = "*expr.Constant_StringValue"
2148 case types.Uint:
2149 valType = "*expr.Constant_Uint64Value"
2150 default:
2151 valType = reflect.TypeOf(lit).String()
2152 }
2153 case ast.ListKind:
2154 valType = "*expr.Expr_ListExpr"
2155 case ast.MapKind, ast.StructKind:
2156 valType = "*expr.Expr_StructExpr"
2157 case ast.SelectKind:
2158 valType = "*expr.Expr_SelectExpr"
2159 }
2160 return fmt.Sprintf("^#%d:%s#", e.ID(), valType)
2161 case ast.EntryExpr:
2162 return fmt.Sprintf("^#%d:%s#", e.ID(), "*expr.Expr_CreateStruct_Entry")
2163 }
2164 return ""
2165}
2166
2167type locationAdorner struct {
2168 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