Search in sources :

Example 1 with CodeWriter

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

the class GenericExporter method write.

private void write(Serializer serializer, String path, SerializerConfig serializerConfig, EntityType type) throws IOException {
    File targetFile = new File(targetFolder, path);
    generatedFiles.add(targetFile);
    Writer w = writerFor(targetFile);
    try {
        CodeWriter writer = createScalaSources ? new ScalaWriter(w) : new JavaWriter(w);
        serializer.serialize(type, serializerConfig, writer);
    } finally {
        w.close();
    }
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) ScalaWriter(com.mysema.codegen.ScalaWriter) CodeWriter(com.mysema.codegen.CodeWriter) CodeWriter(com.mysema.codegen.CodeWriter) ScalaWriter(com.mysema.codegen.ScalaWriter) JavaWriter(com.mysema.codegen.JavaWriter)

Example 2 with CodeWriter

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

the class MetaDataExporter method write.

private void write(Serializer serializer, File targetFile, EntityType type) throws IOException {
    if (!classes.add(targetFile.getPath())) {
        throw new IllegalStateException("Attempted to write multiple times to " + targetFile.getPath() + ", please check your configuration");
    }
    StringWriter w = new StringWriter();
    CodeWriter writer = createScalaSources ? new ScalaWriter(w) : new JavaWriter(w);
    serializer.serialize(type, SimpleSerializerConfig.DEFAULT, writer);
    // conditional creation
    boolean generate = true;
    byte[] bytes = w.toString().getBytes(sourceEncoding);
    if (targetFile.exists() && targetFile.length() == bytes.length) {
        String str = Files.toString(targetFile, Charset.forName(sourceEncoding));
        if (str.equals(w.toString())) {
            generate = false;
        }
    } else {
        targetFile.getParentFile().mkdirs();
    }
    if (generate) {
        Files.write(bytes, targetFile);
    }
}
Also used : StringWriter(java.io.StringWriter) JavaWriter(com.mysema.codegen.JavaWriter) ScalaWriter(com.mysema.codegen.ScalaWriter) CodeWriter(com.mysema.codegen.CodeWriter)

Example 3 with CodeWriter

use of com.mysema.codegen.CodeWriter 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);
    Writer w = writerFor(targetFile);
    try {
        CodeWriter writer = new JavaWriter(w);
        if (typeToConfig.containsKey(type.getJavaClass())) {
            serializer.serialize(type, typeToConfig.get(type.getJavaClass()), writer);
        } else {
            serializer.serialize(type, serializerConfig, writer);
        }
    } finally {
        w.close();
    }
}
Also used : JavaWriter(com.mysema.codegen.JavaWriter) CodeWriter(com.mysema.codegen.CodeWriter) CodeWriter(com.mysema.codegen.CodeWriter) JavaWriter(com.mysema.codegen.JavaWriter)

Aggregations

CodeWriter (com.mysema.codegen.CodeWriter)3 JavaWriter (com.mysema.codegen.JavaWriter)3 ScalaWriter (com.mysema.codegen.ScalaWriter)2 StringWriter (java.io.StringWriter)1