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

Java ProviderWithDependencies类代码示例

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

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



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

示例1: asProvider

import com.google.inject.spi.ProviderWithDependencies; //导入依赖的package包/类
public Provider<T> asProvider() {
    return new ProviderWithDependencies<T>() {
        @Override
        public T get() {
            return Injection.wrappingExceptions(asSupplier());
        }

        @Override
        public Set<Dependency<?>> getDependencies() {
            return dependencies;
        }
    };
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:14,代码来源:InjectableMethod.java


示例2: createResultProvider

import com.google.inject.spi.ProviderWithDependencies; //导入依赖的package包/类
private ProviderWithDependencies<Result> createResultProvider(
    final Key<? extends CheckedProvider<?>> targetKey,
    final Provider<? extends CheckedProvider<?>> targetProvider) {
  return new ProviderWithDependencies<Result>() {
    @Override
    public Result get() {
      try {
        return Result.forValue(targetProvider.get().get());
      } catch (Exception e) {
        for (Class<? extends Throwable> exceptionType : exceptionTypes) {
          if (exceptionType.isInstance(e)) {
            if (scopeExceptions) {
              return Result.forException(e);
            } else {
              throw new ResultException(e);
            }
          }
        }

        if (e instanceof RuntimeException) {
          throw (RuntimeException) e;
        } else {
          // this should never happen
          throw new RuntimeException(e);
        }
      }
    }

    @Override
    public Set<Dependency<?>> getDependencies() {
      return ImmutableSet.<Dependency<?>>of(Dependency.get(targetKey));
    }
  };
}
 
开发者ID:google,项目名称:guice,代码行数:35,代码来源:ThrowingProviderBinder.java


示例3: toInternal

import com.google.inject.spi.ProviderWithDependencies; //导入依赖的package包/类
private ScopedBindingBuilder toInternal(final Key<? extends CheckedProvider<?>> targetKey) {
  final Key<Result> resultKey = Key.get(Result.class, UniqueAnnotations.create());
  // Note that this provider will behave like the final provider Guice creates.
  // It will especially do scoping if the user adds that.
  final Provider<Result> resultProvider = binder.getProvider(resultKey);
  final Provider<? extends CheckedProvider<?>> targetProvider = binder.getProvider(targetKey);
  interfaceKey = createKey();

  // don't bother binding the proxy type if this is in an invalid state.
  if (valid) {
    binder
        .bind(interfaceKey)
        .toProvider(
            new ProviderWithDependencies<P>() {
              private final P instance =
                  interfaceType.cast(
                      Proxy.newProxyInstance(
                          interfaceType.getClassLoader(),
                          new Class<?>[] {interfaceType},
                          new InvocationHandler() {
                            @Override
                            public Object invoke(Object proxy, Method method, Object[] args)
                                throws Throwable {
                              // Allow methods like .equals(..), .hashcode(..), .toString(..) to work.
                              if (method.getDeclaringClass() == Object.class) {
                                return method.invoke(this, args);
                              }

                              if (scopeExceptions) {
                                return resultProvider.get().getOrThrow();
                              } else {
                                Result result;
                                try {
                                  result = resultProvider.get();
                                } catch (ProvisionException pe) {
                                  Throwable cause = pe.getCause();
                                  if (cause instanceof ResultException) {
                                    throw ((ResultException) cause).getCause();
                                  } else {
                                    throw pe;
                                  }
                                }
                                return result.getOrThrow();
                              }
                            }
                          }));

              @Override
              public P get() {
                return instance;
              }

              @Override
              public Set<Dependency<?>> getDependencies() {
                return ImmutableSet.<Dependency<?>>of(Dependency.get(resultKey));
              }
            });
  }

  // The provider is unscoped, but the user may apply a scope to it through the
  // ScopedBindingBuilder this returns.
  return binder.bind(resultKey).toProvider(createResultProvider(targetKey, targetProvider));
}
 
开发者ID:google,项目名称:guice,代码行数:64,代码来源:ThrowingProviderBinder.java


示例4: toInternal

import com.google.inject.spi.ProviderWithDependencies; //导入依赖的package包/类
private ScopedBindingBuilder toInternal(final Key<? extends CheckedProvider> targetKey) {
  final Key<Result> resultKey = Key.get(Result.class, UniqueAnnotations.create());
  final Provider<Result> resultProvider = binder.getProvider(resultKey);
  final Provider<? extends CheckedProvider> targetProvider = binder.getProvider(targetKey);
  interfaceKey = createKey();

  // don't bother binding the proxy type if this is in an invalid state.
  if(valid) {
    binder.bind(interfaceKey).toProvider(new ProviderWithDependencies<P>() {
      private final P instance = interfaceType.cast(Proxy.newProxyInstance(
          interfaceType.getClassLoader(), new Class<?>[] { interfaceType },
          new InvocationHandler() {
            public Object invoke(Object proxy, Method method, Object[] args)
                throws Throwable {
              // Allow methods like .equals(..), .hashcode(..), .toString(..) to work.
              if (method.getDeclaringClass() == Object.class) {
                return method.invoke(this, args);
              }
              return resultProvider.get().getOrThrow();
            }
          }));
        
        public P get() {
          return instance;
        }
        
        public Set<Dependency<?>> getDependencies() {
          return ImmutableSet.<Dependency<?>>of(Dependency.get(resultKey));
        }
      });
  }

  return binder.bind(resultKey).toProvider(new ProviderWithDependencies<Result>() {
    public Result get() {
      try {
        return Result.forValue(targetProvider.get().get());
      } catch (Exception e) {
        for(Class<? extends Throwable> exceptionType : exceptionTypes) {
          if (exceptionType.isInstance(e)) {
            return Result.forException(e);
          }
        }
        
        if (e instanceof RuntimeException) {
          throw (RuntimeException) e;
        } else {
          // this should never happen
          throw new RuntimeException(e);
        }
      }
    }
    
    public Set<Dependency<?>> getDependencies() {
      return ImmutableSet.<Dependency<?>>of(Dependency.get(targetKey));
    }
  });
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:58,代码来源:ThrowingProviderBinder.java


示例5: guicify

import com.google.inject.spi.ProviderWithDependencies; //导入依赖的package包/类
/**
 * Returns a Guice-friendly {@code com.google.inject.Provider} for the given
 * JSR-330 {@code javax.inject.Provider}. The converse method is unnecessary,
 * since Guice providers directly implement the JSR-330 interface.
 * 
 * @since 3.0
 */
public static <T> Provider<T> guicify(javax.inject.Provider<T> provider) {
  if (provider instanceof Provider) {
    return (Provider<T>) provider;
  }

  final javax.inject.Provider<T> delegate = checkNotNull(provider, "provider");
  
  // Ensure that we inject all injection points from the delegate provider.
  Set<InjectionPoint> injectionPoints =
      InjectionPoint.forInstanceMethodsAndFields(provider.getClass());
  if(injectionPoints.isEmpty()) {
    return new Provider<T>() {
      public T get() {
        return delegate.get();
      }
  
      @Override public String toString() {
        return "guicified(" + delegate + ")";
      }
    };
  } else {
    Set<Dependency<?>> mutableDeps = Sets.newHashSet();
    for(InjectionPoint ip : injectionPoints) {
      mutableDeps.addAll(ip.getDependencies());
    }
    final Set<Dependency<?>> dependencies = ImmutableSet.copyOf(mutableDeps);
    return new ProviderWithDependencies<T>() {
      @SuppressWarnings("unused")
      @Inject
      void initialize(Injector injector) {
        injector.injectMembers(delegate);
      }
      
      public Set<Dependency<?>> getDependencies() {
        return dependencies;
      }
      
      public T get() {
        return delegate.get();
      }
  
      @Override public String toString() {
        return "guicified(" + delegate + ")";
      }
    };
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:55,代码来源:Providers.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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