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

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

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

import static shaded.shaded.com.google.common.base.Preconditions.checkNotNull;

import shaded.shaded.com.google.common.base.Preconditions;
import shaded.shaded.com.google.common.collect.Lists;
import shaded.shaded.com.google.inject.spi.ErrorDetail;
import java.io.Serializable;
import java.util.Formatter;
import java.util.List;

/** Generic error message representing a Guice internal error. */
public final class GenericErrorDetail extends InternalErrorDetail
    implements Serializable {
  public GenericErrorDetail(
      ErrorId errorId, String message, List sources, Throwable cause) {
    super(errorId, checkNotNull(message, "message"), sources, cause);
  }

  @Override
  public void formatDetail(List> mergeableErrors, Formatter formatter) {
    Preconditions.checkArgument(mergeableErrors.isEmpty(), "Unexpected mergeable errors");
    List dependencies = getSources();
    for (Object source : Lists.reverse(dependencies)) {
      formatter.format("  ");
      new SourceFormatter(source, formatter, /* omitPreposition= */ false).format();
    }
  }

  @Override
  public GenericErrorDetail withSources(List newSources) {
    return new GenericErrorDetail(errorId, getMessage(), newSources, getCause());
  }
}