use of com.squareup.javapoet.ParameterizedTypeName in project microservice_framework by CJSCommonPlatform.
the class JaxRsImplementationGenerator method methodBodyForMultipartPost.
/**
* Supplier that produces code specific to a Multipart POST httpAction type.
*
* @param resourceMethodName name of the resource method
* @param actionType the HTTP action type for this method
* @param bodyMimeType the mime type to retrieve the file parts from
* @param responseStrategy the response strategy to pass to the ResponseStrategyFactory
* @return the supplier that returns the {@link CodeBlock}
*/
private Supplier<CodeBlock> methodBodyForMultipartPost(final String resourceMethodName, final ActionType actionType, final MimeType bodyMimeType, final String responseStrategy) {
final TypeName stringClassType = TypeName.get(String.class);
final ParameterizedTypeName listType = ParameterizedTypeName.get(ClassName.get(List.class), stringClassType);
final TypeName arrayClassType = TypeName.get(ArrayList.class);
return () -> CodeBlock.builder().addStatement("final $T $L = new $T<>()", listType, PART_DEFINITIONS_VARIABLE, arrayClassType).add(putAllFileFormPartsInPartDefinitionsBuilder(bodyMimeType)).addStatement(REST_PROCESSOR_MULTIPART_METHOD_STATEMENT, responseStrategy, INTERCEPTOR_CHAIN_PROCESSOR_FIELD, ACTION_MAPPER_FIELD, resourceMethodName, actionType.toString(), VALID_PARAMETER_COLLECTION_BUILDER_VARIABLE, FILE_INPUT_DETAILS_FACTORY_FIELD, MULTIPART_FORM_DATA_INPUT, PART_DEFINITIONS_VARIABLE).build();
}
use of com.squareup.javapoet.ParameterizedTypeName in project microservice_framework by CJSCommonPlatform.
the class JaxRsApplicationCodeGenerator method generateGetClassesMethod.
/**
* Generate the getClasses method that returns the set of implemented resource classes.
*
* @param implementationNames the collection of implementation class names
* @return the {@link MethodSpec} that represents the getClasses method
*/
private MethodSpec generateGetClassesMethod(final Collection<String> implementationNames) {
final ParameterizedTypeName wildcardClassType = ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class));
final ParameterizedTypeName classSetType = ParameterizedTypeName.get(ClassName.get(Set.class), wildcardClassType);
return MethodSpec.methodBuilder("getClasses").addModifiers(PUBLIC).addAnnotation(Override.class).addCode(CodeBlock.builder().addStatement("$T classes = $L.providers()", classSetType, COMMON_PROVIDERS_FIELD).add(statementsToAddClassToSetForEach(implementationNames)).addStatement("return classes").build()).returns(classSetType).build();
}
use of com.squareup.javapoet.ParameterizedTypeName in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildTupleResultContainer0.
private void buildTupleResultContainer0(MethodSpec.Builder methodBuilder, ParameterizedTypeName tupleType, List<TypeName> outputParameterTypes) throws ClassNotFoundException {
List<TypeName> typeArguments = tupleType.typeArguments;
CodeBlock.Builder codeBuilder = CodeBlock.builder();
String resultStringSimple = "\n($T) results.get($L)";
if (useNativeJavaTypes) {
resultStringSimple += ".getValue()";
}
String resultStringNativeList = "\nconvertToNative(($T) results.get($L).getValue())";
int size = typeArguments.size();
ClassName classList = ClassName.get(List.class);
for (int i = 0; i < size; i++) {
TypeName param = outputParameterTypes.get(i);
TypeName convertTo = typeArguments.get(i);
String resultString = resultStringSimple;
// elements of arrays to native java types too
if (useNativeJavaTypes && param instanceof ParameterizedTypeName) {
ParameterizedTypeName oldContainer = (ParameterizedTypeName) param;
ParameterizedTypeName newContainer = (ParameterizedTypeName) convertTo;
if (newContainer.rawType.compareTo(classList) == 0 && newContainer.typeArguments.size() == 1) {
convertTo = ParameterizedTypeName.get(classList, oldContainer.typeArguments.get(0));
resultString = resultStringNativeList;
}
}
codeBuilder.add(resultString, convertTo, i);
codeBuilder.add(i < size - 1 ? ", " : "\n");
}
methodBuilder.addStatement("return new $T(\n$L)", tupleType, codeBuilder.build());
}
use of com.squareup.javapoet.ParameterizedTypeName in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method buildFunctionWithInputDecoder.
private MethodSpec buildFunctionWithInputDecoder(AbiDefinition functionDefinition, boolean isOverLoad) throws ClassNotFoundException {
String functionName = getInputOutputFunctionName(functionDefinition, isOverLoad);
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("get" + Strings.capitaliseFirstLetter(functionName) + "Input").addModifiers(Modifier.PUBLIC).addParameter(TransactionReceipt.class, "transactionReceipt");
List<TypeName> returnTypes = buildReturnTypes(buildTypeNames(functionDefinition.getInputs()));
ParameterizedTypeName parameterizedTupleType = ParameterizedTypeName.get(ClassName.get("org.fisco.bcos.web3j.tuples.generated", "Tuple" + returnTypes.size()), returnTypes.toArray(new TypeName[returnTypes.size()]));
methodBuilder.returns(parameterizedTupleType);
methodBuilder.addStatement("String data = transactionReceipt.getInput().substring(10)");
buildVariableLengthReturnFunctionConstructor(methodBuilder, functionDefinition.getName(), "", buildTypeNames(functionDefinition.getInputs()));
methodBuilder.addStatement("$T<Type> results = $T.decode(data, function.getOutputParameters());", List.class, FunctionReturnDecoder.class);
buildTupleResultContainer0(methodBuilder, parameterizedTupleType, buildTypeNames(functionDefinition.getInputs()));
return methodBuilder.build();
}
use of com.squareup.javapoet.ParameterizedTypeName in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method createMappedParameterTypes.
private String createMappedParameterTypes(AbiDefinition.NamedType namedType) {
String name = namedType.getName();
String type = namedType.getType();
AbiDefinition.NamedType.Type innerType = new AbiDefinition.NamedType.Type(type);
ParameterSpec parameterSpec = ParameterSpec.builder(buildTypeName(type), name).build();
if (parameterSpec.type instanceof ParameterizedTypeName) {
List<TypeName> typeNames = ((ParameterizedTypeName) parameterSpec.type).typeArguments;
if (typeNames.size() != 1) {
throw new UnsupportedOperationException("Only a single parameterized type is supported");
} else {
String parameterSpecType = parameterSpec.type.toString();
TypeName typeName = typeNames.get(0);
String typeMapInput = typeName + ".class";
if (typeName instanceof ParameterizedTypeName) {
List<TypeName> typeArguments = ((ParameterizedTypeName) typeName).typeArguments;
if (typeArguments.size() != 1) {
throw new UnsupportedOperationException("Only a single parameterized type is supported");
}
TypeName innerTypeName = typeArguments.get(0);
parameterSpecType = ((ParameterizedTypeName) parameterSpec.type).rawType.toString();
typeMapInput = ((ParameterizedTypeName) typeName).rawType + ".class, " + innerTypeName + ".class";
}
if (innerType.dynamicArray()) {
// dynamic array
return parameterSpec.name + ".isEmpty()?org.fisco.bcos.web3j.abi.datatypes.DynamicArray.empty" + "(\"" + type + "\"):" + "new " + parameterSpecType + "(\n" + " org.fisco.bcos.web3j.abi.Utils.typeMap(" + parameterSpec.name + ", " + typeMapInput + "))";
} else {
// static array
return "new " + parameterSpecType + "(\n" + " org.fisco.bcos.web3j.abi.Utils.typeMap(" + parameterSpec.name + ", " + typeMapInput + "))";
}
}
} else {
return "new " + parameterSpec.type + "(" + parameterSpec.name + ")";
}
}
Aggregations