Merge pull request #1924 from eamonnmcmanus/master
Adjust some minor details of #1391.
This commit is contained in:
commit
a14f1618b5
@ -339,13 +339,13 @@ public final class $Gson$Types {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Type resolve(Type context, Class<?> contextRawType, Type toResolve) {
|
public static Type resolve(Type context, Class<?> contextRawType, Type toResolve) {
|
||||||
return resolve(context, contextRawType, toResolve, new HashMap<TypeVariable, Type>());
|
return resolve(context, contextRawType, toResolve, new HashMap<TypeVariable<?>, Type>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Type resolve(Type context, Class<?> contextRawType, Type toResolve,
|
private static Type resolve(Type context, Class<?> contextRawType, Type toResolve,
|
||||||
Map<TypeVariable, Type> visitedTypeVariables) {
|
Map<TypeVariable<?>, Type> visitedTypeVariables) {
|
||||||
// this implementation is made a little more complicated in an attempt to avoid object-creation
|
// this implementation is made a little more complicated in an attempt to avoid object-creation
|
||||||
TypeVariable resolving = null;
|
TypeVariable<?> resolving = null;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (toResolve instanceof TypeVariable) {
|
if (toResolve instanceof TypeVariable) {
|
||||||
TypeVariable<?> typeVariable = (TypeVariable<?>) toResolve;
|
TypeVariable<?> typeVariable = (TypeVariable<?>) toResolve;
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package com.google.gson.functional;
|
package com.google.gson.functional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test covers the scenario described in #1390 where a type variable needs to be used
|
* This test covers the scenario described in #1390 where a type variable needs to be used
|
||||||
* by a type definition multiple times. Both type variable references should resolve to the
|
* by a type definition multiple times. Both type variable references should resolve to the
|
||||||
@ -18,37 +19,37 @@ import static org.junit.Assert.*;
|
|||||||
*/
|
*/
|
||||||
public class ReusedTypeVariablesFullyResolveTest {
|
public class ReusedTypeVariablesFullyResolveTest {
|
||||||
|
|
||||||
private Gson gson;
|
private Gson gson;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
gson = new GsonBuilder().create();
|
gson = new GsonBuilder().create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums
|
@SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums
|
||||||
@Test
|
@Test
|
||||||
public void testGenericsPreservation() {
|
public void testGenericsPreservation() {
|
||||||
TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class);
|
TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class);
|
||||||
Iterator<TestEnum> iterator = withSet.collection.iterator();
|
Iterator<TestEnum> iterator = withSet.collection.iterator();
|
||||||
assertNotNull(withSet);
|
assertNotNull(withSet);
|
||||||
assertNotNull(withSet.collection);
|
assertNotNull(withSet.collection);
|
||||||
assertEquals(2, withSet.collection.size());
|
assertEquals(2, withSet.collection.size());
|
||||||
TestEnum first = iterator.next();
|
TestEnum first = iterator.next();
|
||||||
TestEnum second = iterator.next();
|
TestEnum second = iterator.next();
|
||||||
|
|
||||||
assertTrue(first instanceof TestEnum);
|
assertTrue(first instanceof TestEnum);
|
||||||
assertTrue(second instanceof TestEnum);
|
assertTrue(second instanceof TestEnum);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TestEnum { ONE, TWO, THREE }
|
enum TestEnum { ONE, TWO, THREE }
|
||||||
|
|
||||||
private static class TestEnumSetCollection extends SetCollection<TestEnum> {}
|
private static class TestEnumSetCollection extends SetCollection<TestEnum> {}
|
||||||
|
|
||||||
private static class SetCollection<T> extends BaseCollection<T, Set<T>> {}
|
private static class SetCollection<T> extends BaseCollection<T, Set<T>> {}
|
||||||
|
|
||||||
private static class BaseCollection<U, C extends Collection<U>>
|
private static class BaseCollection<U, C extends Collection<U>>
|
||||||
{
|
{
|
||||||
public C collection;
|
public C collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user