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


Java TypeToken.of方法代码示例

本文整理汇总了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;
}
 
开发者ID:lucko,项目名称:helper,代码行数:26,代码来源:MergedSubscriptionBuilder.java

示例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());
        }
    };
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:33,代码来源:MoreMetadata.java

示例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)
    );
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:11,代码来源:ReflectiveProperty.java

示例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);
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:NullPointerTester.java

示例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());
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:8,代码来源:CaptorParameterFactory.java

示例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);
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:12,代码来源:ClassArgumentConverter.java

示例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));
}
 
开发者ID:JeffreyFalgout,项目名称:junit5-extensions,代码行数:11,代码来源:GuiceExtension.java

示例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));
}
 
开发者ID:lucko,项目名称:helper,代码行数:4,代码来源:GsonStorageHandler.java

示例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);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:4,代码来源:BaseFieldKey.java

示例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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:6,代码来源:DelegateCodec.java

示例11: writeReplace

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private Object writeReplace() {
  return new DummyHandler(TypeToken.of(interfaceType.getRawType()));
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:DummyProxy.java

示例12: generateTypeToken

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Generates private TypeToken<?> generateTypeToken() {
  return TypeToken.of(generateClass());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:FreshValueGenerator.java

示例13: FindRequest

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public FindRequest(@Nullable Class<T> model) {
    this(model == null ? null : TypeToken.of(model));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:FindRequest.java

示例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()));
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:TypeResolver.java

示例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());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:7,代码来源:Types.java


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