diff --git a/registry/definition.go b/registry/definition.go index 93363a0..4120569 100644 --- a/registry/definition.go +++ b/registry/definition.go @@ -15,8 +15,9 @@ type TypeDefinition struct { Type reflect.Type RealType reflect.Type - TypeAnnotations map[string]cda.Annotation - Fields []*FieldDefinition + TypeAnnotations map[string]cda.Annotation + MethodAnnotations map[string]cda.Annotation + Fields []*FieldDefinition } func (td *TypeDefinition) GetAnnotation(name string) cda.Annotation { diff --git a/registry/registry.go b/registry/registry.go index bbb86cb..1170785 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -315,10 +315,14 @@ func parseFields(t reflect.Type, td *TypeDefinition) { func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) { parseTypeAnnotation(f, td) + parseMethodAnnotation(f, td) } func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) { - if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) { + // if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) { + // return + // } + if cda.TypeAnnotationType != f.Type { return } @@ -332,6 +336,24 @@ func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) { } } +func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) { + // if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) { + // return + // } + if cda.MethodAnnotationType != f.Type { + return + } + + as, err := cda.ParseAnnotation(f.Tag) + if nil != err { + return + } + + if nil != as && 0 < len(as) { + td.MethodAnnotations = as + } +} + func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool { if t == target { return true