本文整理汇总了Java中java.lang.annotation.ElementType.FIELD属性的典型用法代码示例。如果您正苦于以下问题:Java ElementType.FIELD属性的具体用法?Java ElementType.FIELD怎么用?Java ElementType.FIELD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.lang.annotation.ElementType
的用法示例。
在下文中一共展示了ElementType.FIELD属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConstraintViolationExceptionParameter
@Test
public void testConstraintViolationExceptionParameter() {
final Wine bean = new Wine();
final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();
final ConstraintHelper helper = new ConstraintHelper();
final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("name", NotEmpty.class), ElementType.FIELD);
PathImpl path = PathImpl.createPathFromString("name");
violations.add(ConstraintViolationImpl.<Wine> forParameterValidation("name-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
"value", path, notEmptyNameDescriptor, ElementType.PARAMETER, null, null));
path.addParameterNode("parameter1", 0);
final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);
final ValidationJsonException validationJsonException = new ValidationJsonException(violationException);
Assert.assertFalse(validationJsonException.getErrors().isEmpty());
Assert.assertEquals("{parameter1=[{rule=name-Empty}]}", validationJsonException.getErrors().toString());
}
示例2: elementOf
/** Return element type of the a class member. */
static ElementType elementOf(Member member) {
if (member instanceof Constructor) {
return ElementType.CONSTRUCTOR;
}
if (member instanceof Field) {
return ElementType.FIELD;
}
if (member instanceof Method) {
return ElementType.METHOD;
}
throw new AssertionError("unexpected member: " + member);
}
示例3: testConstraintViolationException
@Test
public void testConstraintViolationException() {
final Wine bean = new Wine();
final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();
final ConstraintHelper helper = new ConstraintHelper();
final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("name", NotEmpty.class), ElementType.FIELD);
final ConstraintDescriptor<NotEmpty> notEmptyGrapesDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("grapes", NotEmpty.class), ElementType.FIELD);
final ConstraintDescriptor<Length> lengthNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
getAnnotation("name", Length.class), ElementType.FIELD);
violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
"value", PathImpl.createPathFromString("name"), notEmptyNameDescriptor, ElementType.FIELD, null));
violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("name-length", null, null, "interpolated", Wine.class, bean, new Object(),
"value", PathImpl.createPathFromString("name"), lengthNameDescriptor, ElementType.FIELD, null));
violations.add(ConstraintViolationImpl.<Wine> forBeanValidation("grapes-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
"value", PathImpl.createPathFromString("grapes"), notEmptyGrapesDescriptor, ElementType.FIELD, null));
final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);
final ValidationJsonException validationJsonException = new ValidationJsonException(violationException);
Assert.assertFalse(validationJsonException.getErrors().isEmpty());
Assert.assertEquals("{name=[{rule=name-Empty}, {rule=name-length, parameters={min=0, max=50}}], grapes=[{rule=grapes-Empty}]}",
validationJsonException.getErrors().toString());
}
示例4: getType
@Override
public final ElementType getType()
{
return ElementType.FIELD;
}
示例5: getAnnotationTarget
@Override
public ElementType getAnnotationTarget() {
return ElementType.FIELD;
}