@@ -1093,14 +1093,14 @@ func (g *genValidations) emitCallToOtherTypeFunc(c *generator.Context, node *typ
1093
1093
// Emitted code assumes that the value in question is always a pair of nilable
1094
1094
// variables named "obj" and "oldObj", and the field path to this value is
1095
1095
// named "fldPath".
1096
- func emitCallsToValidators (c * generator.Context , validations []validators.FunctionGen , sw * generator.SnippetWriter ) {
1096
+ func emitCallsToValidators (c * generator.Context , validations []* validators.FunctionGen , sw * generator.SnippetWriter ) {
1097
1097
// Helper func
1098
- sort := func (in []validators.FunctionGen ) []validators.FunctionGen {
1099
- sooner := make ([]validators.FunctionGen , 0 , len (in ))
1100
- later := make ([]validators.FunctionGen , 0 , len (in ))
1098
+ sort := func (in []* validators.FunctionGen ) []* validators.FunctionGen {
1099
+ sooner := make ([]* validators.FunctionGen , 0 , len (in ))
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 {
@@ -1218,16 +1216,15 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
1218
1216
})
1219
1217
for _ , variable := range variables {
1220
1218
fn := variable .Init ()
1221
- supportInitFn , supportInitArgs := fn .SignatureAndArgs ()
1222
1219
targs := generator.Args {
1223
1220
"varName" : c .Universe .Type (types .Name (variable .Var ())),
1224
- "initFn" : c .Universe .Type (supportInitFn ),
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 ()
1227
+ typeArgs := variable .Init ().TypeArgs
1231
1228
if len (typeArgs ) > 0 {
1232
1229
sw .Do ("[" , nil )
1233
1230
for i , typeArg := range typeArgs {
@@ -1239,11 +1236,11 @@ func (g *genValidations) emitValidationVariables(c *generator.Context, t *types.
1239
1236
sw .Do ("]" , nil )
1240
1237
}
1241
1238
sw .Do ("(" , targs )
1242
- for i , arg := range supportInitArgs {
1243
- toGolangSourceDataLiteral (sw , c , arg )
1244
- if i < len (supportInitArgs )- 1 {
1239
+ for i , arg := range fn .Args {
1240
+ if i != 0 {
1245
1241
sw .Do (", " , nil )
1246
1242
}
1243
+ toGolangSourceDataLiteral (sw , c , arg )
1247
1244
}
1248
1245
sw .Do (")\n " , nil )
1249
1246
@@ -1277,22 +1274,21 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context
1277
1274
case * validators.PrivateVar :
1278
1275
sw .Do ("$.|private$" , c .Universe .Type (types .Name (* v )))
1279
1276
case validators.WrapperFunction :
1280
- fn , extraArgs := v .Function .SignatureAndArgs ()
1281
- if len (extraArgs ) == 0 {
1277
+ if extraArgs := v .Function .Args ; len (extraArgs ) == 0 {
1282
1278
// If the function to be wrapped has no additional arguments, we can
1283
1279
// just use it directly.
1284
1280
targs := generator.Args {
1285
- "funcName" : c .Universe .Type (fn ),
1281
+ "funcName" : c .Universe .Type (v . Function . Function ),
1286
1282
}
1287
- for _ , comment := range v .Function .Comments () {
1283
+ for _ , comment := range v .Function .Comments {
1288
1284
sw .Do ("// $.$\n " , comment )
1289
1285
}
1290
1286
sw .Do ("$.funcName|raw$" , targs )
1291
1287
} else {
1292
1288
// If the function to be wrapped has additional arguments, we need
1293
1289
// a "standard signature" validation function to wrap it.
1294
1290
targs := generator.Args {
1295
- "funcName" : c .Universe .Type (fn ),
1291
+ "funcName" : c .Universe .Type (v . Function . Function ),
1296
1292
"field" : mkSymbolArgs (c , fieldPkgSymbols ),
1297
1293
"operation" : mkSymbolArgs (c , operationPkgSymbols ),
1298
1294
"context" : mkSymbolArgs (c , contextPkgSymbols ),
@@ -1305,7 +1301,7 @@ func toGolangSourceDataLiteral(sw *generator.SnippetWriter, c *generator.Context
1305
1301
1306
1302
emitCall := func () {
1307
1303
sw .Do ("return $.funcName|raw$" , targs )
1308
- typeArgs := v .Function .TypeArgs ()
1304
+ typeArgs := v .Function .TypeArgs
1309
1305
if len (typeArgs ) > 0 {
1310
1306
sw .Do ("[" , nil )
1311
1307
for i , typeArg := range typeArgs {
0 commit comments