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


Java Binding.getSource方法代码示例

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


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

示例1: ConvertedConstantBindingImpl

import com.google.inject.Binding; //导入方法依赖的package包/类
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;
}
 
开发者ID:google,项目名称:guice,代码行数:18,代码来源:InjectorImpl.java

示例2: ProviderBindingImpl

import com.google.inject.Binding; //导入方法依赖的package包/类
ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
  super(
      injector,
      key,
      providedBinding.getSource(),
      createInternalFactory(providedBinding),
      Scoping.UNSCOPED);
  this.providedBinding = (BindingImpl<T>) providedBinding;
}
 
开发者ID:google,项目名称:guice,代码行数:10,代码来源:InjectorImpl.java

示例3: checkBindingSource

import com.google.inject.Binding; //导入方法依赖的package包/类
public void checkBindingSource(Binding binding) {
  assertContains(binding.getSource().toString(), getDeclaringSourcePart(getClass()));
  ElementSource source = (ElementSource) binding.getSource();
  assertFalse(source.getModuleClassNames().isEmpty());
  if (isIncludeStackTraceComplete()) {
    assertTrue(source.getStackTrace().length > 0);
  } else {
    assertEquals(0, source.getStackTrace().length);
  }
}
 
开发者ID:google,项目名称:guice,代码行数:11,代码来源:SpiBindingsTest.java

示例4: ConvertedConstantBindingImpl

import com.google.inject.Binding; //导入方法依赖的package包/类
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;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:11,代码来源:InjectorImpl.java

示例5: checkBindingSource

