Search in sources :

Example 6 with JavaWriter

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

the class BeanSerializerTest method interfaces2.

@Test
public void interfaces2() throws IOException {
    BeanSerializer serializer = new BeanSerializer();
    serializer.addInterface(Serializable.class);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public class DomainClass implements Serializable {"));
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 7 with JavaWriter

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

the class BeanSerializerTest method capitalization.

@Test
public void capitalization() throws IOException {
    // property
    type.addProperty(new Property(type, "cId", type));
    BeanSerializer serializer = new BeanSerializer();
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public DomainClass getcId() {"));
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 8 with JavaWriter

use of com.mysema.codegen.JavaWriter 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.mysema.codegen.model.SimpleType) JavaWriter(com.mysema.codegen.JavaWriter) ClassType(com.mysema.codegen.model.ClassType) Test(org.junit.Test)

Example 9 with JavaWriter

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

the class GroovyBeanSerializerTest method properties.

@Test
public void properties() throws IOException {
    // property
    type.addProperty(new Property(type, "entityField", type));
    type.addProperty(new Property(type, "collection", new SimpleType(Types.COLLECTION, typeModel)));
    type.addProperty(new Property(type, "listField", new SimpleType(Types.LIST, typeModel)));
    type.addProperty(new Property(type, "setField", new SimpleType(Types.SET, typeModel)));
    type.addProperty(new Property(type, "arrayField", new ClassType(TypeCategory.ARRAY, String[].class)));
    type.addProperty(new Property(type, "mapField", new SimpleType(Types.MAP, typeModel, typeModel)));
    for (Class<?> cl : Arrays.<Class<?>>asList(Boolean.class, Comparable.class, Integer.class, Date.class, java.sql.Date.class, java.sql.Time.class)) {
        Type classType = new ClassType(TypeCategory.get(cl.getName()), cl);
        type.addProperty(new Property(type, StringUtils.uncapitalize(cl.getSimpleName()), classType));
    }
    GroovyBeanSerializer serializer = new GroovyBeanSerializer();
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    String str = writer.toString();
    //System.err.println(str);
    for (String prop : Arrays.asList("String[] arrayField;", "Boolean boolean$;", "Collection<DomainClass> collection;", "Comparable comparable;", "java.util.Date date;", "DomainClass entityField;", "Integer integer;", "List<DomainClass> listField;", "Map<DomainClass, DomainClass> mapField;", "Set<DomainClass> setField;", "java.sql.Time time;")) {
        assertTrue(prop + " was not contained", str.contains(prop));
    }
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 10 with JavaWriter

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

the class EmbeddableSerializerTest method primitive_array.

@Test
public void primitive_array() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity", false, false);
    EntityType entityType = new EntityType(type);
    entityType.addProperty(new Property(entityType, "bytes", new ClassType(byte[].class)));
    typeMappings.register(entityType, queryTypeFactory.create(entityType));
    serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(writer.toString().contains("public final SimplePath<byte[]> bytes"));
    CompileUtils.assertCompiles("QEntity", 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