MCPcopy Create free account
hub / github.com/google/go-github / genSelectorExprGetter

Method genSelectorExprGetter

github/gen-accessors.go:417–445  ·  view source on GitHub ↗
(x *ast.SelectorExpr, receiverType, fieldName string)

Source from the content-addressed store, hash-verified

415}
416
417func (t *templateData) genSelectorExprGetter(x *ast.SelectorExpr, receiverType, fieldName string) *getter {
418 if strings.ToLower(fieldName[:1]) == fieldName[:1] { // Non-exported field.
419 return nil
420 }
421
422 var xX string
423 if xx, ok := x.X.(*ast.Ident); ok {
424 xX = xx.String()
425 }
426
427 switch xX {
428 case "time", "json":
429 if xX == "json" {
430 t.Imports["encoding/json"] = "encoding/json"
431 } else {
432 t.Imports[xX] = xX
433 }
434 fieldType := fmt.Sprintf("%v.%v", xX, x.Sel.Name)
435 zeroValue := fmt.Sprintf("%v.%v{}", xX, x.Sel.Name)
436 if xX == "time" && x.Sel.Name == "Duration" {
437 zeroValue = "0"
438 }
439 return newGetter(receiverType, fieldName, fieldType, zeroValue, false)
440 default:
441 logf("addSelectorExpr: xX %q, type %q, field %q: unknown x=%+v; skipping.", xX, receiverType, fieldName, x)
442 }
443
444 return nil
445}
446
447type templateData struct {
448 filename string

Callers 2

addSelectorExprMethod · 0.95

Calls 3

newGetterFunction · 0.85
logfFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected