本文整理汇总了Java中java.lang.reflect.AnnotatedType.getAnnotation方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotatedType.getAnnotation方法的具体用法?Java AnnotatedType.getAnnotation怎么用?Java AnnotatedType.getAnnotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.AnnotatedType
的用法示例。
在下文中一共展示了AnnotatedType.getAnnotation方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toGraphQLType
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
@Override
public GraphQLObjectType toGraphQLType(String typeName, AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLObjectType.Builder typeBuilder = newObject()
.name(typeName)
.description(buildContext.typeInfoGenerator.generateTypeDescription(javaType));
GraphQLType graphQLType = javaType.getAnnotation(GraphQLType.class);
List<String> fieldOrder = graphQLType != null ? Arrays.asList(graphQLType.fieldOrder()) : Collections.emptyList();
List<GraphQLFieldDefinition> fields = getFields(javaType, fieldOrder, buildContext, operationMapper);
fields.forEach(typeBuilder::field);
List<GraphQLOutputType> interfaces = getInterfaces(javaType, abstractTypes, fields, buildContext, operationMapper);
interfaces.forEach(inter -> {
if (inter instanceof GraphQLInterfaceType) {
typeBuilder.withInterface((GraphQLInterfaceType) inter);
} else {
typeBuilder.withInterface((GraphQLTypeReference) inter);
}
});
GraphQLObjectType type = new MappedGraphQLObjectType(typeBuilder.build(), javaType);
interfaces.forEach(inter -> buildContext.typeRepository.registerCovariantType(inter.getName(), javaType, type));
buildContext.typeRepository.registerObjectType(type);
return type;
}
示例2: getPossibleJavaTypes
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
private List<AnnotatedType> getPossibleJavaTypes(AnnotatedType javaType, BuildContext buildContext) {
GraphQLUnion annotation = javaType.getAnnotation(GraphQLUnion.class);
List<AnnotatedType> possibleTypes = Collections.emptyList();
if (annotation.possibleTypes().length > 0) {
possibleTypes = Arrays.stream(annotation.possibleTypes())
.map(type -> GenericTypeReflector.getExactSubType(javaType, type))
.collect(Collectors.toList());
}
if (possibleTypes.isEmpty()) {
try {
possibleTypes = annotation.possibleTypeFactory().newInstance().getPossibleTypes();
} catch (InstantiationException | IllegalAccessException e) {
throw new IllegalArgumentException(annotation.possibleTypeFactory().getName() +
" must have a public default constructor", e);
}
}
if (possibleTypes.isEmpty() && annotation.possibleTypeAutoDiscovery()) {
String[] scanPackages = annotation.scanPackages();
if (scanPackages.length == 0 && Utils.arrayNotEmpty(buildContext.basePackages)) {
scanPackages = buildContext.basePackages;
}
possibleTypes = ClassUtils.findImplementations(javaType, scanPackages).stream()
.peek(impl -> {
if (GenericTypeReflector.isMissingTypeParameters(impl.getType())) {
throw new TypeMappingException(javaType.getType(), impl.getType());
}
})
.collect(Collectors.toList());
}
if (possibleTypes.isEmpty()) {
throw new TypeMappingException("No possible types found for union type " + javaType.getType().getTypeName());
}
return possibleTypes;
}
示例3: toGraphQLType
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
@Override
public GraphQLInterfaceType toGraphQLType(String typeName, AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLInterfaceType.Builder typeBuilder = newInterface()
.name(typeName)
.description(buildContext.typeInfoGenerator.generateTypeDescription(javaType));
GraphQLInterface graphQLInterface = javaType.getAnnotation(GraphQLInterface.class);
List<String> fieldOrder = graphQLInterface != null ? Arrays.asList(graphQLInterface.fieldOrder()) : Collections.emptyList();
List<GraphQLFieldDefinition> fields = objectTypeMapper.getFields(javaType, fieldOrder, buildContext, operationMapper);
fields.forEach(typeBuilder::field);
typeBuilder.typeResolver(buildContext.typeResolver);
GraphQLInterfaceType type = new MappedGraphQLInterfaceType(typeBuilder.build(), javaType);
if (javaType.isAnnotationPresent(GraphQLInterface.class)) {
GraphQLInterface meta = javaType.getAnnotation(GraphQLInterface.class);
if (meta.implementationAutoDiscovery()) {
String[] scanPackages = meta.scanPackages();
if (scanPackages.length == 0 && Utils.arrayNotEmpty(buildContext.basePackages)) {
scanPackages = buildContext.basePackages;
}
ClassUtils.findImplementations(javaType, scanPackages).forEach(impl ->
getImplementingType(impl, abstractTypes, operationMapper, buildContext)
.ifPresent(implType -> buildContext.typeRepository.registerDiscoveredCovariantType(type.getName(), impl, implType)));
}
}
return type;
}
示例4: toGraphQLType
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
@Override
public GraphQLOutputType toGraphQLType(AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLUnion annotation = javaType.getAnnotation(GraphQLUnion.class);
List<AnnotatedType> possibleJavaTypes = getPossibleJavaTypes(javaType, buildContext);
return toGraphQLUnion(annotation.name(), annotation.description(), javaType, possibleJavaTypes, abstractTypes, operationMapper, buildContext);
}
示例5: toGraphQLType
import java.lang.reflect.AnnotatedType; //导入方法依赖的package包/类
@Override
public GraphQLOutputType toGraphQLType(AnnotatedType javaType, Set<Type> abstractTypes, OperationMapper operationMapper, BuildContext buildContext) {
GraphQLUnion annotation = javaType.getAnnotation(GraphQLUnion.class);
List<AnnotatedType> possibleJavaTypes = Arrays.asList(((AnnotatedParameterizedType) javaType).getAnnotatedActualTypeArguments());
return toGraphQLUnion(annotation.name(), annotation.description(), javaType, possibleJavaTypes, abstractTypes, operationMapper, buildContext);
}