removed Java 1.5 warnings

This commit is contained in:
Inderjeet Singh 2009-08-31 17:51:47 +00:00
parent 66649a1a62
commit 82771f006c
22 changed files with 44 additions and 9 deletions

View File

@ -319,6 +319,7 @@ public final class GsonBuilder {
* {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces. * {@link JsonSerializer}, and a {@link JsonDeserializer} interfaces.
* @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern * @return a reference to this {@code GsonBuilder} object to fulfill the "Builder" pattern
*/ */
@SuppressWarnings("unchecked")
public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) { public GsonBuilder registerTypeAdapter(Type type, Object typeAdapter) {
Preconditions.checkArgument(typeAdapter instanceof JsonSerializer Preconditions.checkArgument(typeAdapter instanceof JsonSerializer
|| typeAdapter instanceof JsonDeserializer || typeAdapter instanceof InstanceCreator); || typeAdapter instanceof JsonDeserializer || typeAdapter instanceof InstanceCreator);

View File

@ -55,6 +55,7 @@ final class TypeInfoFactory {
return new TypeInfo(actualType); return new TypeInfo(actualType);
} }
@SuppressWarnings("unchecked")
private static Type getActualType( private static Type getActualType(
Type typeToEvaluate, Type parentType, Class<?> rawParentClass) { Type typeToEvaluate, Type parentType, Class<?> rawParentClass) {
if (typeToEvaluate instanceof Class) { if (typeToEvaluate instanceof Class) {

View File

@ -31,6 +31,7 @@ final class TypeInfoMap {
private final Type keyType; private final Type keyType;
private final Type valueType; private final Type valueType;
@SuppressWarnings("unchecked")
public TypeInfoMap(Type mapType) { 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; keyType = String.class;

View File

@ -40,6 +40,7 @@ final class TypeUtils {
* </pre> * </pre>
* <code>TypeUtils.getActualTypeForFirstTypeVariable(fooType)</code> will return Integer.class. * <code>TypeUtils.getActualTypeForFirstTypeVariable(fooType)</code> will return Integer.class.
*/ */
@SuppressWarnings("unchecked")
static Type getActualTypeForFirstTypeVariable(Type type) { static Type getActualTypeForFirstTypeVariable(Type type) {
if (type instanceof Class) { if (type instanceof Class) {
return Object.class; return Object.class;
@ -53,6 +54,7 @@ final class TypeUtils {
} }
} }
@SuppressWarnings("unchecked")
static boolean isArray(Type type) { static boolean isArray(Type type) {
if (type instanceof Class) { if (type instanceof Class) {
return ((Class<?>)type).isArray(); return ((Class<?>)type).isArray();
@ -66,6 +68,7 @@ final class TypeUtils {
/** /**
* This method returns the actual raw class associated with the specified type. * This method returns the actual raw class associated with the specified type.
*/ */
@SuppressWarnings("unchecked")
static Class<?> toRawClass(Type type) { static Class<?> toRawClass(Type type) {
if (type instanceof Class) { if (type instanceof Class) {
return (Class<?>) type; return (Class<?>) type;

View File

@ -85,6 +85,7 @@ public abstract class TypeToken<T> {
/** /**
* Gets type from super class's type parameter. * Gets type from super class's type parameter.
*/ */
@SuppressWarnings("unchecked")
static Type getSuperclassTypeParameter(Class<?> subclass) { static Type getSuperclassTypeParameter(Class<?> subclass) {
Type superclass = subclass.getGenericSuperclass(); Type superclass = subclass.getGenericSuperclass();
if (superclass instanceof Class) { if (superclass instanceof Class) {
@ -154,6 +155,7 @@ public abstract class TypeToken<T> {
/** /**
* Check if this type is assignable from the given Type. * Check if this type is assignable from the given Type.
*/ */
@SuppressWarnings("unchecked")
public boolean isAssignableFrom(Type from) { public boolean isAssignableFrom(Type from) {
if (from == null) { if (from == null) {
return false; return false;
@ -188,6 +190,7 @@ public abstract class TypeToken<T> {
* Private helper function that performs some assignability checks for * Private helper function that performs some assignability checks for
* the provided GenericArrayType. * the provided GenericArrayType.
*/ */
@SuppressWarnings("unchecked")
private static boolean isAssignableFrom(Type from, GenericArrayType to) { private static boolean isAssignableFrom(Type from, GenericArrayType to) {
Type toGenericComponentType = to.getGenericComponentType(); Type toGenericComponentType = to.getGenericComponentType();
if (toGenericComponentType instanceof ParameterizedType) { if (toGenericComponentType instanceof ParameterizedType) {
@ -213,6 +216,7 @@ public abstract class TypeToken<T> {
* Private recursive helper function to actually do the type-safe checking * Private recursive helper function to actually do the type-safe checking
* of assignability. * of assignability.
*/ */
@SuppressWarnings("unchecked")
private static boolean isAssignableFrom(Type from, ParameterizedType to, private static boolean isAssignableFrom(Type from, ParameterizedType to,
Map<String, Type> typeVarMap) { Map<String, Type> typeVarMap) {
@ -289,6 +293,7 @@ public abstract class TypeToken<T> {
* Checks if two types are the same or are equivalent under a variable mapping * Checks if two types are the same or are equivalent under a variable mapping
* given in the type map that was provided. * given in the type map that was provided.
*/ */
@SuppressWarnings("unchecked")
private static boolean matches(Type from, Type to, private static boolean matches(Type from, Type to,
Map<String, Type> typeMap) { Map<String, Type> typeMap) {
if (to.equals(from)) return true; if (to.equals(from)) return true;

View File

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

View File

@ -1,6 +1,5 @@
package com.google.gson; package com.google.gson;
import java.util.Enumeration;
import java.util.Iterator; import java.util.Iterator;
import junit.framework.TestCase; import junit.framework.TestCase;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -65,6 +65,7 @@ public class CustomDeserializerTest extends TestCase {
private static class DataHolder { private static class DataHolder {
private final String data; private final String data;
@SuppressWarnings("unused")
public DataHolder() { public DataHolder() {
throw new IllegalStateException(); throw new IllegalStateException();
} }
@ -81,6 +82,7 @@ public class CustomDeserializerTest extends TestCase {
private static class DataHolderWrapper { private static class DataHolderWrapper {
private final DataHolder wrappedData; private final DataHolder wrappedData;
@SuppressWarnings("unused")
public DataHolderWrapper() { public DataHolderWrapper() {
this(new DataHolder(DEFAULT_VALUE)); this(new DataHolder(DEFAULT_VALUE));
} }

View File

@ -289,6 +289,7 @@ public class DefaultTypeAdaptersTest extends TestCase {
private static class ClassWithBigDecimal { private static class ClassWithBigDecimal {
BigDecimal value; BigDecimal value;
@SuppressWarnings("unused")
ClassWithBigDecimal() { } ClassWithBigDecimal() { }
ClassWithBigDecimal(String value) { ClassWithBigDecimal(String value) {
this.value = new BigDecimal(value); this.value = new BigDecimal(value);
@ -300,6 +301,7 @@ public class DefaultTypeAdaptersTest extends TestCase {
private static class ClassWithBigInteger { private static class ClassWithBigInteger {
BigInteger value; BigInteger value;
@SuppressWarnings("unused")
ClassWithBigInteger() { } ClassWithBigInteger() { }
ClassWithBigInteger(String value) { ClassWithBigInteger(String value) {
this.value = new BigInteger(value); this.value = new BigInteger(value);

View File

@ -117,6 +117,7 @@ public class ExposeFieldsTest extends TestCase {
@Expose(deserialize = false) final double d; @Expose(deserialize = false) final double d;
@Expose(serialize = false, deserialize = false) final char e; @Expose(serialize = false, deserialize = false) final char e;
@SuppressWarnings("unused")
ClassWithExposedFields() { ClassWithExposedFields() {
this(null, null); this(null, null);
} }
@ -141,10 +142,6 @@ public class ExposeFieldsTest extends TestCase {
sb.append("}"); sb.append("}");
return sb.toString(); return sb.toString();
} }
public String getExpectedJsonWithoutAnnotations() {
return String.format("{\"a\":%d,\"b\":%d,\"c\":%d,\"d\":%f,\"e\":\"%c\"}", a, b, c, d, e);
}
} }
private static class ClassWithNoExposedFields { private static class ClassWithNoExposedFields {
@ -170,6 +167,7 @@ public class ExposeFieldsTest extends TestCase {
@Expose @Expose
private final SomeInterface interfaceField; private final SomeInterface interfaceField;
@SuppressWarnings("unused")
public ClassWithInterfaceField() { public ClassWithInterfaceField() {
this(null); this(null);
} }

View File

@ -75,6 +75,7 @@ public class JsonTreeTest extends TestCase {
} }
private static class SubTypeOfBagOfPrimitives extends BagOfPrimitives { private static class SubTypeOfBagOfPrimitives extends BagOfPrimitives {
@SuppressWarnings("unused")
float f = 1.2F; float f = 1.2F;
public SubTypeOfBagOfPrimitives(long l, int i, boolean b, String string, float f) { public SubTypeOfBagOfPrimitives(long l, int i, boolean b, String string, float f) {
super(l, i, b, string); 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 class MyParameterizedMap<K, V> extends LinkedHashMap<K, V> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
int foo = 10; int foo = 10;
} }
@ -248,6 +249,7 @@ public class MapTest extends TestCase {
private static class MyMap extends LinkedHashMap<String, String> { private static class MyMap extends LinkedHashMap<String, String> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
int foo = 10; int foo = 10;
} }

View File

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

View File

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

View File

@ -351,6 +351,7 @@ public class ObjectTest extends TestCase {
assertTrue(json.contains("abc")); assertTrue(json.contains("abc"));
} }
@SuppressWarnings("unused")
private static class ClassWithObjectField { private static class ClassWithObjectField {
Object member; Object member;
} }
@ -377,6 +378,7 @@ public class ObjectTest extends TestCase {
} }
private static class Parent { private static class Parent {
@SuppressWarnings("unused")
int value1 = 1; int value1 = 1;
private class Child { private class Child {
int value2 = 2; int value2 = 2;
@ -389,6 +391,8 @@ public class ObjectTest extends TestCase {
private Set<Float> set; private Set<Float> set;
private SortedSet<Character> sortedSet; private SortedSet<Character> sortedSet;
// For use by Gson
@SuppressWarnings("unused")
ClassWithSubInterfacesOfCollection() { ClassWithSubInterfacesOfCollection() {
} }
@ -481,6 +485,7 @@ public class ObjectTest extends TestCase {
private static class SubTypeOfNested extends Nested { private static class SubTypeOfNested extends Nested {
private final long value = 5; private final long value = 5;
@SuppressWarnings("unused")
public SubTypeOfNested() { public SubTypeOfNested() {
this(null, null); this(null, null);
} }
@ -585,7 +590,7 @@ public class ObjectTest extends TestCase {
public void testArrayOfObjectsWithoutTypeInfoDeserialization() { public void testArrayOfObjectsWithoutTypeInfoDeserialization() {
String json = "[1,'abc',{a:1},5]"; String json = "[1,'abc',{a:1},5]";
try { try {
Object[] objs = gson.fromJson(json, Object[].class); gson.fromJson(json, Object[].class);
} catch (JsonParseException expected) { } catch (JsonParseException expected) {
} }
} }
@ -593,7 +598,7 @@ public class ObjectTest extends TestCase {
public void testArrayWithoutTypeInfoDeserialization() { public void testArrayWithoutTypeInfoDeserialization() {
String json = "[1,'abc',[1,2],5]"; String json = "[1,'abc',[1,2],5]";
try { try {
Object[] objs = gson.fromJson(json, Object[].class); gson.fromJson(json, Object[].class);
} catch (JsonParseException expected) { } catch (JsonParseException expected) {
} }
} }

View File

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

View File

@ -72,6 +72,7 @@ public class PerformanceTest extends TestCase {
private static class ExceptionHolder { private static class ExceptionHolder {
public final String message; public final String message;
public final String stackTrace; public final String stackTrace;
@SuppressWarnings("unused")
public ExceptionHolder() { public ExceptionHolder() {
this("", ""); this("", "");
} }
@ -81,6 +82,7 @@ public class PerformanceTest extends TestCase {
} }
} }
@SuppressWarnings("unused")
private static class CollectionEntry { private static class CollectionEntry {
final String name; final String name;
final String value; final String value;
@ -140,7 +142,7 @@ public class PerformanceTest extends TestCase {
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
ba[i] = 0x05; ba[i] = 0x05;
} }
String json = gson.toJson(ba); gson.toJson(ba);
System.out.printf("Gson could serialize a byte array of size: %d\n", size); System.out.printf("Gson could serialize a byte array of size: %d\n", size);
} }
} }