Search in sources :

Example 46 with Type

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

the class TypeResolver method resolveWithParameters.

private static Type resolveWithParameters(Type type, Type declaringType, EntityType context) {
    Type[] params = new Type[type.getParameters().size()];
    boolean transformed = false;
    for (int i = 0; i < type.getParameters().size(); i++) {
        Type param = type.getParameters().get(i);
        if (param != null && !param.getFullName().equals(type.getFullName())) {
            params[i] = resolve(param, declaringType, context);
            if (!params[i].equals(param)) {
                transformed = true;
            }
        }
    }
    if (transformed) {
        return new SimpleType(type, params);
    } else {
        return type;
    }
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType)

Example 47 with Type

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

the class ProjectionSerializerTest method customGeneratedAnnotation.

@Test
public void customGeneratedAnnotation() throws IOException {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Writer writer = new StringWriter();
    ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings(), Generated.class);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    String generatedSource = writer.toString();
    assertThat(generatedSource, containsString("import com.querydsl.core.annotations.Generated"));
    assertThat(generatedSource, containsString("@Generated(\"com.querydsl.codegen.DefaultProjectionSerializer\")\npublic class"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 48 with Type

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

the class ProjectionSerializerTest method defaultGeneratedAnnotation.

@Test
public void defaultGeneratedAnnotation() throws IOException {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    Writer writer = new StringWriter();
    ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    String generatedSource = writer.toString();
    assertThat(generatedSource, containsString(String.format("import %s;", GeneratedAnnotationResolver.resolveDefault().getName())));
    assertThat(generatedSource, containsString("@Generated(\"com.querydsl.codegen.DefaultProjectionSerializer\")\npublic class"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 49 with Type

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

the class ProjectionSerializerTest method constructors.

@Test
public void constructors() throws IOException {
    Type typeModel = new SimpleType(TypeCategory.ENTITY, "com.querydsl.DomainClass", "com.querydsl", "DomainClass", false, false);
    EntityType type = new EntityType(typeModel);
    // constructor
    Parameter firstName = new Parameter("firstName", Types.STRING);
    Parameter lastName = new Parameter("lastName", Types.STRING);
    Parameter age = new Parameter("age", Types.INTEGER);
    type.addConstructor(new Constructor(Arrays.asList(firstName, lastName, age)));
    Writer writer = new StringWriter();
    ProjectionSerializer serializer = new DefaultProjectionSerializer(new JavaTypeMappings());
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("Expression<String> firstName"));
    assertTrue(writer.toString().contains("Expression<String> lastName"));
    assertTrue(writer.toString().contains("Expression<Integer> age"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) Type(com.querydsl.codegen.utils.model.Type) SimpleType(com.querydsl.codegen.utils.model.SimpleType) StringWriter(java.io.StringWriter) Constructor(com.querydsl.codegen.utils.model.Constructor) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Parameter(com.querydsl.codegen.utils.model.Parameter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Test(org.junit.Test)

Example 50 with Type

use of com.querydsl.codegen.utils.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 : QueryType(com.querydsl.core.annotations.QueryType) Type(com.querydsl.codegen.utils.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Type (com.querydsl.codegen.utils.model.Type)56 SimpleType (com.querydsl.codegen.utils.model.SimpleType)35 ClassType (com.querydsl.codegen.utils.model.ClassType)23 EntityType (com.querydsl.codegen.EntityType)15 Test (org.junit.Test)14 PropertyType (com.querydsl.core.annotations.PropertyType)9 QueryType (com.querydsl.core.annotations.QueryType)9 DeclaredType (javax.lang.model.type.DeclaredType)9 NoType (javax.lang.model.type.NoType)9 Parameter (com.querydsl.codegen.utils.model.Parameter)7 ArrayList (java.util.ArrayList)7 TypeCategory (com.querydsl.codegen.utils.model.TypeCategory)6 StringWriter (java.io.StringWriter)6 ArrayType (javax.lang.model.type.ArrayType)6 ErrorType (javax.lang.model.type.ErrorType)6 ExecutableType (javax.lang.model.type.ExecutableType)6 NullType (javax.lang.model.type.NullType)6 PrimitiveType (javax.lang.model.type.PrimitiveType)6 WildcardType (javax.lang.model.type.WildcardType)6 Annotation (java.lang.annotation.Annotation)5