类java.lang.reflect.AnnotatedParameterizedType源码实例Demo

下面列出了怎么用java.lang.reflect.AnnotatedParameterizedType的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public Set<Type> findConstituentAbstractTypes(AnnotatedType javaType, BuildContext buildContext) {
    if (Scalars.isScalar(javaType.getType())
            || ClassUtils.isSubPackage(ClassUtils.getRawType(javaType.getType()).getPackage(), "java.")
            || buildContext.scalarStrategy.isDirectlyDeserializable(javaType)) {
        return Collections.emptySet();
    }
    if (javaType instanceof AnnotatedParameterizedType) {
        Set<Type> abstractTypes = Arrays.stream(((AnnotatedParameterizedType) javaType).getAnnotatedActualTypeArguments())
                .flatMap(arg -> findConstituentAbstractTypes(arg, buildContext).stream())
                .collect(Collectors.toSet());
        abstractTypes.addAll(findAbstract(javaType, buildContext));
        return abstractTypes;
    }
    if (javaType instanceof AnnotatedArrayType) {
        return findConstituentAbstractTypes(((AnnotatedArrayType) javaType).getAnnotatedGenericComponentType(), buildContext);
    }
    if (javaType instanceof AnnotatedWildcardType || javaType instanceof AnnotatedTypeVariable) {
        throw TypeMappingException.ambiguousType(javaType.getType());
    }
    return findAbstract(javaType, buildContext);
}
 
源代码2 项目: graphql-spqr   文件: DefaultTypeInfoGenerator.java
@Override
public String generateTypeName(AnnotatedType type, MessageBundle messageBundle) {
    if (type instanceof AnnotatedParameterizedType) {
        return generateParameterizedName((AnnotatedParameterizedType) type, messageBundle);
    }
    if (type instanceof AnnotatedArrayType) {
        return generateArrayName((AnnotatedArrayType) type, messageBundle);
    }
    Class<Object> rawType = ClassUtils.getRawType(type.getType());
    if (rawType.getEnclosingClass() != null && hierarchicalNames && isIncluded(rawType)) {
        //TODO Use AnnotatedType#getAnnotatedOwnerType instead of annotate(rawType.getEnclosingClass()) once available
        String enclosingName = generateTypeName(GenericTypeReflector.annotate(rawType.getEnclosingClass()), messageBundle);
        return enclosingName + hierarchicalNameSeparator + generateBaseName(type, messageBundle);
    }
    return generateBaseName(type, messageBundle);
}
 
源代码3 项目: graphql-spqr   文件: DefaultTypeInfoGenerator.java
protected String generateParameterizedName(AnnotatedParameterizedType type, MessageBundle messageBundle) {
    ParameterizedType parameterizedType = (ParameterizedType) type.getType();
    Class<?> rawType = ClassUtils.getRawType(type.getType());
    StringBuilder genericName = new StringBuilder();
    if (parameterizedType.getOwnerType() != null && hierarchicalNames && isIncluded(rawType)) {
        //TODO Use AnnotatedParameterizedType#getAnnotatedOwnerType instead of annotate(pType.getOwnerType()) once available
        String enclosingName = generateTypeName(GenericTypeReflector.annotate(parameterizedType.getOwnerType()), messageBundle);
        genericName.append(enclosingName).append(hierarchicalNameSeparator);
    }

    String baseName = generateBaseName(type, messageBundle);
    genericName.append(baseName);
    Arrays.stream(type.getAnnotatedActualTypeArguments())
            .map(t -> generateTypeName(t, messageBundle))
            .forEach(argName -> genericName.append(genericTypeSeparator).append(argName));
    return genericName.toString();
}
 
