All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shaded.com.google.inject.internal.InternalErrorDetail Maven / Gradle / Ivy

There is a newer version: 4.1.4
Show newest version
package shaded.shaded.com.google.inject.internal;

import shaded.shaded.com.google.common.base.CaseFormat;
import shaded.shaded.com.google.common.collect.ImmutableSet;
import shaded.shaded.com.google.inject.spi.ErrorDetail;
import java.util.List;
import java.util.Optional;

/**
 * Represents an error created by Guice as opposed to custom error added to the binder from
 * application code.
 */
abstract class InternalErrorDetail> extends ErrorDetail {
  // A list of errors that have help documentation.
  private static final ImmutableSet DOCUMENTED_ERRORS =
      ImmutableSet.builder()
          .add(ErrorId.BINDING_ALREADY_SET)
          .add(ErrorId.CAN_NOT_PROXY_CLASS)
          .add(ErrorId.CIRCULAR_PROXY_DISABLED)
          .add(ErrorId.DUPLICATE_BINDING_ANNOTATIONS)
          .add(ErrorId.DUPLICATE_ELEMENT)
          .add(ErrorId.DUPLICATE_SCOPES)
          .add(ErrorId.ERROR_INJECTING_CONSTRUCTOR)
          .add(ErrorId.ERROR_INJECTING_METHOD)
          .add(ErrorId.ERROR_IN_CUSTOM_PROVIDER)
          .add(ErrorId.INJECT_INNER_CLASS)
          .add(ErrorId.MISSING_CONSTRUCTOR)
          .add(ErrorId.MISSING_IMPLEMENTATION)
          .add(ErrorId.NULL_INJECTED_INTO_NON_NULLABLE)
          .add(ErrorId.NULL_VALUE_IN_MAP)
          .add(ErrorId.SCOPE_NOT_FOUND)
          .add(ErrorId.TOO_MANY_CONSTRUCTORS)
          .build();

  private static final String DOC_BASE_URL = "https://github.shaded.shaded.com.google/guice/wiki/";

  protected final ErrorId errorId;

  protected InternalErrorDetail(
      ErrorId errorId, String message, List sources, Throwable cause) {
    super(message, sources, cause);
    this.errorId = errorId;
  }

  @Override
  protected final Optional getLearnMoreLink() {
    if (DOCUMENTED_ERRORS.contains(errorId)) {
      return Optional.of(DOC_BASE_URL + errorId.name());
    }
    return Optional.empty();
  }

  @Override
  protected final Optional getErrorIdentifier() {
    if (errorId == ErrorId.OTHER) {
      return Optional.empty();
    }
    String id = "Guice/" + CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, errorId.name());
    return Optional.of(id);
  }
}