isSupportedFieldType checks if a field type is supported
(t types.Type)
| 86 | |
| 87 | // isSupportedFieldType checks if a field type is supported |
| 88 | func isSupportedFieldType(t types.Type) bool { |
| 89 | // Unwrap alias types (e.g., 'any' is an alias for 'interface{}') |
| 90 | t = types.Unalias(t) |
| 91 | if elem, ok := getOptionalElementType(t); ok { |
| 92 | t = elem |
| 93 | } |
| 94 | |
| 95 | // Handle pointer types |
| 96 | if ptr, ok := t.(*types.Pointer); ok { |
| 97 | t = ptr.Elem() |
| 98 | } |
| 99 | |
| 100 | // Check slice types |
| 101 | if slice, ok := t.(*types.Slice); ok { |
| 102 | // Check if element type is supported |
| 103 | return isSupportedFieldType(slice.Elem()) |
| 104 | } |
| 105 | |
| 106 | // Check map types |
| 107 | if mapType, ok := t.(*types.Map); ok { |
| 108 | // Check if both key and value types are supported |
| 109 | return isSupportedFieldType(mapType.Key()) && isSupportedFieldType(mapType.Elem()) |
| 110 | } |
| 111 | |
| 112 | // Check named types |
| 113 | if named, ok := t.(*types.Named); ok { |
| 114 | typeStr := named.String() |
| 115 | switch typeStr { |
| 116 | case "time.Time", "github.com/apache/fory/go/fory.Date": |
| 117 | return true |
| 118 | } |
| 119 | // Check if it's another struct |
| 120 | if _, ok := named.Underlying().(*types.Struct); ok { |
| 121 | return true |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // Check interface types |
| 126 | if iface, ok := t.(*types.Interface); ok { |
| 127 | // Support empty any for dynamic types |
| 128 | if iface.Empty() { |
| 129 | return true |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | // Check basic types |
| 134 | if basic, ok := t.Underlying().(*types.Basic); ok { |
| 135 | switch basic.Kind() { |
| 136 | case types.Bool, types.Int8, types.Int16, types.Int32, types.Int, types.Int64, |
| 137 | types.Uint8, types.Uint16, types.Uint32, types.Uint, types.Uint64, |
| 138 | types.Float32, types.Float64, types.String: |
| 139 | return true |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return false |
| 144 | } |
| 145 |
no test coverage detected