ing
This commit is contained in:
parent
c40b3be3cc
commit
ee2ede6bd9
|
@ -1,5 +1,9 @@
|
|||
package annotation
|
||||
|
||||
import "reflect"
|
||||
|
||||
var TypeAnnotationType = reflect.TypeOf((*TypeAnnotation)(nil)).Elem()
|
||||
|
||||
type TypeAnnotation interface {
|
||||
Annotation
|
||||
}
|
||||
|
|
|
@ -266,9 +266,7 @@ func parseFields(t reflect.Type, td *TypeDefinition) {
|
|||
f := rt.Field(i)
|
||||
|
||||
if f.Anonymous {
|
||||
if parseAnonymousField(f, td) {
|
||||
continue
|
||||
}
|
||||
parseAnonymousField(f, td)
|
||||
parseFields(f.Type, td)
|
||||
} else {
|
||||
as, err := cda.ParseAnnotation(f.Tag)
|
||||
|
@ -292,22 +290,43 @@ func parseFields(t reflect.Type, td *TypeDefinition) {
|
|||
}
|
||||
}
|
||||
|
||||
func parseAnonymousField(f reflect.StructField, td *TypeDefinition) bool {
|
||||
ct := reflect.TypeOf((*cda.TypeAnnotation)(nil)).Elem()
|
||||
func parseAnonymousField(f reflect.StructField, td *TypeDefinition) {
|
||||
parseTypeAnnotation(f, td)
|
||||
}
|
||||
|
||||
if f.Type != ct {
|
||||
return false
|
||||
func parseTypeAnnotation(f reflect.StructField, td *TypeDefinition) {
|
||||
if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) {
|
||||
return
|
||||
}
|
||||
|
||||
as, err := cda.ParseAnnotation(f.Tag)
|
||||
if nil != err {
|
||||
return false
|
||||
return
|
||||
}
|
||||
|
||||
if nil != as && 0 < len(as) {
|
||||
td.TypeAnnotations = as
|
||||
}
|
||||
}
|
||||
|
||||
func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool {
|
||||
if t == target {
|
||||
return true
|
||||
}
|
||||
|
||||
rt, _, _ := cur.GetTypeInfo(target)
|
||||
if reflect.Struct != rt.Kind() {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < rt.NumField(); i++ {
|
||||
f := rt.Field(i)
|
||||
|
||||
if f.Anonymous {
|
||||
if haveEmbeddingOf(t, f.Type) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user