@ -230,7 +230,7 @@ func genView(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named, thi
writeTemplate ( "sliceField" )
writeTemplate ( "sliceField" )
}
}
continue
continue
case * types . Struct , * types . Named :
case * types . Struct :
strucT := underlying
strucT := underlying
args . FieldType = it . QualifiedName ( fieldType )
args . FieldType = it . QualifiedName ( fieldType )
if codegen . ContainsPointers ( strucT ) {
if codegen . ContainsPointers ( strucT ) {
@ -262,7 +262,7 @@ func genView(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named, thi
mElem := m . Elem ( )
mElem := m . Elem ( )
var template string
var template string
switch u := mElem . ( type ) {
switch u := mElem . ( type ) {
case * types . Struct , * types . Named :
case * types . Struct , * types . Named , * types . Alias :
strucT := u
strucT := u
args . FieldType = it . QualifiedName ( fieldType )
args . FieldType = it . QualifiedName ( fieldType )
if codegen . ContainsPointers ( strucT ) {
if codegen . ContainsPointers ( strucT ) {
@ -281,7 +281,7 @@ func genView(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named, thi
slice := u
slice := u
sElem := slice . Elem ( )
sElem := slice . Elem ( )
switch x := sElem . ( type ) {
switch x := sElem . ( type ) {
case * types . Basic , * types . Named :
case * types . Basic , * types . Named , * types . Alias :
sElem := it . QualifiedName ( sElem )
sElem := it . QualifiedName ( sElem )
args . MapValueView = fmt . Sprintf ( "views.Slice[%v]" , sElem )
args . MapValueView = fmt . Sprintf ( "views.Slice[%v]" , sElem )
args . MapValueType = sElem
args . MapValueType = sElem
@ -292,7 +292,7 @@ func genView(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named, thi
template = "unsupportedField"
template = "unsupportedField"
if _ , isIface := pElem . Underlying ( ) . ( * types . Interface ) ; ! isIface {
if _ , isIface := pElem . Underlying ( ) . ( * types . Interface ) ; ! isIface {
switch pElem . ( type ) {
switch pElem . ( type ) {
case * types . Struct , * types . Named :
case * types . Struct , * types . Named , * types . Alias :
ptrType := it . QualifiedName ( ptr )
ptrType := it . QualifiedName ( ptr )
viewType := appendNameSuffix ( it . QualifiedName ( pElem ) , "View" )
viewType := appendNameSuffix ( it . QualifiedName ( pElem ) , "View" )
args . MapFn = fmt . Sprintf ( "views.SliceOfViews[%v,%v](t)" , ptrType , viewType )
args . MapFn = fmt . Sprintf ( "views.SliceOfViews[%v,%v](t)" , ptrType , viewType )
@ -313,7 +313,7 @@ func genView(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named, thi
pElem := ptr . Elem ( )
pElem := ptr . Elem ( )
if _ , isIface := pElem . Underlying ( ) . ( * types . Interface ) ; ! isIface {
if _ , isIface := pElem . Underlying ( ) . ( * types . Interface ) ; ! isIface {
switch pElem . ( type ) {
switch pElem . ( type ) {
case * types . Struct , * types . Named :
case * types . Struct , * types . Named , * types . Alias :
args . MapValueType = it . QualifiedName ( ptr )
args . MapValueType = it . QualifiedName ( ptr )
args . MapValueView = appendNameSuffix ( it . QualifiedName ( pElem ) , "View" )
args . MapValueView = appendNameSuffix ( it . QualifiedName ( pElem ) , "View" )
args . MapFn = "t.View()"
args . MapFn = "t.View()"
@ -422,7 +422,7 @@ func viewTypeForValueType(typ types.Type) types.Type {
func viewTypeForContainerType ( typ types . Type ) ( * types . Named , * types . Func ) {
func viewTypeForContainerType ( typ types . Type ) ( * types . Named , * types . Func ) {
// The container type should be an instantiated generic type,
// The container type should be an instantiated generic type,
// with its first type parameter specifying the element type.
// with its first type parameter specifying the element type.
containerType , ok := typ. ( * types . Named )
containerType , ok := codegen. NamedTypeOf ( typ )
if ! ok || containerType . TypeArgs ( ) . Len ( ) == 0 {
if ! ok || containerType . TypeArgs ( ) . Len ( ) == 0 {
return nil , nil
return nil , nil
}
}
@ -435,7 +435,7 @@ func viewTypeForContainerType(typ types.Type) (*types.Named, *types.Func) {
if ! ok {
if ! ok {
return nil , nil
return nil , nil
}
}
containerViewGenericType , ok := co ntainerViewTypeObj. Type ( ) . ( * types . Named )
containerViewGenericType , ok := co degen. NamedTypeOf ( co ntainerViewTypeObj. Type ( ) )
if ! ok || containerViewGenericType . TypeParams ( ) . Len ( ) != containerType . TypeArgs ( ) . Len ( ) + 1 {
if ! ok || containerViewGenericType . TypeParams ( ) . Len ( ) != containerType . TypeArgs ( ) . Len ( ) + 1 {
return nil , nil
return nil , nil
}
}
@ -448,7 +448,7 @@ func viewTypeForContainerType(typ types.Type) (*types.Named, *types.Func) {
}
}
// ...and add the element view type.
// ...and add the element view type.
// For that, we need to first determine the named elem type...
// For that, we need to first determine the named elem type...
elemType , ok := baseType ( containerType . TypeArgs ( ) . At ( containerType . TypeArgs ( ) . Len ( ) - 1 ) ) . ( * types . Named )
elemType , ok := codegen . NamedTypeOf ( baseType ( containerType . TypeArgs ( ) . At ( containerType . TypeArgs ( ) . Len ( ) - 1 ) ) )
if ! ok {
if ! ok {
return nil , nil
return nil , nil
}
}
@ -473,7 +473,7 @@ func viewTypeForContainerType(typ types.Type) (*types.Named, *types.Func) {
}
}
// If elemType is an instantiated generic type, instantiate the elemViewType as well.
// If elemType is an instantiated generic type, instantiate the elemViewType as well.
if elemTypeArgs := elemType . TypeArgs ( ) ; elemTypeArgs != nil {
if elemTypeArgs := elemType . TypeArgs ( ) ; elemTypeArgs != nil {
elemViewType = must . Get ( types . Instantiate ( nil , elemViewType , collectTypes ( elemTypeArgs ) , false ) ) . ( * types . Named )
elemViewType , _ = codegen . NamedTypeOf ( must . Get ( types . Instantiate ( nil , elemViewType , collectTypes ( elemTypeArgs ) , false ) ) )
}
}
// And finally set the elemViewType as the last type argument.
// And finally set the elemViewType as the last type argument.
containerViewTypeArgs [ len ( containerViewTypeArgs ) - 1 ] = elemViewType
containerViewTypeArgs [ len ( containerViewTypeArgs ) - 1 ] = elemViewType