@@ -1100,7 +1100,7 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
1100
1100
later := make ([]validators.FunctionGen , 0 , len (in ))
1101
1101
1102
1102
for _ , fg := range in {
1103
- isShortCircuit := (fg .Flags () .IsSet (validators .ShortCircuit ))
1103
+ isShortCircuit := (fg .Flags .IsSet (validators .ShortCircuit ))
1104
1104
1105
1105
if isShortCircuit {
1106
1106
sooner = append (sooner , fg )
@@ -1116,19 +1116,17 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
1116
1116
validations = sort (validations )
1117
1117
1118
1118
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 )
1121
1121
1122
- fn , extraArgs := v .SignatureAndArgs ()
1123
1122
targs := generator.Args {
1124
- "funcName" : c .Universe .Type (fn ),
1123
+ "funcName" : c .Universe .Type (v . Function ),
1125
1124
"field" : mkSymbolArgs (c , fieldPkgSymbols ),
1126
1125
}
1127
1126
1128
1127
emitCall := func () {
1129
1128
sw .Do ("$.funcName|raw$" , targs )
1130
- typeArgs := v .TypeArgs ()
1131
- if len (typeArgs ) > 0 {
1129
+ if typeArgs := v .TypeArgs ; len (typeArgs ) > 0 {
1132
1130
sw .Do ("[" , nil )
1133
1131
for i , typeArg := range typeArgs {
1134
1132
sw .Do ("$.|raw$" , c .Universe .Type (typeArg ))
@@ -1139,29 +1137,29 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
1139
1137
sw .Do ("]" , nil )
1140
1138
}
1141
1139
sw .Do ("(ctx, op, fldPath, obj, oldObj" , targs )
1142
- for _ , arg := range extraArgs {
1140
+ for _ , arg := range v . Args {
1143
1141
sw .Do (", " , nil )
1144
1142
toGolangSourceDataLiteral (sw , c , arg )
1145
1143
}
1146
1144
sw .Do (")" , targs )
1147
1145
}
1148
1146
1149
1147
// If validation is conditional, wrap the validation function with a conditions check.
1150
- if ! v .Conditions () .Empty () {
1148
+ if ! v .Conditions .Empty () {
1151
1149
emitBaseFunction := emitCall
1152
1150
emitCall = func () {
1153
1151
sw .Do ("func() $.field.ErrorList|raw$ {\n " , targs )
1154
1152
sw .Do (" if " , nil )
1155
1153
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 ))
1158
1156
firstCondition = false
1159
1157
}
1160
- if len (v .Conditions () .OptionDisabled ) > 0 {
1158
+ if len (v .Conditions .OptionDisabled ) > 0 {
1161
1159
if ! firstCondition {
1162
1160
sw .Do (" && " , nil )
1163
1161
}
1164
- sw .Do ("!op.Options.Has($.$)" , strconv .Quote (v .Conditions () .OptionDisabled ))
1162
+ sw .Do ("!op.Options.Has($.$)" , strconv .Quote (v .Conditions .OptionDisabled ))
1165
1163
}
1166
1164
sw .Do (" {\n " , nil )
1167
1165
sw .Do (" return " , nil )
@@ -1174,7 +1172,7 @@ func emitCallsToValidators(c *generator.Context, validations []validators.Functi
1174
1172
}
1175
1173
}
1176
1174
1177
- for _ , comment := range v .Comments () {
1175
+ for _ , comment := range v .Comments {
1178
1176
sw .Do ("// $.$\n " , comment )
1179
1177
}
1180
1178
if isShortCircuit {
@@ -1214,21 +1212,19 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
1214
1212
1215
1213
variables := tn .typeValidations .Variables
1216
1214
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 )
1218
1216
})
1219
1217
for _ , variable := range variables {
1220
- fn := variable .Init ()
1221
- supportInitFn , supportInitArgs := fn .SignatureAndArgs ()
1218
+ fn := variable .InitFunc
1222
1219
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 ),
1225
1222
}
1226
- for _ , comment := range fn .Comments () {
1223
+ for _ , comment := range fn .Comments {
1227
1224
sw .Do ("// $.$\n " , comment )
1228
1225
}
1229
1226
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 {
1232
1228
sw .Do ("[" , nil )
1233
1229
for i , typeArg := range typeArgs {
1234
1230
sw .Do ("$.|raw$" , c .Universe .Type (typeArg ))
@@ -1239,11 +1235,11 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
1239
1235
sw .Do ("]" , nil )
1240
1236
}
1241
1237
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 {
1245
1240
sw .Do (", " , nil )
1246
1241
}
1242
+ toGolangSourceDataLiteral (sw , c , arg )
1247
1243
}
1248
1244
sw .Do (")\n " , nil )
1249
1245
@@ -1277,22 +1273,21 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context
1277
1273
case * validators.PrivateVar :
1278
1274
sw .Do ("$.|private$" , c .Universe .Type (types .Name (* v )))
1279
1275
case validators.WrapperFunction :
1280
- fn , extraArgs := v .Function .SignatureAndArgs ()
1281
- if len (extraArgs ) == 0 {
1276
+ if extraArgs := v .Function .Args ; len (extraArgs ) == 0 {
1282
1277
// If the function to be wrapped has no additional arguments, we can
1283
1278
// just use it directly.
1284
1279
targs := generator.Args {
1285
- "funcName" : c .Universe .Type (fn ),
1280
+ "funcName" : c .Universe .Type (v . Function . Function ),
1286
1281
}
1287
- for _ , comment := range v .Function .Comments () {
1282
+ for _ , comment := range v .Function .Comments {
1288
1283
sw .Do ("// $.$\n " , comment )
1289
1284
}
1290
1285
sw .Do ("$.funcName|raw$" , targs )
1291
1286
} else {
1292
1287
// If the function to be wrapped has additional arguments, we need
1293
1288
// a "standard signature" validation function to wrap it.
1294
1289
targs := generator.Args {
1295
- "funcName" : c .Universe .Type (fn ),
1290
+ "funcName" : c .Universe .Type (v . Function . Function ),
1296
1291
"field" : mkSymbolArgs (c , fieldPkgSymbols ),
1297
1292
"operation" : mkSymbolArgs (c , operationPkgSymbols ),
1298
1293
"context" : mkSymbolArgs (c , contextPkgSymbols ),
@@ -1305,7 +1300,7 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context
1305
1300
1306
1301
emitCall := func () {
1307
1302
sw .Do ("return $.funcName|raw$" , targs )
1308
- typeArgs := v .Function .TypeArgs ()
1303
+ typeArgs := v .Function .TypeArgs
1309
1304
if len (typeArgs ) > 0 {
1310
1305
sw .Do ("[" , nil )
1311
1306
for i , typeArg := range typeArgs {
0 commit comments