static FactoryDescriptor create(
      PackageAndClass name,
      ImmutableSet<AnnotationMirror> annotations,
      TypeMirror extendingType,
      ImmutableSet<TypeMirror> implementingTypes,
      boolean publicType,
      ImmutableSet<FactoryMethodDescriptor> methodDescriptors,
      ImmutableSet<ImplementationMethodDescriptor> implementationMethodDescriptors,
      boolean allowSubclasses) {
    ImmutableSetMultimap.Builder<Key, Parameter> parametersForProviders =
        ImmutableSetMultimap.builder();
    for (FactoryMethodDescriptor descriptor : methodDescriptors) {
      for (Parameter parameter : descriptor.providedParameters()) {
        parametersForProviders.put(parameter.key(), parameter);
      }
    }
    ImmutableMap.Builder<Key, ProviderField> providersBuilder = ImmutableMap.builder();
    UniqueNameSet uniqueNames = new UniqueNameSet();
    parametersForProviders
        .build()
        .asMap()
        .forEach(
            (key, parameters) -> {
              switch (parameters.size()) {
                case 0:
                  throw new AssertionError();
                case 1:
                  Parameter parameter = Iterables.getOnlyElement(parameters);
                  providersBuilder.put(
                      key,
                      ProviderField.create(
                          uniqueNames.getUniqueName(parameter.name() + "Provider"),
                          key,
                          parameter.nullable()));
                  break;
                default:
                  String providerName =
                      uniqueNames.getUniqueName(
                          INVALID_IDENTIFIER_CHARACTERS.replaceFrom(key.toString(), '_')
                              + "Provider");
                  Optional<AnnotationMirror> nullable =
                      parameters.stream()
                          .map(Parameter::nullable)
                          .flatMap(Streams::stream)
                          .findFirst();
                  providersBuilder.put(key, ProviderField.create(providerName, key, nullable));
                  break;
              }
            });

    ImmutableBiMap<FactoryMethodDescriptor, ImplementationMethodDescriptor>
        duplicateMethodDescriptors =
            createDuplicateMethodDescriptorsBiMap(
                methodDescriptors, implementationMethodDescriptors);

    ImmutableSet<FactoryMethodDescriptor> deduplicatedMethodDescriptors =
        getDeduplicatedMethodDescriptors(methodDescriptors, duplicateMethodDescriptors);

    ImmutableSet<ImplementationMethodDescriptor> deduplicatedImplementationMethodDescriptors =
        Sets.difference(implementationMethodDescriptors, duplicateMethodDescriptors.values())
            .immutableCopy();

    return new AutoValue_FactoryDescriptor(
        name,
        annotations,
        extendingType,
        implementingTypes,
        publicType,
        deduplicatedMethodDescriptors,
        deduplicatedImplementationMethodDescriptors,
        allowSubclasses,
        providersBuilder.build());
  }
Generates a unique name using {@code base}. If {@code base} has not yet been added, it will
be returned as-is. If your {@code base} is healthy, this will always return {@code base}.
factory/src/main/java/com/google/auto/factory/processor/FactoryDescriptor.java