本文整理了Java中org.springframework.core.convert.TypeDescriptor.getAnnotation()
方法的一些代码示例,展示了TypeDescriptor.getAnnotation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeDescriptor.getAnnotation()
方法的具体详情如下:
包路径:org.springframework.core.convert.TypeDescriptor
类名称:TypeDescriptor
方法名:getAnnotation
[英]Obtain the annotation of the specified annotationType that is on this type descriptor.
As of Spring Framework 4.2, this method supports arbitrary levels of meta-annotations.
[中]获取此类型描述符上指定annotationType的批注。
从Spring Framework 4.2开始,这种方法支持任意级别的元注释。
代码示例来源:origin: org.springframework.boot/spring-boot
private DurationStyle getStyle(TypeDescriptor targetType) {
DurationFormat annotation = targetType.getAnnotation(DurationFormat.class);
return (annotation != null) ? annotation.value() : null;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void fieldAnnotated() throws Exception {
TypeDescriptor typeDescriptor = new TypeDescriptor(getClass().getField("fieldAnnotated"));
assertEquals(1, typeDescriptor.getAnnotations().length);
assertNotNull(typeDescriptor.getAnnotation(FieldAnnotation.class));
}
代码示例来源:origin: org.springframework.boot/spring-boot
private ChronoUnit getDurationUnit(TypeDescriptor sourceType) {
DurationUnit annotation = sourceType.getAnnotation(DurationUnit.class);
return (annotation != null) ? annotation.value() : null;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void parameterAnnotated() throws Exception {
TypeDescriptor t1 = new TypeDescriptor(new MethodParameter(getClass().getMethod("testAnnotatedMethod", String.class), 0));
assertEquals(String.class, t1.getType());
assertEquals(1, t1.getAnnotations().length);
assertNotNull(t1.getAnnotation(ParameterAnnotation.class));
assertTrue(t1.hasAnnotation(ParameterAnnotation.class));
assertEquals(123, t1.getAnnotation(ParameterAnnotation.class).value());
}
代码示例来源:origin: org.springframework.boot/spring-boot
private ChronoUnit getDurationUnit(TypeDescriptor targetType) {
DurationUnit annotation = targetType.getAnnotation(DurationUnit.class);
return (annotation != null) ? annotation.value() : null;
}
代码示例来源:origin: org.springframework.boot/spring-boot
private DataUnit getDataUnit(TypeDescriptor targetType) {
DataSizeUnit annotation = targetType.getAnnotation(DataSizeUnit.class);
return (annotation != null) ? annotation.value() : null;
}
代码示例来源:origin: org.springframework.boot/spring-boot
private CharSequence getDelimiter(TypeDescriptor sourceType) {
Delimiter annotation = sourceType.getAnnotation(Delimiter.class);
return (annotation != null) ? annotation.value() : ",";
}
代码示例来源:origin: org.springframework.boot/spring-boot
private DurationStyle getDurationStyle(TypeDescriptor sourceType) {
DurationFormat annotation = sourceType.getAnnotation(DurationFormat.class);
return (annotation != null) ? annotation.value() : null;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
ExampleAnnotation ann = targetType.getAnnotation(ExampleAnnotation.class);
return (ann != null && ann.active());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Annotation ann = sourceType.getAnnotation(this.annotationType);
if (ann == null) {
throw new IllegalStateException(
"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
}
AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
GenericConverter converter = cachedPrinters.get(converterKey);
if (converter == null) {
Printer<?> printer = this.annotationFormatterFactory.getPrinter(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
cachedPrinters.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Annotation ann = targetType.getAnnotation(this.annotationType);
if (ann == null) {
throw new IllegalStateException(
"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
}
AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
GenericConverter converter = cachedParsers.get(converterKey);
if (converter == null) {
Parser<?> parser = this.annotationFormatterFactory.getParser(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
cachedParsers.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
代码示例来源:origin: org.springframework/spring-context
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Annotation ann = targetType.getAnnotation(this.annotationType);
if (ann == null) {
throw new IllegalStateException(
"Expected [" + this.annotationType.getName() + "] to be present on " + targetType);
}
AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, targetType.getObjectType());
GenericConverter converter = cachedParsers.get(converterKey);
if (converter == null) {
Parser<?> parser = this.annotationFormatterFactory.getParser(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new ParserConverter(this.fieldType, parser, FormattingConversionService.this);
cachedParsers.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
代码示例来源:origin: org.springframework/spring-context
@Override
@SuppressWarnings("unchecked")
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
Annotation ann = sourceType.getAnnotation(this.annotationType);
if (ann == null) {
throw new IllegalStateException(
"Expected [" + this.annotationType.getName() + "] to be present on " + sourceType);
}
AnnotationConverterKey converterKey = new AnnotationConverterKey(ann, sourceType.getObjectType());
GenericConverter converter = cachedPrinters.get(converterKey);
if (converter == null) {
Printer<?> printer = this.annotationFormatterFactory.getPrinter(
converterKey.getAnnotation(), converterKey.getFieldType());
converter = new PrinterConverter(this.fieldType, printer, FormattingConversionService.this);
cachedPrinters.put(converterKey, converter);
}
return converter.convert(source, sourceType, targetType);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testUpCast() throws Exception {
Property property = new Property(getClass(), getClass().getMethod("getProperty"),
getClass().getMethod("setProperty", Map.class));
TypeDescriptor typeDescriptor = new TypeDescriptor(property);
TypeDescriptor upCast = typeDescriptor.upcast(Object.class);
assertTrue(upCast.getAnnotation(MethodAnnotation1.class) != null);
}
代码示例来源:origin: spring-projects/spring-framework
private void assertAnnotationFoundOnMethod(Class<? extends Annotation> annotationType, String methodName) throws Exception {
TypeDescriptor typeDescriptor = new TypeDescriptor(new MethodParameter(getClass().getMethod(methodName), -1));
assertNotNull("Should have found @" + annotationType.getSimpleName() + " on " + methodName + ".",
typeDescriptor.getAnnotation(annotationType));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void property() throws Exception {
Property property = new Property(
getClass(), getClass().getMethod("getProperty"), getClass().getMethod("setProperty", Map.class));
TypeDescriptor desc = new TypeDescriptor(property);
assertEquals(Map.class, desc.getType());
assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType());
assertEquals(Long.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(MethodAnnotation1.class));
assertNotNull(desc.getAnnotation(MethodAnnotation2.class));
assertNotNull(desc.getAnnotation(MethodAnnotation3.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void propertyGenericClassList() throws Exception {
IntegerClass genericBean = new IntegerClass();
Property property = new Property(genericBean.getClass(), genericBean.getClass().getMethod("getListProperty"),
genericBean.getClass().getMethod("setListProperty", List.class));
TypeDescriptor desc = new TypeDescriptor(property);
assertEquals(List.class, desc.getType());
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(MethodAnnotation1.class));
assertTrue(desc.hasAnnotation(MethodAnnotation1.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void mapKeyTypePreserveContext() throws Exception {
TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext"));
assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType());
List<Integer> value = new ArrayList<>(3);
desc = desc.getMapKeyTypeDescriptor(value);
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void mapValueTypePreserveContext() throws Exception {
TypeDescriptor desc = new TypeDescriptor(getClass().getField("mapPreserveContext"));
assertEquals(Integer.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
List<Integer> value = new ArrayList<>(3);
desc = desc.getMapValueTypeDescriptor(value);
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void elementTypePreserveContext() throws Exception {
TypeDescriptor desc = new TypeDescriptor(getClass().getField("listPreserveContext"));
assertEquals(Integer.class, desc.getElementTypeDescriptor().getElementTypeDescriptor().getType());
List<Integer> value = new ArrayList<>(3);
desc = desc.elementTypeDescriptor(value);
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}
内容来源于网络,如有侵权,请联系作者删除!