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


Java Key.get方法代码示例

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


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

示例1: bindDriftClient

import com.google.inject.Key; //导入方法依赖的package包/类
private <T> DriftClientBindingBuilder bindDriftClient(Class<T> clientInterface, String configPrefix, Class<? extends Annotation> annotation)
{
    Annotation clientAnnotation = getDriftClientAnnotation(clientInterface, annotation);

    configBinder(binder).bindConfig(DriftClientConfig.class, clientAnnotation, configPrefix);

    TypeLiteral<DriftClient<T>> typeLiteral = driftClientTypeLiteral(clientInterface);

    Provider<T> instanceProvider = new DriftClientInstanceProvider<>(clientAnnotation, Key.get(typeLiteral, annotation));
    Provider<DriftClient<T>> factoryProvider = new DriftClientProvider<>(clientInterface, clientAnnotation);

    binder.bind(Key.get(clientInterface, annotation)).toProvider(instanceProvider).in(Scopes.SINGLETON);
    binder.bind(Key.get(typeLiteral, annotation)).toProvider(factoryProvider).in(Scopes.SINGLETON);

    if (annotation == DefaultClient.class) {
        binder.bind(Key.get(clientInterface)).toProvider(instanceProvider).in(Scopes.SINGLETON);
        binder.bind(Key.get(typeLiteral)).toProvider(factoryProvider).in(Scopes.SINGLETON);
    }

    return new DriftClientBindingBuilder(binder, clientAnnotation, configPrefix);
}
 
开发者ID:airlift,项目名称:drift,代码行数:22,代码来源:DriftClientBinder.java

示例2: ModuleManifest

