Exemple #1
0
  /**
   * Replaces annotation scopes with instance scopes using the Injector's annotation-to-instance
   * map. If the scope annotation has no corresponding instance, an error will be added and unscoped
   * will be retuned.
   */
  static Scoping makeInjectable(Scoping scoping, InjectorImpl injector, Errors errors) {
    Class<? extends Annotation> scopeAnnotation = scoping.getScopeAnnotation();
    if (scopeAnnotation == null) {
      return scoping;
    }

    Scope scope = injector.state.getScope(scopeAnnotation);
    if (scope != null) {
      return Scoping.forInstance(scope);
    }

    errors.scopeNotFound(scopeAnnotation);
    return Scoping.UNSCOPED;
  }
Exemple #2
0
  /** Scopes an internal factory. */
  static <T> InternalFactory<? extends T> scope(
      Key<T> key, InjectorImpl injector, InternalFactory<? extends T> creator, Scoping scoping) {

    if (scoping.isNoScope()) {
      return creator;
    }

    Scope scope = scoping.getScopeInstance();

    // TODO: use diamond operator once JI-9019884 is fixed
    Provider<T> scoped =
        scope.scope(key, new ProviderToInternalFactoryAdapter<T>(injector, creator));
    return new InternalFactoryToProviderAdapter<>(Initializables.<Provider<? extends T>>of(scoped));
  }