源代码4 项目: graphql-spqr   文件: ClassUtils.java
public static boolean containsTypeAnnotation(AnnotatedType type, Class<? extends Annotation> annotation) {
    if (type.isAnnotationPresent(annotation)) {
        return true;
    }
    if (type instanceof AnnotatedParameterizedType) {
        AnnotatedParameterizedType parameterizedType = ((AnnotatedParameterizedType) type);
        return Arrays.stream(parameterizedType.getAnnotatedActualTypeArguments())
                .anyMatch(param -> containsTypeAnnotation(param, annotation));
    }
    if (type instanceof AnnotatedTypeVariable) {
        AnnotatedTypeVariable variable = ((AnnotatedTypeVariable) type);
        return Arrays.stream(variable.getAnnotatedBounds())
                .anyMatch(bound -> containsTypeAnnotation(bound, annotation));
    }
    if (type instanceof AnnotatedWildcardType) {
        AnnotatedWildcardType wildcard = ((AnnotatedWildcardType) type);
        return Stream.concat(
                Arrays.stream(wildcard.getAnnotatedLowerBounds()),
                Arrays.stream(wildcard.getAnnotatedUpperBounds()))
                .anyMatch(param -> containsTypeAnnotation(param, annotation));
    }
    return type instanceof AnnotatedArrayType && containsTypeAnnotation(((AnnotatedArrayType) type).getAnnotatedGenericComponentType(), annotation);
}
 
源代码5 项目: graphql-spqr   文件: ClassUtils.java
@SuppressWarnings("unchecked")
public static <T extends AnnotatedType> T transformType(T type, UnaryOperator<T> transformer) {
    if (type instanceof AnnotatedArrayType) {
        return (T) TypeFactory.arrayOf(transformer.apply((T) ((AnnotatedArrayType) type).getAnnotatedGenericComponentType()), type.getAnnotations());
    }
    if (type.getType() instanceof Class) {
        return type;
    }
    if (type instanceof AnnotatedParameterizedType) {
        AnnotatedParameterizedType parameterizedType = (AnnotatedParameterizedType) type;
        AnnotatedType[] arguments = Arrays.stream(parameterizedType.getAnnotatedActualTypeArguments())
                .map(param -> transformer.apply((T) param))
                .toArray(AnnotatedType[]::new);
        return (T) TypeFactory.parameterizedAnnotatedClass(GenericTypeReflector.erase(type.getType()), type.getAnnotations(), arguments);
    }
    throw new IllegalArgumentException("Can not find the mappable type for: " + type.getType().getTypeName());
}
 
源代码6 项目: typescript-generator   文件: TypeParser.java
private Type getBareType(AnnotatedType annotatedType) {
    final Type type = annotatedType.getType();
    if (isArrayOfPrimitiveType(type)) {
        return type;
    }
    if (annotatedType instanceof AnnotatedParameterizedType) {
        final AnnotatedParameterizedType annotatedParameterizedType = (AnnotatedParameterizedType) annotatedType;
        final ParameterizedType parameterizedType = (ParameterizedType) type;
        return new JParameterizedType(
                parameterizedType.getRawType(),
                getTypes(annotatedParameterizedType.getAnnotatedActualTypeArguments()),
                parameterizedType.getOwnerType());
    }
    if (annotatedType instanceof AnnotatedArrayType) {
        final AnnotatedArrayType annotatedArrayType = (AnnotatedArrayType) annotatedType;
        return new JGenericArrayType(getType(annotatedArrayType.getAnnotatedGenericComponentType()));
    }
    return type;
}
 
