コード例 #1
0
ファイル: DynamicItem.java プロジェクト: web1992/gerrit
 /**
  * Declare a singleton {@code DynamicItem<T>} with a binder.
  *
  * <p>Items must be defined in a Guice module before they can be bound:
  *
  * <pre>
  *   DynamicSet.itemOf(binder(), new TypeLiteral&lt;Thing&lt;Foo&gt;&gt;() {});
  * </pre>
  *
  * @param binder a new binder created in the module.
  * @param member type of entry to store.
  */
 public static <T> void itemOf(Binder binder, TypeLiteral<T> member) {
   @SuppressWarnings("unchecked")
   Key<DynamicItem<T>> key =
       (Key<DynamicItem<T>>)
           Key.get(Types.newParameterizedType(DynamicItem.class, member.getType()));
   binder.bind(key).toProvider(new DynamicItemProvider<>(member, key)).in(Scopes.SINGLETON);
 }
コード例 #2
0
 public ComputeServiceContext buildComputeServiceContext() {
   // need the generic type information
   return (ComputeServiceContext)
       buildInjector()
           .getInstance(
               Key.get(
                   Types.newParameterizedType(
                       ComputeServiceContextImpl.class, syncClientType, asyncClientType)));
 }
コード例 #3
0
 @SuppressWarnings("unchecked")
 public <T> T create(Class<T> clazz) {
   return (T)
       create(
           clazz,
           (AsyncRestClientProxy<T>)
               injector.getInstance(
                   Key.get(
                       TypeLiteral.get(
                           Types.newParameterizedType(AsyncRestClientProxy.class, clazz)))));
 }
コード例 #4
0
 private AutoBindProvider getAutoBindProvider(Annotation annotation) {
   AutoBindProvider autoBindProvider = null;
   if (annotation.annotationType().isAnnotationPresent(AutoBind.class)) {
     ParameterizedType parameterizedType =
         Types.newParameterizedType(AutoBindProvider.class, annotation.annotationType());
     autoBindProvider =
         (AutoBindProvider<?>) injector.getInstance(Key.get(TypeLiteral.get(parameterizedType)));
   } else if (annotation.annotationType().isAssignableFrom(AutoBind.class)) {
     autoBindProvider =
         injector.getInstance(Key.get(new TypeLiteral<AutoBindProvider<AutoBind>>() {}));
   }
   return autoBindProvider;
 }
コード例 #5
0
ファイル: ShiroModule.java プロジェクト: cysg/shiro
 @SuppressWarnings({"unchecked"})
 private Key<Collection<Realm>> realmCollectionKey() {
   return (Key<Collection<Realm>>)
       Key.get(Types.newParameterizedType(Collection.class, Realm.class));
 }