IsPrimitivePointer returns true if the field generated for the given attribute should be a pointer to a primitive type. The receiver attribute must be an object. If useDefault is true and the attribute has a default value then IsPrimitivePointer returns false. This makes it possible to differentiat
(attName string, useDefault bool)
| 475 | // No True True |
| 476 | // No False True |
| 477 | func (a *AttributeExpr) IsPrimitivePointer(attName string, useDefault bool) bool { |
| 478 | o := AsObject(a.Type) |
| 479 | if o == nil { |
| 480 | panic("checking pointer field on non-object") // bug |
| 481 | } |
| 482 | att := o.Attribute(attName) |
| 483 | if att == nil { |
| 484 | return false |
| 485 | } |
| 486 | if !IsPrimitive(att.Type) { |
| 487 | return false |
| 488 | } |
| 489 | t := unalias(att.Type) |
| 490 | return t.Kind() != BytesKind && t.Kind() != AnyKind && |
| 491 | !a.IsRequired(attName) && (!a.HasDefaultValue(attName) || !useDefault) |
| 492 | } |
| 493 | |
| 494 | func unalias(dt DataType) DataType { |
| 495 | if ut, ok := dt.(UserType); ok { |