本文整理汇总了Java中com.google.common.reflect.TypeToken.of方法的典型用法代码示例。如果您正苦于以下问题:Java TypeToken.of方法的具体用法?Java TypeToken.of怎么用?Java TypeToken.of使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.reflect.TypeToken
的用法示例。
在下文中一共展示了TypeToken.of方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newBuilder
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
* Makes a MergedHandlerBuilder for a super event class
*
* @param superClass the abstract super event class
* @param priority the priority to listen at
* @param eventClasses the event classes to be bound to
* @param <S> the super class type
* @return a {@link MergedSubscriptionBuilder} to construct the event handler
*/
@Nonnull
@SafeVarargs
static <S extends Event> MergedSubscriptionBuilder<S> newBuilder(@Nonnull Class<S> superClass, @Nonnull EventPriority priority, @Nonnull Class<? extends S>... eventClasses) {
Preconditions.checkNotNull(superClass, "superClass");
Preconditions.checkNotNull(eventClasses, "eventClasses");
Preconditions.checkNotNull(priority, "priority");
if (eventClasses.length < 2) {
throw new IllegalArgumentException("merge method used for only one subclass");
}
MergedBuilder<S> h = new MergedBuilder<>(TypeToken.of(superClass));
for (Class<? extends S> clazz : eventClasses) {
h.bindEvent(clazz, priority, e -> e);
}
return h;
}
示例2: JSON_MARSHALLER
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
* A metadata marshaller that encodes objects as JSON using the google-gson library.
*
* <p>All non-ascii characters are unicode escaped to comply with {@code AsciiMarshaller}'s character range
* requirements.
*
* @param clazz the type to serialize
* @param <T>
*/
public static final <T> Metadata.AsciiMarshaller<T> JSON_MARSHALLER(Class<T> clazz) {
return new Metadata.AsciiMarshaller<T>() {
TypeToken<T> typeToken = TypeToken.of(clazz);
private Gson gson = new Gson();
@Override
public String toAsciiString(T value) {
try {
try (StringWriter sw = new StringWriter()) {
gson.toJson(value, typeToken.getType(), new UnicodeEscapingAsciiWriter(sw));
return sw.toString();
}
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public T parseAsciiString(String serialized) {
return gson.fromJson(serialized, typeToken.getType());
}
};
}
示例3: of
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public static ReflectiveProperty of(Field field, Inspectable.Inspect annotation) {
field.setAccessible(true);
return new ReflectiveProperty(
annotation.name().length() > 0 ? annotation.name()
: field.getName(),
TypeToken.of(field.getGenericType()),
new Inspection(annotation),
MethodHandleUtils.privateUnreflectGetter(field)
);
}
示例4: getFirstTypeParameter
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private static TypeToken<?> getFirstTypeParameter(Type type) {
if (type instanceof ParameterizedType) {
return TypeToken.of(
((ParameterizedType) type).getActualTypeArguments()[0]);
} else {
return TypeToken.of(Object.class);
}
}
示例5: 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());
}
示例6: convert
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object convert(Object input, ParameterContext context) throws ArgumentConversionException {
TypeToken<?> parameterType = TypeToken.of(context.getParameter().getParameterizedType());
if (parameterType.getRawType() != Class.class) {
throw new ArgumentConversionException(
String.format("Could not convert: %s. Invalid parameter type.", input));
}
return convert(input.toString(), (TypeToken<? extends Class<?>>) parameterType);
}
示例7: getKey
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private static Key<?> getKey(Optional<Class<?>> containingElement, Parameter parameter) {
Class<?> clazz =
containingElement.orElseGet(() -> parameter.getDeclaringExecutable().getDeclaringClass());
TypeToken<?> classType = TypeToken.of(clazz);
Type resolvedType = classType.resolveType(parameter.getParameterizedType()).getType();
Optional<Key<?>> key =
getOnlyBindingAnnotation(parameter).map(annotation -> Key.get(resolvedType, annotation));
return key.orElse(Key.get(resolvedType));
}
示例8: GsonStorageHandler
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public GsonStorageHandler(String fileName, String fileExtension, File dataFolder, Class<T> clazz) {
this(fileName, fileExtension, dataFolder, TypeToken.of(clazz));
}
示例9: BaseFieldKey
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
protected BaseFieldKey(String name, boolean nullable, Class<T> valueType, FieldGeneratorType fieldGeneratorType){
this(name, nullable, TypeToken.of(valueType), fieldGeneratorType);
}
示例10: DelegateCodec
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public DelegateCodec(ThriftCodecManager codecManager, Type javaType)
{
this.codecManager = codecManager;
this.typeToken = (TypeToken<T>) TypeToken.of(javaType);
}
示例11: writeReplace
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private Object writeReplace() {
return new DummyHandler(TypeToken.of(interfaceType.getRawType()));
}
示例12: generateTypeToken
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Generates private TypeToken<?> generateTypeToken() {
return TypeToken.of(generateClass());
}
示例13: FindRequest
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public FindRequest(@Nullable Class<T> model) {
this(model == null ? null : TypeToken.of(model));
}
示例14: resolve
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public <T> TypeToken<T> resolve(TypeToken<T> type) {
return (TypeToken<T>) TypeToken.of(resolver.resolveType(type.getType()));
}
示例15: toToken
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
* Convert a Guice {@link TypeLiteral} to a Guava {@link TypeToken}
*/
public static <T> TypeToken<T> toToken(TypeLiteral<T> typeLiteral) {
return (TypeToken<T>) TypeToken.of(typeLiteral.getType());
}