Search in sources :

Example 26 with JavaWriter

use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.

the class BeanSerializerTest method annotated_property_not_serialized.

@Test
public void annotated_property_not_serialized() throws IOException {
    Property property = new Property(type, "entityField", type);
    property.addAnnotation(new QueryEntityImpl());
    type.addProperty(property);
    BeanSerializer serializer = new BeanSerializer(false);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    String str = writer.toString();
    assertFalse(str.contains("import com.querydsl.core.annotations.QueryEntity;"));
    assertFalse(str.contains("@QueryEntity"));
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 27 with JavaWriter

use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.

the class EmbeddableSerializerTest method originalCategory.

@Test
public void originalCategory() throws IOException {
    Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class);
    categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>");
    categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>");
    categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>");
    categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>");
    categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>");
    categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>");
    categoryToSuperClass.put(TypeCategory.STRING, "StringPath");
    categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath");
    for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) {
        StringWriter w = new StringWriter();
        SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity", false, false);
        EntityType entityType = new EntityType(type);
        typeMappings.register(entityType, queryTypeFactory.create(entityType));
        serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(w));
        assertTrue(entry.getValue() + " is missing from " + w, w.toString().contains("public class QEntity extends " + entry.getValue() + " {"));
    }
}
Also used : StringWriter(java.io.StringWriter) JavaWriter(com.mysema.codegen.JavaWriter) EnumMap(java.util.EnumMap) EnumMap(java.util.EnumMap) Map(java.util.Map) Test(org.junit.Test)

Example 28 with JavaWriter

use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.

the class EmbeddableSerializerTest method empty.

@Test
public void empty() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
    EntityType entityType = new EntityType(type);
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    CompileUtils.assertCompiles("QEntity", writer.toString());
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 29 with JavaWriter

use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.

the class EmbeddableSerializerTest method superType.

@Test
public void superType() throws IOException {
    EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2", false, false));
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
    EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType)));
    typeMappings.register(superType, queryTypeFactory.create(superType));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);"));
//CompileUtils.assertCompiles("QEntity", writer.toString());
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 30 with JavaWriter

use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.

the class EmbeddableSerializerTest method correct_superclass.

@Test
public void correct_superclass() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "java.util.Locale", "java.util", "Locale", false, false);
    EntityType entityType = new EntityType(type);
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public class QLocale extends BeanPath<Locale> {"));
    CompileUtils.assertCompiles("QLocale", writer.toString());
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Aggregations

JavaWriter (com.mysema.codegen.JavaWriter)36 Test (org.junit.Test)32 CodeWriter (com.mysema.codegen.CodeWriter)3 StringWriter (java.io.StringWriter)3 ScalaWriter (com.mysema.codegen.ScalaWriter)2 SimpleType (com.mysema.codegen.model.SimpleType)2 Writer (java.io.Writer)2 EnumMap (java.util.EnumMap)2 Map (java.util.Map)2 ClassType (com.mysema.codegen.model.ClassType)1 Type (com.mysema.codegen.model.Type)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 DeclaredType (javax.lang.model.type.DeclaredType)1 NoType (javax.lang.model.type.NoType)1 JavaFileObject (javax.tools.JavaFileObject)1