本文整理汇总了Java中java.lang.reflect.AnnotatedType类的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedType类的具体用法?Java AnnotatedType怎么用?Java AnnotatedType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotatedType类属于java.lang.reflect包,在下文中一共展示了AnnotatedType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReturnsZeroLengthArray
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
private static void testReturnsZeroLengthArray() {
for (Class<?> toTest : testData) {
tests++;
AnnotatedType[] res = toTest.getAnnotatedInterfaces();
if (res == null) {
failed++;
System.out.println(toTest + ".class.getAnnotatedInterface() returns" +
"'null' should zero length array");
} else if (res.length != 0) {
failed++;
System.out.println(toTest + ".class.getAnnotatedInterfaces() returns: "
+ Arrays.asList(res) + ", should be a zero length array of AnnotatedType");
}
}
}
示例2: 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");
}
}
}
示例3: 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;
}
}
示例4: checkNull
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
private static void checkNull(Executable e, String msg) {
AnnotatedType a = e.getAnnotatedReceiverType();
if (a != null) {
failures++;
System.err.println(msg + ": " + e);
}
tests++;
}
示例5: getArgumentValue
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
@Override
public Object getArgumentValue(Object rawInput, AnnotatedType type, ResolutionEnvironment resolutionEnvironment) {
if (GenericTypeReflector.isSuperType(setOfStrings, type.getType())) {
return resolutionEnvironment.dataFetchingEnvironment.getSelectionSet().get().keySet();
}
Class raw = GenericTypeReflector.erase(type.getType());
if (Field.class.equals(raw)) {
return resolutionEnvironment.fields.get(0);
}
if (GenericTypeReflector.isSuperType(listOfFields, type.getType())) {
return resolutionEnvironment.fields;
}
if (ValueMapper.class.isAssignableFrom(raw)) {
return resolutionEnvironment.valueMapper;
}
if (ResolutionEnvironment.class.isAssignableFrom(raw)) {
return resolutionEnvironment;
}
throw new IllegalArgumentException("Argument of type " + raw.getName()
+ " can not be injected via @" + GraphQLEnvironment.class.getSimpleName());
}
示例6: of
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
/** Create {@link JavaType} based on {@link AnnotatedType} instance. */
public static JavaType of(AnnotatedType annotatedType) {
if (annotatedType instanceof AnnotatedArrayType) {
return JavaTypes.of((AnnotatedArrayType) annotatedType);
}
if (annotatedType instanceof AnnotatedParameterizedType) {
return JavaTypes.of((AnnotatedParameterizedType) annotatedType);
}
if (annotatedType instanceof AnnotatedTypeVariable) {
return JavaTypes.of((AnnotatedTypeVariable) annotatedType);
}
if (annotatedType instanceof AnnotatedWildcardType) {
return JavaTypes.of((AnnotatedWildcardType) annotatedType);
}
// default case: use underlying raw type
JavaType result = of(annotatedType.getType());
result.getAnnotations().addAll(Annotation.of(annotatedType.getAnnotations()));
return result;
}
示例7: of
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
public static AnnotatedType of(AnnotatedType[] types) {
Objects.requireNonNull(types);
if (types.length < 2) {
if (types.length == 1 && GenericTypeReflector.isSuperType(Union.class, types[0].getType())) {
return types[0];
}
throw new IllegalArgumentException(SINGLE_TYPE_UNION_ERROR);
}
AnnotatedType[] distinctTypes = dedupe(types);
Class union;
try {
union = ClassUtils.forName(Union.class.getName() + distinctTypes.length);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Unions of more than 10 types are not supported");
}
Annotation unionAnnotation = stream(ClassUtils.getAllAnnotations(stream(types)))
.filter(annotation -> annotation.annotationType().equals(GraphQLUnion.class))
.filter(annotation -> !((GraphQLUnion) annotation).description().isEmpty())
.findFirst().orElse(types[0].getAnnotation(GraphQLUnion.class));
return TypeFactory.parameterizedAnnotatedClass(union, new Annotation[] {unionAnnotation}, distinctTypes);
}
示例8: getInputFieldType
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
private AnnotatedType getInputFieldType(AnnotatedType type, BeanPropertyDefinition propertyDefinition) {
AnnotatedParameter ctorParam = propertyDefinition.getConstructorParameter();
if (ctorParam != null) {
Constructor<?> constructor = (Constructor<?>) ctorParam.getOwner().getMember();
return ClassUtils.getParameterTypes(constructor, type)[ctorParam.getIndex()];
}
if (propertyDefinition.getSetter() != null) {
return ClassUtils.getParameterTypes(propertyDefinition.getSetter().getAnnotated(), type)[0];
}
if (propertyDefinition.getGetter() != null) {
return ClassUtils.getReturnType(propertyDefinition.getGetter().getAnnotated(), type);
}
if (propertyDefinition.getField() != null) {
return ClassUtils.getFieldType(propertyDefinition.getField().getAnnotated(), type);
}
throw new UnsupportedOperationException("Unknown input field mapping style encountered");
}
示例9: collectAbstract
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
protected Set<Type> collectAbstract(AnnotatedType javaType, Set<Type> seen, BuildContext buildContext) {
javaType = buildContext.globalEnvironment.converters.getMappableType(javaType);
if (Scalars.isScalar(javaType.getType())) {
return Collections.emptySet();
}
if (GenericTypeReflector.isSuperType(Collection.class, javaType.getType())) {
AnnotatedType elementType = GenericTypeReflector.getTypeParameter(javaType, Collection.class.getTypeParameters()[0]);
return collectAbstractInner(elementType, seen, buildContext);
}
if (GenericTypeReflector.isSuperType(Map.class, javaType.getType())) {
AnnotatedType keyType = GenericTypeReflector.getTypeParameter(javaType, Map.class.getTypeParameters()[0]);
AnnotatedType valueType = GenericTypeReflector.getTypeParameter(javaType, Map.class.getTypeParameters()[1]);
Set<Type> abstractTypes = collectAbstractInner(keyType, seen, buildContext);
abstractTypes.addAll(collectAbstractInner(valueType, seen, buildContext));
return abstractTypes;
}
return collectAbstractInner(javaType, seen, buildContext);
}
示例10: collectAbstractInner
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
private Set<Type> collectAbstractInner(AnnotatedType javaType, Set<Type> seen, BuildContext buildContext) {
if (buildContext.abstractComponentTypes.containsKey(javaType.getType())) {
return buildContext.abstractComponentTypes.get(javaType.getType());
}
if (seen.contains(javaType.getType())) {
return Collections.emptySet();
}
seen.add(javaType.getType());
Set<Type> abstractTypes = new HashSet<>();
if (ClassUtils.isAbstract(javaType)) {
abstractTypes.add(javaType.getType());
}
buildContext.inputFieldStrategy.getInputFields(javaType)
.forEach(childQuery -> abstractTypes.addAll(collectAbstract(childQuery.getJavaType(), seen, buildContext)));
buildContext.abstractComponentTypes.put(javaType.getType(), abstractTypes);
return abstractTypes;
}
示例11: java8TypeAnnotation
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
@Test
public void java8TypeAnnotation() throws Exception {
Method method = ImmutableHasTypeAnnotation.class.getMethod("str");
AnnotatedType returnType = method.getAnnotatedReturnType();
check(returnType.getAnnotation(TypeA.class)).notNull();
check(returnType.getAnnotation(TypeB.class)).notNull();
}
示例12: getResponsePropertySet
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
/**
* Check whether the given <code>method</code> return type is annotated with the {@link PropertySetRef} annotation.
* @param method Method to inspect
* @return Optional {@link PropertySetRef} annotation, if available
*/
private static Optional<PropertySetRef> getResponsePropertySet(Method method) {
final AnnotatedType rt = method.getAnnotatedReturnType();
if (rt != null) {
if (rt.isAnnotationPresent(PropertySetRef.class)) {
return Optional.of(rt.getAnnotation(PropertySetRef.class));
}
// check meta-annotations
List<PropertySetRef> annotations = AnnotationUtils.getAnnotations(rt, PropertySetRef.class);
if (!annotations.isEmpty()) {
return Optional.ofNullable(annotations.get(0));
}
}
return Optional.empty();
}
示例13: getResponsePropertySetModel
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
/**
* Check whether the given <code>method</code> return type is annotated with the {@link ApiPropertySetModel}
* annotation.
* @param method Method to inspect
* @return Optional {@link ApiPropertySetModel} annotation, if available
*/
private static Optional<ApiPropertySetModel> getResponsePropertySetModel(Method method) {
final AnnotatedType rt = method.getAnnotatedReturnType();
if (rt != null) {
if (rt.isAnnotationPresent(ApiPropertySetModel.class)) {
return Optional.of(rt.getAnnotation(ApiPropertySetModel.class));
}
// check meta-annotations
List<ApiPropertySetModel> annotations = AnnotationUtils.getAnnotations(rt, ApiPropertySetModel.class);
if (!annotations.isEmpty()) {
return Optional.ofNullable(annotations.get(0));
}
}
return Optional.empty();
}
示例14: MinijaxPropertyDescriptor
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
public MinijaxPropertyDescriptor(final Class<?> elementClass, final AnnotatedType annotatedType, final Annotation[] annotations) {
super(elementClass, buildConstraintDescriptors(annotatedType, annotations));
if (annotatedType instanceof AnnotatedParameterizedType) {
constrainedContainerElementTypes = MinijaxContainerElementTypeDescriptor.build(elementClass, (AnnotatedParameterizedType) annotatedType);
} else {
constrainedContainerElementTypes = emptySet();
}
}
示例15: buildConstraintDescriptors
import java.lang.reflect.AnnotatedType; //导入依赖的package包/类
private static Set<ConstraintDescriptor<?>> buildConstraintDescriptors(final AnnotatedType annotatedType, final Annotation[] annotations) {
final Set<ConstraintDescriptor<?>> result = new HashSet<>();
for (final Annotation annotation : annotations) {
final MinijaxConstraintDescriptor<?> constraintDescriptor = MinijaxConstraintDescriptor.build(annotatedType, annotation);
if (constraintDescriptor != null) {
result.add(constraintDescriptor);
}
}
return result;
}