コード例 #1
0
  /**
   * Load eager singletons.
   *
   * @param injector the injector
   * @param stage the stage
   * @param errors the errors
   */
  @SuppressWarnings("rawtypes")
  public void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors) {
    @SuppressWarnings("unchecked")
    Set<BindingImpl<?>> candidateBindings =
        ImmutableSet.copyOf(
            Iterables.concat(
                (Collection) injector.state.getExplicitBindingsThisLevel().values(),
                injector.jitBindings.values()));
    for (final BindingImpl<?> binding : candidateBindings) {
      if (binding.getScoping().isEagerSingleton(stage)) {
        try {
          injector.callInContext(
              new ContextualCallable<Void>() {
                Dependency<?> dependency = Dependency.get(binding.getKey());

                public Void call(InternalContext context) {
                  context.setDependency(dependency);
                  Errors errorsForBinding = errors.withSource(dependency);
                  try {
                    binding.getInternalFactory().get(errorsForBinding, context, dependency);
                  } catch (ErrorsException e) {
                    errorsForBinding.merge(e.getErrors());
                  } finally {
                    context.setDependency(null);
                  }

                  return null;
                }
              });
        } catch (ErrorsException e) {
          throw new AssertionError();
        }
      }
    }
  }
コード例 #2
0
 void injectMembers() {
   try {
     injector.callInContext(
         new ContextualCallable<Void>() {
           public Void call(InternalContext context) {
             for (SingleMemberInjector memberInjector : memberInjectors) {
               // Run injections if we're not in tool stage (ie, PRODUCTION or DEV),
               // or if we are in tool stage and the injection point is toolable.
               if (injector.options.stage != Stage.TOOL
                   || memberInjector.getInjectionPoint().isToolable()) {
                 memberInjector.inject(errors, context, null);
               }
             }
             return null;
           }
         });
   } catch (ErrorsException e) {
     throw new AssertionError();
   }
 }
コード例 #3
0
 public static void cleanCaches(Injector injector) {
   ((InjectorImpl) injector).clearCache();
   if (injector.getParent() != null) {
     cleanCaches(injector.getParent());
   }
 }
コード例 #4
0
 /**
  * Parent injector.
  *
  * @param parent the parent
  * @return the injector builder
  */
 InjectorBuilder parentInjector(InjectorImpl parent) {
   shellBuilder.parent(parent);
   return stage(parent.getInstance(Stage.class));
 }