/**
   * Generate imports.
   *
   * @param builder
   */
  public static void generateImports(StringBuilder builder) {
    builder.append("import com.google.inject.Inject;\n");
    builder.append("import com.google.inject.Provider;\n");
    builder.append("import com.google.inject.Singleton;\n");

    builder.append("import java.util.HashMap;\n");
    builder.append("import java.util.Map;\n");
  }
  /**
   * Generate to source of the class.
   *
   * @param rootFolder
   */
  public static void generateExtensionManager(File rootFolder) throws IOException {
    File outFile = new File(rootFolder, REGISTRY_PATH);

    StringBuilder builder = new StringBuilder();
    builder.append("package " + "org.eclipse.che.ide.client;\n\n");
    generateImports(builder);
    generateClass(builder);

    // flush content
    FileUtils.writeStringToFile(outFile, builder.toString());
  }
  /**
   * Generate class declarations.
   *
   * @param builder
   */
  public static void generateClass(StringBuilder builder) {
    // generate class header
    builder.append("/**\n");
    builder.append(
        " * THIS CLASS WILL BE OVERRIDDEN BY MAVEN BUILD. DON'T EDIT CLASS, IT WILL HAVE NO EFFECT.\n");
    builder.append(" */\n");
    builder.append("@Singleton\n");
    builder.append("@SuppressWarnings(\"rawtypes\")\n");
    builder.append("public class DtoFactoryVisitorRegistry\n");
    builder.append("{\n");
    builder.append("\n");

    // field
    builder.append(
        GeneratorUtils.TAB
            + "/** Contains the map will all the DtoFactoryVisitor Providers <FullClassFQN, Provider>. */\n");
    builder.append(
        GeneratorUtils.TAB
            + "protected final Map<String, Provider> providers = new HashMap<>();\n\n");

    // generate constructor

    builder.append(
        GeneratorUtils.TAB
            + "/** Constructor that accepts all found DtoFactoryVisitor Providers. */\n");
    builder.append(GeneratorUtils.TAB + "@Inject\n");
    builder.append(GeneratorUtils.TAB + "public DtoFactoryVisitorRegistry(\n");

    // paste args here
    Iterator<Entry<String, String>> entryIterator = dtoFactoryVisitors.entrySet().iterator();
    while (entryIterator.hasNext()) {
      // <FullFQN, ClassName>
      Entry<String, String> entry = entryIterator.next();
      String hasComma = entryIterator.hasNext() ? "," : "";
      // add constructor argument like:
      // fullFQN classNameToLowerCase,
      String classFQN = String.format("Provider<%s>", entry.getKey());
      String variableName = entry.getValue().toLowerCase();
      builder.append(GeneratorUtils.TAB2 + classFQN + " " + variableName + hasComma + "\n");
    }

    builder.append(GeneratorUtils.TAB + ")\n");
    builder.append(GeneratorUtils.TAB + "{\n");

    // paste add here
    for (Entry<String, String> entries : dtoFactoryVisitors.entrySet()) {
      String fullFqn = entries.getKey();
      String variableName = entries.getValue().toLowerCase();

      String putStatement =
          String.format("this.providers.put(\"%s\", %s);%n", fullFqn, variableName);
      builder.append(GeneratorUtils.TAB2 + putStatement);
    }

    // close constructor
    builder.append(GeneratorUtils.TAB + "}\n\n");

    // generate getter
    builder.append(
        GeneratorUtils.TAB
            + "/** Returns  the map will all the DtoFactoryVisitor Providers <FullClassFQN, Provider>. */\n");
    builder.append(GeneratorUtils.TAB + "public Map<String, Provider> getDtoFactoryVisitors()\n");
    builder.append(GeneratorUtils.TAB + "{\n");
    builder.append(GeneratorUtils.TAB2 + "return providers;\n");
    builder.append(GeneratorUtils.TAB + "}\n");

    // close class
    builder.append("}\n");
  }