From 30867385b7e41d470f7a94fa8815f233d75a39c0 Mon Sep 17 00:00:00 2001 From: Fred Bricon Date: Tue, 4 Jul 2023 12:04:56 +0200 Subject: [PATCH] feat: Add CodeAction to insert expected input for renarde #form Signed-off-by: Fred Bricon --- .../RenardeResolvedJavaTypeFactory.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/extensions/renarde/RenardeResolvedJavaTypeFactory.java b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/extensions/renarde/RenardeResolvedJavaTypeFactory.java index f19c35d03..f15772222 100644 --- a/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/extensions/renarde/RenardeResolvedJavaTypeFactory.java +++ b/src/main/java/com/redhat/devtools/intellij/qute/psi/internal/extensions/renarde/RenardeResolvedJavaTypeFactory.java @@ -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"; @@ -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, @@ -137,13 +146,18 @@ private static void collectJaxrsInfo(PsiMethod method, JavaMethodInfo info) { private static void fillRestParam(PsiParameter parameter, PsiAnnotation formAnnotation, JaxRsParamKind parameterKind, Map restParameters) { + fillRestParam(parameter, formAnnotation, parameterKind, restParameters, false); + } + + private static void fillRestParam(PsiParameter parameter, PsiAnnotation formAnnotation, + JaxRsParamKind parameterKind, Map 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) {