本文整理匯總了Java中com.google.inject.TypeLiteral類的典型用法代碼示例。如果您正苦於以下問題:Java TypeLiteral類的具體用法?Java TypeLiteral怎麽用?Java TypeLiteral使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TypeLiteral類屬於com.google.inject包,在下文中一共展示了TypeLiteral類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: configure
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Override
protected void configure() {
install(new StateModule(timeout));
if (eventLoopGroup.isPresent()) {
install(new RpcModule(local.address(), eventLoopGroup.get()));
} else {
install(new RpcModule(local.address()));
}
install(new LogModule(logDir, stateMachine));
bind(Replica.class).annotatedWith(LocalReplicaInfo.class).toInstance(local);
bind(new TypeLiteral<List<Replica>>() {
}).annotatedWith(ClusterMembers.class).toInstance(members);
bind(RaftService.class);
expose(RaftService.class);
}
示例2: configure
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Override
protected void configure() {
bind(SelectionModulePresenter.class).to(SelectionModulePresenterImpl.class);
bind(SelectionModuleView.class).to(SelectionModuleViewImpl.class);
bind(SelectionElementGenerator.class).to(SelectionGridElementGeneratorImpl.class);
bind(SelectionElementPositionGenerator.class).to(SelectionGridElementGeneratorImpl.class);
bindModuleScoped(SelectionModuleModel.class, new TypeLiteral<ModuleScopedProvider<SelectionModuleModel>>() {
});
bindModuleScoped(SelectionModuleView.class, new TypeLiteral<ModuleScopedProvider<SelectionModuleView>>() {
});
bindModuleScoped(SelectionViewBuilder.class, new TypeLiteral<ModuleScopedProvider<SelectionViewBuilder>>() {
});
install(new GinFactoryModuleBuilder().build(SelectionModuleFactory.class));
}
示例3: bindNumber
import com.google.inject.TypeLiteral; //導入依賴的package包/類
private <T extends Number & Comparable<T>> void bindNumber(Class<T> rawType) {
final TypeLiteral<T> type = TypeLiteral.get(rawType);
final TypeArgument<T> typeArg = new TypeArgument<T>(type){};
final TypeLiteral<NumberParser<T>> parserType = new ResolvableType<NumberParser<T>>(){}.with(typeArg);
bind(parserType);
bind(new ResolvableType<TransfiniteParser<T>>(){}.with(typeArg)).to(parserType);
bind(new ResolvableType<PrimitiveParser<T>>(){}.with(typeArg)).to(parserType);
bind(new ResolvableType<Parser<T>>(){}.with(typeArg)).to(parserType);
final TypeLiteral<VectorParser<T>> vectorParserType = new ResolvableType<VectorParser<T>>(){}.with(typeArg);
bind(vectorParserType);
install(new PropertyManifest<>(type, new ResolvableType<NumberProperty<T>>(){}.with(typeArg)));
if(Types.isAssignable(Comparable.class, type)) {
install(new RangeParserManifest(type));
}
}
示例4: ifCommmandIsInvalidExceptionIsThrown
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Test
public void ifCommmandIsInvalidExceptionIsThrown() throws IOException, URISyntaxException {
String command = "invalid";
Map<String, Object> opts = new HashMap<>();
opts.put(BROWSER, CHROME);
opts.put(DRIVER, chromedriverFile.getAbsolutePath());
opts.put(APPLICATION, configurationFile.getAbsolutePath());
opts.put(URL, localhostUrl);
opts.put(CASE, caseFile.getAbsolutePath());
opts.put(SCREEN, screenString);
opts.put(TIMEOUT, timeoutString);
opts.put(PRECISION, precisionString);
Module module = new DefaultModule(command, opts);
Injector injector = Guice.createInjector(module);
try {
RequestFilter instance = injector.getInstance(
Key.get(new TypeLiteral<IOProvider<RequestFilter>>() {})).get();
} catch (ProvisionException e) {
assertTrue(e.getCause() instanceof NoSuchCommandException);
}
}
示例5: scanForMethods
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Test
public void scanForMethods() throws Exception {
class Woot {
@Yay String foo() {
return "foo";
}
String bar() {
return "bar";
}
}
List<InjectableMethod<?>> methods = InjectableMethod.forAnnotatedMethods(TypeLiteral.get(Woot.class), new Woot(), Yay.class);
Injector injector = Guice.createInjector(Lists.transform(methods, InjectableMethod::bindingModule));
assertEquals("foo", injector.getInstance(String.class));
}
示例6: visit
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Override
public Optional<TypeLiteral<?>> visit(ExposedBinding<?> binding) {
// Lookup the exposed key in the private environment.
// Since this visitor can only be used on an injector binding,
// the private child injector should always be present too.
return ofNullable(binding.getPrivateElements().getInjector())
.flatMap(child -> child.getBinding(binding.getKey())
.acceptTargetVisitor(new BindingTargetTypeResolver(child)));
}
示例7: configure
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Override
protected void configure() {
bind(BukkitCommandRegistry.class);
bind(CommandRegistry.class).to(BukkitCommandRegistry.class);
bind(new TypeLiteral<CommandRegistryImpl<CommandSender>>(){}).to(BukkitCommandRegistry.class);
new ListenerBinder(binder())
.bindListener().to(BukkitCommandRegistry.class);
}
示例8: bindTracker
import com.google.inject.TypeLiteral; //導入依賴的package包/類
protected <T> TrackerProvider<T> bindTracker(java.lang.reflect.Type typeParam, Annotation annotatedWith,
String extensionPoint, String beanParameter)
{
ParameterizedType type = Types.newParameterizedType(PluginTracker.class, typeParam);
TrackerProvider<T> trackerProvider = new TrackerProvider<T>(getPluginId(), extensionPoint, beanParameter);
@SuppressWarnings("unchecked")
TypeLiteral<PluginTracker<T>> typeLiteral = (TypeLiteral<PluginTracker<T>>) TypeLiteral.get(type);
LinkedBindingBuilder<PluginTracker<T>> bindingBuilder = bind(typeLiteral);
if( annotatedWith != null )
{
bindingBuilder = ((AnnotatedBindingBuilder<PluginTracker<T>>) bindingBuilder).annotatedWith(annotatedWith);
}
bindingBuilder.toProvider(trackerProvider).in(Scopes.SINGLETON);
return trackerProvider;
}
示例9: InnerFactoryManifest
import com.google.inject.TypeLiteral; //導入依賴的package包/類
public InnerFactoryManifest(Key<I> innerKey, TypeLiteral<O> outerType) {
if(innerKey == null) {
innerKey = Key.get(new ResolvableType<I>(){}.in(getClass()));
}
this.innerType = innerKey.getTypeLiteral();
this.outerType = outerType != null ? outerType : new ResolvableType<O>(){}.in(getClass());
this.factoryKey = innerKey.ofType(new ResolvableType<InnerFactory<O, I>>(){}
.with(new TypeArgument<O>(this.outerType){},
new TypeArgument<I>(this.innerType){}));
}
示例10: forInheritedMethods
import com.google.inject.TypeLiteral; //導入依賴的package包/類
public static <D> List<InjectableMethod<?>> forInheritedMethods(@Nullable TypeLiteral<D> targetType, @Nullable D target, Predicate<? super Method> filter) {
final TypeLiteral<D> finalTargetType = targetType(targetType, target, null);
return new MethodScanner<>(finalTargetType, filter)
.methods()
.stream()
.map(method -> (InjectableMethod<?>) forMethod(finalTargetType, target, method))
.collect(Collectors.toImmutableList());
}
示例11: configure
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Override
protected void configure() {
bind(TextFeedback.class).to(TextFeedbackPresenter.class);
bind(ImageFeedback.class).to(ImageFeedbackPresenter.class);
bind(FeedbackBlendView.class).to(FeedbackBlendViewImpl.class);
bindPageScoped(PowerFeedbackMediator.class, new TypeLiteral<PageScopedProvider<PowerFeedbackMediator>>() {
});
install(new GinFactoryModuleBuilder().build(FeedbackModuleFactory.class));
install(new GinFactoryModuleBuilder().build(SingleFeedbackSoundPlayerFactory.class));
install(new GinFactoryModuleBuilder().build(MatcherRegistryFactory.class));
}
示例12: configure
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Override
protected void configure() {
publicBinder().forOptional(UserService.class)
.setDefault().to(LocalUserService.class);
bindAndExpose(new TypeLiteral<UserStore<Player>>(){})
.to((Class) UserStore.class);
bindAndExpose(new TypeLiteral<OnlinePlayers<Player>>(){})
.to((Class) OnlinePlayers.class);
}
示例13: FactoryBinding
import com.google.inject.TypeLiteral; //導入依賴的package包/類
FactoryBinding(Map<Key<?>, TypeLiteral<?>> collector, Key<?> factoryKey, Context context, GuiceUtil guiceUtil, MethodCallUtil methodCallUtil) {
super(context, factoryKey);
this.collector = Preconditions.checkNotNull(collector);
this.factoryKey = factoryKey;
this.factoryType = factoryKey.getTypeLiteral();
this.guiceUtil = guiceUtil;
this.methodCallUtil = methodCallUtil;
try {
matchMethods(Preconditions.checkNotNull(factoryKey));
} catch (ErrorsException e) {
e.getErrors().throwConfigurationExceptionIfErrorsExist();
}
}
示例14: dependencyType
import com.google.inject.TypeLiteral; //導入依賴的package包/類
/**
* Return the type that is depended on by injecting the given type.
* These types are the same, unless the injected type is a {@link Provider},
* in which case the dependency is on the provided type.
*/
public static TypeLiteral<?> dependencyType(TypeLiteral<?> injectedType) {
if(isImplicitProvider(injectedType)) {
return providedType((TypeLiteral<? extends Provider<Object>>) injectedType);
} else {
return injectedType;
}
}
示例15: MemberInjectingFactory
import com.google.inject.TypeLiteral; //導入依賴的package包/類
@Inject public MemberInjectingFactory(TypeLiteral<T> type, MembersInjector<T> injector) {
this.type = type;
this.injector = injector;
this.injectionPoint = InjectionPoint.forConstructorOf(type);
this.constructor = (Constructor<T>) injectionPoint.getMember();
this.constructor.setAccessible(true);
dependencies.addAll(Dependency.forInjectionPoints(InjectionPoint.forInstanceMethodsAndFields(type)));
}