println("      initialized = true;"); genPatternInit(type);
println("      initializePatterns(term.getFactory());");
  private void genFactoryMethod(Type type)  {    String decl = "public static " + class_name + " fromTerm(aterm.ATerm term)";    printFoldOpen(decl);    println("  " + decl);    println("  {");    println("    List args;");    println();    printFoldOpen(2, "initialize patterns");    println("    if (!initialized) {");    println("      initialized = true;");    genPatternInit(type);    println("    }");    printFoldClose(2);    println();    Iterator iter = type.alternativeIterator();    while (iter.hasNext()) {      Alternative alt = (Alternative)iter.next();      String alt_id   = buildId(alt.getId());      String alt_class = buildAltClassName(type, alt);      println("    args = pat" + alt_id + ".match(term);");      println("    if (args != null) {");      println("      return new " + alt_class + "(term, args);");      println("    }");      println();    }    println("    throw new RuntimeException(\"illegal " + type.getId() + "\");");    println("  }");    printFoldClose();    println();  }