This commit is contained in:
crusader 2018-04-07 02:27:13 +09:00
parent ce496549b2
commit dc9f7bce0a
2 changed files with 26 additions and 3 deletions

View File

@ -16,6 +16,7 @@ type TypeDefinition struct {
RealType reflect.Type RealType reflect.Type
TypeAnnotations map[string]cda.Annotation TypeAnnotations map[string]cda.Annotation
MethodAnnotations map[string]cda.Annotation
Fields []*FieldDefinition Fields []*FieldDefinition
} }

View File

@ -315,10 +315,14 @@ func parseFields(t reflect.Type, td *TypeDefinition) {
func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) { func parseAnonymousField(f *reflect.StructField, td *TypeDefinition) {
parseTypeAnnotation(f, td) parseTypeAnnotation(f, td)
parseMethodAnnotation(f, td)
} }
func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) { func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) {
if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) { // if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) {
// return
// }
if cda.TypeAnnotationType != f.Type {
return return
} }
@ -332,6 +336,24 @@ func parseTypeAnnotation(f *reflect.StructField, td *TypeDefinition) {
} }
} }
func parseMethodAnnotation(f *reflect.StructField, td *TypeDefinition) {
// if !haveEmbeddingOf(cda.TypeAnnotationType, f.Type) {
// return
// }
if cda.MethodAnnotationType != f.Type {
return
}
as, err := cda.ParseAnnotation(f.Tag)
if nil != err {
return
}
if nil != as && 0 < len(as) {
td.MethodAnnotations = as
}
}
func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool { func haveEmbeddingOf(t reflect.Type, target reflect.Type) bool {
if t == target { if t == target {
return true return true