ing
This commit is contained in:
parent
e92a9693a0
commit
219bb2f0c9
|
@ -5,6 +5,7 @@ import (
|
|||
"reflect"
|
||||
|
||||
cda "git.loafle.net/commons_go/di/annotation"
|
||||
cdur "git.loafle.net/commons_go/di/util/reflect"
|
||||
)
|
||||
|
||||
type TypeDefinition struct {
|
||||
|
@ -22,9 +23,53 @@ func (td *TypeDefinition) GetAnnotation(name string) cda.Annotation {
|
|||
if nil == td.TypeAnnotations {
|
||||
return nil
|
||||
}
|
||||
|
||||
return td.TypeAnnotations[name]
|
||||
}
|
||||
|
||||
func (td *TypeDefinition) GetAnnotationByType(at reflect.Type, includeEmbedding bool) cda.Annotation {
|
||||
if nil == td.TypeAnnotations {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, v := range td.TypeAnnotations {
|
||||
if includeEmbedding {
|
||||
if checkAnnotation(reflect.TypeOf(v), at) {
|
||||
return v
|
||||
}
|
||||
} else {
|
||||
if at == reflect.TypeOf(v) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkAnnotation(t reflect.Type, st reflect.Type) bool {
|
||||
rt, _, _ := cdur.GetTypeInfo(t)
|
||||
if reflect.Struct != rt.Kind() {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < rt.NumField(); i++ {
|
||||
f := rt.Field(i)
|
||||
|
||||
if f.Anonymous {
|
||||
if f.Type == st {
|
||||
return true
|
||||
}
|
||||
if checkAnnotation(f.Type, st) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
type FieldDefinition struct {
|
||||
FieldName string
|
||||
PkgName string
|
||||
|
|
|
@ -73,14 +73,13 @@ func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) {
|
|||
}
|
||||
cr.definitionByType[td.RealType] = td
|
||||
|
||||
// _ca := ca.(*cdia.ComponentAnnotation)
|
||||
ca := td.GetAnnotation(cdia.ComponentTag).(*cdia.Component)
|
||||
name := td.TypeName
|
||||
|
||||
name := ""
|
||||
if nil != ca && "" != strings.Trim(ca.Name, " ") {
|
||||
name = ca.Name
|
||||
} else {
|
||||
name = td.TypeName
|
||||
if a := td.GetAnnotationByType(reflect.TypeOf((*cdia.Component)(nil)), true); nil != a {
|
||||
ca := a.(*cdia.Component)
|
||||
if "" != strings.Trim(ca.Name, " ") {
|
||||
name = ca.Name
|
||||
}
|
||||
}
|
||||
|
||||
if eTD, ok := cr.definitionByName[name]; ok {
|
||||
|
|
Loading…
Reference in New Issue
Block a user