当前位置: 首页>>代码示例>>Java>>正文


Java TypeLiteral.getParameterTypes方法代码示例

本文整理汇总了Java中com.google.inject.TypeLiteral.getParameterTypes方法的典型用法代码示例。如果您正苦于以下问题:Java TypeLiteral.getParameterTypes方法的具体用法?Java TypeLiteral.getParameterTypes怎么用?Java TypeLiteral.getParameterTypes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.inject.TypeLiteral的用法示例。


在下文中一共展示了TypeLiteral.getParameterTypes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractConstructorParameters

import com.google.inject.TypeLiteral; //导入方法依赖的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: injectConstructorHasMatchingParams

import com.google.inject.TypeLiteral; //导入方法依赖的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


注:本文中的com.google.inject.TypeLiteral.getParameterTypes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。