当前位置: 首页>>代码示例>>Java>>正文


Java Dependency.get方法代码示例

本文整理汇总了Java中com.google.inject.spi.Dependency.get方法的典型用法代码示例。如果您正苦于以下问题:Java Dependency.get方法的具体用法?Java Dependency.get怎么用?Java Dependency.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.inject.spi.Dependency的用法示例。


在下文中一共展示了Dependency.get方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDependencyChain

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/** Returns the current dependency chain (all the state stored in the dependencyStack). */
java.util.List<com.google.inject.spi.DependencyAndSource> getDependencyChain() {
  com.google.common.collect.ImmutableList.Builder<com.google.inject.spi.DependencyAndSource>
      builder = com.google.common.collect.ImmutableList.builder();
  for (int i = 0; i < dependencyStackSize; i += 2) {
    Object evenEntry = dependencyStack[i];
    Dependency<?> dependency;
    if (evenEntry instanceof com.google.inject.Key) {
      dependency = Dependency.get((com.google.inject.Key<?>) evenEntry);
    } else {
      dependency = (Dependency<?>) evenEntry;
    }
    builder.add(new com.google.inject.spi.DependencyAndSource(dependency, dependencyStack[i + 1]));
  }
  return builder.build();
}
 
开发者ID:google,项目名称:guice,代码行数:17,代码来源:InternalContext.java

示例2: extractDependency

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
Dependency<ListenableFuture<?>> extractDependency(Errors methodErrors, Parameter parameter) {
  @Nullable Annotation bindingAnnotation =
      Annotations.findBindingAnnotation(
          methodErrors,
          parameter.getDeclaringInvokable(),
          parameter.getAnnotations());

  return Dependency.get(futureKey(
      parameter.getType(),
      bindingAnnotation));
}
 
开发者ID:immutables,项目名称:miscellaneous,代码行数:12,代码来源:Providers.java

示例3: loadEagerSingletons

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
 * Loads eager singletons, or all singletons if we're in Stage.PRODUCTION. Bindings discovered
 * while we're binding these singletons are not be eager.
 */
void loadEagerSingletons(InjectorImpl injector, Stage stage, final Errors errors) {
  List<BindingImpl<?>> candidateBindings = new ArrayList<>();
  @SuppressWarnings("unchecked") // casting Collection<Binding> to Collection<BindingImpl> is safe
  Collection<BindingImpl<?>> bindingsAtThisLevel =
      (Collection) injector.state.getExplicitBindingsThisLevel().values();
  candidateBindings.addAll(bindingsAtThisLevel);
  synchronized (injector.state.lock()) {
    // jit bindings must be accessed while holding the lock.
    candidateBindings.addAll(injector.jitBindings.values());
  }
  InternalContext context = injector.enterContext();
  try {
    for (BindingImpl<?> binding : candidateBindings) {
      if (isEagerSingleton(injector, binding, stage)) {
        Dependency<?> dependency = Dependency.get(binding.getKey());
        Dependency previous = context.pushDependency(dependency, binding.getSource());

        try {
          binding.getInternalFactory().get(context, dependency, false);
        } catch (InternalProvisionException e) {
          errors.withSource(dependency).merge(e);
        } finally {
            context.popStateAndSetDependency(previous);
          }
      }
    }
  } finally {
    context.close();
  }
}
 
开发者ID:google,项目名称:guice,代码行数:35,代码来源:InternalInjectorCreator.java

示例4: doInitialize

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) throws ErrorsException {
  @SuppressWarnings({"unchecked", "rawtypes"})
  PerKeyData<K, V>[] typedPerKeyData =
      new PerKeyData[bindingSelection.getMapBindings().size()];
  perKeyDatas = typedPerKeyData;
  ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
  List<Dependency<?>> dependenciesForKey = Lists.newArrayList();
  int i = 0;
  for (Map.Entry<K, Set<Binding<V>>> entry :
      bindingSelection.getMultimapBindings().entrySet()) {
    // Clear the list of dependencies because we're reusing it for each different key
    dependenciesForKey.clear();

    Set<Binding<V>> bindings = entry.getValue();
    @SuppressWarnings({"unchecked", "rawtypes"})
    Binding<V>[] typedBindings = new Binding[bindings.size()];
    Binding<V>[] bindingsArray = typedBindings;
    int j = 0;
    for (Binding<V> binding : bindings) {
      Dependency<V> dependency = Dependency.get(binding.getKey());
      dependenciesBuilder.add(dependency);
      dependenciesForKey.add(dependency);
      bindingsArray[j] = binding;
      j++;
    }

    @SuppressWarnings("unchecked")
    SingleParameterInjector<V>[] injectors =
        (SingleParameterInjector<V>[])
            injector.getParametersInjectors(dependenciesForKey, errors);

    perKeyDatas[i] = new PerKeyData<>(entry.getKey(), bindingsArray, injectors);
    i++;
  }

  dependencies = dependenciesBuilder.build();
}
 
开发者ID:google,项目名称:guice,代码行数:39,代码来源:RealMapBinder.java

示例5: testMultibindingProviderDependencies

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
public void testMultibindingProviderDependencies() {
  final Annotation setAnn = Names.named("foo");
  Injector injector =
      Guice.createInjector(
          new AbstractModule() {
            @Override
            protected void configure() {
              Multibinder<String> multibinder =
                  Multibinder.newSetBinder(binder(), String.class, setAnn);
              multibinder.addBinding().toInstance("a");
              multibinder.addBinding().toInstance("b");
            }
          });
  HasDependencies providerBinding =
      (HasDependencies) injector.getBinding(new Key<Collection<Provider<String>>>(setAnn) {});
  HasDependencies setBinding =
      (HasDependencies) injector.getBinding(new Key<Set<String>>(setAnn) {});
  // sanity check the size
  assertEquals(setBinding.getDependencies().toString(), 2, setBinding.getDependencies().size());
  Set<Dependency<?>> expected = Sets.newHashSet();
  for (Dependency<?> dep : setBinding.getDependencies()) {
    Key key = dep.getKey();
    Dependency<?> providerDependency =
        Dependency.get(key.ofType(Types.providerOf(key.getTypeLiteral().getType())));
    expected.add(providerDependency);
  }
  assertEquals(expected, providerBinding.getDependencies());
}
 
开发者ID:google,项目名称:guice,代码行数:29,代码来源:MultibinderTest.java


注:本文中的com.google.inject.spi.Dependency.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。