This commit is contained in:
crusader 2018-03-20 11:43:00 +09:00
parent 70018c51f5
commit ae21044261
6 changed files with 14 additions and 36 deletions

View File

@ -6,7 +6,7 @@ import (
"git.loafle.net/commons_go/logging"
cdur "git.loafle.net/commons_go/di/util/reflect"
cur "git.loafle.net/commons_go/util/reflect"
)
var annotationRegistry map[string]*AnnotationDefinition
@ -21,7 +21,7 @@ func RegisterAnnotation(name string, t reflect.Type) {
}
meta := getMetaFields(t)
fRT, _, _ := cdur.GetTypeInfo(t)
fRT, _, _ := cur.GetTypeInfo(t)
def := &AnnotationDefinition{
t: t,

View File

@ -4,7 +4,7 @@ import (
"reflect"
"strings"
cdur "git.loafle.net/commons_go/di/util/reflect"
cur "git.loafle.net/commons_go/util/reflect"
)
type AnnotationFieldMeta struct {
@ -35,7 +35,7 @@ func (o anotationMetaOptions) Contains(optionName string) bool {
func getMetaFields(t reflect.Type) map[string]*AnnotationFieldMeta {
fields := make(map[string]*AnnotationFieldMeta, 0)
rt, _, _ := cdur.GetTypeInfo(t)
rt, _, _ := cur.GetTypeInfo(t)
if reflect.Struct != rt.Kind() {
return fields
}

View File

@ -1,2 +1,3 @@
package: git.loafle.net/commons_go/di
import: []
import:
- package: git.loafle.net/commons_go/util

View File

@ -5,7 +5,7 @@ import (
"reflect"
cda "git.loafle.net/commons_go/di/annotation"
cdur "git.loafle.net/commons_go/di/util/reflect"
cur "git.loafle.net/commons_go/util/reflect"
)
type TypeDefinition struct {
@ -48,7 +48,7 @@ func (td *TypeDefinition) GetAnnotationByType(at reflect.Type, includeEmbedding
}
func checkAnnotation(t reflect.Type, st reflect.Type) bool {
rt, _, _ := cdur.GetTypeInfo(t)
rt, _, _ := cur.GetTypeInfo(t)
if reflect.Struct != rt.Kind() {
return false
}

View File

@ -8,8 +8,8 @@ import (
cda "git.loafle.net/commons_go/di/annotation"
cdia "git.loafle.net/commons_go/di/injection/annotation"
cdur "git.loafle.net/commons_go/di/util/reflect"
"git.loafle.net/commons_go/logging"
cur "git.loafle.net/commons_go/util/reflect"
)
func init() {
@ -58,7 +58,7 @@ func (cr *defaultComponentRegistry) RegisterType(t reflect.Type) {
if nil == t {
logging.Logger().Panic("DI: t[reflect.Type] is nil")
}
if !cdur.IsTypeKind(t, reflect.Struct, true) {
if !cur.IsTypeKind(t, reflect.Struct, true) {
logging.Logger().Panic(fmt.Sprintf("DI: t[reflect.Type] must be specified but is %v", t))
}
@ -119,7 +119,7 @@ func (cr *defaultComponentRegistry) GetInstance(t reflect.Type) interface{} {
var err error
rt, _, _ := cdur.GetTypeInfo(t)
rt, _, _ := cur.GetTypeInfo(t)
td, ok := cr.definitionByType[rt]
if !ok {
td, err = cr.buildDefinition(t)
@ -223,7 +223,7 @@ func (cr *defaultComponentRegistry) buildDefinition(t reflect.Type) (*TypeDefini
return nil, fmt.Errorf("t[reflect.Type] is nil")
}
rt, pkgName, tName := cdur.GetTypeInfo(t)
rt, pkgName, tName := cur.GetTypeInfo(t)
td := &TypeDefinition{}
td.FullName = FullName(pkgName, tName)
td.PkgName = pkgName
@ -239,7 +239,7 @@ func (cr *defaultComponentRegistry) buildDefinition(t reflect.Type) (*TypeDefini
func parseFields(t reflect.Type, td *TypeDefinition) {
// fields := make([]*FieldDefinition, 0)
rt, _, _ := cdur.GetTypeInfo(t)
rt, _, _ := cur.GetTypeInfo(t)
if reflect.Struct != rt.Kind() {
return
}
@ -258,7 +258,7 @@ func parseFields(t reflect.Type, td *TypeDefinition) {
return
}
if nil != as && 0 < len(as) {
fRT, fPkgName, fTName := cdur.GetTypeInfo(f.Type)
fRT, fPkgName, fTName := cur.GetTypeInfo(f.Type)
fd := &FieldDefinition{
FieldName: f.Name,

View File

@ -1,23 +0,0 @@
package reflect
import (
"reflect"
)
func IsTypeKind(t reflect.Type, kind reflect.Kind, removePtr bool) bool {
if reflect.Ptr == t.Kind() {
if removePtr {
return IsTypeKind(t.Elem(), kind, removePtr)
}
}
return kind == t.Kind()
}
func GetTypeInfo(t reflect.Type) (realType reflect.Type, pkgName string, name string) {
if reflect.Ptr == t.Kind() {
return GetTypeInfo(t.Elem())
}
return t, t.PkgPath(), t.Name()
}