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


Java Binder.getProvider方法代码示例

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


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

示例1: PropertyParser

import com.google.inject.Binder; //导入方法依赖的package包/类
/**
 * @param binder         Required so that this class can request injection for itself.
 *                       (we need to instantiate this at configuration time, so we can't expect to have an Injector)
 * @param name           Name of the property (only used for error messages, does not affect parsing)
 * @param aliases
 * @param finders        Used to find the {@link Node}s that {@link I} instances will be parsed from
 * @param splitter       Used to split the value of each {@link Node}s into multiple strings that are
 *                       parsed as {@link I} instances (this only works with a {@link PrimitiveParser})
 * @param aggregator     Used to combine {@link I} instances into an {@link O} instance
 * @param validations    Validations to run on each {@link I} instance
 */
public PropertyParser(Binder binder,
                      String name,
                      Iterable<String> aliases,
                      List<Class<? extends NodeFinder>> finders,
                      Class<? extends NodeSplitter> splitter,
                      Aggregator<O, I> aggregator,
                      List<Class<Validation<? super I>>> validations) {

    Types.assertFullySpecified(aggregator.outerTypeToken());
    Types.assertFullySpecified(aggregator.innerTypeToken());

    this.name = name;
    this.aliases = ImmutableList.copyOf(aliases);
    this.names = ImmutableSet.<String>builder().add(name).addAll(aliases).build();
    this.aggregator = aggregator;

    this.finders = ListUtils.transformedCopyOf(finders, binder::getProvider);
    this.splitter = binder.getProvider(splitter);
    this.validations = ListUtils.transformedCopyOf(validations, binder::getProvider);

    // Figure out which base parser type we need
    final Class<? extends Parser> parserBase;
    if(Types.isAssignable(FeatureDefinition.class, aggregator.innerTypeToken())) {
        // If I is a FeatureDefinition, get a FeatureParser so we can parse references
        parserBase = FeatureParser.class;
    } else if(!NodeSplitter.Atom.class.isAssignableFrom(splitter)) {
        // If the splitter is anything besides Atom, we will need a PrimitiveParser
        parserBase = PrimitiveParser.class;
    } else {
        // Otherwise, get a Parser<I>
        parserBase = Parser.class;
    }

    this.innerParser = binder.getProvider(Key.get(Types.parameterizedTypeLiteral(parserBase, aggregator.innerTypeLiteral())));
    this.validationContext = binder.getProvider(ValidationContext.class);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:48,代码来源:PropertyParser.java

示例2: bindDynamicProvider

import com.google.inject.Binder; //导入方法依赖的package包/类
/**
 * Binds a {@link DynamicBindingProvider} for the specified class.
 *
 * <p>The instance bound to the class can later be retrieved through
 * {@link DynamicBindingProvider#get(Class)} given the same annotation provided during binding
 * time. This method also 'requires' a binding of {@code clazz} to {@code annotation} to exist.
 *
 * <p>This method requires a binder, and must be used from a Guice module that is in the
 * configure phase.
 *
 * @param binder the Guice binder to bind with
 * @param clazz the class to create a {@link DynamicBindingProvider} for
 * @param annotation the binding annotation that must be bound with the provided class
 */
static <T> void bindDynamicProvider(
    Binder binder, Class<T> clazz, Class<? extends Annotation> annotation) {
  binder.getProvider(Key.get(clazz, annotation));

  ParameterizedType type = Types.newParameterizedType(DynamicBindingProvider.class, clazz);
  DynamicBindingProvider<T> provider = new DynamicBindingProviderImpl<T>(TypeLiteral.get(clazz));
  @SuppressWarnings("unchecked")
  Key<DynamicBindingProvider<T>> key = (Key<DynamicBindingProvider<T>>) Key.get(type);
  binder.bind(key).toInstance(provider);
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:25,代码来源:DynamicAnnotations.java


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