public void testFalseRecursiveType_intermediaryTypeMappingDoesNotConfuseMe() { Type returnType = genericReturnType(SubtypeOfWithFalseRecursiveType.class, "revertKeyAndValueTypes"); TypeToken<?> keyType = TypeToken.of(returnType).resolveType(WithFalseRecursiveType.class.getTypeParameters()[0]); assertEquals("java.util.List<K1>", keyType.getType().toString()); }
public static TypeAdapterFactory b(TypeToken<?> paramTypeToken, Object paramObject) { if (paramTypeToken.getType() == paramTypeToken.getRawType()) {} for (boolean bool = true;; bool = false) { return new er.a(paramObject, paramTypeToken, bool, null, (byte)0); } }
public void testFalseRecursiveType_mappingOnTheSameDeclarationNotUsed() { Type returnType = genericReturnType(WithFalseRecursiveType.class, "keyShouldNotResolveToStringList"); TypeToken<?> keyType = TypeToken.of(returnType).resolveType(WithFalseRecursiveType.class.getTypeParameters()[0]); assertEquals("java.util.List<V>", keyType.getType().toString()); }
public void testGenericInterface() { // test the 1st generic interface on the class Type fType = Supplier.class.getTypeParameters()[0]; assertEquals( Integer.class, TypeToken.of(IntegerStringFunction.class).resolveType(fType).getRawType()); // test the 2nd generic interface on the class Type predicateParameterType = Predicate.class.getTypeParameters()[0]; assertEquals( new TypeToken<List<String>>() {}.getType(), TypeToken.of(IntegerStringFunction.class).resolveType(predicateParameterType).getType()); }
public void testInterfaceTypeParameterResolution() throws Exception { assertEquals( String.class, TypeToken.of(new TypeToken<ArrayList<String>>() {}.getType()) .resolveType(List.class.getTypeParameters()[0]) .getType()); }
public final <T> TypeAdapter<T> create(Gson paramGson, TypeToken<T> paramTypeToken) { boolean bool; if (a != null) { if ((a.equals(paramTypeToken)) || ((b) && (a.getType() == paramTypeToken.getRawType()))) { bool = true; } } while (bool) { return new er(d, e, paramGson, paramTypeToken, this, (byte)0); bool = false; continue; bool = c.isAssignableFrom(paramTypeToken.getRawType()); } return null; }
Type getTargetType(String methodName) throws Exception { ParameterizedType parameterType = (ParameterizedType) WithGenericBound.class.getDeclaredMethod(methodName, List.class) .getGenericParameterTypes()[0]; parameterType = (ParameterizedType) TypeToken.of(this.getClass()).resolveType(parameterType).getType(); return parameterType.getActualTypeArguments()[0]; }
public void testResolveType() { assertEquals(String.class, TypeToken.of(this.getClass()).resolveType(String.class).getType()); assertEquals( String.class, TypeToken.of(StringIterable.class) .resolveType(Iterable.class.getTypeParameters()[0]) .getType()); assertEquals( String.class, TypeToken.of(StringIterable.class) .resolveType(Iterable.class.getTypeParameters()[0]) .getType()); try { TypeToken.of(this.getClass()).resolveType(null); fail(); } catch (NullPointerException expected) { } }
public void testConextIsParameterizedType() throws Exception { class Context { @SuppressWarnings("unused") // used by reflection Map<String, Integer> returningMap() { throw new AssertionError(); } } Type context = Context.class.getDeclaredMethod("returningMap").getGenericReturnType(); Type keyType = Map.class.getTypeParameters()[0]; Type valueType = Map.class.getTypeParameters()[1]; // context is parameterized type assertEquals(String.class, TypeToken.of(context).resolveType(keyType).getType()); assertEquals(Integer.class, TypeToken.of(context).resolveType(valueType).getType()); // context is type variable assertEquals(keyType, TypeToken.of(keyType).resolveType(keyType).getType()); assertEquals(valueType, TypeToken.of(valueType).resolveType(valueType).getType()); }
public final T read(JsonReader paramJsonReader) { if (b == null) { return (T)a().read(paramJsonReader); } paramJsonReader = Streams.parse(paramJsonReader); if (paramJsonReader.isJsonNull()) { return null; } return (T)b.deserialize(paramJsonReader, d.getType(), c.a); }
public final void write(JsonWriter paramJsonWriter, T paramT) { if (a == null) { a().write(paramJsonWriter, paramT); return; } if (paramT == null) { paramJsonWriter.nullValue(); return; } Streams.write(a.serialize(paramT, d.getType(), c.b), paramJsonWriter); }
public void testFalseRecursiveType_referenceOfSubtypeDoesNotConfuseMe() { Type returnType = genericReturnType(WithFalseRecursiveType.class, "evenSubtypeWorks"); TypeToken<?> keyType = TypeToken.of(returnType).resolveType(WithFalseRecursiveType.class.getTypeParameters()[0]); assertEquals("java.util.List<java.util.List<V>>", keyType.getType().toString()); }
public void testFalseRecursiveType_notRealRecursiveMapping() { Type returnType = genericReturnType(WithFalseRecursiveType.class, "shouldNotCauseInfiniteLoop"); TypeToken<?> keyType = TypeToken.of(returnType).resolveType(WithFalseRecursiveType.class.getTypeParameters()[0]); assertEquals("java.util.List<K>", keyType.getType().toString()); }
public void testClassWrapper() { TypeToken<String> typeExpression = TypeToken.of(String.class); assertEquals(String.class, typeExpression.getType()); assertEquals(String.class, typeExpression.getRawType()); }
public void testInnerClassWithParameterizedOwner() throws Exception { Type fieldType = ParameterizedOuter.class.getField("field").getGenericType(); assertEquals( fieldType, TypeToken.of(ParameterizedOuter.class).resolveType(fieldType).getType()); }
@Override @SuppressWarnings("unchecked") public boolean isValid(Object newValue) { if (!type.isAssignableFrom(newValue.getClass())) return false; return isValidValue((T) newValue); }