private boolean cascadeValid(PropertyModel propertyModel, TypeContext typeContext) {
    PropertyItem parent = propertyModel.getParentPropertyItem();
    if (parent == null) return true;

    Valid validAnno = parent.getAnnotation(Valid.class);
    if (validAnno != null)
        return true;

    AnnotatedType annotatedType = null;
    if (parent.getField() != null) {
        annotatedType = parent.getField().getAnnotatedType();
    } else if (parent.getGetMethod() != null) {
        annotatedType = parent.getGetMethod().getAnnotatedReturnType();
    } else if (parent.getSetMethod() != null) {
        annotatedType = parent.getGetMethod().getAnnotatedParameterTypes()[0];
    }
    if (annotatedType != null) {
        if (annotatedType instanceof AnnotatedParameterizedType) {
            AnnotatedParameterizedType annotatedParameterizedType = (AnnotatedParameterizedType) annotatedType;
            if (annotatedParameterizedType.getType() instanceof ParameterizedType) {
                Class clazz = (Class) ((ParameterizedType) annotatedParameterizedType.getType()).getRawType();
                if (List.class.isAssignableFrom(clazz)) {
                    if (annotatedParameterizedType.getAnnotatedActualTypeArguments()[0].getAnnotation(Valid.class) != null)
                        return true;
                }
            }
        }
    }
    return false;
}
 
源代码8 项目: jsonschema-generator   文件: FieldScope.java
@Override
public <A extends Annotation> A getContainerItemAnnotation(Class<A> annotationClass) {
    AnnotatedType annotatedType = this.getRawMember().getAnnotatedType();
    if (annotatedType instanceof AnnotatedParameterizedType) {
        AnnotatedType[] typeArguments = ((AnnotatedParameterizedType) annotatedType).getAnnotatedActualTypeArguments();
        if (typeArguments.length > 0) {
            return typeArguments[0].getAnnotation(annotationClass);
        }
    }
    return null;
}
 
源代码9 项目: jsonschema-generator   文件: MethodScope.java
@Override
public <A extends Annotation> A getContainerItemAnnotation(Class<A> annotationClass) {
    AnnotatedType annotatedReturnType = this.getRawMember().getAnnotatedReturnType();
    if (annotatedReturnType instanceof AnnotatedParameterizedType) {
        AnnotatedType[] typeArguments = ((AnnotatedParameterizedType) annotatedReturnType).getAnnotatedActualTypeArguments();
        if (typeArguments.length > 0) {
            return typeArguments[0].getAnnotation(annotationClass);
        }
    }
    return null;
}
 
源代码10 项目: TencentKona-8   文件: RedefineAnnotations.java
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;
}
 
源代码11 项目: jdk8u60   文件: RedefineAnnotations.java
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;
}
 
源代码12 项目: openjdk-jdk8u   文件: RedefineAnnotations.java
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;
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: RedefineAnnotations.java
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;
}
 
源代码14 项目: openjdk-jdk9   文件: RedefineAnnotations.java
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;
}
 
源代码15 项目: openjdk-jdk9   文件: AnonymousExtendsTest.java
public void checkAnnotations(AnnotatedType type, String expected) {
    String actual = Arrays.asList(((AnnotatedParameterizedType) type)
                                  .getAnnotations())
                                  .toString()
                                   + "," +
                    Arrays.asList(((AnnotatedParameterizedType) type)
                                   .getAnnotatedActualTypeArguments()[0].getAnnotations())
                                   .toString();

    if (!actual.equals(expected))
        throw new AssertionError("Unexpected annotations" + actual);
}
 
源代码16 项目: hottub   文件: RedefineAnnotations.java
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;
}
 
源代码17 项目: graphql-spqr   文件: InputFieldDiscoveryTest.java
private void assertTypesMerged(Set<InputField> fields) {
    Optional<InputField> field1 = fields.stream().filter(field -> field.getName().equals("field1")).findFirst();
    Optional<InputField> field2 = fields.stream().filter(field -> field.getName().equals("field2")).findFirst();
    Optional<InputField> field3 = fields.stream().filter(field -> field.getName().equals("field3")).findFirst();
    assertTrue(field1.isPresent() && field2.isPresent() && field3.isPresent());
    AnnotatedType type1 = field1.get().getTypedElement().getJavaType();
    assertTrue(type1.isAnnotationPresent(GraphQLNonNull.class) && type1.isAnnotationPresent(GraphQLId.class));
    AnnotatedType type2 = field2.get().getTypedElement().getJavaType();
    assertTrue(type2.isAnnotationPresent(GraphQLNonNull.class) && type2.isAnnotationPresent(GraphQLId.class));
    AnnotatedType type3 = field3.get().getTypedElement().getJavaType();
    assertTrue(type3.isAnnotationPresent(GraphQLNonNull.class));
    AnnotatedType type31 = ((AnnotatedParameterizedType) type3).getAnnotatedActualTypeArguments()[0];
    assertTrue(type31.isAnnotationPresent(GraphQLNonNull.class) && type31.isAnnotationPresent(GraphQLScalar.class));
}
 
