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


Java Binding.getKey方法代码示例

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


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

示例1: justInTimeResolution

import com.google.inject.Binding; //导入方法依赖的package包/类
@Override
public boolean justInTimeResolution(Injectee injectee) {
  Type type = injectee.getRequiredType();
  Class<?> clazz = MoreTypes.getRawType(type);
  
  if (clazz != null) {
    Binding<?> binding = findBinding(injectee);
    if (binding != null) {
      Key<?> key = binding.getKey();
      Set<Annotation> qualifiers = BindingUtils.getQualifiers(key);
      
      GuiceBindingDescriptor<?> descriptor = new GuiceBindingDescriptor<>(
          type, clazz, qualifiers, binding);
      ServiceLocatorUtilities.addOneDescriptor(locator, descriptor);
      return true;
    }
  }
  
  
  return false;
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:22,代码来源:GuiceJustInTimeResolver.java

示例2: requestInjection

import com.google.inject.Binding; //导入方法依赖的package包/类
/**
 * Registers an instance for member injection when that step is performed.
 *
 * @param instance an instance that optionally has members to be injected (each annotated with
 *      @Inject).
 * @param binding the binding that caused this initializable to be created, if it exists.
 * @param source the source location that this injection was requested
 */
<T> Initializable<T> requestInjection(InjectorImpl injector, T instance, Binding<T> binding,
    Object source, Set<InjectionPoint> injectionPoints) {
  checkNotNull(source);
  
  ProvisionListenerStackCallback<T> provisionCallback =
      binding == null ? null : injector.provisionListenerStore.get(binding);

  // short circuit if the object has no injections or listeners.
  if (instance == null || (injectionPoints.isEmpty()
      && !injector.membersInjectorStore.hasTypeListeners()
      && (provisionCallback == null || !provisionCallback.hasListeners()))) {
    return Initializables.of(instance);
  }

  InjectableReference<T> initializable = new InjectableReference<T>(
      injector, instance, binding == null ? null : binding.getKey(), provisionCallback, source);
  pendingInjection.put(instance, initializable);
  return initializable;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:28,代码来源:Initializer.java

示例3: getBeansOfType

import com.google.inject.Binding; //导入方法依赖的package包/类
@Override
public <T> Collection<T> getBeansOfType(Class<T> clazz)
{
	Injector injector = ensureInjector();
	List<T> beans = new ArrayList<T>();
	Map<Key<?>, Binding<?>> bindings = injector.getBindings();
	for( Binding<?> binding : bindings.values() )
	{
		Key<?> actualKey = null;
		if( binding instanceof UntargettedBinding || binding instanceof ConstructorBinding )
		{
			actualKey = binding.getKey();
		}
		else if( binding instanceof LinkedKeyBinding )
		{
			actualKey = ((LinkedKeyBinding<?>) binding).getLinkedKey();
		}
		else if( binding instanceof ProviderBinding )
		{
			actualKey = ((ProviderBinding<?>) binding).getProvidedKey();
		}
		if( actualKey != null && clazz.isAssignableFrom(actualKey.getTypeLiteral().getRawType()) )
		{
			beans.add(clazz.cast(binding.getProvider().get()));
		}
	}
	return beans;
}
 
开发者ID:equella,项目名称:Equella,代码行数:29,代码来源:GuicePlugin.java

示例4: init

import com.google.inject.Binding; //导入方法依赖的package包/类
@PostConstruct
private void init() {
    List<Binding<ClientCommandHandler>> bindings = injector.findBindingsByType(TypeLiteral.get(ClientCommandHandler.class));
    for (Binding<ClientCommandHandler> binding : bindings) {
        Key<ClientCommandHandler> key = binding.getKey();
        commandHandlers.add(injector.getInstance(key));
    }
}
 
开发者ID:aalmiray,项目名称:javatrove,代码行数:9,代码来源:ClientCommandDispatcherImpl.java

示例5: init

import com.google.inject.Binding; //导入方法依赖的package包/类
@PostConstruct
private void init() {
    List<Binding<ServerCommandHandler>> bindings = injector.findBindingsByType(TypeLiteral.get(ServerCommandHandler.class));
    for (Binding<ServerCommandHandler> binding : bindings) {
        Key<ServerCommandHandler> key = binding.getKey();
        commandHandlers.add(injector.getInstance(key));
    }
}
 
开发者ID:aalmiray,项目名称:javatrove,代码行数:9,代码来源:ServerCommandDispatcherImpl.java

示例6: getInstances

import com.google.inject.Binding; //导入方法依赖的package包/类
@Override
public <T> List<T> getInstances(Class<T> type) {
    List<T> instances = new ArrayList<T>();
    List<Binding<T>> bindings = injector.findBindingsByType(TypeLiteral.get(type));
    for(Binding<T> binding : bindings) {
        Key<T> key = binding.getKey();
        instances.add(injector.getInstance(key));
    }
    return instances;
}
 
开发者ID:flipkart-incubator,项目名称:polyguice,代码行数:11,代码来源:DefaultComponentContext.java

示例7: visit

import com.google.inject.Binding; //导入方法依赖的package包/类
@Override
public <T> Void visit(Binding<T> binding) {
  final Key<T> key = binding.getKey();

  if (!keysToIntercept.contains(key)) {
    return super.visit(binding);
  }

  binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
    @Override
    public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
      binder.addError("Cannot intercept bare binding of %s. " +
          		"You may only intercept bindings that bind a class to something.", key);
      return null;
    }
  });

  Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
  binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));

  ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);

  // we scope the user's provider, not the interceptor. This is dangerous,
  // but convenient. It means that although the user's provider will live
  // in its proper scope, the intereptor gets invoked without a scope
  applyScoping(binding, scopedBindingBuilder);

  keysIntercepted.add(key);
  return null;
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:31,代码来源:InterceptingBindingsBuilder.java

