This commit is contained in:
crusader 2018-09-04 15:32:53 +09:00
parent 178b12d303
commit b94873cf6c

View File

@ -16,9 +16,11 @@ type Registry interface {
GetTypeAnnotations(t reflect.Type) (map[reflect.Type]Annotation, error) GetTypeAnnotations(t reflect.Type) (map[reflect.Type]Annotation, error)
GetFieldAnnotation(t reflect.Type, name string, at 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) 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) GetAllFieldAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error)
GetMethodAnnotation(t reflect.Type, name string, at 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) 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) 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 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) { func GetAllFieldAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error) {
return SystemRegistry.GetAllFieldAnnotations(t) return SystemRegistry.GetAllFieldAnnotations(t)
} }
@ -410,6 +436,30 @@ func (r *AnnotationRegistry) GetMethodAnnotations(t reflect.Type, name string) (
return as, nil 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) { func GetAllMethodAnnotations(t reflect.Type) (map[string]map[reflect.Type]Annotation, error) {
return SystemRegistry.GetAllMethodAnnotations(t) return SystemRegistry.GetAllMethodAnnotations(t)
} }