17
17
18
18
import static java .util .stream .Collectors .toCollection ;
19
19
import static java .util .stream .Collectors .toList ;
20
+ import static software .amazon .awssdk .codegen .internal .Constant .SYNC_CLIENT_DESTINATION_PATH_PARAM_NAME ;
21
+ import static software .amazon .awssdk .codegen .internal .Constant .SYNC_CLIENT_SOURCE_PATH_PARAM_NAME ;
20
22
import static software .amazon .awssdk .codegen .poet .client .AsyncClientInterface .STREAMING_TYPE_VARIABLE ;
21
23
22
24
import com .squareup .javapoet .ClassName ;
23
25
import com .squareup .javapoet .FieldSpec ;
24
26
import com .squareup .javapoet .MethodSpec ;
27
+ import com .squareup .javapoet .ParameterSpec ;
25
28
import com .squareup .javapoet .ParameterizedTypeName ;
26
29
import com .squareup .javapoet .TypeName ;
27
30
import com .squareup .javapoet .TypeSpec ;
@@ -338,17 +341,21 @@ private List<MethodSpec> streamingSimpleMethods(OperationModel opModel) {
338
341
* @return Simple method for streaming input operations to read data from a file.
339
342
*/
340
343
private MethodSpec uploadFromFileSimpleMethod (OperationModel opModel , TypeName responseType , ClassName requestType ) {
341
- return MethodSpec .methodBuilder (opModel .getMethodName ())
344
+ String methodName = opModel .getMethodName ();
345
+ ParameterSpec inputVarParam = ParameterSpec .builder (requestType , opModel .getInput ().getVariableName ()).build ();
346
+ ParameterSpec srcPathParam = ParameterSpec .builder (ClassName .get (Path .class ),
347
+ SYNC_CLIENT_SOURCE_PATH_PARAM_NAME ).build ();
348
+ return MethodSpec .methodBuilder (methodName )
342
349
.returns (responseType )
343
350
.addModifiers (Modifier .PUBLIC , Modifier .DEFAULT )
344
- .addParameter (requestType , opModel . getInput (). getVariableName () )
345
- .addParameter (ClassName . get ( Path . class ), "filePath" )
351
+ .addParameter (inputVarParam )
352
+ .addParameter (srcPathParam )
346
353
.addJavadoc (opModel .getDocs (model , ClientType .SYNC , SimpleMethodOverload .FILE ))
347
354
.addExceptions (getExceptionClasses (model , opModel ))
348
- .addStatement ("return $L($L , $T.fromFile($L ))" , opModel . getMethodName () ,
349
- opModel . getInput (). getVariableName () ,
355
+ .addStatement ("return $L($N , $T.fromFile($N ))" , methodName ,
356
+ inputVarParam ,
350
357
ClassName .get (RequestBody .class ),
351
- "filePath" )
358
+ srcPathParam )
352
359
.build ();
353
360
}
354
361
@@ -390,17 +397,21 @@ private MethodSpec bytesSimpleMethod(OperationModel opModel, TypeName responseTy
390
397
* @return Simple method for streaming output operations to write response content to a file.
391
398
*/
392
399
private MethodSpec downloadToFileSimpleMethod (OperationModel opModel , TypeName responseType , ClassName requestType ) {
393
- return MethodSpec .methodBuilder (opModel .getMethodName ())
400
+ String methodName = opModel .getMethodName ();
401
+ ParameterSpec inputVarParam = ParameterSpec .builder (requestType , opModel .getInput ().getVariableName ()).build ();
402
+ ParameterSpec dstFileParam =
403
+ ParameterSpec .builder (ClassName .get (Path .class ), SYNC_CLIENT_DESTINATION_PATH_PARAM_NAME ).build ();
404
+ return MethodSpec .methodBuilder (methodName )
394
405
.returns (responseType )
395
406
.addModifiers (Modifier .PUBLIC , Modifier .DEFAULT )
396
- .addParameter (requestType , opModel . getInput (). getVariableName () )
397
- .addParameter (ClassName . get ( Path . class ), "filePath" )
407
+ .addParameter (inputVarParam )
408
+ .addParameter (dstFileParam )
398
409
.addJavadoc (opModel .getDocs (model , ClientType .SYNC , SimpleMethodOverload .FILE ))
399
410
.addExceptions (getExceptionClasses (model , opModel ))
400
- .addStatement ("return $L($L , $T.toFile($L ))" , opModel . getMethodName () ,
401
- opModel . getInput (). getVariableName () ,
411
+ .addStatement ("return $L($N , $T.toFile($N ))" , methodName ,
412
+ inputVarParam ,
402
413
ClassName .get (ResponseTransformer .class ),
403
- "filePath" )
414
+ dstFileParam )
404
415
.build ();
405
416
}
406
417
@@ -411,19 +422,25 @@ private MethodSpec downloadToFileSimpleMethod(OperationModel opModel, TypeName r
411
422
private MethodSpec streamingInputOutputFileSimpleMethod (OperationModel opModel ,
412
423
TypeName responseType ,
413
424
ClassName requestType ) {
414
- return MethodSpec .methodBuilder (opModel .getMethodName ())
425
+ String methodName = opModel .getMethodName ();
426
+ ParameterSpec inputVarParam = ParameterSpec .builder (requestType , opModel .getInput ().getVariableName ()).build ();
427
+ ParameterSpec srcFileParam = ParameterSpec .builder (ClassName .get (Path .class ), SYNC_CLIENT_SOURCE_PATH_PARAM_NAME ).build ();
428
+ ParameterSpec dstFileParam =
429
+ ParameterSpec .builder (ClassName .get (Path .class ), SYNC_CLIENT_DESTINATION_PATH_PARAM_NAME ).build ();
430
+ return MethodSpec .methodBuilder (methodName )
415
431
.returns (responseType )
416
432
.addModifiers (Modifier .PUBLIC , Modifier .DEFAULT )
417
- .addParameter (requestType , opModel . getInput (). getVariableName () )
418
- .addParameter (ClassName . get ( Path . class ), "sourcePath" )
419
- .addParameter (ClassName . get ( Path . class ), "destinationPath" )
433
+ .addParameter (inputVarParam )
434
+ .addParameter (srcFileParam )
435
+ .addParameter (dstFileParam )
420
436
.addJavadoc (opModel .getDocs (model , ClientType .SYNC , SimpleMethodOverload .FILE ))
421
437
.addExceptions (getExceptionClasses (model , opModel ))
422
- .addStatement ("return $L($L, $T.fromFile(sourcePath), $T.toFile(destinationPath))" ,
423
- opModel .getMethodName (),
424
- opModel .getInput ().getVariableName (),
425
- ClassName .get (RequestBody .class ),
426
- ClassName .get (ResponseTransformer .class ))
438
+ .addStatement ("return $L($N, $T.fromFile($N), $T.toFile($N))" ,
439
+ methodName ,
440
+ inputVarParam ,
441
+ ClassName .get (RequestBody .class ), srcFileParam ,
442
+ ClassName .get (ResponseTransformer .class ),
443
+ dstFileParam )
427
444
.build ();
428
445
}
429
446
0 commit comments