private void createModelForElement(Element element, Set<JavaFile> modelFiles) {
if (element.complex) {
final JavaFile modelFile = new JavaFile(packageName, element.fullyQualifiedName);
modelFiles.add(modelFile);
final ClassBody modelClass = modelFile.class_("public class %s", element.fullyQualifiedName);
List<String> constructorArgs = new ArrayList<String>();
for (Element child : element.children) {
createModelForElement(child, modelFiles);
createGetter(modelClass, child);
createField(modelClass, child);
constructorArgs.add(makeConstructorArg(child));
}
for (Element attribute : element.attributes) {
createModelForElement(attribute, modelFiles);
createGetter(modelClass, attribute);
createField(modelClass, attribute);
constructorArgs.add(makeConstructorArg(attribute));
}
final Block constructor = modelClass.method("public %s(%s)", element.fullyQualifiedName, join(", ", constructorArgs));
for (Element child : element.children) {
constructor.add("this.%s = %s;", child.valueHandlerMethodName, child.valueHandlerMethodName);
}
for (Element attribute : element.attributes) {
constructor.add("this.%s = %s;", attribute.valueHandlerMethodName, attribute.valueHandlerMethodName);