Skip to content

Commit

Permalink
Validation factory parameter order (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodforGod authored Jul 24, 2023
1 parent c166334 commit e908f3b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ public static List<ValidMeta.Constraint> getValidatedByConstraints(ProcessingEnv
.filter(ft -> ft instanceof DeclaredType)
.map(factoryType -> {
final DeclaredType factoryRawType = (DeclaredType) factoryType;
final Map<String, Object> parameters = env.getElementUtils().getElementValuesWithDefaults(annotation).entrySet().stream()
final Map<String, Object> parametersWithDefaults = env.getElementUtils().getElementValuesWithDefaults(annotation).entrySet().stream()
.collect(Collectors.toMap(
ae -> ae.getKey().getSimpleName().toString(),
ae -> castParameterValue(ae.getValue()),
(v1, v2) -> v2,
LinkedHashMap::new
));

final Map<String, Object> parameters = new LinkedHashMap<>();
for (Element parameter : annotation.getAnnotationType().asElement().getEnclosedElements()) {
if (parameter instanceof ExecutableElement ep) {
final String parameterName = ep.getSimpleName().toString();
final Object parameterValue = parametersWithDefaults.get(parameterName);
parameters.put(parameterName, parameterValue);
}
}

if (parameters.size() > 0) {
factoryRawType.asElement().getEnclosedElements()
.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ protected Validator<ValidBar> getBarValidator() {
return (Validator<ValidBar>) clazz.getConstructors()[0].newInstance(
sizeListConstraintFactory(TypeRef.of(Integer.class)),
notBlankStringConstraintFactory(),
sizeStringConstraintFactory(),
listValidator(getTazValidator(), TypeRef.of(ValidTaz.class)));
} catch (RuntimeException e) {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class ValidBar {

@Nullable
@NotBlank
@Size(max = 50)
private String id;
@Size(min = 1, max = 5)
@Size(max = 5, min = 1)
private List<Integer> codes;
@Valid
private List<ValidTaz> tazs;
Expand Down

0 comments on commit e908f3b

Please sign in to comment.