use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.
the class AbstractQuerydslProcessor method serialize.
private void serialize(Serializer serializer, Collection<EntityType> models) {
for (EntityType model : models) {
try {
Type type = conf.getTypeMappings().getPathType(model, model, true);
String packageName = type.getPackageName();
String className = !packageName.isEmpty() ? (packageName + "." + type.getSimpleName()) : type.getSimpleName();
// skip if type is excluded class or in excluded package
if (conf.isExcludedPackage(model.getPackageName()) || conf.isExcludedClass(model.getFullName())) {
continue;
}
Set<TypeElement> elements = context.typeElements.get(model.getFullName());
if (elements == null) {
elements = new HashSet<TypeElement>();
}
for (Property property : model.getProperties()) {
if (property.getType().getCategory() == TypeCategory.CUSTOM) {
Set<TypeElement> customElements = context.typeElements.get(property.getType().getFullName());
if (customElements != null) {
elements.addAll(customElements);
}
}
}
processingEnv.getMessager().printMessage(Kind.NOTE, "Generating " + className + " for " + elements);
JavaFileObject fileObject = processingEnv.getFiler().createSourceFile(className, elements.toArray(new Element[elements.size()]));
Writer writer = fileObject.openWriter();
try {
SerializerConfig serializerConfig = conf.getSerializerConfig(model);
serializer.serialize(model, serializerConfig, new JavaWriter(writer));
} finally {
if (writer != null) {
writer.close();
}
}
} catch (IOException e) {
System.err.println(e.getMessage());
processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage());
}
}
}
use of com.mysema.codegen.JavaWriter 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();
}
}
use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.
the class BeanSerializerTest method annotations.
@Test
public void annotations() throws IOException {
type.addAnnotation(new QueryEntityImpl());
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"));
}
use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.
the class BeanSerializerTest method interfaces.
@Test
public void interfaces() throws IOException {
BeanSerializer serializer = new BeanSerializer();
serializer.addInterface(new ClassType(Serializable.class));
serializer.serialize(type, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer));
assertTrue(writer.toString().contains("public class DomainClass implements Serializable {"));
}
use of com.mysema.codegen.JavaWriter in project querydsl by querydsl.
the class BeanSerializerTest 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));
}
BeanSerializer serializer = new BeanSerializer();
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));
}
}
Aggregations