Преглед на файлове

codecgen: use real type names if available before constructing name based on kind.

This will allow you perform codegeneration for types like:

  type Test struct {
    Tests Tests
  }
  type Tests []*Test

Fixes #68
Ugorji Nwoke преди 10 години
родител
ревизия
7d9b80c277
променени са 1 файла, в които са добавени 6 реда и са изтрити 0 реда
  1. 6 0
      codec/gen.go

+ 6 - 0
codec/gen.go

@@ -1388,6 +1388,9 @@ func genTypeName(t reflect.Type, tRef reflect.Type) (n string) {
 		ptrPfx += "*"
 		t = t.Elem()
 	}
+	if tn := t.Name(); tn != "" {
+		return ptrPfx + tn
+	}
 	switch t.Kind() {
 	case reflect.Map:
 		return ptrPfx + "map[" + genTypeName(t.Key(), tRef) + "]" + genTypeName(t.Elem(), tRef)
@@ -1412,6 +1415,9 @@ func genMethodNameT(t reflect.Type, tRef reflect.Type) (n string) {
 		ptrPfx += "Ptrto"
 		t = t.Elem()
 	}
+	if tn := t.Name(); tn != "" {
+		return ptrPfx + tn
+	}
 	switch t.Kind() {
 	case reflect.Map:
 		return ptrPfx + "Map" + genMethodNameT(t.Key(), tRef) + genMethodNameT(t.Elem(), tRef)