TypeToken getRawType - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for TypeToken getRawType method.

This code example shows how to use the following methods:getRawType, getType
import com.google.common.reflect.Invokable;
import com.google.common.reflect.TypeToken;
 
public class Optionals2 { 
   public static Class<?> unwrapIfOptional(TypeToken<?> type) {
      if (type.getRawType().isAssignableFrom(Optional.class)) {
         ParameterizedType futureType = ParameterizedType.class.cast(type.getType());
         // TODO: error checking in case this is a type, not a class. 
         Type t = futureType.getActualTypeArguments()[0];
         if (t instanceof WildcardType) {
            t = ((WildcardType) t).getUpperBounds()[0];
         } 
         return Class.class.cast(t);
      } 
      return type.getRawType();
   } 
 
   public static boolean isReturnTypeOptional(Invokable<?, ?> method) {
      return method.getReturnType().getRawType().isAssignableFrom(Optional.class);
   } 
7
CodeRank
This code example shows how to use the following methods:getRawType, getType
      } 
      return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
   } 
 
   static Type getReturnTypeFor(TypeToken<?> typeToken) {
      Type returnVal = typeToken.getType();
      if (typeToken.getRawType().getTypeParameters().length == 0) {
         returnVal = typeToken.getRawType();
      } 
      return returnVal;
   } 
 
   // TODO: refactor this out of here 
   @VisibleForTesting 
   @SuppressWarnings({ "rawtypes", "unchecked" }) 
   public Function<HttpResponse, ?> getTransformerForMethod(Invocation invocation, Injector injector) {
      Invokable<?, ?> invoked = invocation.getInvokable();
      Function<HttpResponse, ?> transformer;
      if (invoked.isAnnotationPresent(SelectJson.class)) {
         Type returnVal = getReturnTypeFor(invoked.getReturnType());
6
CodeRank
This code example shows how to use the following methods:getRawType, getType
   * @param <T> the type of object to construct from the request body 
   * @return an instance of {@code T} if this parser can construct this type, otherwise {@code null} 
   * @throws Exception any exception thrown while parsing 
   */ 
  abstract protected <T> T parse(Context context, TypedData requestBody, TypeToken<T> type) throws Exception; 
 
} 
6
CodeRank
This code example shows how to use the following methods:getRawType, getType
    this.contentType = contentType;
 
    TypeToken<O> typeToken = new TypeToken<O>(getClass()) {
    }; 
 
    if (typeToken.getType() instanceof Class) {
      @SuppressWarnings("unchecked") Class<O> rawType = (Class<O>) typeToken.getRawType();
      this.optsType = rawType;
    } else { 
      throw new IllegalArgumentException("Type parameter O of ParserSupport must be a Class");
    } 
  } 
 
  /** 
   * {@inheritDoc} 
   */ 
  @Override 
  public final String getContentType() {
    return contentType;
  } 
6
CodeRank
This code example shows how to use the following methods:getRawType
     * 
     * @param type   the actor's type 
     * @param params the actor's constructor parameters. 
     */ 
    public static <Message, V, T extends Actor<Message, V>> ActorSpec<T, Message, V> of(TypeToken<T> type, Object... params) {
        return new ActorSpec<T, Message, V>((Class<T>) type.getRawType(), params);
    } 
 
    private final AtomicReference<Class<T>> classRef;
    private final String className;
    private final Object[] params; 
    private Class<?>[] ctorParamTypes;
    private Constructor<T> ctor;
 
    /** 
     * Specifies an actor of a given type and given constructor parameters. 
     * 
     * @param className the name of the actor class 
     * @param params    the parameters to pass to the actor's constructors 
     */ 
5
CodeRank
This code example shows how to use the following methods:getRawType
     
    /** returns the Class of anything which isn't a class; if input is class it is pass-through */ 
    public static Class<?> type(Object x) {
        if (x==null) return null; 
        if (x instanceof Class) return (Class<?>)x;
        if (x instanceof TypeToken) return ((TypeToken<?>)x).getRawType();
        return x.getClass(); 
    } 
 
    /** like type, but removes any array modifiers */ 
    public static Class<?> componentType(Object x) {
        Class<?> c = type(x);
        if (c==null) return null;
        while (c.isArray()) {
            c = c.getComponentType();
        } 
        return c;
    } 
 
    /**  returns a simplified name of the class, just the simple name if it seems useful, else the full name */ 
4
CodeRank
This code example shows how to use the following methods:getRawType
 
    @Override 
    public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
    { 
        return List.class.isAssignableFrom(type) &&
                TypeToken.of(genericType).resolveType(LIST_GENERIC_TOKEN).getRawType().equals(Page.class) &&
                mediaType.isCompatible(PRESTO_PAGES_TYPE);
    } 
 
    @Override 
    public long getSize(List<Page> pages, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType)
    { 
        return -1; 
    } 
 
    @Override 
    public void writeTo(List<Page> pages,
            Class<?> type,
            Type genericType,
            Annotation[] annotations,
4
CodeRank
This code example shows how to use the following methods:getRawType
      if (classloader == null) {
        classloader = new ByteCodeClassLoader(typeClassloader);
        classloaders.put(key.getType(), classloader);
      } 
 
      return (Class<DatumWriter<?>>) classloader.addClass(classDef, key.getType().getRawType())
                                                .loadClass(classDef.getClassName());
    } 
  } 
 
  private static final class CacheKey { 
    private final Schema schema;
    private final TypeToken<?> type;
 
    private CacheKey(Schema schema, TypeToken<?> type) {
      this.schema = schema;
      this.type = type;
    } 
 
    public Schema getSchema() {
4
CodeRank
This code example shows how to use the following methods:getRawType
    public void marshallJson(ObjectNode node, String fieldName, T payload) throws Exception
    { 
        if ( payload == null )
        { 
            //noinspection unchecked 
            payload = (T)payloadType.getRawType().newInstance();
        } 
         
        node.putPOJO(fieldName, payload);
    } 
 
	@Override 
    public T unMarshallJson(JsonNode node) throws Exception
    { 
        T payload;
        ObjectMapper mapper = new ObjectMapper();
        //noinspection unchecked 
        payload = (T)mapper.readValue(node, payloadType.getRawType());
        return payload;
    } 
4
CodeRank
This code example shows how to use the following methods:getRawType
  @Override 
  public void visit(Object instance, TypeToken<?> inspectType, TypeToken<?> declareType, Field field) throws Exception {
    if (field.isAnnotationPresent(Property.class)) {
 
      // Key name is "className.fieldName". 
      String key = declareType.getRawType().getName() + '.' + field.getName();
      if (properties.containsKey(key)) {
        return; 
      } 
 
      String value = getStringValue(instance, field);
      if (value != null) {
        properties.put(key, value);
      } 
    } 
  } 
 
  /** 
   * Gets the value of the field in the given instance as String. 
   * Currently only allows primitive types, boxed types, String and Enum. 
4
CodeRank
getRawType Method Overview
Returns the raw type of T.
See Code Examples for other Guava TypeToken Methods: