本文整理汇总了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;
}
示例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;
}