本文整理了Java中com.google.inject.Binding.getKey()
方法的一些代码示例,展示了Binding.getKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binding.getKey()
方法的具体详情如下:
包路径:com.google.inject.Binding
类名称:Binding
方法名:getKey
[英]Returns the key for this binding.
[中]返回此绑定的键。
代码示例来源:origin: com.google.inject/guice
@Override
public Key<String> getSourceKey() {
return originalBinding.getKey();
}
代码示例来源:origin: ninjaframework/ninja
@Override
public Object visitEagerSingleton() {
injector.getInstance(binding.getKey());
return null;
}
代码示例来源:origin: apache/incubator-druid
private Emitter findEmitter(String emitterType, List<Binding<Emitter>> emitterBindings)
{
for (Binding<Emitter> binding : emitterBindings) {
if (Names.named(emitterType).equals(binding.getKey().getAnnotation())) {
return binding.getProvider().get();
}
}
return null;
}
代码示例来源:origin: com.google.inject/guice
@Override
public <T> Void visit(Binding<T> binding) {
overriddenKeys.add(binding.getKey());
return super.visit(binding);
}
代码示例来源:origin: apache/incubator-druid
private TLSCertificateChecker findChecker(
String checkerType,
List<Binding<TLSCertificateChecker>> checkerBindings
)
{
for (Binding<TLSCertificateChecker> binding : checkerBindings) {
if (Names.named(checkerType).equals(binding.getKey().getAnnotation())) {
return binding.getProvider().get();
}
}
return null;
}
}
代码示例来源:origin: com.google.inject/guice
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) {
ImmutableMap.Builder<K, Provider<V>> mapOfProvidersBuilder = ImmutableMap.builder();
ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
for (Map.Entry<K, Binding<V>> entry : bindingSelection.getMapBindings().entrySet()) {
mapOfProvidersBuilder.put(entry.getKey(), entry.getValue().getProvider());
dependenciesBuilder.add(Dependency.get(getKeyOfProvider(entry.getValue().getKey())));
}
mapOfProviders = mapOfProvidersBuilder.build();
dependencies = dependenciesBuilder.build();
}
代码示例来源:origin: com.google.inject/guice
boolean isIndexable(Binding<?> binding) {
return binding.getKey().getAnnotation() instanceof Element;
}
代码示例来源:origin: com.google.inject/guice
boolean containsElement(com.google.inject.spi.Element element) {
if (element instanceof Binding) {
Binding<?> binding = (Binding<?>) element;
return keyMatches(binding.getKey())
|| binding.getKey().equals(getPermitDuplicatesKey())
|| binding.getKey().equals(setKey)
|| binding.getKey().equals(collectionOfProvidersKey)
|| binding.getKey().equals(collectionOfJavaxProvidersKey);
} else {
return false;
}
}
代码示例来源:origin: com.google.inject/guice
/** Cleans up any state that may have been cached when constructing the JIT binding. */
private void removeFailedJitBinding(Binding<?> binding, InjectionPoint ip) {
failedJitBindings.add(binding.getKey());
jitBindings.remove(binding.getKey());
membersInjectorStore.remove(binding.getKey().getTypeLiteral());
provisionListenerStore.remove(binding);
if (ip != null) {
constructors.remove(ip);
}
}
代码示例来源:origin: com.google.inject/guice
/**
* Returns a new {@link ProvisionListenerStackCallback} for the key or {@code null} if there are
* no listeners
*/
@SuppressWarnings(
"unchecked") // the ProvisionListenerStackCallback type always agrees with the passed type
public <T> ProvisionListenerStackCallback<T> get(Binding<T> binding) {
// Never notify any listeners for internal bindings.
if (!INTERNAL_BINDINGS.contains(binding.getKey())) {
ProvisionListenerStackCallback<T> callback =
(ProvisionListenerStackCallback<T>)
cache.getUnchecked(new KeyBinding(binding.getKey(), binding));
return callback.hasListeners() ? callback : null;
}
return null;
}
代码示例来源:origin: com.google.inject/guice
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) {
ImmutableMap.Builder<K, Set<Provider<V>>> multimapOfProvidersBuilder =
ImmutableMap.builder();
ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
for (Map.Entry<K, Set<Binding<V>>> entry :
bindingSelection.getMultimapBindings().entrySet()) {
ImmutableSet.Builder<Provider<V>> providersBuilder = ImmutableSet.builder();
for (Binding<V> binding : entry.getValue()) {
providersBuilder.add(binding.getProvider());
dependenciesBuilder.add(Dependency.get(getKeyOfProvider(binding.getKey())));
}
multimapOfProvidersBuilder.put(entry.getKey(), providersBuilder.build());
}
multimapOfProviders = multimapOfProvidersBuilder.build();
dependencies = dependenciesBuilder.build();
}
代码示例来源:origin: com.google.inject/guice
/** Indexes bindings by type. */
void index() {
for (Binding<?> binding : state.getExplicitBindingsThisLevel().values()) {
bindingsMultimap.put(binding.getKey().getTypeLiteral(), binding);
}
}
代码示例来源:origin: com.google.inject/guice
@Override
public <T> Void visit(Binding<T> binding) {
if (!overriddenKeys.remove(binding.getKey())) {
super.visit(binding);
// Record when a scope instance is used in a binding
Scope scope = getScopeInstanceOrNull(binding);
if (scope != null) {
List<Object> existing = scopeInstancesInUse.get(scope);
if (existing == null) {
existing = Lists.newArrayList();
scopeInstancesInUse.put(scope, existing);
}
existing.add(binding.getSource());
}
}
return null;
}
代码示例来源:origin: com.google.inject/guice
IndexedBinding(Binding<?> binding, BindingType type, Object scope, Object extraEquality) {
this.scope = scope;
this.type = type;
this.extraEquality = extraEquality;
this.typeLiteral = binding.getKey().getTypeLiteral();
Element annotation = (Element) binding.getKey().getAnnotation();
this.annotationName = annotation.setName();
this.annotationType = annotation.type();
}
代码示例来源:origin: ninjaframework/ninja
@Override
public Object visitScope(Scope scope) {
if (scope.equals(Scopes.SINGLETON)) {
Object target = injector.getInstance(binding.getKey());
if (binding instanceof ProviderInstanceBinding) {
Provider providerInstance = ((ProviderInstanceBinding) binding).getProviderInstance();
if (providerInstance instanceof ProviderMethod) {
// @Provides methods don't get picked up by TypeListeners, so we need to manually register them
if (lifecycleSupport.hasLifecycleMethod(target.getClass())) {
lifecycleSupport.registerLifecycle(target);
}
}
}
}
return null;
}
代码示例来源:origin: com.google.inject/guice
@Override
protected void doInitialize(InjectorImpl injector, Errors errors) throws ErrorsException {
@SuppressWarnings("unchecked")
K[] keysArray = (K[]) new Object[bindingSelection.getMapBindings().size()];
keys = keysArray;
ImmutableSet.Builder<Dependency<?>> dependenciesBuilder = ImmutableSet.builder();
int i = 0;
for (Map.Entry<K, Binding<V>> entry : bindingSelection.getMapBindings().entrySet()) {
dependenciesBuilder.add(Dependency.get(entry.getValue().getKey()));
keys[i] = entry.getKey();
i++;
}
ImmutableSet<Dependency<?>> localDependencies = dependenciesBuilder.build();
dependencies = localDependencies;
List<Dependency<?>> dependenciesList = localDependencies.asList();
// We know the type because we built up our own sets of dependencies, it's just
// that the interface uses a "?" generic
@SuppressWarnings("unchecked")
SingleParameterInjector<V>[] typedInjectors =
(SingleParameterInjector<V>[]) injector.getParametersInjectors(dependenciesList, errors);
injectors = typedInjectors;
}
代码示例来源:origin: apache/incubator-druid
@Inject
public void inject(Injector injector)
{
final List<Binding<Emitter>> emitterBindings = injector.findBindingsByType(new TypeLiteral<Emitter>(){});
emitter = findEmitter(emitterType, emitterBindings);
if (emitter == null) {
emitter = findEmitter(NoopEmitterModule.EMITTER_TYPE, emitterBindings);
}
if (emitter == null) {
List<String> knownTypes = new ArrayList<>();
for (Binding<Emitter> binding : emitterBindings) {
final Annotation annotation = binding.getKey().getAnnotation();
if (annotation != null) {
knownTypes.add(((Named) annotation).value());
}
}
throw new ISE("Unknown emitter type[%s]=[%s], known types[%s]", EMITTER_PROPERTY, emitterType, knownTypes);
}
}
代码示例来源:origin: com.google.inject/guice
void rewrite(Binder binder, PrivateElements privateElements, Set<Key<?>> keysToSkip) {
PrivateBinder privateBinder =
binder.withSource(privateElements.getSource()).newPrivateBinder();
Set<Key<?>> skippedExposes = Sets.newHashSet();
for (Key<?> key : privateElements.getExposedKeys()) {
if (keysToSkip.remove(key)) {
skippedExposes.add(key);
} else {
privateBinder.withSource(privateElements.getExposedSource(key)).expose(key);
}
}
for (Element element : privateElements.getElements()) {
if (element instanceof Binding && skippedExposes.remove(((Binding) element).getKey())) {
continue;
}
if (element instanceof PrivateElements) {
rewrite(privateBinder, (PrivateElements) element, skippedExposes);
continue;
}
element.applyTo(privateBinder);
}
}
代码示例来源:origin: com.google.inject/guice
/** Implementation of {@link OptionalBinderBinding#containsElement}. */
boolean containsElement(Element element) {
// All of our bindings are ProviderInstanceBindings whose providers extend
// RealOptionalBinderProviderWithDependencies and have 'this' as its binding selection.
if (element instanceof ProviderInstanceBinding) {
javax.inject.Provider<?> providerInstance =
((ProviderInstanceBinding<?>) element).getUserSuppliedProvider();
if (providerInstance instanceof RealOptionalBinderProviderWithDependencies) {
return ((RealOptionalBinderProviderWithDependencies<?, ?>) providerInstance)
.bindingSelection.equals(this);
}
}
if (element instanceof Binding) {
Key<?> elementKey = ((Binding) element).getKey();
// if it isn't one of the things we bound directly it might be an actual or default key
return elementKey.equals(getKeyForActualBinding())
|| elementKey.equals(getKeyForDefaultBinding());
}
return false; // cannot match;
}
代码示例来源:origin: com.google.inject/guice
private boolean containsElement(Element element) {
if (entrySetBinder.containsElement(element)) {
return true;
}
Key<?> key;
if (element instanceof Binding) {
key = ((Binding<?>) element).getKey();
} else {
return false; // cannot match;
}
return key.equals(getMapKey())
|| key.equals(getProviderMapKey())
|| key.equals(getJavaxProviderMapKey())
|| key.equals(getMultimapKey())
|| key.equals(getProviderSetMultimapKey())
|| key.equals(getJavaxProviderSetMultimapKey())
|| key.equals(getProviderCollectionMultimapKey())
|| key.equals(getJavaxProviderCollectionMultimapKey())
|| key.equals(entrySetBinder.getSetKey())
|| key.equals(getEntrySetJavaxProviderKey())
|| matchesValueKey(key);
}
内容来源于网络,如有侵权,请联系作者删除!