示例8: visit

import com.google.inject.Binding; //导入方法依赖的package包/类
@Override
public <T> Void visit(Binding<T> binding) {
  final Key<T> key = binding.getKey();

  if (!keysToIntercept.contains(key)) {
    return super.visit(binding);
  }

  binding.acceptTargetVisitor(new DefaultBindingTargetVisitor<T, Void>() {
    @Override
    public Void visit(UntargettedBinding<? extends T> untargettedBinding) {
      binder.addError("Cannot intercept bare binding of %s. " +
          		"You may only intercept bindings that bind a class to something.", key);
      return null;
    }
  });

  Key<T> anonymousKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
  binder.bind(key).toProvider(new InterceptingProvider<T>(key, binder.getProvider(anonymousKey)));

  ScopedBindingBuilder scopedBindingBuilder = bindKeyToTarget(binding, binder, anonymousKey);

  // we scope the user's provider, not the interceptor. This is dangerous,
  // but convenient. It means that although the user's provider will live
  // in its proper scope, the interceptor gets invoked without a scope
  applyScoping(binding, scopedBindingBuilder);

  keysIntercepted.add(key);
  return null;
}
 
开发者ID:zorzella,项目名称:guiceberry,代码行数:31,代码来源:InterceptingBindingsBuilder.java

示例9: _getServiceHandlersGuiceBindingKeys

import com.google.inject.Binding; //导入方法依赖的package包/类
/**
 * Introspects the injector bindings to find all binding keys for {@link ServiceHandler} types
 * @param injector
 * @return
 */
