public Type getPathType(Type type, EntityType model, boolean raw) { return getPathType(type, model, raw, false, false); }
private void serialize(Serializer serializer, Map<Class<?>, EntityType> types) throws IOException { for (Map.Entry<Class<?>, EntityType> entityType : types.entrySet()) { Type type = typeMappings.getPathType(entityType.getValue(), entityType.getValue(), true); String packageName = type.getPackageName(); String className = packageName.length() > 0 ? (packageName + "." + type.getSimpleName()) : type.getSimpleName(); SerializerConfig config = serializerConfig; if (entityType.getKey().isAnnotationPresent(Config.class)) { config = SimpleSerializerConfig.getConfig(entityType.getKey().getAnnotation(Config.class)); } String fileSuffix = createScalaSources ? ".scala" : ".java"; write(serializer, className.replace('.', '/') + fileSuffix, config, entityType.getValue()); } }
protected void introDefaultInstance(CodeWriter writer, EntityType model, String defaultName) throws IOException { String simpleName = !defaultName.isEmpty() ? defaultName : model.getModifiedSimpleName(); Type queryType = typeMappings.getPathType(model, model, true); String alias = simpleName; if (keywords.contains(simpleName.toUpperCase())) { alias += "1"; } writer.publicStaticFinal(queryType, simpleName, NEW + queryType.getSimpleName() + "(\"" + alias + "\")"); }
protected void introPackage(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, false); if (!queryType.getPackageName().isEmpty()) { writer.packageDecl(queryType.getPackageName()); } }
protected void introJavadoc(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, true); writer.javadoc(queryType.getSimpleName() + " is a Querydsl query type for " + model.getSimpleName()); }
Type queryType = typeMappings.getPathType(model, model, true); if (!model.getPackageName().isEmpty() && !queryType.getPackageName().equals(model.getPackageName())
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();
protected void intro(EntityType model, CodeWriter writer) throws IOException { String simpleName = model.getSimpleName(); Type queryType = typeMappings.getPathType(model, model, false);
protected void introSuper(CodeWriter writer, EntityType model) throws IOException { EntityType superType = model.getSuperType().getEntityType(); Type superQueryType = typeMappings.getPathType(superType, model, false); if (!superType.hasEntityFields()) { writer.publicFinal(superQueryType, "_super", NEW + writer.getRawName(superQueryType) + "(this)"); } else { writer.publicFinal(superQueryType, "_super"); } }
@SuppressWarnings(UNCHECKED) protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, true);
protected void entityField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); if (field.isInherited()) { writer.line("// inherited"); } if (config.useEntityAccessors()) { writer.protectedField(queryType, field.getEscapedName()); } else { writer.publicFinal(queryType, field.getEscapedName()); } }
@Override @SuppressWarnings(UNCHECKED) protected void introClassHeader(CodeWriter writer, EntityType model) throws IOException { Type queryType = typeMappings.getPathType(model, model, true);
protected void listAccessor(EntityType model, Property field, CodeWriter writer) throws IOException { String escapedName = field.getEscapedName(); Type queryType = typeMappings.getPathType(field.getParameter(0), model, false); writer.beginPublicMethod(queryType, escapedName, new Parameter("index", Types.INT)); writer.line(RETURN + escapedName + ".get(index);").end(); writer.beginPublicMethod(queryType, escapedName, new Parameter("index", new ClassType(Expression.class, Types.INTEGER))); writer.line(RETURN + escapedName + ".get(index);").end(); }
protected void entityAccessor(EntityType model, Property field, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); writer.beginPublicMethod(queryType, field.getEscapedName()); writer.line("if (", field.getEscapedName(), " == null) {"); writer.line(" ", field.getEscapedName(), " = new ", writer.getRawName(queryType), "(forProperty(\"", field.getName(), "\"));"); writer.line("}"); writer.line(RETURN, field.getEscapedName(), SEMICOLON); writer.end(); }
protected void mapAccessor(EntityType model, Property field, CodeWriter writer) throws IOException { String escapedName = field.getEscapedName(); Type queryType = typeMappings.getPathType(field.getParameter(1), model, false); writer.beginPublicMethod(queryType, escapedName, new Parameter("key", field.getParameter(0))); writer.line(RETURN + escapedName + ".get(key);").end(); writer.beginPublicMethod(queryType, escapedName, new Parameter("key", new ClassType(Expression.class, field.getParameter(0)))); writer.line(RETURN + escapedName + ".get(key);").end(); }
protected void initEntityField(CodeWriter writer, SerializerConfig config, EntityType model, Property field) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); if (!field.isInherited()) { boolean hasEntityFields = field.getType() instanceof EntityType && ((EntityType) field.getType()).hasEntityFields(); writer.line("this." + field.getEscapedName() + ASSIGN, "inits.isInitialized(\"" + field.getName() + "\") ? ", NEW + writer.getRawName(queryType) + "(forProperty(\"" + field.getName() + "\")", hasEntityFields ? (", inits.get(\"" + field.getName() + "\")") : EMPTY, ") : null;"); } else if (!config.useEntityAccessors()) { writer.line("this.", field.getEscapedName(), ASSIGN, "_super.", field.getEscapedName(), SEMICOLON); } }
protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { Supertype superType = model.getSuperType(); if (superType != null) { EntityType entityType = superType.getEntityType(); if (entityType != null && entityType.hasEntityFields()) { Type superQueryType = typeMappings.getPathType(entityType, model, false); writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);"); } } for (Property field : model.getProperties()) { if (field.getType().getCategory() == TypeCategory.ENTITY) { initEntityField(writer, config, model, field); } else if (field.isInherited() && superType != null && superType.getEntityType().hasEntityFields()) { writer.line("this.", field.getEscapedName(), " = _super.", field.getEscapedName(), SEMICOLON); } } }
protected void customField(EntityType model, Property field, SerializerConfig config, CodeWriter writer) throws IOException { Type queryType = typeMappings.getPathType(field.getType(), model, false); writer.line("// custom"); if (field.isInherited()) { writer.line("// inherited"); Supertype superType = model.getSuperType(); if (!superType.getEntityType().hasEntityFields()) { String value = NEW + writer.getRawName(queryType) + "(_super." + field.getEscapedName() + ")"; writer.publicFinal(queryType, field.getEscapedName(), value); } else { writer.publicFinal(queryType, field.getEscapedName()); } } else { String value = NEW + writer.getRawName(queryType) + "(forProperty(\"" + field.getName() + "\"))"; writer.publicFinal(queryType, field.getEscapedName(), value); } }
Type queryType = typeMappings.getPathType(propertyType, model, false); Type genericQueryType = null; String localRawName = writer.getRawName(property.getType()); genericQueryType = typeMappings.getPathType(getRaw(property.getParameter(0)), model, false); String genericKey = writer.getGenericName(true, property.getParameter(0)); localRawName = writer.getRawName(property.getParameter(0)); queryType = typeMappings.getPathType(property.getParameter(0), model, true); genericQueryType = typeMappings.getPathType(getRaw(property.getParameter(0)), model, false); genericKey = writer.getGenericName(true, property.getParameter(0)); localRawName = writer.getRawName(property.getParameter(0)); queryType = typeMappings.getPathType(property.getParameter(0), model, true); genericQueryType = typeMappings.getPathType(getRaw(property.getParameter(0)), model, false); genericKey = writer.getGenericName(true, property.getParameter(0)); localRawName = writer.getRawName(property.getParameter(0)); queryType = typeMappings.getPathType(property.getParameter(0), model, true); genericKey = writer.getGenericName(true, property.getParameter(0)); String genericValue = writer.getGenericName(true, property.getParameter(1)); genericQueryType = typeMappings.getPathType(getRaw(property.getParameter(1)), model, false); String keyType = writer.getRawName(property.getParameter(0)); String valueType = writer.getRawName(property.getParameter(1)); queryType = typeMappings.getPathType(property.getParameter(1), model, true);
@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()); }