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); } }
private void addExternalParents(EntityType entityType) { Deque<Type> superTypes = new ArrayDeque<Type>(); if (entityType.getSuperType() != null) { superTypes.push(entityType.getSuperType().getType()); } while (!superTypes.isEmpty()) { Type superType = superTypes.pop(); if (!context.allTypes.containsKey(superType.getFullName())) { TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(superType.getFullName()); if (typeElement == null) { throw new IllegalStateException("Found no type for " + superType.getFullName()); } if (conf.isStrictMode() && !TypeUtils.hasAnnotationOfType(typeElement, conf.getEntityAnnotations())) { continue; } EntityType superEntityType = elementHandler.handleEntityType(typeElement); if (superEntityType.getSuperType() != null) { superTypes.push(superEntityType.getSuperType().getType()); } context.allTypes.put(superType.getFullName(), superEntityType); } } }
private boolean superTypeHasEntityFields(EntityType model) { Supertype superType = model.getSuperType(); return null != superType && null != superType.getEntityType() && superType.getEntityType().hasEntityFields(); }
private static Type resolveVar(Type resolved, String varName, Type declaringType, EntityType context) { // get parameter index of var in declaring type int index = -1; for (int i = 0; i < declaringType.getParameters().size(); i++) { Type param = unwrap(declaringType.getParameters().get(i)); if (Objects.equal(getVarName(param), varName)) { index = i; } } if (index == -1) { throw new IllegalStateException("Did not find type " + varName + " in " + declaringType + " for " + context); } Supertype type = context.getSuperType(); while (!type.getEntityType().equals(declaringType)) { type = type.getEntityType().getSuperType(); } if (!type.getType().getParameters().isEmpty()) { return type.getType().getParameters().get(index); } else { // raw type return resolved; } }
protected void serialize(EntityType model, Property field, Type type, CodeWriter writer, String factoryMethod, String... args) throws IOException { Supertype superType = model.getSuperType(); // construct value StringBuilder value = new StringBuilder(); if (field.isInherited() && superType != null) { if (!superType.getEntityType().hasEntityFields()) { value.append("_super." + field.getEscapedName()); } } else { value.append(factoryMethod + "(\"" + field.getName() + QUOTE); for (String arg : args) { value.append(COMMA + arg); } value.append(")"); } // serialize it if (field.isInherited()) { writer.line("//inherited"); } if (value.length() > 0) { writer.publicFinal(type, field.getEscapedName(), value.toString()); } else { writer.publicFinal(type, field.getEscapedName()); } }
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 intro(EntityType model, SerializerConfig config, CodeWriter writer) throws IOException { introPackage(writer, model); introImports(writer, config, model); writer.nl(); introJavadoc(writer, model); introClassHeader(writer, model); introFactoryMethods(writer, model); introInits(writer, model); if (config.createDefaultVariable()) { introDefaultInstance(writer, model, config.defaultVariableName()); } if (model.getSuperType() != null && model.getSuperType().getEntityType() != null) { introSuper(writer, model); } }
writer.annotation(annotation); if (printSupertype && model.getSuperType() != null) { writer.beginClass(model, model.getSuperType().getType()); } else { writer.beginClass(model);
if (printSupertype && model.getSuperType() != null) { superType = model.getSuperType().getType(); } else if (printSupertype && model.getSuperType() != null) { writer.beginClass(model, model.getSuperType().getType()); } else { writer.beginClass(model);
private void delegate(final EntityType model, Delegate delegate, SerializerConfig config, CodeWriter writer) throws IOException { Parameter[] params = delegate.getParameters().toArray(new Parameter[delegate.getParameters().size()]); writer.beginPublicMethod(delegate.getReturnType(), delegate.getName(), params); // body start writer.beginLine(RETURN + writer.getRawName(delegate.getDelegateType()) + "." + delegate.getName() + "("); writer.append("this"); if (!model.equals(delegate.getDeclaringType())) { int counter = 0; EntityType type = model; while (type != null && !type.equals(delegate.getDeclaringType())) { type = type.getSuperType() != null ? type.getSuperType().getEntityType() : null; counter++; } for (int i = 0; i < counter; i++) { writer.append("._super"); } } for (Parameter parameter : delegate.getParameters()) { writer.append(COMMA + parameter.getName()); } writer.append(");\n"); // body end writer.end(); }
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); } }
protected EntityType createEntityType(Type type, Map<Class<?>, EntityType> types) { Class<?> key = type.getJavaClass(); if (allTypes.containsKey(key)) { return allTypes.get(key); } else { EntityType entityType = new EntityType(type, variableNameFunction); registerConfig(entityType); typeMappings.register(entityType, queryTypeFactory.create(entityType)); Class<?> superClass = key.getSuperclass(); if (entityType.getSuperType() == null && superClass != null && !superClass.equals(Object.class)) { entityType.addSupertype(new Supertype(typeFactory.get(superClass, key.getGenericSuperclass()))); } types.put(key, entityType); allTypes.put(key, entityType); return entityType; } }
for (Map.Entry<Class<?>, EntityType> entry : allTypes.entrySet()) { EntityType entityType = entry.getValue(); if (entityType.getSuperType() != null && !allTypes.containsKey(entityType.getSuperType().getType().getJavaClass())) { additions.add(entityType.getSuperType());
if (printSupertype && model.getSuperType() != null) { superType = model.getSuperType().getType(); } else if (printSupertype && model.getSuperType() != null) { writer.beginClass(model, model.getSuperType().getType()); } else { writer.beginClass(model);
if (printSupertype && model.getSuperType() != null) { superType = model.getSuperType().getType(); } else if (printSupertype && model.getSuperType() != null) { writer.beginClass(model, model.getSuperType().getType()); } else { writer.beginClass(model);
if (printSupertype && model.getSuperType() != null) { superType = model.getSuperType().getType(); } else if (printSupertype && model.getSuperType() != null) { writer.beginClass(model, model.getSuperType().getType()); } else { writer.beginClass(model);