import com.google.inject.Key; //导入方法依赖的package包/类
public ModuleManifest(@Nullable TypeLiteral<Module> type) {
    // Figure out the module type. If the given type is null,
    // then try to resolve it from this object's superclass.
    this.type = type != null ? Types.assertFullySpecified(type)
                             : new ResolvableType<Module>(){}.in(getClass());
    this.rawType = (Class<Module>) this.type.getRawType();
    this.simpleName = rawType.getSimpleName();

    // Resolve the scope type automatically
    this.scope = (Class<Scope>) new ResolvableType<Scope>(){}.in(getClass()).getRawType();

    // Construct various keys related to the module/scope
    this.key = Key.get(this.type);
    this.optionalKey = Keys.optional(this.key);
    this.wrapperKey = ProvisionWrapper.keyOf(this.type);
    this.contextKey = Key.get(new ResolvableType<Context>(){}.in(getClass()));
    this.setElementKey = Key.get(new ResolvableType<ProvisionWrapper<? extends Base>>(){}.in(getClass()));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:ModuleManifest.java

示例3: TypeMapBinder

import com.google.inject.Key; //导入方法依赖的package包/类
public TypeMapBinder(Binder binder, @Nullable TypeLiteral<K> keyType, @Nullable TypeLiteral<V> valueType) {
    this.keyType = keyType != null ? keyType : new ResolvableType<K>(){}.in(getClass());
    this.valueType = valueType != null ? valueType : new ResolvableType<V>(){}.in(getClass());

    final TypeArgument<K> keyTypeArg = new TypeArgument<K>(this.keyType){};
    final TypeArgument<V> valueTypeArg = new TypeArgument<V>(this.valueType){};

    this.collectionKey = Key.get(new ResolvableType<TypeMap<K, V>>(){}.with(keyTypeArg, valueTypeArg));
    this.backingCollectionKey = Key.get(new ResolvableType<Map<TypeToken<? extends K>, Set<V>>>(){}.with(keyTypeArg, valueTypeArg));

    this.backingCollectionBinder = MapBinder.newMapBinder(
        binder,
        new ResolvableType<TypeToken<? extends K>>(){}.with(keyTypeArg),
        this.valueType
    ).permitDuplicates();

    binder.install(new KeyedManifest.Impl(collectionKey) {
        @Override
        public void configure() {
            final Provider<Map<TypeToken<? extends K>, Set<V>>> backingCollectionProvider = getProvider(backingCollectionKey);
            bind(collectionType()).toProvider(() -> ImmutableTypeMap.copyOf(backingCollectionProvider.get()));
        }
    });
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:25,代码来源:TypeMapBinder.java

示例4: get

import com.google.inject.Key; //导入方法依赖的package包/类
@Override
public synchronized T get(Class<? extends Annotation> bindingAnnotation) {
  BindingAnnotations.checkIsBindingAnnotation(bindingAnnotation);

  Key<T> key = Key.get(type, bindingAnnotation);
  return injector.getInstance(key);
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:8,代码来源:DynamicBindingProviderImpl.java

示例5: configure

import com.google.inject.Key; //导入方法依赖的package包/类
@Override
protected void configure() {
    // @ModelSync ExecutorService must be bound elsewhere
    final Key<Executor> executorKey = Key.get(Executor.class, ModelSync.class);
    final Key<ExecutorService> executorServiceKey = Key.get(ExecutorService.class, ModelSync.class);
    final Key<ListeningExecutorService> listeningExecutorServiceKey = Key.get(ListeningExecutorService.class, ModelSync.class);

    bind(executorKey).to(executorServiceKey);

    expose(executorKey);
    expose(executorServiceKey);
    expose(listeningExecutorServiceKey);

    new ModelListenerBinder(publicBinder());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:16,代码来源:ModelsManifest.java

示例6: FeatureBinder

import com.google.inject.Key; //导入方法依赖的package包/类
public FeatureBinder(Binder binder, @Nullable TypeLiteral<T> type) {
    this.binder = binder;
    this.type = type != null ? type : new ResolvableType<T>(){}.in(getClass());
    this.typeArg = new TypeArgument<T>(this.type){};
    this.key = Key.get(this.type);

    binder.install(new FeatureManifest<>(this.type));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:9,代码来源:FeatureBinder.java

示例7: bindProvider

import com.google.inject.Key; //导入方法依赖的package包/类
private Key<SectionNode> bindProvider()
{
	if( key == null )
	{
		key = Key.get(SectionNode.class, this);
		bind(key).toProvider(this);
	}
	return key;
}
 
开发者ID:equella,项目名称:Equella,代码行数:10,代码来源:SectionsModule.java

示例8: SetBinder

import com.google.inject.Key; //导入方法依赖的package包/类
protected SetBinder(Binder binder, @Nullable Key<T> key) {
    if(key == null) {
        key = Key.get(new ResolvableType<T>(){}.in(getClass()));
    }

    this.binder = binder.skipSources(SetBinder.class);
    this.elementType = key.getTypeLiteral();
    this.collectionType = new ResolvableType<Set<T>>(){}.with(new TypeArgument<T>(this.elementType){});
    this.multibinder = Multibinder.newSetBinder(binder, key);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:SetBinder.java

示例9: dependencyKey

import com.google.inject.Key; //导入方法依赖的package包/类
public static Key<?> dependencyKey(Key<?> key) {
    if(isImplicitProvider(key.getTypeLiteral())) {
        return Key.get(providedType((TypeLiteral<? extends Provider<Object>>) key.getTypeLiteral()));
    } else {
        return key;
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:Injection.java

示例10: TransformableBinder

import com.google.inject.Key; //导入方法依赖的package包/类
public TransformableBinder(Binder binder, @Nullable Key<T> keyOrNull) {
    this.binder = binder.skipSources(TransformableBinder.class, TransformingProvider.class);
    this.key = keyOrNull != null ? keyOrNull : Key.get(new ResolvableType<T>(){}.in(getClass()));
    this.untransformedKey = Keys.get(key, new UntransformedImpl());

    final TypeLiteral<Transformer<T>> transformerType = new ResolvableType<Transformer<T>>(){}.with(new TypeArgument<T>(key.getTypeLiteral()){});
    final Annotation annotation = key.getAnnotation();
    this.transformerSetKey = Keys.get(Types.setOf(transformerType), annotation);
    this.transformerBinder = Multibinder.newSetBinder(this.binder, Keys.get(transformerType, annotation));

    this.binder.install(new TransformingProvider());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:13,代码来源:TransformableBinder.java

示例11: get

import com.google.inject.Key; //导入方法依赖的package包/类
protected <T> T get(Class<T> clazz) {
    T result = getFromSpring(clazz);
    if (result != null) {
        return result;
    }
    Key<T> key = Key.get(clazz);
    return injector.getInstance(key);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:9,代码来源:DependencyContainer.java

示例12: InnerFactoryManifest

import com.google.inject.Key; //导入方法依赖的package包/类
public InnerFactoryManifest(Key<I> innerKey, TypeLiteral<O> outerType) {
    if(innerKey == null) {
        innerKey = Key.get(new ResolvableType<I>(){}.in(getClass()));
    }
    this.innerType = innerKey.getTypeLiteral();
    this.outerType = outerType != null ? outerType : new ResolvableType<O>(){}.in(getClass());

    this.factoryKey = innerKey.ofType(new ResolvableType<InnerFactory<O, I>>(){}
                                          .with(new TypeArgument<O>(this.outerType){},
                                                new TypeArgument<I>(this.innerType){}));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:12,代码来源:InnerFactoryManifest.java

示例13: ProvisionAtParseTime

import com.google.inject.Key; //导入方法依赖的package包/类
public ProvisionAtParseTime(Class<T> type) {
    this(Key.get(type));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:ProvisionAtParseTime.java

示例14: get

import com.google.inject.Key; //导入方法依赖的package包/类
public static <T> Key<T> get(TypeLiteral<T> type, @Nullable Annotation annotation) {
    return annotation == null ? Key.get(type) : Key.get(type, annotation);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:Keys.java

示例15: bindDynamicProvider

import com.google.inject.Key; //导入方法依赖的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.Key.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。