import com.google.inject.Binding; //导入方法依赖的package包/类
public void checkBindingSource(Binding binding) {
  assertContains(binding.getSource().toString(), getDeclaringSourcePart(getClass()));
  ElementSource source = (ElementSource) binding.getSource();
  assertTrue(source.getModuleClassNames().size() > 0);
  if (isIncludeStackTraceComplete()) {
    assertTrue(source.getStackTrace().length > 0);
  } else {
    assertEquals(0, source.getStackTrace().length);
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:11,代码来源:SpiBindingsTest.java

示例6: newInterfaceNode

import com.google.inject.Binding; //导入方法依赖的package包/类
/** Returns a new interface node for the given {@link Binding}. */
private InterfaceNode newInterfaceNode(Binding<?> binding) {
  return new InterfaceNode(NodeId.newTypeId(binding.getKey()), binding.getSource());
}
 
开发者ID:google,项目名称:guice,代码行数:5,代码来源:DefaultNodeCreator.java

示例7: testGetCallStack_IntegrationTest

import com.google.inject.Binding; //导入方法依赖的package包/类
public void testGetCallStack_IntegrationTest() throws Exception {
  List<Element> elements = Elements.getElements(new A());
  for (Element element : elements) {
    if (element instanceof Binding) {
      Binding<?> binding = (Binding<?>) element;
      Class<? extends Annotation> annotationType = binding.getKey().getAnnotationType();
      if (annotationType != null && annotationType.equals(SampleAnnotation.class)) {
        ElementSource elementSource = (ElementSource) binding.getSource();
        List<String> moduleClassNames = elementSource.getModuleClassNames();
        // Check module class names
        // Module C
        assertEquals("com.google.inject.spi.ElementSourceTest$C", moduleClassNames.get(0));
        // Module B
        assertEquals("com.google.inject.spi.ElementSourceTest$B", moduleClassNames.get(1));
        // Module A
        assertEquals("com.google.inject.spi.ElementSourceTest$A", moduleClassNames.get(2));
        StackTraceElement[] callStack = elementSource.getStackTrace();
        switch (getIncludeStackTraceOption()) {
          case OFF:
            // Check declaring source
            StackTraceElement stackTraceElement =
                (StackTraceElement) elementSource.getDeclaringSource();
            assertEquals(
                new StackTraceElement(
                    "com.google.inject.spi.ElementSourceTest$C", "configure", null, -1),
                stackTraceElement);
            // Check call stack
            assertEquals(0, callStack.length);
            return;
          case ONLY_FOR_DECLARING_SOURCE:
            // Check call stack
            assertEquals(0, callStack.length);
            return;
          case COMPLETE:
            // Check call stack
            int skippedCallStackSize = new Throwable().getStackTrace().length - 1;
            assertEquals(skippedCallStackSize + 15, elementSource.getStackTrace().length);
            assertEquals(
                "com.google.inject.spi.Elements$RecordingBinder", callStack[0].getClassName());
            assertEquals(
                "com.google.inject.spi.Elements$RecordingBinder", callStack[1].getClassName());
            assertEquals("com.google.inject.AbstractModule", callStack[2].getClassName());
            // Module C
            assertEquals(
                "com.google.inject.spi.ElementSourceTest$C", callStack[3].getClassName());
            assertEquals("configure", callStack[3].getMethodName());
            assertEquals("Unknown Source", callStack[3].getFileName());
            assertEquals("com.google.inject.AbstractModule", callStack[4].getClassName());
            assertEquals(
                "com.google.inject.spi.Elements$RecordingBinder", callStack[5].getClassName());
            // Module B
            assertEquals(
                "com.google.inject.spi.ElementSourceTest$B", callStack[6].getClassName());
            assertEquals(
                "com.google.inject.spi.Elements$RecordingBinder", callStack[7].getClassName());
            // Module A
            assertEquals("com.google.inject.AbstractModule", callStack[8].getClassName());
            assertEquals(
                "com.google.inject.spi.ElementSourceTest$A", callStack[9].getClassName());
            assertEquals("com.google.inject.AbstractModule", callStack[10].getClassName());
            assertEquals(
                "com.google.inject.spi.Elements$RecordingBinder", callStack[11].getClassName());
            assertEquals("com.google.inject.spi.Elements", callStack[12].getClassName());
            assertEquals("com.google.inject.spi.Elements", callStack[13].getClassName());
            assertEquals("com.google.inject.spi.ElementSourceTest", callStack[14].getClassName());
            // Check modules index
            List<Integer> indexes = elementSource.getModuleConfigurePositionsInStackTrace();
            assertEquals(4, (int) indexes.get(0));
            assertEquals(6, (int) indexes.get(1));
            assertEquals(10, (int) indexes.get(2));
            return;
        }
      }
    }
  }
  fail("The test should not reach this line.");
}
 
开发者ID:google,项目名称:guice,代码行数:78,代码来源:ElementSourceTest.java

示例8: toBinders

import com.google.inject.Binding; //导入方法依赖的package包/类
/**
 * Turns the given Guice {@link Binding}s into HK2 {@link Binder}s.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Set<Binder> toBinders(Map<Key<?>, Binding<?>> bindings) {
  Set<Binder> binders = new HashSet<>();
  
  for (Map.Entry<Key<?>, Binding<?>> entry : bindings.entrySet()) {
    Key<?> key = entry.getKey();
    Binding<?> binding = entry.getValue();
    
    Object source = binding.getSource();
    if (!(source instanceof ElementSource)) {
      
      // Things like the Injector itself don't have an ElementSource.
      if (LOG.isTraceEnabled()) {
        LOG.trace("Adding binding: key={}, source={}", key, source);
      }
      
      binders.add(new GuiceBinder(key, binding));
      continue;
    }
    
    ElementSource element = (ElementSource)source;
    List<String> names = element.getModuleClassNames();
    String name = names.get(0);
    
    // Skip everything that is declared in a JerseyModule
    try {

      Class<?> module;

      // Attempt to load the classes via the context class loader first, in order to support
      // environments that enforce tighter constraints on class loading (such as in an OSGi container)
      ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
      if(classLoader != null) {
        module = classLoader.loadClass(name);
      } else {
        module = Class.forName(name);
      }
      if (JerseyModule.class.isAssignableFrom(module)) {
        if (LOG.isTraceEnabled()) {
          LOG.trace("Ignoring binding {} in {}", key, module);
        }
        
        continue;
      }
    } catch (ClassNotFoundException err) {
      // Some modules may not be able to be instantiated directly here as a class if we're running
      // in a container that enforcer tighter class loader constraints (such as the
      // org.ops4j.peaberry.osgi.OSGiModule Guice module when running in an OSGi container),
      // so we're only logging a warning here instead of throwing a hard exception
      if (LOG.isWarnEnabled()) {
        LOG.warn("Unavailable to load class in order to validate module: name={}", name);
      }
    }
    
    binders.add(new GuiceBinder(key, binding));
  }
  
  return binders;
}
 
开发者ID:Squarespace,项目名称:jersey2-guice,代码行数:63,代码来源:JerseyGuiceUtils.java

示例9: ProviderBindingImpl

import com.google.inject.Binding; //导入方法依赖的package包/类
ProviderBindingImpl(InjectorImpl injector, Key<Provider<T>> key, Binding<T> providedBinding) {
  super(injector, key, providedBinding.getSource(), createInternalFactory(providedBinding),
      Scoping.UNSCOPED);
  this.providedBinding = (BindingImpl<T>) providedBinding;
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:6,代码来源:InjectorImpl.java

示例10: newImplementationNode

import com.google.inject.Binding; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:google,项目名称:guice,代码行数:13,代码来源:DefaultNodeCreator.java

示例11: newImplementationNode

import com.google.inject.Binding; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:13,代码来源:DefaultNodeCreator.java


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