Search in sources :

Example 1 with TypeSuper

use of com.querydsl.codegen.utils.model.TypeSuper in project querydsl by querydsl.

the class TypeFactory method create.

private Type create(boolean entity, Class<?> cl, AnnotationHelper annotationHelper, Annotation annotation, java.lang.reflect.Type genericType, List<?> key) {
    if (cl.isPrimitive()) {
        cl = PrimitiveUtils.wrap(cl);
    }
    Type value;
    Type[] tempParams = (Type[]) Array.newInstance(Type.class, ReflectionUtils.getTypeParameterCount(genericType));
    cache.put(key, new ClassType(cl, tempParams));
    Type[] parameters = getParameters(cl, genericType);
    if (cl.isArray()) {
        Type componentType = get(cl.getComponentType());
        if (cl.getComponentType().isPrimitive()) {
            componentType = Types.PRIMITIVES.get(componentType);
        }
        value = componentType.asArrayType();
    } else if (cl.isEnum()) {
        value = new ClassType(TypeCategory.ENUM, cl);
    } else if (Number.class.isAssignableFrom(cl) && Comparable.class.isAssignableFrom(cl)) {
        value = new ClassType(TypeCategory.NUMERIC, cl, parameters);
    } else if (entity) {
        value = createOther(cl, entity, annotationHelper, annotation, parameters);
    } else if (Map.class.isAssignableFrom(cl)) {
        value = new SimpleType(Types.MAP, parameters[0], asGeneric(parameters[1]));
    } else if (List.class.isAssignableFrom(cl)) {
        value = new SimpleType(Types.LIST, asGeneric(parameters[0]));
    } else if (Set.class.isAssignableFrom(cl)) {
        value = new SimpleType(Types.SET, asGeneric(parameters[0]));
    } else if (Collection.class.isAssignableFrom(cl)) {
        value = new SimpleType(Types.COLLECTION, asGeneric(parameters[0]));
    } else {
        value = createOther(cl, entity, annotationHelper, annotation, parameters);
    }
    if (genericType instanceof TypeVariable) {
        TypeVariable tv = (TypeVariable) genericType;
        if (tv.getBounds().length == 1 && tv.getBounds()[0].equals(Object.class)) {
            value = new TypeSuper(tv.getName(), value);
        } else {
            value = new TypeExtends(tv.getName(), value);
        }
    }
    if (entity && !(value instanceof EntityType)) {
        value = new EntityType(value, variableNameFunction);
    }
    return value;
}
Also used : ClassType(com.querydsl.codegen.utils.model.ClassType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) TypeExtends(com.querydsl.codegen.utils.model.TypeExtends) Type(com.querydsl.codegen.utils.model.Type) ClassType(com.querydsl.codegen.utils.model.ClassType) WildcardType(java.lang.reflect.WildcardType) SimpleType(com.querydsl.codegen.utils.model.SimpleType) TypeVariable(java.lang.reflect.TypeVariable) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) TypeSuper(com.querydsl.codegen.utils.model.TypeSuper)

Aggregations

ClassType (com.querydsl.codegen.utils.model.ClassType)1 SimpleType (com.querydsl.codegen.utils.model.SimpleType)1 Type (com.querydsl.codegen.utils.model.Type)1 TypeExtends (com.querydsl.codegen.utils.model.TypeExtends)1 TypeSuper (com.querydsl.codegen.utils.model.TypeSuper)1 TypeVariable (java.lang.reflect.TypeVariable)1 WildcardType (java.lang.reflect.WildcardType)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1