本文整理了Java中java.lang.annotation.Annotation.annotationType()
方法的一些代码示例,展示了Annotation.annotationType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotation.annotationType()
方法的具体详情如下:
包路径:java.lang.annotation.Annotation
类名称:Annotation
方法名:annotationType
[英]Returns the type of this annotation.
[中]返回此批注的类型。
代码示例来源:origin: spring-projects/spring-framework
@Override
@SuppressWarnings("unchecked")
@Nullable
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
for (Annotation ann : annotations) {
if (ann.annotationType() == annotationClass) {
return (T) ann;
}
}
return null;
}
@Override
代码示例来源:origin: spring-projects/spring-framework
/**
* Construct a new {@code DefaultAnnotationAttributeExtractor}.
* @param annotation the annotation to synthesize; never {@code null}
* @param annotatedElement the element that is annotated with the supplied
* annotation; may be {@code null} if unknown
*/
DefaultAnnotationAttributeExtractor(Annotation annotation, @Nullable Object annotatedElement) {
super(annotation.annotationType(), annotatedElement, annotation);
}
代码示例来源:origin: google/guava
private static boolean isNullable(Annotation[] annotations) {
for (Annotation annotation : annotations) {
if (NULLABLE_ANNOTATION_SIMPLE_NAMES.contains(annotation.annotationType().getSimpleName())) {
return true;
}
}
return false;
}
代码示例来源:origin: spring-projects/spring-framework
private AspectJAnnotationType determineAnnotationType(A annotation) {
AspectJAnnotationType type = annotationTypeMap.get(annotation.annotationType());
if (type != null) {
return type;
}
throw new IllegalStateException("Unknown annotation type: " + annotation);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean hasAnnotation(String annotationName) {
for (Annotation ann : this.annotations) {
if (ann.annotationType().getName().equals(annotationName)) {
return true;
}
}
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public Set<String> getAnnotationTypes() {
Set<String> types = new LinkedHashSet<>();
for (Annotation ann : this.annotations) {
types.add(ann.annotationType().getName());
}
return types;
}
代码示例来源:origin: spring-projects/spring-framework
private void addAnnotationsToMap(
Map<Class<? extends Annotation>, Annotation> annotationMap, @Nullable AnnotatedElement object) {
if (object != null) {
for (Annotation annotation : object.getAnnotations()) {
annotationMap.put(annotation.annotationType(), annotation);
}
}
}
代码示例来源:origin: square/retrofit
private static Set<? extends Annotation> jsonAnnotations(Annotation[] annotations) {
Set<Annotation> result = null;
for (Annotation annotation : annotations) {
if (annotation.annotationType().isAnnotationPresent(JsonQualifier.class)) {
if (result == null) result = new LinkedHashSet<>();
result.add(annotation);
}
}
return result != null ? unmodifiableSet(result) : Collections.<Annotation>emptySet();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
public Object process(@Nullable AnnotatedElement annotatedElement, Annotation annotation, int metaDepth) {
types.add(annotation.annotationType().getName());
return CONTINUE;
}
}, new HashSet<>(), 1);
代码示例来源:origin: square/retrofit
@Override public @Nullable Converter<ResponseBody, ?> responseBodyConverter(
Type type, Annotation[] annotations, Retrofit retrofit) {
for (Annotation annotation : annotations) {
Converter.Factory factory = factories.get(annotation.annotationType());
if (factory != null) {
return factory.responseBodyConverter(type, annotations, retrofit);
}
}
return null;
}
代码示例来源:origin: square/retrofit
@Override public @Nullable Converter<?, RequestBody> requestBodyConverter(Type type,
Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
for (Annotation annotation : parameterAnnotations) {
Converter.Factory factory = factories.get(annotation.annotationType());
if (factory != null) {
return factory.requestBodyConverter(type, parameterAnnotations, methodAnnotations,
retrofit);
}
}
return null;
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Determine if the supplied {@link Annotation} is defined in the core JDK
* {@code java.lang.annotation} package.
* @param annotation the annotation to check
* @return {@code true} if the annotation is in the {@code java.lang.annotation} package
*/
public static boolean isInJavaLangAnnotationPackage(@Nullable Annotation annotation) {
return (annotation != null && isInJavaLangAnnotationPackage(annotation.annotationType()));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) {
for (Annotation annotation : getAnnotations()) {
if (annotation.annotationType() == annotationClass) {
return true;
}
}
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
for (Annotation annotation : getAnnotations()) {
if (annotation.annotationType() == annotationClass) {
return (T) annotation;
}
}
return null;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
for (Annotation ann : getAnnotations()) {
builder.append("@").append(ann.annotationType().getName()).append(' ');
}
builder.append(getResolvableType().toString());
return builder.toString();
}
代码示例来源:origin: spring-projects/spring-framework
private String formatAnnotation(Annotation annotation) {
Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
map.forEach((key, value) -> {
if (value.equals(DEFAULT_VALUE_NONE)) {
map.put(key, "NONE");
}
});
return annotation.annotationType().getName() + map;
}
代码示例来源:origin: spring-projects/spring-framework
private String formatAnnotation(Annotation annotation) {
Map<String, Object> map = AnnotationUtils.getAnnotationAttributes(annotation);
map.forEach((key, value) -> {
if (value.equals(DEFAULT_VALUE_NONE)) {
map.put(key, "NONE");
}
});
return annotation.annotationType().getName() + map;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void getDefaultValueFromNonPublicAnnotation() {
Annotation[] declaredAnnotations = NonPublicAnnotatedClass.class.getDeclaredAnnotations();
assertEquals(1, declaredAnnotations.length);
Annotation annotation = declaredAnnotations[0];
assertNotNull(annotation);
assertEquals("NonPublicAnnotation", annotation.annotationType().getSimpleName());
assertEquals(-1, getDefaultValue(annotation, VALUE));
assertEquals(-1, getDefaultValue(annotation));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
@SuppressWarnings("unchecked")
public void findAnnotationDescriptorForTypesForClassWithMetaAnnotatedInterface() {
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(
ClassWithMetaAnnotatedInterface.class, Service.class, Component.class, Order.class, Transactional.class);
assertNotNull(descriptor);
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
assertEquals(Meta1.class, descriptor.getDeclaringClass());
assertEquals(rawAnnotation, descriptor.getAnnotation());
assertEquals(Meta1.class, descriptor.getComposedAnnotation().annotationType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void findAnnotationDescriptorForClassWithMetaAnnotatedInterface() {
Component rawAnnotation = AnnotationUtils.findAnnotation(ClassWithMetaAnnotatedInterface.class, Component.class);
AnnotationDescriptor<Component> descriptor =
findAnnotationDescriptor(ClassWithMetaAnnotatedInterface.class, Component.class);
assertNotNull(descriptor);
assertEquals(ClassWithMetaAnnotatedInterface.class, descriptor.getRootDeclaringClass());
assertEquals(Meta1.class, descriptor.getDeclaringClass());
assertEquals(rawAnnotation, descriptor.getAnnotation());
assertEquals(Meta1.class, descriptor.getComposedAnnotation().annotationType());
}
内容来源于网络,如有侵权,请联系作者删除!