• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ProviderInstanceBinding类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ProviderInstanceBinding类属于com.google.inject.spi包,在下文中一共展示了ProviderInstanceBinding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: visit

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public Void visit(ProviderInstanceBinding<? extends T> providerInstanceBinding) {
  // Detect provider methods and handle them
  // TODO(bstoler): Update this when the SPI explicitly has a case for
  // provider methods
  Provider<? extends T> provider = providerInstanceBinding.getProviderInstance();
  if (provider instanceof ProviderMethod) {
    Context context = Context.forElement(providerInstanceBinding);
    bindingsCollection.addBinding(targetKey,
        bindingFactory.getProviderMethodBinding((ProviderMethod<?>) provider, context));
    return null;
  }

  if (provider instanceof GwtDotCreateProvider) {
    addImplicitBinding(providerInstanceBinding);
    return null;
  }

  // OTt, use the normal default handler (and error)
  return super.visit(providerInstanceBinding);
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:21,代码来源:GuiceBindingVisitor.java


示例2: instantiation

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
private static String instantiation(Binding<?> binding) {
  if (binding instanceof InstanceBinding<?>) {
    return instanceLiteral((InstanceBinding<?>) binding);
  } else if (binding instanceof ProviderKeyBinding<?>) {
    return providerCall(((ProviderKeyBinding<?>) binding).getProviderKey()) + ".get()";
  } else if (binding instanceof LinkedKeyBinding<?>) {
    return providerCall(((LinkedKeyBinding<?>) binding).getLinkedKey());
  } else if (binding instanceof ConstructorBinding<?>) {
    return constructorCall((ConstructorBinding<?>) binding);
  } else if (binding instanceof ProviderBinding<?>) {
    return provider((ProviderBinding<?>) binding);
  } else if (binding instanceof ProviderInstanceBinding<?>) {
    return instantiation((ProviderInstanceBinding<?>) binding);
  } else {
    throw new DeguicifierException();
  }
}
 
开发者ID:mikosik,项目名称:deguicifier,代码行数:18,代码来源:Generators.java


示例3: providesMethodCall

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
private static String providesMethodCall(ProviderInstanceBinding<?> binding,
    ProviderMethod<?> provider) {
  Method providesMethod = provider.getMethod();
  Class<?> moduleClass = providesMethod.getDeclaringClass();
  if (moduleClass.isLocalClass()) {
    throw new DeguicifierException();
  }
  try {
    moduleClass.getConstructor();
  } catch (NoSuchMethodException e) {
    throw new DeguicifierException(e);
  }
  String statement =
      "new " + moduleClass.getCanonicalName() + "()." + providesMethod.getName() + "("
          + argumentList(binding) + ")";
  return statement;
}
 
开发者ID:mikosik,项目名称:deguicifier,代码行数:18,代码来源:Generators.java


示例4: testGetInstanceName_providerMethod

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testGetInstanceName_providerMethod() throws Exception {
  final ProviderMethod<?>[] methodHolder = new ProviderMethod[1];

  Injector injector = Guice.createInjector(new ProvidingModule());
  injector
      .getBinding(Integer.class)
      .acceptTargetVisitor(
          new DefaultBindingTargetVisitor<Object, Void>() {
            @SuppressWarnings("unchecked")
            @Override
            public Void visit(ProviderInstanceBinding<?> binding) {
              methodHolder[0] = (ProviderMethod) binding.getUserSuppliedProvider();
              return null;
            }
          });

  assertEquals(
      "Method provider should pretty print as the method signature",
      "#provideInteger(String)",
      nameFactory.getInstanceName(methodHolder[0]));
}
 
开发者ID:google,项目名称:guice,代码行数:22,代码来源:ShortNameFactoryTest.java


示例5: containsElement

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


示例6: initialize

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
 * This will get the authoritative {@link BindingSelection} from the map provider. This
 * guarantees that everyone has the same instance of the bindingSelection and sees consistent
 * state.
 */
@Override
final void initialize(InjectorImpl injector, Errors errors) throws ErrorsException {
  Binding<Map<K, V>> mapBinding = injector.getExistingBinding(mapKey);
  ProviderInstanceBinding<Map<K, V>> providerInstanceBinding =
      (ProviderInstanceBinding<Map<K, V>>) mapBinding;
  @SuppressWarnings("unchecked")
  RealMapProvider<K, V> mapProvider =
      (RealMapProvider<K, V>) providerInstanceBinding.getUserSuppliedProvider();

  this.bindingSelection = mapProvider.getBindingSelection();

  if (bindingSelection.tryInitialize(injector, errors)) {
    doInitialize(injector, errors);
  }
}
 
开发者ID:google,项目名称:guice,代码行数:21,代码来源:RealMapBinder.java


示例7: getProviderMapEntry

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
 * Will find and return the {@link com.google.inject.spi.Element} that is a {@link
 * ProviderMapEntry} with a key that matches the one supplied by the user in {@code k}.
 *
 * <p>Will return {@code null} if it cannot be found.
 */
private static com.google.inject.spi.Element getProviderMapEntry(
    Object kToFind, Iterable<com.google.inject.spi.Element> elements) {
  for (com.google.inject.spi.Element element : elements) {
    if (element instanceof ProviderInstanceBinding) {
      javax.inject.Provider<?> usp =
          ((ProviderInstanceBinding<?>) element).getUserSuppliedProvider();
      if (usp instanceof ProviderMapEntry) {
        ProviderMapEntry<?, ?> pme = (ProviderMapEntry<?, ?>) usp;

        // Check if the key from the ProviderMapEntry matches the one we're looking for
        if (kToFind.equals(pme.getKey())) {
          return element;
        }
      }
    }
  }
  // No matching ProviderMapEntry found
  return null;
}
 
开发者ID:google,项目名称:guice,代码行数:26,代码来源:MapBinderTest.java


示例8: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor,
    ProviderInstanceBinding<? extends B> binding) {
  if(visitor instanceof ServletModuleTargetVisitor) {
    if(servletInstance != null) {
      return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
          new InstanceServletBindingImpl(initParams,
              pattern,
              servletInstance,
              patternMatcher));
    } else {
      return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
          new LinkedServletBindingImpl(initParams,
              pattern,
              servletKey,
              patternMatcher));
    }
  } else {
    return visitor.visit(binding);
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:21,代码来源:ServletDefinition.java


示例9: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor,
    ProviderInstanceBinding<? extends B> binding) {
  if(visitor instanceof ServletModuleTargetVisitor) {
    if(filterInstance != null) {
      return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
          new InstanceFilterBindingImpl(initParams,
              pattern,
              filterInstance,
              patternMatcher));
    } else {
      return ((ServletModuleTargetVisitor<B, V>)visitor).visit(
          new LinkedFilterBindingImpl(initParams,
              pattern,
              filterKey,
              patternMatcher));
    }
  } else {
    return visitor.visit(binding);
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:21,代码来源:FilterDefinition.java


示例10: testGetInstanceName_providerMethod

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testGetInstanceName_providerMethod() throws Exception {
  final ProviderMethod<?>[] methodHolder = new ProviderMethod[1];
  
  Injector injector = Guice.createInjector(new ProvidingModule());
  injector.getBinding(Integer.class).acceptTargetVisitor(
      new DefaultBindingTargetVisitor<Object, Void>() {
        @SuppressWarnings("unchecked") @Override
        public Void visit(ProviderInstanceBinding<?> binding) {
          methodHolder[0] = (ProviderMethod) binding.getUserSuppliedProvider();
          return null;
        }
      });
  
  assertEquals("Method provider should pretty print as the method signature",
      "#provideInteger(String)", nameFactory.getInstanceName(methodHolder[0]));
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:17,代码来源:ShortNameFactoryTest.java


示例11: testGetInstanceName_providerMethod

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testGetInstanceName_providerMethod() throws Exception {
  final ProviderMethod<?>[] methodHolder = new ProviderMethod[1];
  
  Injector injector = Guice.createInjector(new ProvidingModule());
  injector.getBinding(Integer.class).acceptTargetVisitor(
      new DefaultBindingTargetVisitor<Object, Void>() {
        @SuppressWarnings("unchecked") @Override
        public Void visit(ProviderInstanceBinding<?> binding) {
          methodHolder[0] = (ProviderMethod) binding.getProviderInstance();
          return null;
        }
      });
  
  assertEquals("Method provider should pretty print as the method signature",
      "#provideInteger(String)", nameFactory.getInstanceName(methodHolder[0]));
}
 
开发者ID:utopiazh,项目名称:google-guice,代码行数:17,代码来源:ShortNameFactoryTest.java


示例12: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
 * This is needed for 'initialize(injector)' below to be called so the provider
 * can get the injector after it is instantiated.
 */
@Override
public <B, V> V acceptExtensionVisitor(
        BindingTargetVisitor<B, V> visitor,
        ProviderInstanceBinding<? extends B> binding) {
    return visitor.visit(binding);
}
 
开发者ID:Netflix,项目名称:fabricator,代码行数:11,代码来源:ComponentFactoryFactoryProvider.java


示例13: binds_provider_instance

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@Test
public void binds_provider_instance() {
  given(module = new AbstractModule() {
    @Override
    protected void configure() {
      bind(Interface.class).toProvider(new InterfaceProvider());
    }
  });
  given(injector = Guice.createInjector(module));
  when(injector.getBinding(Interface.class));
  thenReturned(instanceOf(ProviderInstanceBinding.class));
}
 
开发者ID:mikosik,项目名称:deguicifier,代码行数:13,代码来源:BindingTypesTest.java


示例14: binds_provider_instance_from_method

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@Test
public void binds_provider_instance_from_method() {
  given(module = new AbstractModule() {
    @Override
    protected void configure() {}

    @Provides
    public Interface provide() {
      return new Implementation();
    }
  });
  given(injector = Guice.createInjector(module));
  when(injector.getBinding(Interface.class));
  thenReturned(instanceOf(ProviderInstanceBinding.class));
}
 
开发者ID:mikosik,项目名称:deguicifier,代码行数:16,代码来源:BindingTypesTest.java


示例15: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@SuppressWarnings("unchecked") // The real type of B must be T
@Override
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) {
    if (visitor instanceof ContextSensitiveBindingVisitor) {
        return ((ContextSensitiveBindingVisitor<T, V>)visitor).visit(this);
    } else {
        return visitor.visit(binding);
    }
}
 
开发者ID:tavianator,项目名称:sangria,代码行数:10,代码来源:ContextSensitiveBinder.java


示例16: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@SuppressWarnings("unchecked") // B must be Lazy<T>
@Override
public <B, V> V acceptExtensionVisitor(BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) {
    if (visitor instanceof LazyBindingVisitor) {
        return ((LazyBindingVisitor<T, V>)visitor).visit(this);
    } else {
        return visitor.visit(binding);
    }
}
 
开发者ID:tavianator,项目名称:sangria,代码行数:10,代码来源:LazyBinder.java


示例17: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@Override
public <B, V> V acceptExtensionVisitor(
    BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) {
  if (visitor instanceof ServletModuleTargetVisitor) {
    if (servletInstance != null) {
      return ((ServletModuleTargetVisitor<B, V>) visitor)
          .visit(new InstanceServletBindingImpl(initParams, servletInstance, patternMatcher));
    } else {
      return ((ServletModuleTargetVisitor<B, V>) visitor)
          .visit(new LinkedServletBindingImpl(initParams, servletKey, patternMatcher));
    }
  } else {
    return visitor.visit(binding);
  }
}
 
开发者ID:google,项目名称:guice,代码行数:16,代码来源:ServletDefinition.java


示例18: acceptExtensionVisitor

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
@Override
public <B, V> V acceptExtensionVisitor(
    BindingTargetVisitor<B, V> visitor, ProviderInstanceBinding<? extends B> binding) {
  if (visitor instanceof ServletModuleTargetVisitor) {
    if (filterInstance != null) {
      return ((ServletModuleTargetVisitor<B, V>) visitor)
          .visit(new InstanceFilterBindingImpl(initParams, filterInstance, patternMatcher));
    } else {
      return ((ServletModuleTargetVisitor<B, V>) visitor)
          .visit(new LinkedFilterBindingImpl(initParams, filterKey, patternMatcher));
    }
  } else {
    return visitor.visit(binding);
  }
}
 
开发者ID:google,项目名称:guice,代码行数:16,代码来源:FilterDefinition.java


示例19: visit

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
/**
 * Same as {@link #visit(InstanceBinding)}, but the binding edge is {@link
 * BindingEdge.Type#PROVIDER}.
 */
@Override
public Collection<Edge> visit(ProviderInstanceBinding<?> binding) {
  return new ImmutableList.Builder<Edge>()
      .add(
          new BindingEdge(
              NodeId.newTypeId(binding.getKey()),
              NodeId.newInstanceId(binding.getKey()),
              BindingEdge.Type.PROVIDER))
      .addAll(newDependencyEdges(NodeId.newInstanceId(binding.getKey()), binding))
      .build();
}
 
开发者ID:google,项目名称:guice,代码行数:16,代码来源:DefaultEdgeCreator.java


示例20: testVisitProviderInstance

import com.google.inject.spi.ProviderInstanceBinding; //导入依赖的package包/类
public void testVisitProviderInstance() {
  Binding<?> binding = getBinding(Key.get(ConstructedClass.class), new ProviderInstanceModule());
  Collection<Key<?>> dependencies = visitor.visit((ProviderInstanceBinding<?>) binding);

  // Dependencies will only be on the field- and method-injected classes.
  assertDependencies(dependencies, Key.get(E.class), Key.get(F.class));
}
 
开发者ID:google,项目名称:guice,代码行数:8,代码来源:TransitiveDependencyVisitorTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VCFHeaderLineType类代码示例发布时间:2022-05-21
下一篇:
Java UiTemplate类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap