Author: gunnar.morling
Date: 2010-09-05 06:48:06 -0400 (Sun, 05 Sep 2010)
New Revision: 20310
Added:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
Log:
HV-299: Implemented check, that each constraint annotation type defines the members
groups() and payload()
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
===================================================================
---
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java 2010-09-04
07:40:43 UTC (rev 20309)
+++
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java 2010-09-05
10:48:06 UTC (rev 20310)
@@ -18,11 +18,20 @@
package org.hibernate.validator.ap.checks;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.WildcardType;
+import javax.lang.model.util.SimpleAnnotationValueVisitor6;
+import javax.lang.model.util.TypeKindVisitor6;
import javax.lang.model.util.Types;
+import javax.validation.Payload;
import org.hibernate.validator.ap.util.AnnotationApiHelper;
import org.hibernate.validator.ap.util.CollectionHelper;
@@ -30,7 +39,8 @@
import static javax.lang.model.util.ElementFilter.methodsIn;
/**
- * Checks, that each constraint annotation type declares the members message(), groups()
and payload().
+ * Checks, that each constraint annotation type declares the members message(), groups()
and payload() as
+ * defined by the BV spec.
*
* @author Gunnar Morling
*/
@@ -58,6 +68,18 @@
return theValue;
}
+ /**
+ * Checks that the given type element
+ * <p/>
+ * <ul>
+ * <li>has a method with name "message",</li>
+ * <li>the return type of this method is {@link String}.</li>
+ * </ul>
+ *
+ * @param element The element of interest.
+ *
+ * @return A possibly non-empty set of constraint check errors, never null.
+ */
private Set<ConstraintCheckError> checkMessageAttribute(TypeElement element) {
ExecutableElement messageMethod = getMethod( element, "message" );
@@ -79,14 +101,116 @@
return Collections.emptySet();
}
+ /**
+ * Checks that the given type element
+ * <p/>
+ * <ul>
+ * <li>has a method with name "groups",</li>
+ * <li>the return type of this method is
<code>Class<?>[]</code>,</li>
+ * <li>the default value of this method is
<code>{}</code>.</li>
+ * </ul>
+ *
+ * @param element The element of interest.
+ *
+ * @return A possibly non-empty set of constraint check errors, never null.
+ */
private Set<ConstraintCheckError> checkGroupsAttribute(TypeElement element) {
+
+ ExecutableElement groupsMethod = getMethod( element, "groups" );
+
+ if ( groupsMethod == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( element, null,
"CONSTRAINT_TYPE_MUST_DECLARE_GROUPS_MEMBER" )
+ );
+ }
+
+ DeclaredType type = getComponentTypeOfArrayReturnType( groupsMethod );
+
+ if ( type == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( groupsMethod, null,
"RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ boolean typeHasNameClass = type.asElement().getSimpleName().contentEquals(
"Class" );
+ boolean typeHasExactlyOneTypeArgument = type.getTypeArguments().size() == 1;
+ boolean typeArgumentIsUnboundWildcard = validateWildcardBounds(
type.getTypeArguments().get( 0 ), null, null );
+
+ if ( !( typeHasNameClass && typeHasExactlyOneTypeArgument &&
typeArgumentIsUnboundWildcard ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( groupsMethod, null,
"RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ if ( !isEmptyArray( groupsMethod.getDefaultValue() ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( groupsMethod, null,
"DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY" )
+ );
+ }
+
return Collections.emptySet();
}
+ /**
+ * Checks that the given type element
+ * <p/>
+ * <ul>
+ * <li>has a method with name "payload",</li>
+ * <li>the return type of this method is <code>Class<? extends
Payload>[]</code>,</li>
+ * <li>the default value of this method is
<code>{}</code>.</li>
+ * </ul>
+ *
+ * @param element The element of interest.
+ *
+ * @return A possibly non-empty set of constraint check errors, never null.
+ */
private Set<ConstraintCheckError> checkPayloadAttribute(TypeElement element) {
+
+ ExecutableElement payloadMethod = getMethod( element, "payload" );
+
+ if ( payloadMethod == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( element, null,
"CONSTRAINT_TYPE_MUST_DECLARE_PAYLOAD_MEMBER" )
+ );
+ }
+
+ DeclaredType type = getComponentTypeOfArrayReturnType( payloadMethod );
+
+ if ( type == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( payloadMethod, null,
"PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ boolean typeHasNameClass = type.asElement().getSimpleName().contentEquals(
"Class" );
+ boolean typeHasExactlyOneTypeArgument = type.getTypeArguments().size() == 1;
+ boolean typeArgumentIsWildcardWithPayloadExtendsBound = validateWildcardBounds(
+ type.getTypeArguments().get( 0 ), annotationApiHelper.getMirrorForType( Payload.class
), null
+ );
+
+ if ( !( typeHasNameClass && typeHasExactlyOneTypeArgument &&
typeArgumentIsWildcardWithPayloadExtendsBound ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( payloadMethod, null,
"PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ if ( !isEmptyArray( payloadMethod.getDefaultValue() ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( payloadMethod, null,
"PAYLOAD_DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY" )
+ );
+ }
+
return Collections.emptySet();
}
+ /**
+ * Returns the method of the given type with the given name.
+ *
+ * @param element The type of interest.
+ * @param name The name of the method which should be returned.
+ *
+ * @return The method of the given type with the given name or null if no such method
exists.
+ */
private ExecutableElement getMethod(TypeElement element, String name) {
for ( ExecutableElement oneMethod : methodsIn( element.getEnclosedElements() ) ) {
@@ -99,4 +223,91 @@
return null;
}
+ /**
+ * Returns the component type of the array-typed return value of the given method.
+ *
+ * @param method The method of interest.
+ *
+ * @return The component type of the array-typed return value of the given method or
null,
+ * if the given method has no array-typed return value.
+ */
+ private DeclaredType getComponentTypeOfArrayReturnType(ExecutableElement method) {
+
+ return method.getReturnType().accept(
+ new TypeKindVisitor6<DeclaredType, Void>() {
+
+ @Override
+ public DeclaredType visitArray(ArrayType t, Void p) {
+
+ return t.getComponentType().accept(
+ new TypeKindVisitor6<DeclaredType, Void>() {
+
+ @Override
+ public DeclaredType visitDeclared(DeclaredType t, Void p) {
+ return t;
+ }
+
+ }, null
+ );
+ }
+
+ }, null
+ );
+
+ }
+
+ /**
+ * Returns true, if the given type mirror is a wildcard type with the given extends and
super bounds, false otherwise.
+ *
+ * @param type The type to check.
+ * @param expectedExtendsBound A mirror representing the expected extends bound.
+ * @param expectedSuperBound A mirror representing the expected super bound.
+ *
+ * @return True, if the given type mirror is a wildcard type with the given extends and
super bounds, false otherwise.
+ */
+ private boolean validateWildcardBounds(TypeMirror type, final TypeMirror
expectedExtendsBound, final TypeMirror expectedSuperBound) {
+
+ Boolean theValue = type.accept(
+ new TypeKindVisitor6<Boolean, Void>() {
+
+ @Override
+ public Boolean visitWildcard(WildcardType t, Void p) {
+
+ boolean extendsBoundMatches = ( t.getExtendsBound() == null ? expectedExtendsBound
== null : expectedExtendsBound != null && typeUtils
+ .isSameType( t.getExtendsBound(), expectedExtendsBound ) );
+ boolean superBoundMatches = ( t.getSuperBound() == null ? expectedSuperBound ==
null : expectedSuperBound != null && typeUtils
+ .isSameType( t.getSuperBound(), expectedSuperBound ) );
+
+ return extendsBoundMatches && superBoundMatches;
+ }
+
+ }, null
+ );
+
+ return Boolean.TRUE.equals( theValue );
+ }
+
+ /**
+ * Checks whether the given annotation value is an empty array or not.
+ *
+ * @param annotationValue The annotation value of interest.
+ *
+ * @return True, if the given annotation value is an empty array, false otherwise.
+ */
+ private boolean isEmptyArray(AnnotationValue annotationValue) {
+
+ return annotationValue != null && Boolean.TRUE.equals(
+ annotationValue.accept(
+ new SimpleAnnotationValueVisitor6<Boolean, Void>() {
+
+ @Override
+ public Boolean visitArray(List<? extends AnnotationValue> values, Void p) {
+ return values.size() == 0;
+ }
+
+ }, null
+ )
+ );
+ }
+
}
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
===================================================================
---
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-09-04
07:40:43 UTC (rev 20309)
+++
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-09-05
10:48:06 UTC (rev 20310)
@@ -16,3 +16,9 @@
CONSTRAINT_TYPE_WITHOUT_VALIDATOR=For non-composed constraints a validator implementation
must be specified using @Constraint#validatedBy().
CONSTRAINT_TYPE_MUST_DECLARE_MESSAGE_MEMBER=Constraint annotation types must declare a
member 'String message()'.
RETURN_TYPE_MUST_BE_STRING=Return type of constraint annotation type member
'message()' must be 'String'.
+CONSTRAINT_TYPE_MUST_DECLARE_GROUPS_MEMBER=Constraint annotation types must declare a
member 'Class<?>[] groups() default {}'.
+RETURN_TYPE_MUST_BE_CLASS_ARRAY=Return type of constraint annotation type member
'groups()' must be 'Class<?>[]'.
+DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY=Default value of the 'groups()' member must be
an empty array.
+CONSTRAINT_TYPE_MUST_DECLARE_PAYLOAD_MEMBER=Constraint annotation types must declare a
member 'Class<? extends Payload>[] payload() default {}'.
+PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY=Return type of constraint annotation type member
'payload()' must be 'Class<? extends Payload>[]'.
+PAYLOAD_DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY=Default value of the 'payload()' member
must be an empty array.
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
---
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-09-04
07:40:43 UTC (rev 20309)
+++
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-09-05
10:48:06 UTC (rev 20310)
@@ -24,7 +24,9 @@
import
org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalRetentionPolicies;
import
org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalTargets;
+import
org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongGroupsAttribute;
import
org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongMessageAttribute;
+import
org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongPayloadAttribute;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithoutValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.DummyValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
@@ -118,4 +120,50 @@
new DiagnosticExpectation( Kind.ERROR, 35 ), new DiagnosticExpectation( Kind.ERROR,
50 )
);
}
+
+ @Test
+ public void
testThatConstraintAnnotationTypeWithMissingOrWrongGroupsAttributeCausesCompilationError()
{
+
+ File sourceFile1 = compilerHelper.getSourceFile(
ConstraintsWithWrongGroupsAttribute.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics,
sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 35 ),
+ new DiagnosticExpectation( Kind.ERROR, 52 ),
+ new DiagnosticExpectation( Kind.ERROR, 67 ),
+ new DiagnosticExpectation( Kind.ERROR, 82 ),
+ new DiagnosticExpectation( Kind.ERROR, 97 ),
+ new DiagnosticExpectation( Kind.ERROR, 112 ),
+ new DiagnosticExpectation( Kind.ERROR, 127 )
+ );
+ }
+
+ @Test
+ public void
testThatConstraintAnnotationTypeWithMissingOrPayloadGroupsAttributeCausesCompilationError()
{
+
+ File sourceFile1 = compilerHelper.getSourceFile(
ConstraintsWithWrongPayloadAttribute.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics,
sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 35 ),
+ new DiagnosticExpectation( Kind.ERROR, 53 ),
+ new DiagnosticExpectation( Kind.ERROR, 68 ),
+ new DiagnosticExpectation( Kind.ERROR, 83 ),
+ new DiagnosticExpectation( Kind.ERROR, 98 ),
+ new DiagnosticExpectation( Kind.ERROR, 113 ),
+ new DiagnosticExpectation( Kind.ERROR, 128 ),
+ new DiagnosticExpectation( Kind.ERROR, 143 )
+ );
+ }
+
}
Added:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
===================================================================
---
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
(rev 0)
+++
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java 2010-09-05
10:48:06 UTC (rev 20310)
@@ -0,0 +1,148 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithWrongGroupsAttribute {
+
+ /**
+ * Compilation error expected due to missing groups attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithoutGroupsParameter {
+
+ String message() default "";
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute of wrong type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithWrongType1 {
+
+ String message() default "";
+
+ int[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute of non-array class type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithWrongType2 {
+
+ String message() default "";
+
+ Class<?> groups();
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute with super bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithSuperBound {
+
+ String message() default "";
+
+ Class<? super Long>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute with extends bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithExtendsBound {
+
+ String message() default "";
+
+ Class<? extends Long>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due missing default value for groups attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithoutDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups();
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to non-empty default value for groups attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithNonEmptyDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups() default { Object.class };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * No compilation error expected.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithCorrectGroupsParameter {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+}
Property changes on:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
===================================================================
---
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
(rev 0)
+++
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java 2010-09-05
10:48:06 UTC (rev 20310)
@@ -0,0 +1,165 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithWrongPayloadAttribute {
+
+ /**
+ * Compilation error expected due to missing payload attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithoutPayloadParameter {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+ }
+
+ /**
+ * Compilation error expected due to payload attribute of wrong type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithWrongType1 {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ int[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute of non-array class type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithWrongType2 {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload> payload();
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute with wrong extends bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithWrongExtendsBound {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Long>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute without extend bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithoutExtendsBound {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<?>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute with super bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithSuperBound {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? super Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due missing default value for payload attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithoutDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload();
+
+ }
+
+ /**
+ * Compilation error expected due to non-empty default value for payload attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithNonEmptyDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { SamplePayload.class };
+
+ }
+
+ /**
+ * No compilation error expected.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithCorrectPayloadParameter {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ public static class SamplePayload implements Payload {
+ }
+
+}
Property changes on:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
___________________________________________________________________
Name: svn:keywords
+ Id