當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。