源代码18 项目: vertx-codegen   文件: TypeUse.java
@Override
public String rawName() {
  if (annotatedType instanceof AnnotatedParameterizedType) {
    return ((ParameterizedType)(annotatedType.getType())).getRawType().getTypeName();
  } else {
    return null;
  }
}
 
源代码19 项目: smallrye-graphql   文件: MethodInfo.java
private AnnotatedType[] returnTypeAnnotations() {
    if (method.getAnnotatedReturnType() instanceof AnnotatedParameterizedType)
        return ((AnnotatedParameterizedType) method.getAnnotatedReturnType()).getAnnotatedActualTypeArguments();
    else
        return new AnnotatedType[0];
}
 
源代码20 项目: graphql-spqr   文件: UnionInlineMapper.java
@Override
public GraphQLOutputType toGraphQLType(AnnotatedType javaType, Set<Class<? extends TypeMapper>> mappersToSkip, TypeMappingEnvironment env) {
    GraphQLUnion annotation = javaType.getAnnotation(GraphQLUnion.class);
    List<AnnotatedType> possibleJavaTypes = Arrays.asList(((AnnotatedParameterizedType) javaType).getAnnotatedActualTypeArguments());
    return toGraphQLUnion(env.buildContext.interpolate(annotation.name()), env.buildContext.interpolate(annotation.description()), javaType, possibleJavaTypes, env);
}
 
源代码21 项目: graphql-spqr   文件: Union.java
public static AnnotatedType unionize(AnnotatedType[] types, MessageBundle messageBundle) {
    Objects.requireNonNull(types);
    if (types.length < 2) {
        if (types.length == 1 && ClassUtils.isSuperClass(Union.class, types[0])) {
            return types[0];
        }
        throw new IllegalArgumentException(SINGLE_TYPE_UNION_ERROR);
    }
    AnnotatedType t1 = types[0];
    if (stream(types).anyMatch(t -> t.isAnnotationPresent(GraphQLUnion.class))) {
        if (stream(types).allMatch(t -> t.isAnnotationPresent(GraphQLUnion.class) && nameEquals(t, t1, messageBundle))) {
            return of(types);
        } else {
            throw new IllegalArgumentException("All union members must be explicitly annotated: " + Arrays.toString(types));
        }
    }
    if (stream(types).allMatch(t -> t instanceof AnnotatedParameterizedType)) {
        AnnotatedParameterizedType p1 = (AnnotatedParameterizedType) t1;
        AnnotatedParameterizedType[] pTypes = stream(types)
                .map(t -> (AnnotatedParameterizedType) t)
                .toArray(AnnotatedParameterizedType[]::new);
        AnnotatedType[] params = new AnnotatedType[p1.getAnnotatedActualTypeArguments().length];
        for (int i = 0; i < p1.getAnnotatedActualTypeArguments().length; i++) {
            final int j = i;
            params[i] = unionize(stream(pTypes)
                    .map(p -> p.getAnnotatedActualTypeArguments()[j])
                    .toArray(AnnotatedType[]::new), messageBundle);
        }
        Class<?> rawType = ((Class<?>) ((ParameterizedType) p1.getType()).getRawType());
        return TypeFactory.parameterizedAnnotatedClass(rawType, ClassUtils.getAllAnnotations(stream(types)), params);
    }
    if (stream(types).allMatch(t -> t instanceof AnnotatedArrayType)) {
        AnnotatedType[] components = stream(types)
                .map(type -> ((AnnotatedArrayType) type).getAnnotatedGenericComponentType())
                .toArray(AnnotatedType[]::new);
        return TypeFactory.arrayOf(unionize(components, messageBundle), ClassUtils.getAllAnnotations(stream(types)));
    }
    if (stream(types).allMatch(t -> types[0].getType().equals(t.getType()))) {
        return types[0];
    }
    throw new IllegalArgumentException("Types are incompatible and can not be unionized: ");
}
 
