func fieldName(ident ...*ast.Ident) string { if len(ident) == 0 { return "" } fail.If(len(ident) != 1, "more than one identifier", ident) return ident[0].Name }
func newField(name string, field ast.Expr) Field { switch typed := field.(type) { case *ast.FuncType: fn := &Func{name, make([]Field, 0), make([]Field, 0)} fn.Params.addAll(typed.Params) fn.Results.addAll(typed.Results) return fn case *ast.ChanType: return Chan{Dir: typed.Dir, Type: newField("", typed.Value)} case *ast.Ident: return TypedField{name, typed.Name} default: fail.If(false, fmt.Sprintf("unsupported type:%T\n", typed)) return nil } }