println("      args.add(result);"); println("      result = (aterm.ATermList) " + manyPattern + ".make(args);"); println("    }"); println(); println("    return result;"); println("  }"); println(); }
String continueConversion = ""; String head = "First"; if (!getConverter().isReserved(elementType)) { continueConversion = ".toTerm()"; head = "Head"; } println( "    aterm.ATermList result = factory.makeList(nodes[0].get" + head + "()" + continueConversion + ");"); println("    for (int i = 1; i < length; i++) {"); println("      java.util.List args = new java.util.LinkedList();"); println("      args.add(nodes[i].get" + head + "()" + continueConversion + ");");  Iterator separators = type.separatorFieldIterator(); while (separators.hasNext()) { Field separator = (Field) separators.next(); String fieldId = separator.getId(); String fieldType = separator.getType(); String capitalizedFieldId = StringConversions.makeCapitalizedIdentifier(fieldId); String fieldGetter = "get" + capitalizedFieldId + "()";  continueConversion = ".toTerm()"; if (getConverter().isReserved(fieldType)) { continueConversion = ""; } println("      args.add(nodes[i]." + fieldGetter + continueConversion + ");"); }  println("      args.add(result);"); println("      result = (aterm.ATermList) " + manyPattern + ".make(args);"); println("    }"); println(); println("    return result;"); println("  }"); println(); }
	private void genFactorySeparatedListToTerm(SeparatedListType type) {		String paramTypeName = TypeGenerator.qualifiedClassName(getJavaGenerationParameters(), type);		String manyPattern = patternListVariable(type);		println("  public aterm.ATerm toTerm(" + paramTypeName + " arg) {");		println("    if (arg.isEmpty()) {");		println("      return factory.getEmpty();");		println("    }");		println();		println("    if (arg.isSingle()) {");		println("      return factory.makeList(arg.getHead().toTerm());");		println("    }");		println();		println("    int length = arg.getLength();");		println("    " + paramTypeName + "[] nodes = new " + paramTypeName + "[length];");		println();		println("    for (int i = 0; i < length; i++) {");		println("      nodes[length-i-1] = arg;");		println("      arg = arg.getTail();");		println("    }");		println();		println("    aterm.ATermList result = factory.makeList(nodes[0].getHead().toTerm());");		println("    for (int i = 1; i < length; i++) {");		println("      java.util.List args = new java.util.LinkedList();");		println("      args.add(nodes[i].getHead().toTerm());");		Iterator separators = type.separatorFieldIterator();		while (separators.hasNext()) {			Field separator = (Field) separators.next();			String fieldId = separator.getId();			String capitalizedFieldId = StringConversions.makeCapitalizedIdentifier(fieldId);			String fieldGetter = "get" + capitalizedFieldId + "()";			println("      args.add(nodes[i]." + fieldGetter + ".toTerm());");		}		println("      args.add(result);");		println("      result = (aterm.ATermList) " + manyPattern + ".make(args);");		println("    }");		println();		println("    return result;");		println("  }");		println();	}