Search in sources :

Example 6 with ClassType

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

the class CustomTypeTest method customType.

@Test
public void customType() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
    EntityType entityType = new EntityType(type);
    entityType.addProperty(new Property(entityType, "property", new ClassType(Double[].class)));
    typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    assertTrue(typeMappings.isRegistered(entityType.getProperties().iterator().next().getType()));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public final com.querydsl.codegen.Point property = " + "new com.querydsl.codegen.Point(forProperty(\"property\"));"));
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) JavaWriter(com.querydsl.codegen.utils.JavaWriter) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 7 with ClassType

use of com.querydsl.codegen.utils.model.ClassType 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 8 with ClassType

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

the class ScalaWriterTest method setUp.

@Before
public void setUp() {
    testType = new ClassType(JavaWriterTest.class);
    testType2 = new SimpleType("com.querydsl.codegen.utils.Test", "com.querydsl.codegen.utils", "Test");
    testSuperType = new SimpleType("com.querydsl.codegen.utils.Superclass", "com.querydsl.codegen.utils", "Superclass");
    testInterface1 = new SimpleType("com.querydsl.codegen.utils.TestInterface1", "com.querydsl.codegen.utils", "TestInterface1");
    testInterface2 = new SimpleType("com.querydsl.codegen.utils.TestInterface2", "com.querydsl.codegen.utils", "TestInterface2");
}
Also used : SimpleType(com.querydsl.codegen.utils.model.SimpleType) ClassType(com.querydsl.codegen.utils.model.ClassType) Before(org.junit.Before)

Example 9 with ClassType

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

the class InnerClassesTest method Scala.

@Test
public void Scala() {
    StringWriter str = new StringWriter();
    ScalaWriter writer = new ScalaWriter(str);
    assertEquals("com.querydsl.codegen.utils.InnerClassesTest$Entity", writer.getRawName(new ClassType(Entity.class)));
}
Also used : StringWriter(java.io.StringWriter) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 10 with ClassType

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

the class InnerClassesTest method Java.

@Test
public void Java() {
    StringWriter str = new StringWriter();
    JavaWriter writer = new JavaWriter(str);
    assertEquals("com.querydsl.codegen.utils.InnerClassesTest.Entity", writer.getRawName(new ClassType(Entity.class)));
}
Also used : StringWriter(java.io.StringWriter) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Aggregations

ClassType (com.querydsl.codegen.utils.model.ClassType)35 Test (org.junit.Test)24 SimpleType (com.querydsl.codegen.utils.model.SimpleType)18 Type (com.querydsl.codegen.utils.model.Type)14 List (java.util.List)7 JavaWriter (com.querydsl.codegen.utils.JavaWriter)6 StringWriter (java.io.StringWriter)6 Parameter (com.querydsl.codegen.utils.model.Parameter)4 TypeCategory (com.querydsl.codegen.utils.model.TypeCategory)3 PrimaryKeyData (com.querydsl.sql.codegen.support.PrimaryKeyData)3 ArrayList (java.util.ArrayList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Property (com.querydsl.codegen.Property)2 Cat (com.querydsl.codegen.utils.support.Cat)2 JoinType (com.querydsl.core.JoinType)2 ColumnImpl (com.querydsl.sql.ColumnImpl)2 Annotation (java.lang.annotation.Annotation)2 Before (org.junit.Before)2 EntityType (com.querydsl.codegen.EntityType)1 ScalaWriter (com.querydsl.codegen.utils.ScalaWriter)1