com.google.inject.Binding.getSource()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中com.google.inject.Binding.getSource()方法的一些代码示例,展示了Binding.getSource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Binding.getSource()方法的具体详情如下:
包路径:com.google.inject.Binding
类名称:Binding
方法名:getSource

Binding.getSource介绍

[英]Returns an arbitrary object containing information about the "place" where this binding was configured. Used by Guice in the production of descriptive error messages.
[中]返回任意对象,其中包含有关配置此绑定的“位置”的信息。Guice在生成描述性错误消息时使用。

代码示例

代码示例来源:origin: com.google.inject/guice

ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
 super(
   injector,
   key,
   providedBinding.getSource(),
   createInternalFactory(providedBinding),
   Scoping.UNSCOPED);
 this.providedBinding = (BindingImpl<T>) providedBinding;
}

代码示例来源:origin: com.google.inject/guice

private static <K, V> InternalProvisionException createNullValueException(
   K key, Binding<V> binding) {
  return InternalProvisionException.create(
    "Map injection failed due to null value for key \"%s\", bound at: %s",
    key, binding.getSource());
 }
}

代码示例来源:origin: com.google.inject/guice

private InternalProvisionException newNullEntryException(int i) {
 return InternalProvisionException.create(
   "Set injection failed due to null element bound at: %s", bindings.get(i).getSource());
}

代码示例来源:origin: com.google.inject/guice

private static <K, V> void reportDuplicateKeysError(
  Multimap<K, Binding<V>> duplicates, Errors errors) {
 StringBuilder sb = new StringBuilder("Map injection failed due to duplicated key ");
 boolean first = true;
 for (Map.Entry<K, Collection<Binding<V>>> entry : duplicates.asMap().entrySet()) {
  K dupKey = entry.getKey();
  if (first) {
   first = false;
   sb.append("\"" + dupKey + "\", from bindings:\n");
  } else {
   sb.append("\n and key: \"" + dupKey + "\", from bindings:\n");
  }
  for (Binding<V> dup : entry.getValue()) {
   sb.append("\t at " + Errors.convert(dup.getSource()) + "\n");
  }
 }
 // TODO(user): Add a different error for every duplicated key
 errors.addMessage(sb.toString());
}

代码示例来源: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

"Set injection failed due to duplicated element \"%s\""
     + "\n    Bound at %s\n    Bound at %s",
   newValue, duplicateBinding.getSource(), newBinding.getSource());
} else {
     + "\n    \"%s\"\n        bound at %s"
     + "\n    \"%s\"\n        bound at %s",
   oldValue, duplicateBinding.getSource(), newValue, newBinding.getSource());

代码示例来源:origin: com.google.inject/guice

ConvertedConstantBindingImpl(
  InjectorImpl injector,
  Key<T> key,
  T value,
  Binding<String> originalBinding,
  TypeConverterBinding typeConverterBinding) {
 super(
   injector,
   key,
   originalBinding.getSource(),
   new ConstantFactory<T>(Initializables.of(value)),
   Scoping.UNSCOPED);
 this.value = value;
 provider = Providers.of(value);
 this.originalBinding = originalBinding;
 this.typeConverterBinding = typeConverterBinding;
}

代码示例来源:origin: com.google.inject/guice

for (Key<V> key : keysOnlyFromBindings) {
 sb.append(
   Errors.format("  %s bound at: %s%n", key, valueKeyToBinding.get(key).getSource()));
   Errors.format(
     "  '%s' bound at: %s%n",
     valueKeyToKey.get(key), valueKeyToEntryBinding.get(key).getSource()));

代码示例来源:origin: com.google.inject/guice

if (have.contains(want) || want.contains(have)) {
 Formatter fmt = new Formatter();
 Messages.formatSource(fmt, bindingMap.get(bindingKey).getSource());
 String match = String.format("%s bound%s", convert(bindingKey), fmt.toString());
 possibleMatches.add(match);

代码示例来源:origin: org.sonatype.sisu/sisu-guice

ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
 super(
   injector,
   key,
   providedBinding.getSource(),
   createInternalFactory(providedBinding),
   Scoping.UNSCOPED);
 this.providedBinding = (BindingImpl<T>) providedBinding;
}

代码示例来源:origin: org.sonatype.sisu/sisu-guice

private static <K, V> InternalProvisionException createNullValueException(
   K key, Binding<V> binding) {
  return InternalProvisionException.create(
    "Map injection failed due to null value for key \"%s\", bound at: %s",
    key, binding.getSource());
 }
}

代码示例来源:origin: com.jwebmp.inject/guice

private static <K, V> InternalProvisionException createNullValueException(
   K key, Binding<V> binding) {
  return InternalProvisionException.create(
    "Map injection failed due to null value for key \"%s\", bound at: %s",
    key, binding.getSource());
 }
}

代码示例来源:origin: com.google/inject

ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
 super(injector, key, providedBinding.getSource(), createInternalFactory(providedBinding),
   Scoping.UNSCOPED);
 this.providedBinding = (BindingImpl<T>) providedBinding;
}

代码示例来源:origin: org.xbib/guice

ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
  super(injector, key, providedBinding.getSource(), createInternalFactory(providedBinding),
      Scoping.UNSCOPED);
  this.providedBinding = (BindingImpl<T>) providedBinding;
}

代码示例来源:origin: Nextdoor/bender

ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
 super(injector, key, providedBinding.getSource(), createInternalFactory(providedBinding),
   Scoping.UNSCOPED);
 this.providedBinding = (BindingImpl<T>) providedBinding;
}

代码示例来源:origin: io.github.gwtplus.gin/gin

protected Void visitOther(com.google.inject.Binding<? extends T> binding) {
 messages.add(new Message(binding.getSource(), PrettyPrinter.format(
   "Unsupported binding provided for key: %s: %s", targetKey, binding)));
 return null;
}

代码示例来源:origin: org.sonatype.spice.inject/guice-plexus-locators

public String getDescription()
{
  final Object source = bean.getBinding().getSource();
  if ( source instanceof PlexusBeanDescription )
  {
    return ( (PlexusBeanDescription) source ).getDescription();
  }
  return null;
}

代码示例来源:origin: com.google.code.guice/guice

private <T> InternalFactory<T> handleConstantConversionError(
  Member member, Binding<String> stringBinding, Class<?> rawType,
  Exception e) {
 errorHandler.handle(
   StackTraceElements.forMember(member),
   ErrorMessages.CONSTANT_CONVERSION_ERROR,
   stringBinding.getSource(),
   rawType,
   e.getMessage());
 return invalidFactory();
}

代码示例来源:origin: org.eclipse.sisu/org.eclipse.sisu.inject.tests

public void testImportSource()
{
  final Injector injector = Guice.createInjector( new WireModule( new TestModule() ) );
  assertEquals( LocatorWiring.class.getName(), injector.getBinding( Y.class ).getSource().toString() );
}

代码示例来源:origin: com.google.inject.extensions/guice-grapher

/**
 * Returns a new implementation node for the given binding.
 *
 * @param binding binding for the node to create
 * @param members members to add to the node
 * @return implementation node for the given binding
 */
private ImplementationNode newImplementationNode(
  Binding<?> binding, Collection<Member> members) {
 return new ImplementationNode(
   NodeId.newTypeId(binding.getKey()), binding.getSource(), members);
}

相关文章