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


Java Key.getAnnotationType方法代碼示例

本文整理匯總了Java中com.google.inject.Key.getAnnotationType方法的典型用法代碼示例。如果您正苦於以下問題:Java Key.getAnnotationType方法的具體用法?Java Key.getAnnotationType怎麽用?Java Key.getAnnotationType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.inject.Key的用法示例。


在下文中一共展示了Key.getAnnotationType方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractConstructorParameters

import com.google.inject.Key; //導入方法依賴的package包/類
/**
 * Matches constructor parameters to method parameters for injection and records remaining parameters as required keys.
 */
private String[] extractConstructorParameters(Key<?> factoryKey, TypeLiteral<?> implementation, Constructor constructor, List<Key<?>> methodParams,
                                              Errors errors, Set<Dependency> dependencyCollector) throws ErrorsException {

    // Get parameters with annotations.
    List<TypeLiteral<?>> ctorParams = implementation.getParameterTypes(constructor);
    Annotation[][] ctorParamAnnotations = constructor.getParameterAnnotations();

    int p = 0;
    String[] parameterNames = new String[ctorParams.size()];
    for (TypeLiteral<?> ctorParam : ctorParams) {
        Key<?> ctorParamKey = getKey(ctorParam, constructor, ctorParamAnnotations[p], errors);

        if (ctorParamKey.getAnnotationType() == Assisted.class) {
            int location = methodParams.indexOf(ctorParamKey);

            // This should never happen since the constructor was already checked
            // in #[inject]constructorHasMatchingParams(..).
            Preconditions.checkState(location != -1);

            parameterNames[p] = ReflectUtil.formatParameterName(location);
        } else {
            dependencyCollector.add(new Dependency(factoryKey, ctorParamKey, false, true, constructor.toString()));
        }

        p++;
    }

    return parameterNames;
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:33,代碼來源:FactoryBinding.java

示例2: addAjaxFilters

import com.google.inject.Key; //導入方法依賴的package包/類
private void addAjaxFilters()
{
    Injector injector = getInjector();
    for (Key<?> key : injector.getBindings().keySet())
    {
        Class<?> atype = key.getAnnotationType();
        if (atype != null && Filtering.class.isAssignableFrom(atype))
        {
            String scriptName = Filtering.class.cast(key.getAnnotation()).value();
            Provider<AjaxFilter> provider = injector.getProvider((Key<AjaxFilter>) key);
            if ("".equals(scriptName))
            {
                addAjaxFilter(new InternalAjaxFilter(provider));
            }
            else
            {
                addAjaxFilter(new InternalAjaxFilter(provider), scriptName);
            }
        }
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:22,代碼來源:InternalAjaxFilterManager.java

示例3: addCreators

import com.google.inject.Key; //導入方法依賴的package包/類
private void addCreators()
{
    Injector injector = getInjector();
    for (Key<?> key : injector.getBindings().keySet())
    {
        Class<?> atype = key.getAnnotationType();
        if (atype != null && Remoted.class.isAssignableFrom(atype))
        {
            String scriptName = Remoted.class.cast(key.getAnnotation()).value();
            if (scriptName.equals(""))
            {
                Class cls = (Class) key.getTypeLiteral().getType();
                scriptName = cls.getSimpleName();
            }
            addCreator(scriptName, new InternalCreator(injector, key, scriptName));
        }
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:19,代碼來源:InternalCreatorManager.java

示例4: injectConstructorHasMatchingParams

import com.google.inject.Key; //導入方法依賴的package包/類
/**
 * Matching logic for {@literal @}{@link Inject} constructor and method parameters.
 * <p/>
 * This returns true if all assisted parameters required by the constructor are provided by the factory method.
 */
private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type, Constructor<?> constructor, List<Key<?>> paramList, Errors errors)
        throws ErrorsException {
    List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
    Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
    int p = 0;
    for (TypeLiteral<?> param : params) {
        Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors);
        if (paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) {
            return false;
        }
    }

    return true;
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:20,代碼來源:FactoryBinding.java

示例5: assistKey

import com.google.inject.Key; //導入方法依賴的package包/類
/**
 * Returns a key similar to {@code key}, but with an {@literal @}Assisted binding annotation.
 * <p/>
 * This fails if another binding annotation is clobbered in the process. If the key already has the {@literal @}Assisted annotation, it is returned as-is to
 * preserve any String value.
 */
private <T> Key<T> assistKey(Method method, Key<T> key, Errors errors) throws ErrorsException {
    if (key.getAnnotationType() == null) {
        return Key.get(key.getTypeLiteral(), DEFAULT_ANNOTATION);
    } else if (key.getAnnotationType() == Assisted.class) {
        return key;
    } else {
        errors.withSource(method).addMessage(
                PrettyPrinter.format("Only @Assisted is allowed for factory parameters, but found @%s", key.getAnnotationType()));
        throw errors.toException();
    }
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:18,代碼來源:FactoryBinding.java

示例6: 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

示例7: addConverters

import com.google.inject.Key; //導入方法依賴的package包/類
private void addConverters()
{
    Injector injector = getInjector();
    for (Key<?> key : injector.getBindings().keySet())
    {
        Class<?> atype = key.getAnnotationType();
        if (atype != null && Converting.class.isAssignableFrom(atype))
        {
            Converting ann = Converting.class.cast(key.getAnnotation());
            
            String match = ann.match();
            Class type = ann.type();
            Class impl = ann.impl();
            
            if ("".equals(match))
            {
                // Use the type name as a match string
                match = type.getName();
            }

            Provider<Converter> provider = null;
            Class cvtType;
            
            if (impl.equals(Void.class))
            {
                // No impl specified, so there should be a Converter
                // for this key.
                
                provider = injector.getProvider((Key<Converter>) key);
                cvtType = type;
            }
            else
            {
                // Impl class specified, so the Converter for key is
                // bogus (the injected constructor InternalConverter
                // is just to keep Guice happy); see the two-arg 
                // bindConversion method in AbstractDwrModule.
                
                try 
                {
                    // First try looking for a Converter for impl in the bindings.
                 
                    Key<Converter> ikey = Key.get(Converter.class, new ConvertingImpl(impl));
                    provider = injector.getProvider(ikey);
                }
                catch (RuntimeException e)
                {
                    // Ignore any trouble we have looking things up.
                }
                
                if (provider == null)
                {
                    // It wasn't in the bindings, so use a Provider that
                    // looks in the underlying ConverterManager.
                
                    final String implMatch = impl.getName();
                    provider = new Provider<Converter>()
                    {
                        public Converter get()
                        {
                            return getConverterByMatchString(implMatch);
                        }
                    };
                }
                
                cvtType = impl;
            }
            addConverter(match, new InternalConverter(cvtType, provider));
        }
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:72,代碼來源:InternalConverterManager.java


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