源代码22 项目: graphql-spqr   文件: ClassUtils.java
private static AnnotatedType getCommonSuperType(List<AnnotatedType> types, Set<String> seenTypeCombos, AnnotatedType fallback) {
    if (types == null || types.isEmpty()) {
        throw new IllegalArgumentException("At least one type must be provided");
    }
    if (types.size() == 1) {
        return types.get(0);
    }
    Annotation[] mergedAnnotations = getMergedAnnotations(types.toArray(new AnnotatedType[0]));
    if (types.stream().map(AnnotatedType::getType).allMatch(type -> type.equals(types.get(0).getType()))) {
        return GenericTypeReflector.replaceAnnotations(types.get(0), mergedAnnotations);
    }
    List<Class<?>> classes = types.stream().map(AnnotatedType::getType).map(ClassUtils::getRawType).collect(Collectors.toList());
    String typeNames = types.stream().map(type -> type.getType().getTypeName()).sorted().collect(Collectors.joining(","));
    if (seenTypeCombos.contains(typeNames)) {
        return fallbackOrException(fallback);
    }
    seenTypeCombos.add(typeNames);

    //deal with arrays first as they are special
    if (types.stream().allMatch(type -> type instanceof AnnotatedArrayType)) {
        List<AnnotatedType> componentTypes = types.stream()
                .map(type -> ((AnnotatedArrayType) type).getAnnotatedGenericComponentType())
                .collect(Collectors.toList());
        AnnotatedType componentType = getCommonSuperType(componentTypes, seenTypeCombos, fallback);
        return TypeFactory.arrayOf(componentType, mergedAnnotations);
    }

    Class<?> commonRawSuperType = getCommonSuperTypes(classes).get(0);
    if (classes.stream().noneMatch(ROOT_TYPES::contains) && ROOT_TYPES.contains(commonRawSuperType)) {
        return fallbackOrException(fallback);
    }
    List<AnnotatedType> normalizedTypes = types.stream()
            .map(type -> GenericTypeReflector.getExactSuperType(type, commonRawSuperType))
            .collect(Collectors.toList());
    if (normalizedTypes.stream().anyMatch(type -> isMissingTypeParameters(type.getType()))) {
        throw new TypeMappingException("Automatic type inference failed because some of the types are missing generic type parameter(s).");
    }
    if (normalizedTypes.stream().allMatch(type -> type.getType() instanceof Class)) {
        return annotate(commonRawSuperType, mergedAnnotations);
    }
    if (normalizedTypes.stream().allMatch(type -> type instanceof AnnotatedParameterizedType)) {
        AnnotatedType[] parameters = Arrays.stream(commonRawSuperType.getTypeParameters())
                .map(param -> normalizedTypes.stream().map(type -> GenericTypeReflector.getTypeParameter(type, param)).collect(Collectors.toList()))
                .map(paramTypes -> getCommonSuperType(paramTypes, seenTypeCombos, fallback))
                .toArray(AnnotatedType[]::new);
        return TypeFactory.parameterizedAnnotatedClass(commonRawSuperType, mergedAnnotations, parameters);
    }
    return fallbackOrException(fallback);
}
 
源代码23 项目: vertx-codegen   文件: TypeUse.java
public TypeInternal getArgAt(int index) {
  AnnotatedParameterizedType annotatedParameterizedType = (AnnotatedParameterizedType) annotatedType;
  return new ReflectType(annotatedParameterizedType.getAnnotatedActualTypeArguments()[index]);
}