ing
This commit is contained in:
parent
c896f9da22
commit
40f41364ad
|
@ -277,7 +277,9 @@ func GetMethodAnnotation(instanceType reflect.Type, annotationType reflect.Type,
|
||||||
return registry.GetMethodAnnotation(instanceType, annotationType, methodName)
|
return registry.GetMethodAnnotation(instanceType, annotationType, methodName)
|
||||||
}
|
}
|
||||||
func (cr *defaultComponentRegistry) GetMethodAnnotation(instanceType reflect.Type, annotationType reflect.Type, methodName string) cda.Annotation {
|
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 {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -315,9 +317,14 @@ func parseFields(t reflect.Type, td *TypeDefinition) {
|
||||||
f := rt.Field(i)
|
f := rt.Field(i)
|
||||||
|
|
||||||
if f.Anonymous {
|
if f.Anonymous {
|
||||||
parseAnonymousField(&f, td)
|
if parseAnonymousField(&f, td) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
parseFields(f.Type, td)
|
parseFields(f.Type, td)
|
||||||
} else {
|
} else {
|
||||||
|
if parseMethodAnnotation(&f, td) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
as, err := cda.ParseAnnotation(f.Tag)
|
as, err := cda.ParseAnnotation(f.Tag)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return
|
||||||
|
@ -339,40 +346,41 @@ func parseFields(t reflect.Type, td *TypeDefinition) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) {
|
func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) bool {
|
||||||
parseTypeAnnotation(f, td)
|
if parseTypeAnnotation(f, td) {
|
||||||
parseMethodAnnotation(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) {
|
// if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) {
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
if cda.TypeAnnotationType != f.Type {
|
if cda.TypeAnnotationType != f.Type {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
as, err := cda.ParseAnnotation(f.Tag)
|
as, err := cda.ParseAnnotation(f.Tag)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != as && 0 < len(as) {
|
if nil != as && 0 < len(as) {
|
||||||
td.TypeAnnotations = as
|
td.TypeAnnotations = as
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) {
|
func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) bool {
|
||||||
// if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
if cda.MethodAnnotationType != f.Type {
|
if cda.MethodAnnotationType != f.Type {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
as, err := cda.ParseAnnotation(f.Tag)
|
as, err := cda.ParseAnnotation(f.Tag)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if nil != as && 0 < len(as) {
|
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 = make(map[string]map[string]cda.Annotation, 0)
|
||||||
}
|
}
|
||||||
td.MethodAnnotations[f.Name] = as
|
td.MethodAnnotations[f.Name] = as
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool {
|
func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user