Search in sources :

Example 26 with JavaWriter

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

the class AbstractDomainExporter method write.

private void write(Serializer serializer, String path, EntityType type) throws IOException {
    File targetFile = new File(targetFolder, path);
    generatedFiles.add(targetFile);
    try (Writer w = writerFor(targetFile)) {
        CodeWriter writer = new JavaWriter(w);
        if (typeToConfig.containsKey(type.getJavaClass())) {
            serializer.serialize(type, typeToConfig.get(type.getJavaClass()), writer);
        } else {
            serializer.serialize(type, serializerConfig, writer);
        }
    }
}
Also used : JavaWriter(com.querydsl.codegen.utils.JavaWriter) File(java.io.File) CodeWriter(com.querydsl.codegen.utils.CodeWriter) OutputStreamWriter(java.io.OutputStreamWriter) CodeWriter(com.querydsl.codegen.utils.CodeWriter) Writer(java.io.Writer) JavaWriter(com.querydsl.codegen.utils.JavaWriter)

Example 27 with JavaWriter

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

Example 28 with JavaWriter

use of com.querydsl.codegen.utils.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.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 29 with JavaWriter

use of com.querydsl.codegen.utils.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 : SimpleType(com.querydsl.codegen.utils.model.SimpleType) JavaWriter(com.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) ClassType(com.querydsl.codegen.utils.model.ClassType) Test(org.junit.Test)

Example 30 with JavaWriter

use of com.querydsl.codegen.utils.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.querydsl.codegen.utils.JavaWriter) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

JavaWriter (com.querydsl.codegen.utils.JavaWriter)45 Test (org.junit.Test)41 Matchers.containsString (org.hamcrest.Matchers.containsString)13 SimpleType (com.querydsl.codegen.utils.model.SimpleType)8 ClassType (com.querydsl.codegen.utils.model.ClassType)6 Writer (java.io.Writer)6 StringWriter (java.io.StringWriter)5 Type (com.querydsl.codegen.utils.model.Type)4 CodeWriter (com.querydsl.codegen.utils.CodeWriter)3 ScalaWriter (com.querydsl.codegen.utils.ScalaWriter)2 File (java.io.File)2 OutputStreamWriter (java.io.OutputStreamWriter)2 EnumMap (java.util.EnumMap)2 Map (java.util.Map)2 Property (com.querydsl.codegen.Property)1 SimpleCompiler (com.querydsl.codegen.utils.SimpleCompiler)1 Constructor (com.querydsl.codegen.utils.model.Constructor)1 Parameter (com.querydsl.codegen.utils.model.Parameter)1 ColumnImpl (com.querydsl.sql.ColumnImpl)1 PrimaryKeyData (com.querydsl.sql.codegen.support.PrimaryKeyData)1