本文整理汇总了Java中com.google.inject.Key.getTypeLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java Key.getTypeLiteral方法的具体用法?Java Key.getTypeLiteral怎么用?Java Key.getTypeLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.inject.Key
的用法示例。
在下文中一共展示了Key.getTypeLiteral方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FactoryBinding
import com.google.inject.Key; //导入方法依赖的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();
}
}
示例2: InnerFactoryManifest
import com.google.inject.Key; //导入方法依赖的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){}));
}
示例3: SetBinder
import com.google.inject.Key; //导入方法依赖的package包/类
protected SetBinder(Binder binder, @Nullable Key<T> key) {
if(key == null) {
key = Key.get(new ResolvableType<T>(){}.in(getClass()));
}
this.binder = binder.skipSources(SetBinder.class);
this.elementType = key.getTypeLiteral();
this.collectionType = new ResolvableType<Set<T>>(){}.with(new TypeArgument<T>(this.elementType){});
this.multibinder = Multibinder.newSetBinder(binder, key);
}
示例4: child
import com.google.inject.Key; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends Section> NodeProvider child(Key<T> key)
{
TypeLiteral<T> typeLiteral = key.getTypeLiteral();
bind(typeLiteral).to((Class<? extends T>) typeLiteral.getRawType());
children.add(key);
return this;
}
示例5: analyzeDependencies
import com.google.inject.Key; //导入方法依赖的package包/类
private void analyzeDependencies(final Collection<Dependency<?>> dependencies)
{
for( final Dependency<?> d : dependencies )
{
final Key<?> key = d.getKey();
InjectionPoint injectionPoint = d.getInjectionPoint();
if( injectionPoint != null && injectionPoint.isOptional() )
{
continue;
}
if( key.getAnnotationType() == Assisted.class )
{
continue;
}
TypeLiteral<?> typeLiteral = key.getTypeLiteral();
Class<?> rawType = typeLiteral.getRawType();
if( rawType == Injector.class )
{
continue;
}
if( rawType == MembersInjector.class )
{
Key<?> injectedKey = key
.ofType(((ParameterizedType) typeLiteral.getType()).getActualTypeArguments()[0]);
dependentKeys.add(injectedKey);
analyzeImplementation(injectedKey.getTypeLiteral(), true);
}
else if( rawType == Provider.class )
{
dependentKeys.add(key.ofType(((ParameterizedType) typeLiteral.getType()).getActualTypeArguments()[0]));
}
else
{
dependentKeys.add(key);
}
}
}
示例6: matchMethods
import com.google.inject.Key; //导入方法依赖的package包/类
private void matchMethods(Key<?> factoryKey) throws ErrorsException {
Errors errors = new Errors();
dependencies.add(new Dependency(Dependency.GINJECTOR, factoryKey, getContext()));
Class<?> factoryRawType = factoryType.getRawType();
// getMethods() includes inherited methods from super-interfaces.
for (Method method : factoryRawType.getMethods()) {
Key<?> returnType = getKey(factoryType.getReturnType(method), method, method.getAnnotations(), errors);
// Get parameters with annotations.
List<TypeLiteral<?>> params = factoryType.getParameterTypes(method);
Annotation[][] paramAnnotations = method.getParameterAnnotations();
int p = 0;
List<Key<?>> paramList = new ArrayList<Key<?>>();
for (TypeLiteral<?> param : params) {
Key<?> paramKey = getKey(param, method, paramAnnotations[p++], errors);
paramList.add(assistKey(method, paramKey, errors));
}
// Try to match up the method to the constructor.
TypeLiteral<?> implementation = collector.get(returnType);
if (implementation == null) {
implementation = returnType.getTypeLiteral();
}
Constructor<?> constructor = findMatchingConstructor(method, implementation, paramList, errors);
if (constructor == null) {
continue; // Errors are collected and thrown below.
}
// Calculate a map from method to constructor parameters and required
// keys.
String[] parameterNames = extractConstructorParameters(factoryKey, implementation, constructor, paramList, errors, dependencies);
TypeLiteral<?> methodDeclaringType = factoryType.getSupertype(method.getDeclaringClass());
assistData.add(new AssistData(implementation, MethodLiteral.get(constructor, implementation), MethodLiteral.get(method, methodDeclaringType),
parameterNames));
implementations.add(implementation);
dependencies.addAll(guiceUtil.getMemberInjectionDependencies(factoryKey, implementation));
}
errors.throwConfigurationExceptionIfErrorsExist();
}
示例7: TypeArgument
import com.google.inject.Key; //导入方法依赖的package包/类
public TypeArgument(@NonNull final Key<? extends T> key) {
this(key.getTypeLiteral());
}
示例8: bindDynamicProvider
import com.google.inject.Key; //导入方法依赖的package包/类
/**
* Binds a {@link DynamicBindingProvider} for the specified key.
*
* <p>The instance bound to the key can later be retrieved through
* {@link DynamicBindingProvider#get(Class)} given the same annotation provided during binding
* time. This method also 'requires' a binding for {@code key}.
*
* <p>This method requires a binder, and must be used from a Guice module that is in the
* configure phase.
*
* <p>Note: The annotation on the key will only be used for required binding checks by Guice.
*
* @param binder the Guice binder to bind with
* @param key the key to create a {@link DynamicBindingProvider} for
*/
static <T> void bindDynamicProvider(Binder binder, Key<?> key) {
binder.getProvider(key);
ParameterizedType type =
Types.newParameterizedType(DynamicBindingProvider.class, key.getTypeLiteral().getType());
@SuppressWarnings("unchecked")
DynamicBindingProvider<T> provider =
new DynamicBindingProviderImpl<T>((TypeLiteral<T>) key.getTypeLiteral());
@SuppressWarnings("unchecked")
Key<DynamicBindingProvider<T>> dynamicKey = (Key<DynamicBindingProvider<T>>) Key.get(type);
binder.bind(dynamicKey).toInstance(provider);
}