Search in sources :

Example 1 with TypeExtends

use of com.querydsl.codegen.utils.model.TypeExtends 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)

Example 2 with TypeExtends

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

the class TypeFactory method getGenericParameter.

@SuppressWarnings("rawtypes")
private Type getGenericParameter(Class<?> cl, java.lang.reflect.Type genericType, int i) {
    java.lang.reflect.Type parameter = ReflectionUtils.getTypeParameter(genericType, i);
    if (parameter instanceof TypeVariable) {
        TypeVariable variable = (TypeVariable) parameter;
        Type rv = get(ReflectionUtils.getTypeParameterAsClass(genericType, i), null, parameter);
        return new TypeExtends(variable.getName(), rv);
    } else if (parameter instanceof WildcardType && ((WildcardType) parameter).getUpperBounds()[0].equals(Object.class) && ((WildcardType) parameter).getLowerBounds().length == 0) {
        return ANY;
    } else {
        Type rv = get(ReflectionUtils.getTypeParameterAsClass(genericType, i), null, parameter);
        if (parameter instanceof WildcardType) {
            rv = new TypeExtends(rv);
        }
        return rv;
    }
}
Also used : 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) WildcardType(java.lang.reflect.WildcardType) TypeVariable(java.lang.reflect.TypeVariable)

Aggregations

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