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

shaded.com.google.inject.internal.ScopeNotFoundError 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.collect.Lists;
import shaded.shaded.com.google.inject.spi.ErrorDetail;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;

/** Error reported by Guice when a scope annotation is not bound to any scope implementation. */
final class ScopeNotFoundError extends InternalErrorDetail {

  private final Class scopeAnnotation;

  ScopeNotFoundError(Class scopeAnnotation, List sources) {
    super(
        ErrorId.SCOPE_NOT_FOUND,
        String.format("No scope is bound to %s.", Messages.convert(scopeAnnotation)),
        sources,
        null);
    this.scopeAnnotation = scopeAnnotation;
  }

  @Override
  public boolean isMergeable(ErrorDetail other) {
    return other instanceof ScopeNotFoundError
        && ((ScopeNotFoundError) other).scopeAnnotation.equals(scopeAnnotation);
  }

  @Override
  protected void formatDetail(List> mergeableErrors, Formatter formatter) {
    List> sourcesSet = new ArrayList<>();
    sourcesSet.add(getSources());
    mergeableErrors.stream().map(ErrorDetail::getSources).forEach(sourcesSet::add);

    formatter.format("%n%s%n", "Used at:");
    int sourceListIndex = 1;
    for (List sources : sourcesSet) {
      ErrorFormatter.formatSources(sourceListIndex++, Lists.reverse(sources), formatter);
    }
  }

  @Override
  public ScopeNotFoundError withSources(List newSources) {
    return new ScopeNotFoundError(scopeAnnotation, newSources);
  }
}