TypeDescriptor implements Serializable { public Type getType() { return token.getType(); } private  TypeDescriptor(TypeToken<T> token); protected  TypeDescriptor(); protected  TypeDescriptor(Object instance); @SuppressWarnings("unchecked") protected  TypeDescriptor(Class<?> clazz); static TypeDescriptor<T> of(Class<T> type); @SuppressWarnings("unchecked") static TypeDescriptor<?> of(Type type); Type getType(); Class<? super T> getRawType(); TypeDescriptor<?> getComponentType(); final TypeDescriptor<? super T> getSupertype(Class<? super T> superclass); final boolean isArray(); final TypeVariable<Class<? super T>> getTypeParameter(String paramName); final boolean isSupertypeOf(TypeDescriptor<?> source); final boolean isSubtypeOf(TypeDescriptor<?> parent); List<TypeDescriptor<?>> getArgumentTypes(Method method); TypeDescriptor<?> resolveType(Type type); @SuppressWarnings("rawtypes") Iterable<TypeDescriptor> getTypes(); @SuppressWarnings("rawtypes") Iterable<TypeDescriptor> getInterfaces(); @SuppressWarnings("rawtypes") Iterable<TypeDescriptor> getClasses(); @SuppressWarnings("unchecked") TypeDescriptor<T> where(
      TypeParameter<X> typeParameter, TypeDescriptor<X> typeDescriptor); @SuppressWarnings("unchecked") TypeDescriptor<T> where(Type formal, Type actual); boolean hasUnresolvedParameters(); @Override String toString(); @Override boolean equals(@Nullable Object other); @Override int hashCode();  }
@Test public void testTypeDescriptorGeneric() throws Exception { TypeDescriptor<List<String>> descriptor = new TypeDescriptor<List<String>>() {}; TypeToken<List<String>> token = new TypeToken<List<String>>() {}; assertEquals(token.getType(), descriptor.getType()); }
@Test public void testTypeDescriptorNested() throws Exception { TypeRememberer<String> rememberer = new TypeRememberer<String>() {}; assertEquals(new TypeToken<String>() {}.getType(), rememberer.descriptorByClass.getType()); assertEquals(new TypeToken<String>() {}.getType(), rememberer.descriptorByInstance.getType()); TypeRememberer<List<String>> genericRememberer = new TypeRememberer<List<String>>() {}; assertEquals( new TypeToken<List<String>>() {}.getType(), genericRememberer.descriptorByClass.getType()); assertEquals( new TypeToken<List<String>>() {}.getType(), genericRememberer.descriptorByInstance.getType()); }
@Test public void testTypeDescriptorNested2() throws Exception { TypeRemembererer<String, Integer> remembererer = new TypeRemembererer<String, Integer>() {}; assertEquals(new TypeToken<String>() {}.getType(), remembererer.descriptor1.getType()); assertEquals(new TypeToken<Integer>() {}.getType(), remembererer.descriptor2.getType()); TypeRemembererer<List<String>, Set<Integer>> genericRemembererer = new TypeRemembererer<List<String>, Set<Integer>>() {}; assertEquals( new TypeToken<List<String>>() {}.getType(), genericRemembererer.descriptor1.getType()); assertEquals( new TypeToken<Set<Integer>>() {}.getType(), genericRemembererer.descriptor2.getType()); }
@Test public void testEnclosing() throws Exception { TypeRememberer<List<String>> rememberer = new GenericMaker<String>() {}.getRememberer(); assertEquals( new TypeToken<List<String>>() {}.getType(), rememberer.descriptorByInstance.getType()); }
@Test public void testEnclosing2() throws Exception { TypeRememberer<List<Set<String>>> rememberer = new GenericMaker2<String>() { @Override public GenericMaker<Set<String>> getGenericMaker() { return new GenericMaker<Set<String>>() {}; } }.getGenericMaker().getRememberer(); assertEquals( new TypeToken<List<Set<String>>>() {}.getType(), rememberer.descriptorByInstance.getType()); }