use of com.squareup.javapoet.ParameterSpec in project celesta by CourseOrchestra.
the class CursorGenerator method buildSetAutoIncrement.
private MethodSpec buildSetAutoIncrement(Map<String, ? extends ColumnMeta<?>> columns) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("_setAutoIncrement").addModifiers(Modifier.PROTECTED).addAnnotation(Override.class);
ParameterSpec param = ParameterSpec.builder(int.class, "val").build();
builder.addParameter(param);
columns.entrySet().stream().filter(e -> e.getValue() instanceof IntegerColumn).filter(e -> ((IntegerColumn) e.getValue()).getSequence() != null).findAny().ifPresent(e -> builder.addStatement("this.$N = $N", camelize(e.getKey()), param.name));
return builder.build();
}
use of com.squareup.javapoet.ParameterSpec in project web3j by web3j.
the class SolidityFunctionWrapper method buildParameterTypes.
private List<ParameterSpec> buildParameterTypes(List<AbiDefinition.NamedType> namedTypes, boolean primitives) throws ClassNotFoundException {
List<ParameterSpec> result = new ArrayList<>(namedTypes.size());
for (int i = 0; i < namedTypes.size(); i++) {
AbiDefinition.NamedType namedType = namedTypes.get(i);
String name = createValidParamName(namedType.getName(), i);
String type = namedTypes.get(i).getType();
if (type.equals("tuple")) {
result.add(ParameterSpec.builder(structClassNameMap.get(namedType.structIdentifier()), name).build());
} else if (type.startsWith("tuple") && type.contains("[")) {
result.add(ParameterSpec.builder(buildStructArrayTypeName(namedType, primitives), name).build());
} else {
result.add(ParameterSpec.builder(buildTypeName(type, primitives), name).build());
}
}
return result;
}
use of com.squareup.javapoet.ParameterSpec in project web3j by web3j.
the class MethodSpecGeneratorTest method testGenerate.
@Test
public void testGenerate() {
List<ParameterSpec> parameterSpec = Collections.singletonList(ParameterSpec.builder(Web3j.class, "web3j", Modifier.FINAL).build());
String javaPoetStringFormat1 = "$T $L = $S";
Object[] replacementValues1 = new Object[] { String.class, "hello ", "Hello how are you" };
String javaPoetStringFormat2 = "$T $L = $T.build()";
Object[] replacementValues2 = new Object[] { Web3j.class, "web3j", Web3j.class };
Map<String, Object[]> statementBody = new LinkedHashMap<>();
statementBody.put(javaPoetStringFormat1, replacementValues1);
statementBody.put(javaPoetStringFormat2, replacementValues2);
MethodSpecGenerator methodSpecGenerator = new MethodSpecGenerator("unitTest", Test.class, Modifier.PUBLIC, parameterSpec, statementBody);
MethodSpec generatedMethodSpec = methodSpecGenerator.generate();
assertEquals("@org.junit.jupiter.api.Test\n" + "public void unitTest(final org.web3j.protocol.Web3j web3j) throws java.lang.Exception {\n" + " java.lang.String hello = \"Hello how are you\";\n" + " org.web3j.protocol.Web3j web3j = org.web3j.protocol.Web3j.build();\n" + "}\n", generatedMethodSpec.toString());
}
use of com.squareup.javapoet.ParameterSpec in project dialogue by palantir.
the class ServiceImplementationGenerator method clientImpl.
private MethodSpec clientImpl(EndpointDefinition def) {
List<ParameterSpec> params = def.arguments().stream().map(arg -> ParameterSpec.builder(ArgumentTypes.caseOf(arg.argType()).primitive((javaTypeName, _parameterSerializerMethodName, _isList) -> javaTypeName).rawRequestBody(typeName -> typeName).optional((optionalJavaType, _unused) -> optionalJavaType).mapType(typeName -> typeName).customType(typeName -> typeName), arg.argName().get()).build()).collect(Collectors.toList());
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(def.endpointName().get()).addModifiers(Modifier.PUBLIC).addParameters(params).addAnnotation(Override.class);
methodBuilder.addCode("$T $L = $T.builder();", Request.Builder.class, REQUEST, Request.class);
def.arguments().forEach(arg -> methodBuilder.addCode(generateParam(arg)));
methodBuilder.returns(def.returns().returnType());
boolean isAsync = def.returns().asyncInnerType().isPresent();
String executeCode = isAsync ? "$L.clients().call($L, $L.build(), $L);" : "$L.clients().callBlocking($L, $L.build(), $L);";
CodeBlock execute = CodeBlock.of(executeCode, serviceDefinition.conjureRuntimeArgName(), def.channelFieldName(), REQUEST, def.returns().deserializerFieldName());
methodBuilder.addCode(!def.returns().isVoid() || isAsync ? "return $L" : "$L", execute);
return methodBuilder.build();
}
use of com.squareup.javapoet.ParameterSpec in project web3sdk by FISCO-BCOS.
the class SolidityFunctionWrapper method addParameter.
private MethodSpec.Builder addParameter(MethodSpec.Builder methodBuilder, String type, String name) {
ParameterSpec parameterSpec = buildParameterType(type, name);
TypeName typeName = getWrapperType(parameterSpec.type);
ParameterSpec inputParameter = ParameterSpec.builder(typeName, parameterSpec.name).build();
methodBuilder.addParameter(inputParameter);
return methodBuilder;
}
Aggregations