當前位置: 首頁>>代碼示例>>Java>>正文


Java Key.getTypeLiteral方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:16,代碼來源:FactoryBinding.java

示例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){}));
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:12,代碼來源:InnerFactoryManifest.java

示例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);
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:11,代碼來源:SetBinder.java

示例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;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:9,代碼來源:SectionsModule.java

示例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);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:38,代碼來源:DependencyAnalyzer.java

示例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();
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:45,代碼來源:FactoryBinding.java

示例7: TypeArgument

import com.google.inject.Key; //導入方法依賴的package包/類
public TypeArgument(@NonNull final Key<? extends T> key) {
  this(key.getTypeLiteral());
}
 
開發者ID:KyoriPowered,項目名稱:violet,代碼行數:4,代碼來源:TypeArgument.java

示例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);
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:28,代碼來源:DynamicAnnotations.java


注:本文中的com.google.inject.Key.getTypeLiteral方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。