当前位置: 首页>>代码示例>>Java>>正文


Java ElementType.FIELD属性代码示例

本文整理汇总了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());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:21,代码来源:ValidationJsonExceptionTest.java

示例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);
}
 
开发者ID:sormuras,项目名称:listing,代码行数:13,代码来源:Tool.java

示例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());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:28,代码来源:ValidationJsonExceptionTest.java

示例4: getType

@Override
public final ElementType getType()
{
    return ElementType.FIELD;
}
 
开发者ID:MrGregorix,项目名称:Gasket,代码行数:5,代码来源:ReflectAnnotatedField.java

示例5: getAnnotationTarget

@Override
public ElementType getAnnotationTarget() {
  return ElementType.FIELD;
}
 
开发者ID:sormuras,项目名称:listing,代码行数:4,代码来源:FieldDeclaration.java


注:本文中的java.lang.annotation.ElementType.FIELD属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。