private static String generateIdentifier(String name, Set<String> existingNames) {
    if (!SourceVersion.isKeyword(name)) {
      return name;
    }
    for (int i = 0; ; i++) {
      String newName = name + i;
      if (!existingNames.contains(newName)) {
        return newName;
      }
    }
  }
A factory for {@link TypeSpec}s used in {@link AutoValueExtension} implementations.

<p>This is copied from {@link
com.google.auto.value.extension.memoized.processor.MemoizeExtension} until we find a better
location to consolidate the code.
value/src/main/java/com/google/auto/value/extension/toprettystring/processor/ExtensionClassTypeSpecBuilder.java