use of com.squareup.javapoet.ParameterSpec in project aws-sdk-java-v2 by aws.
the class ClientClassUtils method consumerBuilderVariant.
static MethodSpec consumerBuilderVariant(MethodSpec spec, String javadoc) {
Validate.validState(spec.parameters.size() > 0, "A first parameter is required to generate a consumer-builder method.");
Validate.validState(spec.parameters.get(0).type instanceof ClassName, "The first parameter must be a class.");
ParameterSpec firstParameter = spec.parameters.get(0);
ClassName firstParameterClass = (ClassName) firstParameter.type;
TypeName consumer = ParameterizedTypeName.get(ClassName.get(Consumer.class), firstParameterClass.nestedClass("Builder"));
MethodSpec.Builder result = MethodSpec.methodBuilder(spec.name).returns(spec.returnType).addExceptions(spec.exceptions).addAnnotations(spec.annotations).addJavadoc(javadoc).addModifiers(Modifier.PUBLIC, Modifier.DEFAULT).addTypeVariables(spec.typeVariables).addParameter(ParameterSpec.builder(consumer, firstParameter.name).build());
// Parameters
StringBuilder methodBody = new StringBuilder("return $L($T.builder().applyMutation($L).build()");
for (int i = 1; i < spec.parameters.size(); i++) {
ParameterSpec parameter = spec.parameters.get(i);
methodBody.append(", ").append(parameter.name);
result.addParameter(parameter);
}
methodBody.append(")");
result.addStatement(methodBody.toString(), spec.name, firstParameterClass, firstParameter.name);
return result.build();
}
use of com.squareup.javapoet.ParameterSpec in project aws-sdk-java-v2 by aws.
the class SyncClientInterface method downloadToFileSimpleMethod.
/**
* @return Simple method for streaming output operations to write response content to a file.
*/
private MethodSpec downloadToFileSimpleMethod(OperationModel opModel, TypeName responseType, ClassName requestType) {
String methodName = opModel.getMethodName();
ParameterSpec inputVarParam = ParameterSpec.builder(requestType, opModel.getInput().getVariableName()).build();
ParameterSpec dstFileParam = ParameterSpec.builder(ClassName.get(Path.class), SYNC_CLIENT_DESTINATION_PATH_PARAM_NAME).build();
return MethodSpec.methodBuilder(methodName).returns(responseType).addModifiers(Modifier.PUBLIC, Modifier.DEFAULT).addParameter(inputVarParam).addParameter(dstFileParam).addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.FILE)).addExceptions(getExceptionClasses(model, opModel)).addStatement("return $L($N, $T.toFile($N))", methodName, inputVarParam, ClassName.get(ResponseTransformer.class), dstFileParam).build();
}
use of com.squareup.javapoet.ParameterSpec in project aws-sdk-java-v2 by aws.
the class SyncClientInterface method streamingInputOutputFileSimpleMethod.
/**
* Generate a simple method for operations with streaming input and output members.
* Streaming input member that reads data from a file and a streaming output member that write response content to a file.
*/
private MethodSpec streamingInputOutputFileSimpleMethod(OperationModel opModel, TypeName responseType, ClassName requestType) {
String methodName = opModel.getMethodName();
ParameterSpec inputVarParam = ParameterSpec.builder(requestType, opModel.getInput().getVariableName()).build();
ParameterSpec srcFileParam = ParameterSpec.builder(ClassName.get(Path.class), SYNC_CLIENT_SOURCE_PATH_PARAM_NAME).build();
ParameterSpec dstFileParam = ParameterSpec.builder(ClassName.get(Path.class), SYNC_CLIENT_DESTINATION_PATH_PARAM_NAME).build();
return MethodSpec.methodBuilder(methodName).returns(responseType).addModifiers(Modifier.PUBLIC, Modifier.DEFAULT).addParameter(inputVarParam).addParameter(srcFileParam).addParameter(dstFileParam).addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.FILE)).addExceptions(getExceptionClasses(model, opModel)).addStatement("return $L($N, $T.fromFile($N), $T.toFile($N))", methodName, inputVarParam, ClassName.get(RequestBody.class), srcFileParam, ClassName.get(ResponseTransformer.class), dstFileParam).build();
}
use of com.squareup.javapoet.ParameterSpec in project aws-sdk-java-v2 by aws.
the class SyncClientInterface method uploadFromFileSimpleMethod.
/**
* @return Simple method for streaming input operations to read data from a file.
*/
private MethodSpec uploadFromFileSimpleMethod(OperationModel opModel, TypeName responseType, ClassName requestType) {
String methodName = opModel.getMethodName();
ParameterSpec inputVarParam = ParameterSpec.builder(requestType, opModel.getInput().getVariableName()).build();
ParameterSpec srcPathParam = ParameterSpec.builder(ClassName.get(Path.class), SYNC_CLIENT_SOURCE_PATH_PARAM_NAME).build();
return MethodSpec.methodBuilder(methodName).returns(responseType).addModifiers(Modifier.PUBLIC, Modifier.DEFAULT).addParameter(inputVarParam).addParameter(srcPathParam).addJavadoc(opModel.getDocs(model, ClientType.SYNC, SimpleMethodOverload.FILE)).addExceptions(getExceptionClasses(model, opModel)).addStatement("return $L($N, $T.fromFile($N))", methodName, inputVarParam, ClassName.get(RequestBody.class), srcPathParam).build();
}
use of com.squareup.javapoet.ParameterSpec in project raml-module-builder by folio-org.
the class ResourceMethodExtensionPlugin method addAnnotations.
private Builder addAnnotations(GMethod method, MethodSpec.Builder methodSpec) {
MethodSpec.Builder ret = cloneMethodWithoutParams(methodSpec);
MethodSpec spec = methodSpec.build();
List<ParameterSpec> modifiedParams = new ArrayList<>(spec.parameters);
Iterator<GParameter> methodParams = method.queryParameters().iterator();
for (int j = 0; j < modifiedParams.size(); j++) {
ParameterSpec orgParam = modifiedParams.get(j);
List<AnnotationSpec> an = orgParam.annotations;
for (AnnotationSpec a : an) {
if (a.type.toString().equals("javax.ws.rs.QueryParam")) {
modifiedParams.set(j, annotateNew(methodParams.next(), orgParam));
}
if (a.type.toString().equals("javax.ws.rs.PathParam")) {
GResource curRes = method.resource();
while (curRes != null) {
for (GParameter u : curRes.uriParameters()) {
if (u.name().equals(orgParam.name)) {
modifiedParams.set(j, annotateNew(u, orgParam));
}
}
curRes = curRes.parentResource();
}
}
}
}
ret.addParameters(modifiedParams);
return ret;
}
Aggregations