public void extendTypes() { for (EntityType entityType : entityTypeCache.values()) { if (entityType.getProperties().isEmpty()) { for (Map.Entry<List<String>, EntityType> entry : entityTypeCache.entrySet()) { if (entry.getKey().get(0).equals(entityType.getFullName()) && !entry.getValue().getProperties().isEmpty()) { for (Property property : entry.getValue().getProperties()) { entityType.addProperty(property); } break; } } } } } }
private Set<String> getAnnotationTypes(EntityType model) { Set<String> imports = new HashSet<String>(); for (Annotation annotation : model.getAnnotations()) { imports.add(annotation.annotationType().getName()); } if (propertyAnnotations) { for (Property property : model.getProperties()) { for (Annotation annotation : property.getAnnotations()) { imports.add(annotation.annotationType().getName()); } } } return imports; }
private Set<String> getAnnotationTypes(EntityType model) { Set<String> imports = new HashSet<String>(); for (Annotation annotation : model.getAnnotations()) { imports.add(annotation.annotationType().getName()); } if (propertyAnnotations) { for (Property property : model.getProperties()) { for (Annotation annotation : property.getAnnotations()) { imports.add(annotation.annotationType().getName()); } } } return imports; }
public void extendTypes() { for (Map.Entry<List<?>, Type> entry : cache.entrySet()) { if (entry.getValue() instanceof EntityType) { EntityType entityType = (EntityType) entry.getValue(); if (entityType.getProperties().isEmpty()) { for (Type type : cache.values()) { if (type.getFullName().equals(entityType.getFullName()) && type instanceof EntityType) { EntityType base = (EntityType) type; for (Property property : base.getProperties()) { entityType.addProperty(property); } } } } } } }
private void validateMetaTypes() { @SuppressWarnings("unchecked") // Only concatenated Iterable<? extends EntityType> entityTypes = Iterables.concat( context.supertypes.values(), context.entityTypes.values(), context.extensionTypes.values(), context.embeddableTypes.values(), context.projectionTypes.values()); for (EntityType entityType : entityTypes) { for (Property property : entityType.getProperties()) { if (property.getInits() != null && property.getInits().size() > 0) { validateInits(entityType, property); } } } }
private Set<String> getUsedClassNames(EntityType model) { Set<String> result = Sets.newHashSet(); result.add(model.getSimpleName()); for (Property property : model.getProperties()) { result.add(property.getType().getSimpleName()); for (Type type : property.getType().getParameters()) { if (type != null) { result.add(type.getSimpleName()); } } } return result; }
protected void introInits(CodeWriter writer, EntityType model) throws IOException { List<String> inits = new ArrayList<String>(); for (Property property : model.getProperties()) { for (String init : property.getInits()) { inits.add(property.getEscapedName() + DOT + init); } } if (!inits.isEmpty()) { inits.add(0, STAR); String initsAsString = QUOTE + JOINER.join(inits) + QUOTE; writer.privateStaticFinal(PATH_INITS_TYPE, "INITS", "new PathInits(" + initsAsString + ")"); } else if (model.hasEntityFields() || superTypeHasEntityFields(model)) { writer.privateStaticFinal(PATH_INITS_TYPE, "INITS", "PathInits.DIRECT2"); } }
protected void addToString(EntityType model, CodeWriter writer) throws IOException { writer.line("@Override"); writer.beginPublicMethod(Types.STRING, "toString"); StringBuilder builder = new StringBuilder(); for (Property property : model.getProperties()) { String propertyName = property.getEscapedName(); if (builder.length() > 0) { builder.append(" + \", "); } else { builder.append("\""); } builder.append(propertyName + " = \" + "); if (property.getType().getCategory() == TypeCategory.ARRAY) { builder.append("Arrays.toString(" + propertyName + ")"); } else { builder.append(propertyName); } } writer.line(" return ", builder.toString(), ";"); writer.end(); }
protected void addFullConstructor(EntityType model, CodeWriter writer) throws IOException { // public empty constructor writer.beginConstructor(); writer.end(); // full constructor writer.beginConstructor(model.getProperties(), propertyToParameter); for (Property property : model.getProperties()) { writer.line("this.", property.getEscapedName(), " = ", property.getEscapedName(), ";"); } writer.end(); }
protected boolean hasOwnEntityProperties(EntityType model) { if (model.hasEntityFields()) { for (Property property : model.getProperties()) { if (!property.isInherited() && property.getType().getCategory() == TypeCategory.ENTITY) { return true; } } } return false; }
public void include(Supertype supertype) { EntityType entityType = supertype.getEntityType(); for (Delegate delegate : entityType.getDelegates()) { addDelegate(delegate); } for (Property property : entityType.getProperties()) { addProperty(property.createCopy(this)); } }
} else { Set<TypeCategory> collections = Sets.newHashSet(TypeCategory.COLLECTION, TypeCategory.LIST, TypeCategory.SET); for (Property property : model.getProperties()) { if (!property.isInherited() && collections.contains(property.getType().getCategory())) { inits = true;
elements = new HashSet<TypeElement>(); for (Property property : model.getProperties()) { if (property.getType().getCategory() == TypeCategory.CUSTOM) { Set<TypeElement> customElements = context.typeElements.get(property.getType().getFullName());
Class<? extends Path> pathType; if (model.getProperties().isEmpty()) { switch (category) { case COMPARABLE : pathType = ComparablePath.class; break;
if (model.getProperties().isEmpty()) { switch (category) { case COMPARABLE : pathType = ComparablePath.class; break;
for (Property property : model.getProperties()) { if (propertyAnnotations) { for (Annotation annotation : property.getAnnotations()) {
for (Property property : model.getProperties()) { if (propertyAnnotations) { for (Annotation annotation : property.getAnnotations()) { for (Property property : model.getProperties()) { String propertyName = property.getEscapedName();
@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\"));")); }
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); } } }
@Override public void serialize(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException { intro(model, config, writer); // properties serializeProperties(model, config, writer); // constructors constructors(model, config, writer); // delegates for (Delegate delegate : model.getDelegates()) { delegate(model, delegate, config, writer); } // property accessors for (Property property : model.getProperties()) { TypeCategory category = property.getType().getCategory(); if (category == TypeCategory.MAP && config.useMapAccessors()) { mapAccessor(model, property, writer); } else if (category == TypeCategory.LIST && config.useListAccessors()) { listAccessor(model, property, writer); } else if (category == TypeCategory.ENTITY && config.useEntityAccessors()) { entityAccessor(model, property, writer); } } outro(model, writer); }