本文整理汇总了Java中java.lang.reflect.AnnotatedType.getAnnotations方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedType.getAnnotations方法的具体用法?Java AnnotatedType.getAnnotations怎么用?Java AnnotatedType.getAnnotations使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.AnnotatedType
的用法示例。
在下文中一共展示了AnnotatedType.getAnnotations方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReturnsEmptyAT
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private static void testReturnsEmptyAT() {
for (Class<?> toTest : nonNullTestData) {
tests++;
AnnotatedType res = toTest.getAnnotatedSuperclass();
if (res == null) {
failed++;
System.out.println(toTest + ".getAnnotatedSuperclass() returns 'null' should be non-null");
} else if (res.getAnnotations().length != 0) {
failed++;
System.out.println(toTest + ".getAnnotatedSuperclass() returns: "
+ Arrays.asList(res.getAnnotations()) + ", should be an empty AnnotatedType");
}
}
}
示例2: verifyArrayFieldTypeAnnotations
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private void verifyArrayFieldTypeAnnotations(Class c)
throws NoSuchFieldException, NoSuchMethodException {
Annotation anno;
AnnotatedType at;
at = c.getDeclaredField("typeAnnotatedArray").getAnnotatedType();
anno = at.getAnnotations()[0];
verifyTestAnn(arrayTA[0], anno, "array1");
arrayTA[0] = anno;
for (int i = 1; i <= 3; i++) {
at = ((AnnotatedArrayType) at).getAnnotatedGenericComponentType();
anno = at.getAnnotations()[0];
verifyTestAnn(arrayTA[i], anno, "array" + (i + 1));
arrayTA[i] = anno;
}
}
示例3: build
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
public static Set<ContainerElementTypeDescriptor> build(
final Class<?> elementClass,
final AnnotatedParameterizedType annotatedType) {
final Set<ContainerElementTypeDescriptor> result = new HashSet<>();
final Class<?> containerClass = ReflectionUtils.getRawType(annotatedType);
int argIndex = 0;
for (final AnnotatedType typeArg : annotatedType.getAnnotatedActualTypeArguments()) {
final Set<ConstraintDescriptor<?>> constraintDescriptors = new HashSet<>();
for (final Annotation annotation : typeArg.getAnnotations()) {
final MinijaxConstraintDescriptor<?> constraintDescriptor = MinijaxConstraintDescriptor.build(typeArg, annotation);
if (constraintDescriptor != null) {
constraintDescriptors.add(constraintDescriptor);
}
}
if (!constraintDescriptors.isEmpty()) {
result.add(new MinijaxContainerElementTypeDescriptor(elementClass, containerClass, argIndex, constraintDescriptors));
}
argIndex++;
}
return result;
}
示例4: checkEmptyAT
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private static void checkEmptyAT(AnnotatedType a, String msg) {
if (a.getAnnotations().length != 0) {
failures++;
System.err.print(msg);
}
tests++;
}
示例5: verifyInnerFieldTypeAnnotations
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private void verifyInnerFieldTypeAnnotations(Class c)
throws NoSuchFieldException, NoSuchMethodException {
AnnotatedType at = c.getDeclaredField("typeAnnotatedInner").getAnnotatedType();
Annotation anno = at.getAnnotations()[0];
verifyTestAnn(innerTA, anno, "inner");
innerTA = anno;
}
示例6: verifyMapFieldTypeAnnotations
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private void verifyMapFieldTypeAnnotations(Class c)
throws NoSuchFieldException, NoSuchMethodException {
Annotation anno;
AnnotatedType atBase;
AnnotatedType atParameter;
atBase = c.getDeclaredField("typeAnnotatedMap").getAnnotatedType();
anno = atBase.getAnnotations()[0];
verifyTestAnn(mapTA[0], anno, "map1");
mapTA[0] = anno;
atParameter =
((AnnotatedParameterizedType) atBase).
getAnnotatedActualTypeArguments()[0];
anno = ((AnnotatedWildcardType) atParameter).getAnnotations()[0];
verifyTestAnn(mapTA[1], anno, "map2");
mapTA[1] = anno;
anno =
((AnnotatedWildcardType) atParameter).
getAnnotatedUpperBounds()[0].getAnnotations()[0];
verifyTestAnn(mapTA[2], anno, "map3");
mapTA[2] = anno;
atParameter =
((AnnotatedParameterizedType) atBase).
getAnnotatedActualTypeArguments()[1];
anno = ((AnnotatedParameterizedType) atParameter).getAnnotations()[0];
verifyTestAnn(mapTA[3], anno, "map4");
mapTA[3] = anno;
anno =
((AnnotatedParameterizedType) atParameter).
getAnnotatedActualTypeArguments()[0].getAnnotations()[0];
verifyTestAnn(mapTA[4], anno, "map5");
mapTA[4] = anno;
}
示例7: checkEmptyAT
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private static void checkEmptyAT(Executable e, String msg) {
AnnotatedType a = e.getAnnotatedReceiverType();
if (a.getAnnotations().length != 0) {
failures++;
System.err.print(msg + ": " + e);
}
tests++;
}
示例8: checkApiRules
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private void checkApiRules(Class<?> publicClass) {
List<Class<?>> declaredClasses = publicClasses(publicClass.getDeclaredClasses());
if (!declaredClasses.isEmpty()) {
throw new IllegalStateException("There are no inner classes in the public API");
}
Class<?> componentType = publicClass.getComponentType();
if (componentType != null) {
throw new IllegalStateException("There are no array classes in the public API");
}
AnnotatedType annotatedSuperclass = publicClass.getAnnotatedSuperclass();
if (annotatedSuperclass != null && annotatedSuperclass.getAnnotations().length > 0) {
throw new IllegalStateException("There are no annotated super classes in the public API");
}
AnnotatedType[] annotatedInterfaces = publicClass.getAnnotatedInterfaces();
for (AnnotatedType annotatedInterface : annotatedInterfaces) {
if (annotatedInterface.getAnnotations().length > 0) {
throw new IllegalStateException("There are no annotated interfaces in the public API");
}
}
List<Constructor<?>> declaredConstructors = publicConstructors(publicClass.getDeclaredConstructors());
if (!declaredConstructors.isEmpty()) {
throw new IllegalStateException("There are no constructors in the public API");
}
Method[] declaredMethods = publicClass.getDeclaredMethods();
if (existProtectedElements(stream(declaredMethods), Method::getModifiers)) {
throw new IllegalStateException("There are no protected methods in the public API");
}
Field[] declaredFields = publicClass.getDeclaredFields();
if (existProtectedElements(stream(declaredFields), Field::getModifiers)) {
throw new IllegalStateException("There are no protected fields in the public API");
}
}
示例9: removeNonNull
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private AnnotatedType removeNonNull(AnnotatedType type) {
Collection<Annotation> keptAnnotations = new ArrayList<>(type.getAnnotations().length - 1);
for (Annotation annotation : type.getAnnotations()) {
if (!nonNullAnnotations.contains(annotation.annotationType())) {
keptAnnotations.add(annotation);
}
}
return GenericTypeReflector.replaceAnnotations(type, keptAnnotations.toArray(new Annotation[keptAnnotations.size()]));
}