Skip to content

Commit

Permalink
feat: Add CodeAction to insert expected input for renarde #form
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jul 4, 2023
1 parent 1c9f7f7 commit 3086738
Showing 1 changed file with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public class RenardeResolvedJavaTypeFactory extends AbstractResolvedJavaTypeFact

private static final String JAKARTA_WS_RS_FORM_PARAM_ANNOTATION = "jakarta.ws.rs.FormParam";


private static final String JAVAX_VALIDATION_CONSTRAINTS_NOTBLANK_ANNOTATION = "javax.validation.constraints.NotBlank";

private static final String JAKARTA_VALIDATION_CONSTRAINTS_NOTBLANK_ANNOTATION = "jakarta.validation.constraints.NotBlank";

private static final String REST_PATH_ANNOTATION = "org.jboss.resteasy.reactive.RestPath";

private static final String JAVAX_WS_RS_PATH_PARAM_ANNOTATION = "javax.ws.rs.PathParam";
Expand Down Expand Up @@ -104,7 +109,11 @@ private static void collectJaxrsInfo(PsiMethod method, JavaMethodInfo info) {
if (restParameters == null) {
restParameters = new HashMap<>();
}
fillRestParam(parameter, formAnnotation, JaxRsParamKind.FORM, restParameters);
PsiAnnotation notBlankAnnotation = AnnotationUtils.getAnnotation(parameter,
JAVAX_VALIDATION_CONSTRAINTS_NOTBLANK_ANNOTATION,
JAKARTA_VALIDATION_CONSTRAINTS_NOTBLANK_ANNOTATION);
boolean required = notBlankAnnotation != null;
fillRestParam(parameter, formAnnotation, JaxRsParamKind.FORM, restParameters, required);
} else {
// @RestPath, @PathParam
PsiAnnotation pathAnnotation = AnnotationUtils.getAnnotation(parameter, REST_PATH_ANNOTATION,
Expand Down Expand Up @@ -137,13 +146,18 @@ private static void collectJaxrsInfo(PsiMethod method, JavaMethodInfo info) {

private static void fillRestParam(PsiParameter parameter, PsiAnnotation formAnnotation,
JaxRsParamKind parameterKind, Map<String, RestParam> restParameters) {
fillRestParam(parameter, formAnnotation, parameterKind, restParameters, false);
}

private static void fillRestParam(PsiParameter parameter, PsiAnnotation formAnnotation,
JaxRsParamKind parameterKind, Map<String, RestParam> restParameters, boolean required) {
String parameterName = parameter.getName();
String formName = parameterName;
String value = AnnotationUtils.getAnnotationMemberValue(formAnnotation, "value");
if (value != null) {
formName = value;
}
restParameters.put(parameterName, new RestParam(formName, parameterKind, false));
restParameters.put(parameterName, new RestParam(formName, parameterKind, required));
}

private static boolean isPostMethod(PsiMethod method) {
Expand Down

0 comments on commit 3086738

Please sign in to comment.