private Type createEnumType(DeclaredType declaredType, TypeElement typeElement, boolean deep) { // fallback Type enumType = createType(typeElement, TypeCategory.ENUM, declaredType.getTypeArguments(), deep); for (Class<? extends Annotation> entityAnn : entityAnnotations) { if (typeElement.getAnnotation(entityAnn) != null) { EntityType entityType = new EntityType(enumType, variableNameFunction); typeMappings.register(entityType, queryTypeFactory.create(entityType)); return entityType; } } return enumType; }
public <T> void addCustomType(Class<T> type, Class<? extends Expression<T>> queryType) { module.get(TypeMappings.class).register(new ClassType(type), new ClassType(queryType)); }
public EntityType handleProjectionType(TypeElement e) { Type c = typeFactory.getType(e.asType(), true); EntityType entityType = new EntityType(c.as(TypeCategory.ENTITY), configuration.getVariableNameFunction()); typeMappings.register(entityType, queryTypeFactory.create(entityType)); List<? extends Element> elements = e.getEnclosedElements(); handleConstructors(entityType, elements); return entityType; }
@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> {")); }
@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 EntityPathBase<Locale> {")); CompileUtils.assertCompiles("QLocale", writer.toString()); }
@Test public void no_package() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "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("public class QEntity extends EntityPathBase<Entity> {")); CompileUtils.assertCompiles("QEntity", writer.toString()); }
@Test public void no_package() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "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("public class QEntity extends BeanPath<Entity> {")); CompileUtils.assertCompiles("QEntity", writer.toString()); }
@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()); }
@Test public void delegates() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); Delegate delegate = new Delegate(type, type, "test", Collections.<Parameter>emptyList(), Types.STRING); entityType.addDelegate(delegate); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("return Entity.test(this);")); CompileUtils.assertCompiles("QEntity", writer.toString()); }
@Test public void delegates() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); Delegate delegate = new Delegate(type, type, "test", Collections.<Parameter>emptyList(), Types.STRING); entityType.addDelegate(delegate); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("return Entity.test(this);")); CompileUtils.assertCompiles("QEntity", writer.toString()); }
@Test public void superType() throws IOException { EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType))); typeMappings.register(superType, queryTypeFactory.create(superType)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);")); //CompileUtils.assertCompiles("QEntity", writer.toString()); }
@Test public void javadocs_for_innerClass() throws IOException { EntityType entityType = new EntityType(new ClassType(Entity.class)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("QEntitySerializerTest_Entity is a Querydsl query type for Entity")); CompileUtils.assertCompiles("QEntitySerializerTest_Entity", writer.toString()); }
@Test public void superType() throws IOException { EntityType superType = new EntityType(new SimpleType(TypeCategory.ENTITY, "Entity2", "", "Entity2",false,false)); SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type, Collections.singleton(new Supertype(superType, superType))); typeMappings.register(superType, queryTypeFactory.create(superType)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public final QEntity2 _super = new QEntity2(this);")); //CompileUtils.assertCompiles("QEntity", writer.toString()); }
@Test public void different_package() throws IOException { queryTypeFactory = new QueryTypeFactoryImpl("Q", "", ".gen"); EntityType entityType = new EntityType(new ClassType(Entity.class)); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(writer.toString().contains("public class QEntitySerializerTest_Entity " + "extends EntityPathBase<EntitySerializerTest.Entity>")); CompileUtils.assertCompiles("QEntitySerializerTest_Entity", writer.toString()); }
@Test public void empty() throws IOException { SimpleType type = new SimpleType(TypeCategory.ENTITY, "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); CompileUtils.assertCompiles("QEntity", writer.toString()); }
@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\"));")); }
@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()); }
@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()); }
@Test public void isRegistered() { TypeMappings typeMappings = new JavaTypeMappings(); typeMappings.register(new ClassType(Double[].class), new ClassType(Point.class)); assertTrue(typeMappings.isRegistered(new ClassType(Double[].class))); }
@Test public void getPathType_of_innerClass() { TypeMappings typeMappings = new JavaTypeMappings(); EntityType model = new EntityType(new ClassType(TypeMappingsTest.class)); EntityType type = new EntityType(new ClassType(Entity.class)); typeMappings.register(type, new QueryTypeFactoryImpl("Q","","").create(type)); Type pathType = typeMappings.getPathType(type, model, false); assertEquals("QTypeMappingsTest_Entity", pathType.getSimpleName()); }