use of com.squareup.javapoet.ParameterSpec in project raml-module-builder by folio-org.
the class ResourceMethodExtensionPlugin method annotateNew.
private ParameterSpec annotateNew(GParameter get, ParameterSpec orgParam) {
TypeDeclaration typeDeclaration = (TypeDeclaration) get.implementation();
ParameterSpec.Builder newParam = cloneSingleParamNoAnnotations(orgParam);
List<AnnotationSpec> newAnnotations = getAnnotationsAsModifiableList(orgParam);
if (typeDeclaration instanceof StringTypeDeclaration) {
StringTypeDeclaration n = (StringTypeDeclaration) typeDeclaration;
if (n.pattern() != null) {
AnnotationSpec.Builder annoBuilder = AnnotationSpec.builder(javax.validation.constraints.Pattern.class);
annoBuilder.addMember("regexp", "$S", n.pattern());
newAnnotations.add(annoBuilder.build());
}
}
if (typeDeclaration instanceof NumberTypeDeclaration) {
NumberTypeDeclaration n = (NumberTypeDeclaration) typeDeclaration;
if (n.minimum() != null) {
AnnotationSpec.Builder annoBuilder = AnnotationSpec.builder(javax.validation.constraints.Min.class);
annoBuilder.addMember(ANNOTATION_VALUE, "$L", (Long) n.minimum().longValue());
newAnnotations.add(annoBuilder.build());
}
if (n.maximum() != null) {
AnnotationSpec.Builder annoBuilder = AnnotationSpec.builder(javax.validation.constraints.Max.class);
annoBuilder.addMember(ANNOTATION_VALUE, "$L", (Long) n.maximum().longValue());
newAnnotations.add(annoBuilder.build());
}
}
newParam.addAnnotations(newAnnotations);
return newParam.build();
}
use of com.squareup.javapoet.ParameterSpec in project web3j by web3j.
the class SolidityFunctionWrapper method addParameters.
String addParameters(MethodSpec.Builder methodBuilder, List<AbiDefinition.NamedType> namedTypes, boolean useNativeJavaTypes) throws ClassNotFoundException {
final List<ParameterSpec> inputParameterTypes = buildParameterTypes(namedTypes, useJavaPrimitiveTypes);
final List<ParameterSpec> nativeInputParameterTypes = new ArrayList<>(inputParameterTypes.size());
for (int i = 0; i < inputParameterTypes.size(); ++i) {
final TypeName typeName = getTypenameForArray(namedTypes.get(i), useJavaPrimitiveTypes);
nativeInputParameterTypes.add(ParameterSpec.builder(typeName, inputParameterTypes.get(i).name).build());
}
methodBuilder.addParameters(nativeInputParameterTypes);
if (useNativeJavaTypes) {
return Collection.join(inputParameterTypes, ", \n", // this results in fully qualified names being generated
this::createMappedParameterTypes);
} else {
return Collection.join(inputParameterTypes, ", ", parameterSpec -> parameterSpec.name);
}
}
use of com.squareup.javapoet.ParameterSpec in project conjure-java by palantir.
the class BeanBuilderGenerator method createAddFieldIfMissing.
private static MethodSpec createAddFieldIfMissing(int fieldCount) {
ParameterizedTypeName listOfStringType = ParameterizedTypeName.get(List.class, String.class);
ParameterSpec listParam = ParameterSpec.builder(listOfStringType, "prev").build();
ParameterSpec fieldValueParam = ParameterSpec.builder(TypeName.BOOLEAN, "initialized").build();
ParameterSpec fieldNameParam = ParameterSpec.builder(ClassName.get(String.class), "fieldName").build();
return MethodSpec.methodBuilder("addFieldIfMissing").addModifiers(Modifier.PRIVATE, Modifier.STATIC).returns(listOfStringType).addParameter(listParam).addParameter(fieldValueParam).addParameter(fieldNameParam).addStatement("$T missingFields = $N", listOfStringType, listParam).beginControlFlow("if (!$N)", fieldValueParam).beginControlFlow("if (missingFields == null)").addStatement("missingFields = new $T<>($L)", ArrayList.class, fieldCount).endControlFlow().addStatement("missingFields.add($N)", fieldNameParam).endControlFlow().addStatement("return missingFields").build();
}
use of com.squareup.javapoet.ParameterSpec in project conjure-java by palantir.
the class BeanGenerator method createAddFieldIfMissing.
private static MethodSpec createAddFieldIfMissing(int fieldCount) {
ParameterizedTypeName listOfStringType = ParameterizedTypeName.get(List.class, String.class);
ParameterSpec listParam = ParameterSpec.builder(listOfStringType, "prev").build();
ParameterSpec fieldValueParam = ParameterSpec.builder(ClassName.OBJECT, "fieldValue").build();
ParameterSpec fieldNameParam = ParameterSpec.builder(ClassName.get(String.class), "fieldName").build();
return MethodSpec.methodBuilder("addFieldIfMissing").addModifiers(Modifier.PRIVATE, Modifier.STATIC).returns(listOfStringType).addParameter(listParam).addParameter(fieldValueParam).addParameter(fieldNameParam).addStatement("$T missingFields = $N", listOfStringType, listParam).beginControlFlow("if ($N == null)", fieldValueParam).beginControlFlow("if (missingFields == null)").addStatement("missingFields = new $T<>($L)", ArrayList.class, fieldCount).endControlFlow().addStatement("missingFields.add($N)", fieldNameParam).endControlFlow().addStatement("return missingFields").build();
}
use of com.squareup.javapoet.ParameterSpec in project conjure-java by palantir.
the class JerseyServiceGenerator method createAuthParameter.
private Optional<ParameterSpec> createAuthParameter(Optional<AuthType> auth, boolean withAnnotations) {
if (!auth.isPresent()) {
return Optional.empty();
}
ClassName annotationClassName;
ClassName tokenClassName;
String paramName;
String tokenName;
if (auth.get().accept(AuthTypeVisitor.IS_HEADER)) {
annotationClassName = ClassName.get("javax.ws.rs", "HeaderParam");
tokenClassName = ClassName.get("com.palantir.tokens.auth", "AuthHeader");
paramName = Auth.AUTH_HEADER_PARAM_NAME;
tokenName = "Authorization";
} else if (auth.get().accept(AuthTypeVisitor.IS_COOKIE)) {
annotationClassName = ClassName.get("javax.ws.rs", "CookieParam");
tokenClassName = ClassName.get("com.palantir.tokens.auth", "BearerToken");
paramName = Auth.COOKIE_AUTH_PARAM_NAME;
tokenName = auth.get().accept(AuthTypeVisitor.COOKIE).getCookieName();
} else {
throw new IllegalStateException("Unrecognized auth type: " + auth.get());
}
ParameterSpec.Builder paramSpec = ParameterSpec.builder(tokenClassName, paramName);
if (withAnnotations) {
paramSpec.addAnnotation(AnnotationSpec.builder(annotationClassName).addMember("value", "$S", tokenName).build());
if (options.requireNotNullAuthAndBodyParams()) {
paramSpec.addAnnotation(AnnotationSpec.builder(NOT_NULL).build());
}
}
return Optional.of(paramSpec.build());
}
Aggregations