Search in sources :

Example 21 with JavaWriter

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

the class PackageSuffixTest method correct_imports.

@Test
public void correct_imports() throws IOException {
    SimpleType type = new SimpleType(TypeCategory.ENTITY, "test.Entity", "test", "Entity", 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("import test.Entity;"));
    assertTrue(writer.toString().contains("public class QEntity extends EntityPathBase<Entity> {"));
}
Also used : SimpleType(com.mysema.codegen.model.SimpleType) JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 22 with JavaWriter

use of com.mysema.codegen.JavaWriter 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 ProjectionSerializer(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 : StringWriter(java.io.StringWriter) JavaWriter(com.mysema.codegen.JavaWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 23 with JavaWriter

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

the class BeanSerializerTest method annotated_property.

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

Example 24 with JavaWriter

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

the class BeanSerializerTest method toString_.

@Test
public void toString_() 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)));
    BeanSerializer serializer = new BeanSerializer();
    serializer.setAddToString(true);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
    assertTrue(String.valueOf(writer).contains("    @Override\n" + "    public String toString()"));
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) Test(org.junit.Test)

Example 25 with JavaWriter

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

the class BeanSerializerTest method fullConstructor.

@Test
public void fullConstructor() 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)));
    BeanSerializer serializer = new BeanSerializer();
    serializer.setAddFullConstructor(true);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
//System.out.println(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