code: public void generateFactory(MessageFile messageFile, File outDir) {
          Map<FactoryKind, List<Map.Entry<String, Message>>> groupedEntries =
                  messageFile.messages.entrySet().stream()
                          .collect(Collectors.groupingBy(e -> FactoryKind.parseFrom(e.getKey().split("\\.")[1])));
          //generate nested classes
          List<String> nestedDecls = new ArrayList<>();
          Set<String> importedTypes = new TreeSet<>();
          for (Map.Entry<FactoryKind, List<Map.Entry<String, Message>>> entry : groupedEntries.entrySet()) {
              if (entry.getKey() == FactoryKind.OTHER) continue;
              //emit members
              String members = entry.getValue().stream()
                      .flatMap(e -> generateFactoryMethodsAndFields(e.getKey(), e.getValue()).stream())
                      .collect(Collectors.joining("\n\n"));
              //emit nested class
              String factoryDecl =
                      StubKind.FACTORY_CLASS.format(entry.getKey().factoryClazz, indent(members, 1));
              nestedDecls.add(indent(factoryDecl, 1));
              //add imports
              entry.getValue().stream().forEach(e ->
                      importedTypes.addAll(importedTypes(e.getValue().getMessageInfo().getTypes())));
          }
          String clazz = StubKind.TOPLEVEL.format(
                  packageName(messageFile.file),
                  String.join("\n", generateImports(importedTypes)),
                  toplevelName(messageFile.file),
                  String.join("\n", nestedDecls));
          try (FileWriter fw = new FileWriter(new File(outDir, toplevelName(messageFile.file) + ".java"))) {
              fw.append(clazz);
          } catch (Throwable ex) {
              throw new AssertionError(ex);
          }
      }
docs: Main entry-point: generate a Java enum-like set of nested factory classes into given output
  folder. The factories are populated as mandated by the comments in the input resource file.