本文整理汇总了Java中com.google.common.reflect.TypeToken.resolveType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeToken.resolveType方法的具体用法?Java TypeToken.resolveType怎么用?Java TypeToken.resolveType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.reflect.TypeToken
的用法示例。
在下文中一共展示了TypeToken.resolveType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMessageType
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private TypeToken<? extends Message> getMessageType(TypeToken decl, Method method) {
if(method.getParameterTypes().length < 1 || method.getParameterTypes().length > 3) {
throw new IllegalStateException("Message handler method must take 1 to 3 parameters");
}
final TypeToken<Message> base = new TypeToken<Message>(){};
for(Type param : method.getGenericParameterTypes()) {
final TypeToken paramToken = decl.resolveType(param);
Types.assertFullySpecified(paramToken);
if(base.isAssignableFrom(paramToken)) {
messageRegistry.typeName(paramToken.getRawType()); // Verify message type is registered
return paramToken;
}
}
throw new IllegalStateException("Message handler has no message parameter");
}
示例2: getDefaultValue
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private <T> T getDefaultValue(TypeToken<T> type) {
// We assume that all defaults are generics-safe, even if they aren't,
// we take the risk.
@SuppressWarnings("unchecked")
T defaultValue = (T) defaults.getInstance(type.getRawType());
if (defaultValue != null) {
return defaultValue;
}
@SuppressWarnings("unchecked") // All arbitrary instances are generics-safe
T arbitrary = (T) ArbitraryInstances.get(type.getRawType());
if (arbitrary != null) {
return arbitrary;
}
if (type.getRawType() == Class.class) {
// If parameter is Class<? extends Foo>, we return Foo.class
@SuppressWarnings("unchecked")
T defaultClass = (T) getFirstTypeParameter(type.getType()).getRawType();
return defaultClass;
}
if (type.getRawType() == TypeToken.class) {
// If parameter is TypeToken<? extends Foo>, we return TypeToken<Foo>.
@SuppressWarnings("unchecked")
T defaultType = (T) getFirstTypeParameter(type.getType());
return defaultType;
}
if (type.getRawType() == Converter.class) {
TypeToken<?> convertFromType = type.resolveType(
Converter.class.getTypeParameters()[0]);
TypeToken<?> convertToType = type.resolveType(
Converter.class.getTypeParameters()[1]);
@SuppressWarnings("unchecked") // returns default for both F and T
T defaultConverter = (T) defaultConverter(convertFromType, convertToType);
return defaultConverter;
}
if (type.getRawType().isInterface()) {
return newDefaultReturningProxy(type);
}
return null;
}
示例3: resolveIn
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public GenericMethodType<? extends T> resolveIn(TypeToken<?> context) {
final TypeToken<? extends T> returnType = (TypeToken<? extends T>) context.resolveType(this.returnType.getType());
final ImmutableList<TypeToken<?>> parameterTypes = this.parameterTypes.stream()
.map(t -> context.resolveType(t.getType()))
.collect(Collectors.toImmutableList());
return returnType.equals(this.returnType) && parameterTypes.equals(this.parameterTypes)
? this
: new GenericMethodType<>(returnType, parameterTypes);
}
示例4: getParameterValue
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public Object getParameterValue(Parameter parameter) {
TypeToken<?> parameterType = TypeToken.of(parameter.getParameterizedType());
TypeToken<?> captorParameter =
parameterType.resolveType(ArgumentCaptor.class.getTypeParameters()[0]);
return ArgumentCaptor.forClass(captorParameter.getRawType());
}
示例5: get
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
Parameter get(String methodName, TypeToken<?> type) {
TypeToken<?> typeParam = type.resolveType(Class.class.getTypeParameters()[0]);
String description = Annotation.class.isAssignableFrom(typeParam.getRawType())
? "@" + Deprecated.class.getSimpleName()
: Deprecated.class.getName();
return new Parameter(Deprecated.class, description);
}
示例6: resolveIn
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public TypeToken<? extends T> resolveIn(TypeToken<? extends D> context) {
return (TypeToken<? extends T>) context.resolveType(typeVariable);
}
示例7: getInnerToken
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private TypeToken<?> getInnerToken(TypeToken<?> type) {
return type.resolveType(Set.class.getTypeParameters()[0]);
}