@@ -1100,7 +1100,7 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
11001100 later := make ([]validators.FunctionGen , 0 , len (in ))
11011101
11021102 for _ , fg := range in {
1103- isShortCircuit := (fg .Flags () .IsSet (validators .ShortCircuit ))
1103+ isShortCircuit := (fg .Flags .IsSet (validators .ShortCircuit ))
11041104
11051105 if isShortCircuit {
11061106 sooner = append (sooner , fg )
@@ -1116,19 +1116,17 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
11161116 validations = sort (validations )
11171117
11181118 for _ , v := range validations {
1119- isShortCircuit := v .Flags () .IsSet (validators .ShortCircuit )
1120- isNonError := v .Flags () .IsSet (validators .NonError )
1119+ isShortCircuit := v .Flags .IsSet (validators .ShortCircuit )
1120+ isNonError := v .Flags .IsSet (validators .NonError )
11211121
1122- fn , extraArgs := v .SignatureAndArgs ()
11231122 targs := generator.Args {
1124- "funcName" : c .Universe .Type (fn ),
1123+ "funcName" : c .Universe .Type (v . Function ),
11251124 "field" : mkSymbolArgs (c , fieldPkgSymbols ),
11261125 }
11271126
11281127 emitCall := func () {
11291128 sw .Do ("$.funcName|raw$" , targs )
1130- typeArgs := v .TypeArgs ()
1131- if len (typeArgs ) > 0 {
1129+ if typeArgs := v .TypeArgs ; len (typeArgs ) > 0 {
11321130 sw .Do ("[" , nil )
11331131 for i , typeArg := range typeArgs {
11341132 sw .Do ("$.|raw$" , c .Universe .Type (typeArg ))
@@ -1139,29 +1137,29 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
11391137 sw .Do ("]" , nil )
11401138 }
11411139 sw .Do ("(ctx, op, fldPath, obj, oldObj" , targs )
1142- for _ , arg := range extraArgs {
1140+ for _ , arg := range v . Args {
11431141 sw .Do (", " , nil )
11441142 toGolangSourceDataLiteral (sw , c , arg )
11451143 }
11461144 sw .Do (")" , targs )
11471145 }
11481146
11491147 // If validation is conditional, wrap the validation function with a conditions check.
1150- if ! v .Conditions () .Empty () {
1148+ if ! v .Conditions .Empty () {
11511149 emitBaseFunction := emitCall
11521150 emitCall = func () {
11531151 sw .Do ("func() $.field.ErrorList|raw$ {\n " , targs )
11541152 sw .Do (" if " , nil )
11551153 firstCondition := true
1156- if len (v .Conditions () .OptionEnabled ) > 0 {
1157- sw .Do ("op.Options.Has($.$)" , strconv .Quote (v .Conditions () .OptionEnabled ))
1154+ if len (v .Conditions .OptionEnabled ) > 0 {
1155+ sw .Do ("op.Options.Has($.$)" , strconv .Quote (v .Conditions .OptionEnabled ))
11581156 firstCondition = false
11591157 }
1160- if len (v .Conditions () .OptionDisabled ) > 0 {
1158+ if len (v .Conditions .OptionDisabled ) > 0 {
11611159 if ! firstCondition {
11621160 sw .Do (" && " , nil )
11631161 }
1164- sw .Do ("!op.Options.Has($.$)" , strconv .Quote (v .Conditions () .OptionDisabled ))
1162+ sw .Do ("!op.Options.Has($.$)" , strconv .Quote (v .Conditions .OptionDisabled ))
11651163 }
11661164 sw .Do (" {\n " , nil )
11671165 sw .Do (" return " , nil )
@@ -1174,7 +1172,7 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
11741172 }
11751173 }
11761174
1177- for _ , comment := range v .Comments () {
1175+ for _ , comment := range v .Comments {
11781176 sw .Do ("// $.$\n " , comment )
11791177 }
11801178 if isShortCircuit {
@@ -1214,21 +1212,19 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
12141212
12151213 variables := tn .typeValidations .Variables
12161214 slices .SortFunc (variables , func (a , b validators.VariableGen ) int {
1217- return cmp .Compare (a .Var () .Name , b .Var () .Name )
1215+ return cmp .Compare (a .Variable .Name , b .Variable .Name )
12181216 })
12191217 for _ , variable := range variables {
1220- fn := variable .Init ()
1221- supportInitFn , supportInitArgs := fn .SignatureAndArgs ()
1218+ fn := variable .InitFunc
12221219 targs := generator.Args {
1223- "varName" : c .Universe .Type (types .Name (variable .Var () )),
1224- "initFn" : c .Universe .Type (supportInitFn ),
1220+ "varName" : c .Universe .Type (types .Name (variable .Variable )),
1221+ "initFn" : c .Universe .Type (fn . Function ),
12251222 }
1226- for _ , comment := range fn .Comments () {
1223+ for _ , comment := range fn .Comments {
12271224 sw .Do ("// $.$\n " , comment )
12281225 }
12291226 sw .Do ("var $.varName|private$ = $.initFn|raw$" , targs )
1230- typeArgs := variable .Init ().TypeArgs ()
1231- if len (typeArgs ) > 0 {
1227+ if typeArgs := fn .TypeArgs ; len (typeArgs ) > 0 {
12321228 sw .Do ("[" , nil )
12331229 for i , typeArg := range typeArgs {
12341230 sw .Do ("$.|raw$" , c .Universe .Type (typeArg ))
@@ -1239,11 +1235,11 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
12391235 sw .Do ("]" , nil )
12401236 }
12411237 sw .Do ("(" , targs )
1242- for i , arg := range supportInitArgs {
1243- toGolangSourceDataLiteral (sw , c , arg )
1244- if i < len (supportInitArgs )- 1 {
1238+ for i , arg := range fn .Args {
1239+ if i != 0 {
12451240 sw .Do (", " , nil )
12461241 }
1242+ toGolangSourceDataLiteral (sw , c , arg )
12471243 }
12481244 sw .Do (")\n " , nil )
12491245
@@ -1277,22 +1273,21 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context
12771273 case * validators.PrivateVar :
12781274 sw .Do ("$.|private$" , c .Universe .Type (types .Name (* v )))
12791275 case validators.WrapperFunction :
1280- fn , extraArgs := v .Function .SignatureAndArgs ()
1281- if len (extraArgs ) == 0 {
1276+ if extraArgs := v .Function .Args ; len (extraArgs ) == 0 {
12821277 // If the function to be wrapped has no additional arguments, we can
12831278 // just use it directly.
12841279 targs := generator.Args {
1285- "funcName" : c .Universe .Type (fn ),
1280+ "funcName" : c .Universe .Type (v . Function . Function ),
12861281 }
1287- for _ , comment := range v .Function .Comments () {
1282+ for _ , comment := range v .Function .Comments {
12881283 sw .Do ("// $.$\n " , comment )
12891284 }
12901285 sw .Do ("$.funcName|raw$" , targs )
12911286 } else {
12921287 // If the function to be wrapped has additional arguments, we need
12931288 // a "standard signature" validation function to wrap it.
12941289 targs := generator.Args {
1295- "funcName" : c .Universe .Type (fn ),
1290+ "funcName" : c .Universe .Type (v . Function . Function ),
12961291 "field" : mkSymbolArgs (c , fieldPkgSymbols ),
12971292 "operation" : mkSymbolArgs (c , operationPkgSymbols ),
12981293 "context" : mkSymbolArgs (c , contextPkgSymbols ),
@@ -1305,7 +1300,7 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context
13051300
13061301 emitCall := func () {
13071302 sw .Do ("return $.funcName|raw$" , targs )
1308- typeArgs := v .Function .TypeArgs ()
1303+ typeArgs := v .Function .TypeArgs
13091304 if len (typeArgs ) > 0 {
13101305 sw .Do ("[" , nil )
13111306 for i , typeArg := range typeArgs {
0 commit comments