From b94873cf6c40c8a46393f4e9f229eee152e2eb1b Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 4 Sep 2018 15:32:53 +0900 Subject: [PATCH] ing --- registry.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/registry.go b/registry.go index dbbe991..342ddd0 100644 --- a/registry.go +++ b/registry.go @@ -16,9 +16,11 @@ type Registry interface { GetTypeAnnotations(t reflect.Type) (map[reflect.Type]Annotation, error) GetFieldAnnotation(t reflect.Type, name string, at reflect.Type) (Annotation, error) GetFieldAnnotations(t reflect.Type, name string) (map[reflect.Type]Annotation, error) + GetFieldAnnotationsByType(t reflect.Type, at reflect.Type) (map[string]Annotation, error) GetAllFieldAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error) GetMethodAnnotation(t reflect.Type, name string, at reflect.Type) (Annotation, error) GetMethodAnnotations(t reflect.Type, name string) (map[reflect.Type]Annotation, error) + GetMethodAnnotationsByType(t reflect.Type, at reflect.Type) (map[string]Annotation, error) GetAllMethodAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error) } @@ -347,6 +349,30 @@ func (r *AnnotationRegistry) GetFieldAnnotations(t reflect.Type, name string) (m return as, nil } +func GetFieldAnnotationsByType(t reflect.Type, at reflect.Type) (map[string]Annotation, error) { + return SystemRegistry.GetFieldAnnotationsByType(t, at) +} +func (r *AnnotationRegistry) GetFieldAnnotationsByType(t reflect.Type, at reflect.Type) (map[string]Annotation, error) { + td, err := r.getTypeDefinition(t) + if nil != err { + return nil, err + } + + if 0 == len(td.fieldAnnotation) { + return nil, nil + } + + as := make(map[string]Annotation, 0) + + for k, v := range td.fieldAnnotation { + if a, ok := v[at]; ok { + as[k] = a + } + } + + return as, nil +} + func GetAllFieldAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error) { return SystemRegistry.GetAllFieldAnnotations(t) } @@ -410,6 +436,30 @@ func (r *AnnotationRegistry) GetMethodAnnotations(t reflect.Type, name string) ( return as, nil } +func GetMethodAnnotationsByType(t reflect.Type, at reflect.Type) (map[string]Annotation, error) { + return SystemRegistry.GetMethodAnnotationsByType(t, at) +} +func (r *AnnotationRegistry) GetMethodAnnotationsByType(t reflect.Type, at reflect.Type) (map[string]Annotation, error) { + td, err := r.getTypeDefinition(t) + if nil != err { + return nil, err + } + + if 0 == len(td.methodAnnotation) { + return nil, nil + } + + as := make(map[string]Annotation, 0) + + for k, v := range td.methodAnnotation { + if a, ok := v[at]; ok { + as[k] = a + } + } + + return as, nil +} + func GetAllMethodAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error) { return SystemRegistry.GetAllMethodAnnotations(t) }