当前位置: 首页>>代码示例>>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;未经允许,请勿转载。