當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。