diff --git a/registry/registry.go b/registry/registry.go index d12c7db..095cdaf 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -277,7 +277,9 @@ func GetMethodAnnotation(instanceType reflect.Type, annotationType reflect.Type, return registry.GetMethodAnnotation(instanceType, annotationType, methodName) } func (cr *defaultComponentRegistry) GetMethodAnnotation(instanceType reflect.Type, annotationType reflect.Type, methodName string) cda.Annotation { - def, ok := cr.definitionByType[instanceType] + rt, _, _ := cur.GetTypeInfo(instanceType) + + def, ok := cr.definitionByType[rt] if !ok { return nil } @@ -315,9 +317,14 @@ func parseFields(t reflect.Type, td *TypeDefinition) { f := rt.Field(i) if f.Anonymous { - parseAnonymousField(&f, td) + if parseAnonymousField(&f, td) { + continue + } parseFields(f.Type, td) } else { + if parseMethodAnnotation(&f, td) { + continue + } as, err := cda.ParseAnnotation(f.Tag) if nil != err { return @@ -339,40 +346,41 @@ func parseFields(t reflect.Type, td *TypeDefinition) { } } -func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) { - parseTypeAnnotation(f, td) - parseMethodAnnotation(f, td) +func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) bool { + if parseTypeAnnotation(f, td) { + return true + } + return false } -func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) { +func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) bool { // if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) { // return // } if cda.TypeAnnotationType != f.Type { - return + return false } as, err := cda.ParseAnnotation(f.Tag) if nil != err { - return + return false } if nil != as && 0 < len(as) { td.TypeAnnotations = as + return true } + return false } -func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) { - // if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) { - // return - // } +func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) bool { if cda.MethodAnnotationType != f.Type { - return + return false } as, err := cda.ParseAnnotation(f.Tag) if nil != err { - return + return false } if nil != as && 0 < len(as) { @@ -380,7 +388,9 @@ func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) { td.MethodAnnotations = make(map[string]map[string]cda.Annotation, 0) } td.MethodAnnotations[f.Name] = as + return true } + return false } func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool {