Removed all the JDK warnings about unused fields in test classes or unused constructors for use by Gson or instanceof calls on parameterized types.

This commit is contained in:
Inderjeet Singh 2009-09-23 17:45:16 +00:00
parent 29ab864b2f
commit 3b0f8f4340
22 changed files with 73 additions and 32 deletions

View File

@ -320,15 +320,15 @@ public final class GsonBuilder {
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
Preconditions.checkArgument(typeAdapter instanceof JsonSerializer
|| typeAdapter instanceof JsonDeserializer || typeAdapter instanceof InstanceCreator);
if (typeAdapter instanceof InstanceCreator) {
Preconditions.checkArgument(typeAdapter instanceof JsonSerializer<?>
|| typeAdapter instanceof JsonDeserializer<?> || typeAdapter instanceof InstanceCreator<?>);
if (typeAdapter instanceof InstanceCreator<?>) {
registerInstanceCreator(type, (InstanceCreator<?>) typeAdapter);
}
if (typeAdapter instanceof JsonSerializer) {
if (typeAdapter instanceof JsonSerializer<?>) {
registerSerializer(type, (JsonSerializer<?>) typeAdapter);
}
if (typeAdapter instanceof JsonDeserializer) {
if (typeAdapter instanceof JsonDeserializer<?>) {
registerDeserializer(type, (JsonDeserializer<?>) typeAdapter);
}
return this;

View File

@ -57,7 +57,7 @@ final class TypeInfoFactory {
private static Type getActualType(
Type typeToEvaluate, Type parentType, Class<?> rawParentClass) {
if (typeToEvaluate instanceof Class) {
if (typeToEvaluate instanceof Class<?>) {
return typeToEvaluate;
} else if (typeToEvaluate instanceof ParameterizedType) {
ParameterizedType castedType = (ParameterizedType) typeToEvaluate;
@ -73,13 +73,13 @@ final class TypeInfoFactory {
if (componentType.equals(actualType)) {
return castedType;
} else {
if (actualType instanceof Class) {
if (actualType instanceof Class<?>) {
return TypeUtils.wrapWithArray(TypeUtils.toRawClass(actualType));
} else {
return new GenericArrayTypeImpl(actualType);
}
}
} else if (typeToEvaluate instanceof TypeVariable) {
} else if (typeToEvaluate instanceof TypeVariable<?>) {
if (parentType instanceof ParameterizedType) {
// The class definition has the actual types used for the type variables.
// Find the matching actual type for the Type Variable used for the field.

View File

@ -32,7 +32,7 @@ final class TypeInfoMap {
private final Type valueType;
public TypeInfoMap(Type mapType) {
if (mapType instanceof Class && Properties.class.isAssignableFrom((Class<?>) mapType)) {
if (mapType instanceof Class<?> && Properties.class.isAssignableFrom((Class<?>) mapType)) {
keyType = String.class;
valueType = String.class;
} else if (mapType instanceof ParameterizedType) {

View File

@ -41,7 +41,7 @@ final class TypeUtils {
* <code>TypeUtils.getActualTypeForFirstTypeVariable(fooType)</code> will return Integer.class.
*/
static Type getActualTypeForFirstTypeVariable(Type type) {
if (type instanceof Class) {
if (type instanceof Class<?>) {
return Object.class;
} else if (type instanceof ParameterizedType) {
return ((ParameterizedType)type).getActualTypeArguments()[0];
@ -54,7 +54,7 @@ final class TypeUtils {
}
static boolean isArray(Type type) {
if (type instanceof Class) {
if (type instanceof Class<?>) {
return ((Class<?>)type).isArray();
} else if (type instanceof GenericArrayType) {
return true;
@ -67,7 +67,7 @@ final class TypeUtils {
* This method returns the actual raw class associated with the specified type.
*/
static Class<?> toRawClass(Type type) {
if (type instanceof Class) {
if (type instanceof Class<?>) {
return (Class<?>) type;
} else if (type instanceof ParameterizedType) {
ParameterizedType actualType = (ParameterizedType)type;

View File

@ -87,7 +87,7 @@ public abstract class TypeToken<T> {
*/
static Type getSuperclassTypeParameter(Class<?> subclass) {
Type superclass = subclass.getGenericSuperclass();
if (superclass instanceof Class) {
if (superclass instanceof Class<?>) {
throw new RuntimeException("Missing type parameter.");
}
return ((ParameterizedType) superclass).getActualTypeArguments()[0];
@ -163,7 +163,7 @@ public abstract class TypeToken<T> {
return true;
}
if (type instanceof Class) {
if (type instanceof Class<?>) {
return rawType.isAssignableFrom(getRawType(from));
} else if (type instanceof ParameterizedType) {
return isAssignableFrom(from, (ParameterizedType) type,
@ -194,7 +194,7 @@ public abstract class TypeToken<T> {
Type t = from;
if (from instanceof GenericArrayType) {
t = ((GenericArrayType) from).getGenericComponentType();
} else if (from instanceof Class) {
} else if (from instanceof Class<?>) {
Class<?> classType = (Class<?>) from;
while (classType.isArray()) {
classType = classType.getComponentType();
@ -238,7 +238,7 @@ public abstract class TypeToken<T> {
for (int i = 0; i < tArgs.length; i++) {
Type arg = tArgs[i];
TypeVariable<?> var = tParams[i];
while (arg instanceof TypeVariable) {
while (arg instanceof TypeVariable<?>) {
TypeVariable<?> v = (TypeVariable<?>) arg;
arg = typeVarMap.get(v.getName());
}
@ -293,7 +293,7 @@ public abstract class TypeToken<T> {
Map<String, Type> typeMap) {
if (to.equals(from)) return true;
if (from instanceof TypeVariable) {
if (from instanceof TypeVariable<?>) {
return to.equals(typeMap.get(((TypeVariable<?>)from).getName()));
}

View File

@ -51,6 +51,7 @@ public class ExposeAnnotationBasedExclusionStrategyTest extends TestCase {
assertFalse(strategy.shouldSkipField(f));
}
@SuppressWarnings("unused")
private static class MockObject {
@Expose
public final int exposedField = 0;

View File

@ -53,6 +53,7 @@ public class SerializedNameAnnotationInterceptingNamingPolicyTest extends TestCa
assertEquals(fieldName, policy.translateName(f));
}
@SuppressWarnings("unused")
private static class SomeObject {
@SerializedName(ANNOTATED_FIELD_NAME) public final int fieldWithAnnotation = 1;
public final int fieldWithoutAnnotation = 1;

View File

@ -223,6 +223,7 @@ public class TypeInfoFactoryTest extends TestCase {
assertEquals(List[].class, typeInfo.getRawClass());
}
@SuppressWarnings("unused")
private static class ObjectWithDifferentFields<T> {
public static enum TestEnum {
TEST_1, TEST_2;

View File

@ -67,6 +67,7 @@ public class VersionExclusionStrategyTest extends TestCase {
@Since(VERSION)
private static class MockObject {
@SuppressWarnings("unused")
@Since(VERSION)
public final int someField = 0;
}

View File

@ -283,7 +283,8 @@ public class CollectionTest extends TestCase {
private static class ObjectWithWildcardCollection {
private final Collection<? extends BagOfPrimitives> collection;
@SuppressWarnings("unchecked")
// For use by Gson
@SuppressWarnings({ "unchecked", "unused" })
public ObjectWithWildcardCollection() {
this(Collections.EMPTY_LIST);
}
@ -300,7 +301,8 @@ public class CollectionTest extends TestCase {
private static class Entry {
int value;
// For use by Gson
Entry() {
@SuppressWarnings("unused")
private Entry() {
this(10);
}
Entry(int value) {

View File

@ -120,7 +120,8 @@ public class ConcurrencyTest extends TestCase {
finishedLatch.await();
assertFalse(failed.get());
}
@SuppressWarnings("unused")
private static class MyObject {
String a;
String b;

View File

@ -65,7 +65,9 @@ public class CustomDeserializerTest extends TestCase {
private static class DataHolder {
private final String data;
public DataHolder() {
// For use by Gson
@SuppressWarnings("unused")
private DataHolder() {
throw new IllegalStateException();
}
@ -81,7 +83,9 @@ public class CustomDeserializerTest extends TestCase {
private static class DataHolderWrapper {
private final DataHolder wrappedData;
public DataHolderWrapper() {
// For use by Gson
@SuppressWarnings("unused")
private DataHolderWrapper() {
this(new DataHolder(DEFAULT_VALUE));
}

View File

@ -169,6 +169,7 @@ public class CustomTypeAdaptersTest extends TestCase {
}
private static class Derived extends Base {
@SuppressWarnings("unused")
int derivedValue = 3;
}

View File

@ -289,7 +289,9 @@ public class DefaultTypeAdaptersTest extends TestCase {
private static class ClassWithBigDecimal {
BigDecimal value;
ClassWithBigDecimal() { }
// For use by Gson
@SuppressWarnings("unused")
private ClassWithBigDecimal() { }
ClassWithBigDecimal(String value) {
this.value = new BigDecimal(value);
}
@ -300,7 +302,9 @@ public class DefaultTypeAdaptersTest extends TestCase {
private static class ClassWithBigInteger {
BigInteger value;
ClassWithBigInteger() { }
// For use by Gson
@SuppressWarnings("unused")
private ClassWithBigInteger() { }
ClassWithBigInteger(String value) {
this.value = new BigInteger(value);
}

View File

@ -110,6 +110,7 @@ public class ExposeFieldsTest extends TestCase {
assertNotNull(obj.interfaceField);
}
@SuppressWarnings("unused")
private static class ClassWithExposedFields {
@Expose private final Integer a;
private final Integer b;
@ -117,7 +118,8 @@ public class ExposeFieldsTest extends TestCase {
@Expose(deserialize = false) final double d;
@Expose(serialize = false, deserialize = false) final char e;
ClassWithExposedFields() {
// For use by Gson
private ClassWithExposedFields() {
this(null, null);
}
@ -166,7 +168,9 @@ public class ExposeFieldsTest extends TestCase {
@Expose
private final SomeInterface interfaceField;
public ClassWithInterfaceField() {
// For use by Gson
@SuppressWarnings("unused")
private ClassWithInterfaceField() {
this(null);
}

View File

@ -75,6 +75,7 @@ public class JsonTreeTest extends TestCase {
}
private static class SubTypeOfBagOfPrimitives extends BagOfPrimitives {
@SuppressWarnings("unused")
float f = 1.2F;
public SubTypeOfBagOfPrimitives(long l, int i, boolean b, String string, float f) {
super(l, i, b, string);

View File

@ -172,6 +172,7 @@ public class MapTest extends TestCase {
private static class MyParameterizedMap<K, V> extends LinkedHashMap<K, V> {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
int foo = 10;
}
@ -248,6 +249,7 @@ public class MapTest extends TestCase {
private static class MyMap extends LinkedHashMap<String, String> {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
int foo = 10;
}

View File

@ -82,6 +82,7 @@ public class NamingPolicyTest extends TestCase {
assertEquals("{\"a\":3.0}", actual);
}
@SuppressWarnings("unused")
private static class ClassWithDuplicateFields {
public Integer a;
@SerializedName("a") public Double b;

View File

@ -151,6 +151,7 @@ public class NullObjectAndFieldTest extends TestCase {
private Long value;
}
@SuppressWarnings("unused")
private static class ClassWithMembers {
String str;
int[] array;

View File

@ -366,6 +366,7 @@ public class ObjectTest extends TestCase {
}
private static class ClassWithObjectField {
@SuppressWarnings("unused")
Object member;
}
@ -391,6 +392,7 @@ public class ObjectTest extends TestCase {
}
private static class Parent {
@SuppressWarnings("unused")
int value1 = 1;
private class Child {
int value2 = 2;
@ -404,7 +406,8 @@ public class ObjectTest extends TestCase {
private SortedSet<Character> sortedSet;
// For use by Gson
ClassWithSubInterfacesOfCollection() {
@SuppressWarnings("unused")
private ClassWithSubInterfacesOfCollection() {
}
public ClassWithSubInterfacesOfCollection(List<Integer> list, Queue<Long> queue, Set<Float> set,
@ -496,7 +499,9 @@ public class ObjectTest extends TestCase {
private static class SubTypeOfNested extends Nested {
private final long value = 5;
public SubTypeOfNested() {
// Used by Gson
@SuppressWarnings("unused")
private SubTypeOfNested() {
this(null, null);
}

View File

@ -271,7 +271,9 @@ public class ParameterizedTypesTest extends TestCase {
private final List<? extends T> listOfWildcardTypeParameters;
private final List<? extends T>[] arrayOfListOfWildcardTypeParameters;
public ObjectWithTypeVariables() {
// For use by Gson
@SuppressWarnings("unused")
private ObjectWithTypeVariables() {
this(null, null, null, null, null, null);
}
@ -386,7 +388,9 @@ public class ParameterizedTypesTest extends TestCase {
C c;
D d;
E e;
MultiParameters() {
// For use by Gson
@SuppressWarnings("unused")
private MultiParameters() {
}
MultiParameters(A a, B b, C c, D d, E e) {
super();
@ -461,9 +465,11 @@ public class ParameterizedTypesTest extends TestCase {
// Begin: tests to reproduce issue 103
private static class Quantity {
@SuppressWarnings("unused")
int q = 10;
}
private static class MyQuantity extends Quantity {
@SuppressWarnings("unused")
int q2 = 20;
}
private interface Measurable<T> {

View File

@ -72,7 +72,10 @@ public class PerformanceTest extends TestCase {
private static class ExceptionHolder {
public final String message;
public final String stackTrace;
public ExceptionHolder() {
// For use by Gson
@SuppressWarnings("unused")
private ExceptionHolder() {
this("", "");
}
public ExceptionHolder(String message, String stackTrace) {
@ -81,11 +84,13 @@ public class PerformanceTest extends TestCase {
}
}
@SuppressWarnings("unused")
private static class CollectionEntry {
final String name;
final String value;
CollectionEntry() {
// For use by Gson
private CollectionEntry() {
this(null, null);
}