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 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; }
typeMappings.register(type, queryTypeFactory.create(type));
@Nullable private EntityType createEntityType(TypeMirror typeMirror, List<String> key, boolean deep) { entityTypeCache.put(key, null); Type value = visitor.visit(typeMirror, deep); if (value != null) { EntityType entityType = null; if (value instanceof EntityType) { entityType = (EntityType) value; } else { entityType = new EntityType(value, variableNameFunction); typeMappings.register(entityType, queryTypeFactory.create(entityType)); } entityTypeCache.put(key, entityType); if (deep) { for (Type superType : getSupertypes(typeMirror, deep)) { entityType.addSupertype(new Supertype(superType)); } } return entityType; } else { return null; } }
(superTypeElement != null && superTypeElement.getAnnotation(entityAnn) != null)) { EntityType entityType = new EntityType(type, variableNameFunction); typeMappings.register(entityType, queryTypeFactory.create(entityType)); return entityType;
@Test public void originalCategory() throws IOException { Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class); categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>"); categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>"); categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>"); categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>"); categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>"); categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>"); categoryToSuperClass.put(TypeCategory.STRING, "StringPath"); categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath"); for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) { StringWriter w = new StringWriter(); SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(w)); assertTrue(entry.getValue() + " is missing from " + w, w.toString().contains("public class QEntity extends " + entry.getValue() + " {")); } }
@Test public void original_category() throws IOException { Map<TypeCategory, String> categoryToSuperClass = new EnumMap<TypeCategory, String>(TypeCategory.class); categoryToSuperClass.put(TypeCategory.COMPARABLE, "ComparablePath<Entity>"); categoryToSuperClass.put(TypeCategory.ENUM, "EnumPath<Entity>"); categoryToSuperClass.put(TypeCategory.DATE, "DatePath<Entity>"); categoryToSuperClass.put(TypeCategory.DATETIME, "DateTimePath<Entity>"); categoryToSuperClass.put(TypeCategory.TIME, "TimePath<Entity>"); categoryToSuperClass.put(TypeCategory.NUMERIC, "NumberPath<Entity>"); categoryToSuperClass.put(TypeCategory.STRING, "StringPath"); categoryToSuperClass.put(TypeCategory.BOOLEAN, "BooleanPath"); for (Map.Entry<TypeCategory, String> entry : categoryToSuperClass.entrySet()) { SimpleType type = new SimpleType(entry.getKey(), "Entity", "", "Entity",false,false); EntityType entityType = new EntityType(type); typeMappings.register(entityType, queryTypeFactory.create(entityType)); serializer.serialize(entityType, SimpleSerializerConfig.DEFAULT, new JavaWriter(writer)); assertTrue(entry.toString(), writer.toString().contains("public class QEntity extends " + entry.getValue() + " {")); } }
@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 prefix_and_package_suffix() { QueryTypeFactory factory = new QueryTypeFactoryImpl("Q", "", ".query"); assertEquals("com.querydsl.codegen.query.QPoint", factory.create(type).getFullName()); }
@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 prefix_and_suffix() { QueryTypeFactory factory = new QueryTypeFactoryImpl("Q", "Type", ""); assertEquals("com.querydsl.codegen.QPointType", factory.create(type).getFullName()); }
@Test public void prefix_only() { QueryTypeFactory factory = new QueryTypeFactoryImpl("Q", "", ""); assertEquals("com.querydsl.codegen.QPoint", factory.create(type).getFullName()); }
@Test public void suffix_only() { QueryTypeFactory factory = new QueryTypeFactoryImpl("", "Type", ""); assertEquals("com.querydsl.codegen.PointType", factory.create(type).getFullName()); }
@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()); }