private static Collection<Key<? extends ServiceHandler>> _getServiceHandlersGuiceBindingKeys(final Injector injector) {
	List<Binding<ServiceHandler>> bindings = injector.findBindingsByType(TypeLiteral.get(ServiceHandler.class));
	Collection<Key<? extends ServiceHandler>> outKeys = Lists.newArrayListWithExpectedSize(bindings.size());
	for (Binding<ServiceHandler> binding : bindings) {
		Key<? extends ServiceHandler> key = binding.getKey();
		outKeys.add(key);
	}
	return outKeys;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:15,代码来源:ServicesLifeCycleUtil.java

示例10: requestInjection

import com.google.inject.Binding; //导入方法依赖的package包/类
/**
 * Registers an instance for member injection when that step is performed.
 *
 * @param instance an instance that optionally has members to be injected (each annotated
 *     with @Inject).
 * @param binding the binding that caused this initializable to be created, if it exists.
 * @param source the source location that this injection was requested
 */
<T> Initializable<T> requestInjection(
    InjectorImpl injector,
    T instance,
    Binding<T> binding,
    Object source,
    Set<InjectionPoint> injectionPoints) {
  checkNotNull(source);
  Preconditions.checkState(
      !validationStarted, "Member injection could not be requested after validation is started");
  ProvisionListenerStackCallback<T> provisionCallback =
      binding == null ? null : injector.provisionListenerStore.get(binding);

  // short circuit if the object has no injections or listeners.
  if (instance == null
      || (injectionPoints.isEmpty()
          && !injector.membersInjectorStore.hasTypeListeners()
          && provisionCallback == null)) {
    return Initializables.of(instance);
  }

  if (initializablesCache.containsKey(instance)) {
    @SuppressWarnings("unchecked") // Map from T to InjectableReference<T>
    Initializable<T> cached = (Initializable<T>) initializablesCache.get(instance);
    return cached;
  }

  InjectableReference<T> injectableReference =
      new InjectableReference<T>(
          injector,
          instance,
          binding == null ? null : binding.getKey(),
          provisionCallback,
          source,
          cycleDetectingLockFactory.create(instance.getClass()));
  initializablesCache.put(instance, injectableReference);
  pendingInjections.add(injectableReference);
  return injectableReference;
}
 
开发者ID:google,项目名称:guice,代码行数:47,代码来源:Initializer.java

示例11: reattachSet

import com.google.inject.Binding; //导入方法依赖的package包/类
private void reattachSet(
    ListMultimap<TypeLiteral<?>, ReloadableRegistrationHandle<?>> oldHandles,
    Map<TypeLiteral<?>, DynamicSet<?>> sets,
    @Nullable Injector src,
    Plugin newPlugin) {
  if (src == null || sets == null || sets.isEmpty()) {
    return;
  }

  for (Map.Entry<TypeLiteral<?>, DynamicSet<?>> e : sets.entrySet()) {
    @SuppressWarnings("unchecked")
    TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();

    @SuppressWarnings("unchecked")
    DynamicSet<Object> set = (DynamicSet<Object>) e.getValue();

    // Index all old handles that match this DynamicSet<T> keyed by
    // annotations. Ignore the unique annotations, thereby favoring
    // the @Named annotations or some other non-unique naming.
    Map<Annotation, ReloadableRegistrationHandle<?>> am = new HashMap<>();
    List<ReloadableRegistrationHandle<?>> old = oldHandles.get(type);
    Iterator<ReloadableRegistrationHandle<?>> oi = old.iterator();
    while (oi.hasNext()) {
      ReloadableRegistrationHandle<?> h = oi.next();
      Annotation a = h.getKey().getAnnotation();
      if (a != null && !UNIQUE_ANNOTATION.isInstance(a)) {
        am.put(a, h);
        oi.remove();
      }
    }

    // Replace old handles with new bindings, favoring cases where there
    // is an exact match on an @Named annotation. If there is no match
    // pick any handle and replace it. We generally expect only one
    // handle of each DynamicSet type when using unique annotations, but
    // possibly multiple ones if @Named was used. Plugin authors that want
    // atomic replacement across reloads should use @Named annotations with
    // stable names that do not change across plugin versions to ensure the
    // handles are swapped correctly.
    oi = old.iterator();
    for (Binding<?> binding : bindings(src, type)) {
      @SuppressWarnings("unchecked")
      Binding<Object> b = (Binding<Object>) binding;
      Key<Object> key = b.getKey();
      if (key.getAnnotation() == null) {
        continue;
      }

      @SuppressWarnings("unchecked")
      ReloadableRegistrationHandle<Object> h1 =
          (ReloadableRegistrationHandle<Object>) am.remove(key.getAnnotation());
      if (h1 != null) {
        replace(newPlugin, h1, b);
      } else if (oi.hasNext()) {
        @SuppressWarnings("unchecked")
        ReloadableRegistrationHandle<Object> h2 =
            (ReloadableRegistrationHandle<Object>) oi.next();
        oi.remove();
        replace(newPlugin, h2, b);
      } else {
        newPlugin.add(set.add(b.getKey(), b.getProvider()));
      }
    }
  }
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:66,代码来源:PluginGuiceEnvironment.java

示例12: providerField

import com.google.inject.Binding; //导入方法依赖的package包/类
private static String providerField(Binding<?> binding, String statement) {
  Key<?> key = binding.getKey();
  TypeLiteral<?> type = key.getTypeLiteral();
  return "private final Provider<" + canonicalName(type) + "> " + providerFieldName(key) + " = "
      + scoped(binding, provider(type, statement)) + ";\n";
}
 
开发者ID:mikosik,项目名称:deguicifier,代码行数:7,代码来源:Generators.java

示例13: initialize

import com.google.inject.Binding; //导入方法依赖的package包/类
void initialize(InjectorImpl injector, Errors errors) throws ErrorsException {
  // This will be called multiple times, once by each Factory. We only want
  // to do the work to initialize everything once, so guard this code with
  // isInitialized.
  if (isInitialized) {
    return;
  }
  List<Binding<T>> bindings = Lists.newArrayList();
  Set<Indexer.IndexedBinding> index = Sets.newHashSet();
  Indexer indexer = new Indexer(injector);
  List<Dependency<?>> dependencies = Lists.newArrayList();
  List<Dependency<?>> providerDependencies = Lists.newArrayList();
  for (Binding<?> entry : injector.findBindingsByType(elementType)) {
    if (keyMatches(entry.getKey())) {
      @SuppressWarnings("unchecked") // protected by findBindingsByType()
      Binding<T> binding = (Binding<T>) entry;
      if (index.add(binding.acceptTargetVisitor(indexer))) {
        // TODO(lukes): most of these are linked bindings since user bindings are linked to
        // a user binding through the @Element annotation.  Since this is an implementation
        // detail we could 'dereference' the @Element if it is a LinkedBinding and avoid
        // provisioning through the FactoryProxy at runtime.
        // Ditto for OptionalBinder/MapBinder
        bindings.add(binding);
        Key<T> key = binding.getKey();
        // TODO(lukes): we should mark this as a non-nullable dependency since we don't accept
        // null.
        // Add a dependency on Key<T>
        dependencies.add(Dependency.get(key));
        // and add a dependency on Key<Provider<T>>
        providerDependencies.add(
            Dependency.get(key.ofType(Types.providerOf(key.getTypeLiteral().getType()))));
      }
    }
  }

  this.bindings = ImmutableList.copyOf(bindings);
  this.dependencies = ImmutableSet.copyOf(dependencies);
  this.providerDependencies = ImmutableSet.copyOf(providerDependencies);
  this.permitDuplicates = permitsDuplicates(injector);
  // This is safe because all our dependencies are assignable to T and we never assign to
  // elements of this array.
  @SuppressWarnings("unchecked")
  SingleParameterInjector<T>[] typed =
      (SingleParameterInjector<T>[]) injector.getParametersInjectors(dependencies, errors);
  this.parameterinjectors = typed;
  isInitialized = true;
}
 
开发者ID:google,项目名称:guice,代码行数:48,代码来源:RealMultibinder.java


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