Search in sources :

Example 21 with Type

use of com.mysema.codegen.model.Type in project querydsl by querydsl.

the class GenericExporter method addConstructors.

private void addConstructors(Class<?> cl, EntityType type) {
    for (Constructor<?> constructor : cl.getConstructors()) {
        if (constructor.isAnnotationPresent(QueryProjection.class)) {
            List<Parameter> parameters = Lists.newArrayList();
            for (int i = 0; i < constructor.getParameterTypes().length; i++) {
                Type parameterType = typeFactory.get(constructor.getParameterTypes()[i], constructor.getGenericParameterTypes()[i]);
                for (Annotation annotation : constructor.getParameterAnnotations()[i]) {
                    if (annotation.annotationType().equals(QueryType.class)) {
                        QueryType queryType = (QueryType) annotation;
                        parameterType = parameterType.as(TypeCategory.valueOf(queryType.value().name()));
                    }
                }
                parameters.add(new Parameter("param" + i, parameterType));
            }
            type.addConstructor(new com.mysema.codegen.model.Constructor(parameters));
        }
    }
}
Also used : Type(com.mysema.codegen.model.Type) Parameter(com.mysema.codegen.model.Parameter) Annotation(java.lang.annotation.Annotation)

Example 22 with Type

use of com.mysema.codegen.model.Type in project querydsl by querydsl.

the class GenericExporter method getPropertyType.

private Type getPropertyType(Class<?> cl, AnnotatedElement annotated, Class<?> type, java.lang.reflect.Type genericType) {
    Type propertyType = null;
    if (annotated.isAnnotationPresent(embeddedAnnotation)) {
        Class<?> embeddableType = type;
        if (Collection.class.isAssignableFrom(type)) {
            embeddableType = ReflectionUtils.getTypeParameterAsClass(genericType, 0);
        } else if (Map.class.isAssignableFrom(type)) {
            embeddableType = ReflectionUtils.getTypeParameterAsClass(genericType, 1);
        }
        if (!embeddableType.getName().startsWith("java.")) {
            typeFactory.addEmbeddableType(embeddableType);
            if (!embeddableTypes.containsKey(embeddableType) && !entityTypes.containsKey(embeddableType) && !superTypes.containsKey(embeddableType)) {
                EntityType entityType = createEntityType(embeddableType, embeddableTypes);
                addProperties(embeddableType, entityType);
                if (embeddableType == type) {
                    propertyType = entityType;
                }
            }
        }
    }
    if (propertyType == null) {
        propertyType = typeFactory.get(type, annotated, genericType);
        if (propertyType instanceof EntityType && !allTypes.containsKey(ClassUtils.getFullName(type))) {
            String fullName = ClassUtils.getFullName(type);
            if (!allTypes.containsKey(fullName)) {
                allTypes.put(fullName, (EntityType) propertyType);
            }
        }
    }
    return propertyType;
}
Also used : Type(com.mysema.codegen.model.Type)

Example 23 with Type

use of com.mysema.codegen.model.Type in project querydsl by querydsl.

the class TypeElementHandler method transformParams.

public List<Parameter> transformParams(List<? extends VariableElement> params) {
    List<Parameter> parameters = new ArrayList<Parameter>(params.size());
    for (VariableElement param : params) {
        Type paramType = getType(param);
        parameters.add(new Parameter(param.getSimpleName().toString(), paramType));
    }
    return parameters;
}
Also used : QueryType(com.querydsl.core.annotations.QueryType) Type(com.mysema.codegen.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) EntityType(com.querydsl.codegen.EntityType) Parameter(com.mysema.codegen.model.Parameter) VariableElement(javax.lang.model.element.VariableElement)

Example 24 with Type

use of com.mysema.codegen.model.Type in project querydsl by querydsl.

the class TypeElementHandler method toProperty.

private Property toProperty(EntityType entityType, String name, TypeMirror type, Annotations annotations) {
    // type
    Type propertyType = typeFactory.getType(type, true);
    if (annotations.isAnnotationPresent(QueryType.class)) {
        PropertyType propertyTypeAnn = annotations.getAnnotation(QueryType.class).value();
        if (propertyTypeAnn != PropertyType.NONE) {
            TypeCategory typeCategory = TypeCategory.valueOf(annotations.getAnnotation(QueryType.class).value().name());
            if (typeCategory == null) {
                return null;
            }
            propertyType = propertyType.as(typeCategory);
        } else {
            return null;
        }
    }
    // inits
    List<String> inits = Collections.emptyList();
    if (annotations.isAnnotationPresent(QueryInit.class)) {
        inits = ImmutableList.copyOf(annotations.getAnnotation(QueryInit.class).value());
    }
    return new Property(entityType, name, propertyType, inits);
}
Also used : QueryType(com.querydsl.core.annotations.QueryType) Type(com.mysema.codegen.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) EntityType(com.querydsl.codegen.EntityType) QueryInit(com.querydsl.core.annotations.QueryInit) TypeCategory(com.mysema.codegen.model.TypeCategory) PropertyType(com.querydsl.core.annotations.PropertyType) QueryType(com.querydsl.core.annotations.QueryType) Property(com.querydsl.codegen.Property)

Example 25 with Type

use of com.mysema.codegen.model.Type in project querydsl by querydsl.

the class Generic2Test method resolve.

@Test
public void resolve() {
    TypeFactory factory = new TypeFactory(Collections.<Class<? extends Annotation>>emptyList());
    Type type = factory.get(AbstractCollectionAttribute.class);
    assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(false));
    assertEquals("com.querydsl.codegen.Generic2Test.AbstractCollectionAttribute", type.getGenericName(true));
}
Also used : Type(com.mysema.codegen.model.Type) Test(org.junit.Test)

Aggregations

Type (com.mysema.codegen.model.Type)31 SimpleType (com.mysema.codegen.model.SimpleType)11 EntityType (com.querydsl.codegen.EntityType)8 Test (org.junit.Test)8 ClassType (com.mysema.codegen.model.ClassType)6 PropertyType (com.querydsl.core.annotations.PropertyType)5 QueryType (com.querydsl.core.annotations.QueryType)5 Parameter (com.mysema.codegen.model.Parameter)4 TypeCategory (com.mysema.codegen.model.TypeCategory)4 Property (com.querydsl.codegen.Property)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)3 DeclaredType (javax.lang.model.type.DeclaredType)3 NoType (javax.lang.model.type.NoType)3 Annotation (java.lang.annotation.Annotation)2 Field (java.lang.reflect.Field)2 MappingException (org.hibernate.MappingException)2 org.hibernate.mapping (org.hibernate.mapping)2 JavaWriter (com.mysema.codegen.JavaWriter)1 ScalaWriter (com.mysema.codegen.ScalaWriter)1 QueryDelegate (com.querydsl.core.annotations.QueryDelegate)1