Search in sources :

Example 51 with Type

use of com.querydsl.codegen.utils.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 = new ArrayList<>();
            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.querydsl.codegen.utils.model.Constructor(parameters));
        }
    }
}
Also used : QueryType(com.querydsl.core.annotations.QueryType) Type(com.querydsl.codegen.utils.model.Type) PropertyType(com.querydsl.core.annotations.PropertyType) ArrayList(java.util.ArrayList) Parameter(com.querydsl.codegen.utils.model.Parameter) QueryType(com.querydsl.core.annotations.QueryType) Annotation(java.lang.annotation.Annotation)

Example 52 with Type

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

the class Inheritance2Test method base_base.

@Test
public void base_base() throws SecurityException, NoSuchFieldException {
    TypeFactory typeFactory = new TypeFactory();
    Field field = Base.class.getDeclaredField("base");
    Type type = typeFactory.get(field.getType(), field.getGenericType());
    assertEquals(0, type.getParameters().size());
}
Also used : Field(java.lang.reflect.Field) Type(com.querydsl.codegen.utils.model.Type) Test(org.junit.Test)

Example 53 with Type

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

the class Inheritance2Test method base_base2.

@Test
public void base_base2() throws SecurityException, NoSuchFieldException {
    TypeFactory typeFactory = new TypeFactory();
    Field field = Base.class.getDeclaredField("base2");
    Type type = typeFactory.get(field.getType(), field.getGenericType());
    assertEquals(2, type.getParameters().size());
    assertNull(((TypeExtends) type.getParameters().get(0)).getVarName());
    assertNull(((TypeExtends) type.getParameters().get(1)).getVarName());
}
Also used : Field(java.lang.reflect.Field) Type(com.querydsl.codegen.utils.model.Type) Test(org.junit.Test)

Example 54 with Type

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

the class Generic2Test method resolve2.

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

Example 55 with Type

use of com.querydsl.codegen.utils.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.querydsl.codegen.utils.model.Type) Test(org.junit.Test)

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