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)); } }
private boolean superTypeHasEntityFields(EntityType model) { Supertype superType = model.getSuperType(); return null != superType && null != superType.getEntityType() && superType.getEntityType().hasEntityFields(); }
/** * Set the name suffix * * @param suffix */ public void setNameSuffix(String suffix) { codegenModule.bind(CodegenModule.SUFFIX, suffix); }
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()); } }
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(); }
public Property createCopy(EntityType targetModel) { if (!declaringType.getParameters().isEmpty()) { Type newType = TypeResolver.resolve(type, declaringType, targetModel); if (!newType.equals(type) || !newType.getClass().equals(type.getClass())) { return new Property(targetModel, name, newType, inits, false); } else { return new Property(targetModel, name, type, inits, targetModel.getSuperType() != null); } } else { return new Property(targetModel, name, type, inits, targetModel.getSuperType() != null); } }
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; }
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"); } }
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(); }
public void addProperty(Property field) { if (!propertyNames.contains(field.getName())) { propertyNames.add(field.getName()); escapedPropertyNames.add(field.getEscapedName()); properties.add(validateField(field)); } }
@SuppressWarnings("unchecked") @Override public Collection<String> getKeywords() { return module.get(Collection.class, CodegenModule.KEYWORDS); }
/** * Export the given packages * * @param packages packages to be scanned */ public void export(String... packages) { scanPackages(packages); innerExport(); }
/** * Export the given classes * * @param classes classes to be scanned */ public void export(Class<?>...classes) { for (Class<?> cl : classes) { handleClass(cl); } innerExport(); }
private Type[] getGenericParameters(Class<?> cl, java.lang.reflect.Type genericType, int parameterCount) { Type[] types = new Type[parameterCount]; for (int i = 0; i < types.length; i++) { types[i] = getGenericParameter(cl, genericType, i); } return types; }
private static Type unwrap(Type type) { if (type instanceof EntityType) { return ((EntityType) type).getInnerType(); } else { return type; } }
/** * Set the typemappings class to be used * * @param typeMappingsClass */ public void setTypeMappingsClass(Class<? extends TypeMappings> typeMappingsClass) { codegenModule.bind(TypeMappings.class, typeMappingsClass); }
/** * Set the keywords to be used * * @param keywords */ public void setKeywords(Collection<String> keywords) { codegenModule.bind(CodegenModule.KEYWORDS, keywords); }
/** * Set the name prefix * * @param prefix */ public void setNamePrefix(String prefix) { codegenModule.bind(CodegenModule.PREFIX, prefix); }
/** * Set the serializer class to be used * * @param serializerClass */ public void setSerializerClass(Class<? extends Serializer> serializerClass) { codegenModule.bind(serializerClass); this.serializerClass = serializerClass; }
/** * Set the package suffix * * @param suffix */ public void setPackageSuffix(String suffix) { codegenModule.bind(CodegenModule.PACKAGE_SUFFIX, suffix); }