<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 13, 2017 at 10:55 AM, Gunnar Morling <span dir="ltr"><<a href="mailto:gunnar@hibernate.org" target="_blank">gunnar@hibernate.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Right, Emmanuel's example isn't legal:<br>
<br>
"It is a compile-time error if, in a declaration context or type<br>
context, there are multiple annotations of a repeatable annotation<br>
type T and any annotations of the containing annotation type of T."<br>
<br>
But it's also says that given a single instance of the repeatable<br>
annotation type and the container annotation is valid:<br>
<br>
@Min<br>
@Min.List({@Min})<br>
BooYahh foo;<br>
<br>
I'm not sure how the ordering is defined - and if so, how. If we could<br>
confirm that this case can be resolved deterministically, too, then it<br>
should be doable.<br></blockquote><div><br></div><div>Oh, right. :) Yeah, it would probably be natural to assume that the resulting Min.List would contain all Min annotations in the order in which they were encountered, but any assumption could also be dangerous. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> A meta-annotation might look cleaner, but it might become painful to define a lot of these.<br>
<br>
</span>What exactly do you mean here? Can you give an example?<br>
<div class="gmail-HOEnZb"><div class="gmail-h5"><br></div></div></blockquote><div><br></div><div>I'm thinking of an extension to the composed constraint feature. So:</div><div><br></div><div>@Size(min=3)</div><div>@ConstraintsApplyTo(WRAPPED_VALUE)</div><div>@Constraint</div><div>public @interface Nickname {</div><div> String message() default "";</div><div> Class<?> groups() default {};</div><div> Class<? extends Payload>[] payload() default {};</div><div>}</div><div><br></div><div><span style="font-size:12.8px">@Size(min=1) @Nickname </span><span style="font-size:12.8px">List<String> nicknames;</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">The example is necessarily contrived where we're talking about a "normal" typed extraction container, but should be applicable to:</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">@Size(min=1) @Nickname StringList nicknames;</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">As I warned, however, defining these might become tedious. It might be helpful to define a mechanism (like that supported by Spring) to map annotation elements:</span></div><div><span style="font-size:12.8px"><br></span></div><div><div>@Size</div><div>@ConstraintsApplyTo(WRAPPED_VALUE)</div><div>@Constraint</div><div>public @interface WrappedSize {</div><div><br></div><div> @MapTo(type=Size.class, attribute="min")</div><div> int min() default 0;</div><div><br></div><div> @MapTo(type=Size.class, attribute="max")</div><div> int max() default Integer.MAX_VALUE;</div><div><br></div><div><div> String message() default "";</div><div> Class<?> groups() default {};</div><div> Class<? extends Payload>[] payload() default {};</div></div><div>}</div></div><div><br></div><div><div><span style="font-size:12.8px">@Size(1) @WrappedSize(min=3) StringList nicknames;</span></div></div><div><br></div><div><span style="font-size:12.8px">Matt</span></div><div><span style="font-size:12.8px"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">
<br>
2017-01-13 17:39 GMT+01:00 Matt Benson <<a href="mailto:mbenson@apache.org">mbenson@apache.org</a>>:<br>
><br>
><br>
> On Fri, Jan 13, 2017 at 10:23 AM, Matt Benson <<a href="mailto:mbenson@apache.org">mbenson@apache.org</a>> wrote:<br>
>><br>
>><br>
>> On Fri, Jan 13, 2017 at 8:57 AM, Emmanuel Bernard <<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>><br>
>> wrote:<br>
>>><br>
>>> s/other/order from the JVM/<br>
>>><br>
>>> > On 13 Jan 2017, at 15:54, Emmanuel Bernard <<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>><br>
>>> > wrote:<br>
>>> ><br>
>>> > I looked at that, and I’m not sure you are guaranteed to get an other.<br>
>>> > Plus you have this problem<br>
>>> ><br>
>>> > @Min<br>
>>> > @Min.List({@Min, @Min})<br>
>>> > @Min<br>
>>> > BooYahh foo;<br>
>>> ><br>
>><br>
>><br>
>> I would have thought the same; however per [1] order is guaranteed. Your<br>
>> additional concern is still there. Maybe it would be cleaner to support this<br>
>> using meta-constraint annotations.<br>
><br>
><br>
> Actually, per the same section of the JLS, your example is referred to as<br>
> "obtuse" (which I'm sure was the point you were making) would generate a<br>
> compile error. So we could perhaps support Gunnar's approach after all. A<br>
> meta-annotation might look cleaner, but it might become painful to define a<br>
> lot of these.<br>
><br>
> Matt<br>
>><br>
>><br>
>>><br>
>>> >> On 13 Jan 2017, at 15:22, Gunnar Morling <<a href="mailto:gunnar@hibernate.org">gunnar@hibernate.org</a>> wrote:<br>
>>> >><br>
>>> >> As a variation of Matt's idea, an optional index() parameter could be<br>
>>> >> added:<br>
>>> >><br>
>>> >> @Size(1)<br>
>>> >> @Size(3)<br>
>>> >> @ApplyConstraintTo(constraint=<wbr>Size.class, index=1,<br>
>>> >> target=WRAPPED_VALUE)<br>
>>> >> List<String> nicknames;<br>
>>> >><br>
>>> >> It could be omitted (via a default value of -1 or similar) if there is<br>
>>> >> only one constraint of the type in question:<br>
>>> >><br>
>>> >> @NotNull<br>
>>> >> @Email<br>
>>> >> @ApplyConstraintTo(constraint=<wbr>NotNull.class,<br>
>>> >> target=ANNOTATED_ELEMENT)<br>
>>> >> Optional<String> email;<br>
>>> >><br>
>>> >> Does the trick, though it's still a tad verbose.<br>
>>> >><br>
>>> >><br>
>>> >> 2017-01-13 14:58 GMT+01:00 Emmanuel Bernard <<a href="mailto:emmanuel@hibernate.org">emmanuel@hibernate.org</a>>:<br>
>>> >>><br>
>>> >>> On 13 Jan 2017, at 13:29, Guillaume Smet <<a href="mailto:guillaume.smet@gmail.com">guillaume.smet@gmail.com</a>><br>
>>> >>> wrote:<br>
>>> >>><br>
>>> >>> On Fri, Jan 13, 2017 at 1:01 PM, Gunnar Morling<br>
>>> >>> <<a href="mailto:gunnar@hibernate.org">gunnar@hibernate.org</a>><br>
>>> >>> wrote:<br>
>>> >>>><br>
>>> >>>> Unfortunately, validationAppliesTo() is already taken:<br>
>>> >>>><br>
>>> >>>><br>
>>> >>>> <a href="http://beanvalidation.org/latest-draft/spec/#constraintsdefinitionimplementation-constraintdefinition-validationappliesto" rel="noreferrer" target="_blank">http://beanvalidation.org/<wbr>latest-draft/spec/#<wbr>constraintsdefinitionimplement<wbr>ation-constraintdefinition-<wbr>validationappliesto</a><br>
>>> >>>><br>
>>> >>>> It's used to distinguish between return value and cross-parameter<br>
>>> >>>> constraints.<br>
>>> >>>><br>
>>> >>>> Any other name I can think of right now would make up for much<br>
>>> >>>> confusion with that option.<br>
>>> >>><br>
>>> >>><br>
>>> >>> Too good to be true :).<br>
>>> >>><br>
>>> >>> That being said, I'm wondering if we could reuse it and just add 2<br>
>>> >>> other<br>
>>> >>> values to ConstraintTarget. All in all, it's the same concept. The<br>
>>> >>> default<br>
>>> >>> being IMPLICIT is not too bad either.<br>
>>> >>><br>
>>> >>><br>
>>> >>> Right I think it’s worth exploring.<br>
>>> >>> I still like my group repurposing trick though even if it offenses<br>
>>> >>> the clean<br>
>>> >>> camp :)<br>
>>> >>><br>
>><br>
>><br>
>> I still can't figure out how you would use the group trick in conjunction<br>
>> with validation of a "real" group.<br>
>><br>
>> Matt<br>
>><br>
>> [1] <a href="http://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.7.5" rel="noreferrer" target="_blank">http://docs.oracle.com/javase/<wbr>specs/jls/se8/html/jls-9.html#<wbr>jls-9.7.5</a><br>
>><br>
>>><br>
>>> >>> ______________________________<wbr>_________________<br>
>>> >>> beanvalidation-dev mailing list<br>
>>> >>> <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
>>> >>> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
>>> >><br>
>>> >> ______________________________<wbr>_________________<br>
>>> >> beanvalidation-dev mailing list<br>
>>> >> <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
>>> >> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
>>> ><br>
>>> ><br>
>>> > ______________________________<wbr>_________________<br>
>>> > beanvalidation-dev mailing list<br>
>>> > <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
>>> > <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
>>><br>
>>><br>
>>> ______________________________<wbr>_________________<br>
>>> beanvalidation-dev mailing list<br>
>>> <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
>>> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
>><br>
>><br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> beanvalidation-dev mailing list<br>
> <a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
> <a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a><br>
<br>
______________________________<wbr>_________________<br>
beanvalidation-dev mailing list<br>
<a href="mailto:beanvalidation-dev@lists.jboss.org">beanvalidation-dev@lists.<wbr>jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/beanvalidation-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/<wbr>beanvalidation-dev</a></div></div></blockquote></div><br></div></div>