From 2b1f3eec15969d5771a957ba810e3c3a80519a3e Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Tue, 28 Sep 2010 13:42:43 +0000 Subject: [PATCH] Removed a bunch of unused code and unnecessary else statements. --- .../main/java/com/google/gson/Escaper.java | 3 +- .../com/google/gson/GenericArrayTypeImpl.java | 9 ++- gson/src/main/java/com/google/gson/Gson.java | 8 +-- .../java/com/google/gson/GsonBuilder.java | 4 +- .../gson/JsonArrayDeserializationVisitor.java | 4 +- .../java/com/google/gson/JsonElement.java | 12 ++-- .../google/gson/JsonFieldNameValidator.java | 3 +- .../main/java/com/google/gson/JsonObject.java | 9 +-- .../main/java/com/google/gson/JsonParser.java | 3 +- .../java/com/google/gson/JsonPrimitive.java | 57 ++++--------------- .../google/gson/JsonSerializationVisitor.java | 6 +- .../com/google/gson/JsonStreamParser.java | 6 +- .../gson/ModifyFirstLetterNamingPolicy.java | 8 +-- .../java/com/google/gson/ObjectNavigator.java | 21 ++++--- .../google/gson/ParameterizedTypeImpl.java | 23 ++++---- ...ameAnnotationInterceptingNamingPolicy.java | 7 +-- .../java/com/google/gson/TypeInfoArray.java | 8 +-- .../java/com/google/gson/TypeInfoFactory.java | 16 ++---- .../com/google/gson/stream/JsonReader.java | 3 +- .../FunctionWithInternalDependenciesTest.java | 2 +- .../java/com/google/gson/MixedStreamTest.java | 2 +- .../com/google/gson/PrimitiveTypeAdapter.java | 3 +- .../functional/CustomTypeAdaptersTest.java | 5 +- .../com/google/gson/functional/EnumTest.java | 18 +++--- 24 files changed, 79 insertions(+), 161 deletions(-) diff --git a/gson/src/main/java/com/google/gson/Escaper.java b/gson/src/main/java/com/google/gson/Escaper.java index 309e7a69..99632c25 100644 --- a/gson/src/main/java/com/google/gson/Escaper.java +++ b/gson/src/main/java/com/google/gson/Escaper.java @@ -127,9 +127,8 @@ class Escaper { char c = (char) codepoint; return JS_ESCAPE_CHARS.contains(c) || (escapeHtmlCharacters && HTML_ESCAPE_CHARS.contains(c)); - } else { - return false; } + return false; } private static boolean isControlCharacter(int codePoint) { diff --git a/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java b/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java index 0a886441..dd11894d 100644 --- a/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java +++ b/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java @@ -56,12 +56,11 @@ final class GenericArrayTypeImpl implements GenericArrayType { public boolean equals(Object o) { if (!(o instanceof GenericArrayType)) { return false; - } else { - GenericArrayType that = (GenericArrayType) o; - Type thatComponentType = that.getGenericComponentType(); - return genericComponentType == null ? - thatComponentType == null : genericComponentType.equals(thatComponentType); } + GenericArrayType that = (GenericArrayType) o; + Type thatComponentType = that.getGenericComponentType(); + return genericComponentType == null ? + thatComponentType == null : genericComponentType.equals(thatComponentType); } @Override diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java index cf2779fa..10de31e8 100644 --- a/gson/src/main/java/com/google/gson/Gson.java +++ b/gson/src/main/java/com/google/gson/Gson.java @@ -87,7 +87,6 @@ public final class Gson { new SyntheticFieldExclusionStrategy(true); static final ModifierBasedExclusionStrategy DEFAULT_MODIFIER_BASED_EXCLUSION_STRATEGY = new ModifierBasedExclusionStrategy(new int[] { Modifier.TRANSIENT, Modifier.STATIC }); - static final JsonFormatter DEFAULT_JSON_FORMATTER = new JsonCompactFormatter(); static final FieldNamingStrategy2 DEFAULT_NAMING_POLICY = new SerializedNameAnnotationInterceptingNamingPolicy(new JavaFieldNamingPolicy()); @@ -109,7 +108,6 @@ public final class Gson { /** Map containing Type or Class objects as keys */ private final ParameterizedTypeHandlerMap> deserializers; - private final JsonFormatter formatter; private final boolean serializeNulls; private final boolean htmlSafe; @@ -152,21 +150,19 @@ public final class Gson { public Gson() { this(DEFAULT_EXCLUSION_STRATEGY, DEFAULT_EXCLUSION_STRATEGY, DEFAULT_NAMING_POLICY, new MappedObjectConstructor(DefaultTypeAdapters.getDefaultInstanceCreators()), - DEFAULT_JSON_FORMATTER, false, DefaultTypeAdapters.getDefaultSerializers(), + false, DefaultTypeAdapters.getDefaultSerializers(), DefaultTypeAdapters.getDefaultDeserializers(), DEFAULT_JSON_NON_EXECUTABLE, true); } Gson(ExclusionStrategy serializationStrategy, ExclusionStrategy deserializationStrategy, FieldNamingStrategy2 fieldNamingPolicy, MappedObjectConstructor objectConstructor, - JsonFormatter formatter, boolean serializeNulls, - ParameterizedTypeHandlerMap> serializers, + boolean serializeNulls, ParameterizedTypeHandlerMap> serializers, ParameterizedTypeHandlerMap> deserializers, boolean generateNonExecutableGson, boolean htmlSafe) { this.serializationStrategy = serializationStrategy; this.deserializationStrategy = deserializationStrategy; this.fieldNamingPolicy = fieldNamingPolicy; this.objectConstructor = objectConstructor; - this.formatter = formatter; this.serializeNulls = serializeNulls; this.serializers = serializers; this.deserializers = deserializers; diff --git a/gson/src/main/java/com/google/gson/GsonBuilder.java b/gson/src/main/java/com/google/gson/GsonBuilder.java index ecac6657..b896ce8c 100644 --- a/gson/src/main/java/com/google/gson/GsonBuilder.java +++ b/gson/src/main/java/com/google/gson/GsonBuilder.java @@ -542,10 +542,8 @@ public final class GsonBuilder { MappedObjectConstructor objConstructor = new MappedObjectConstructor(customInstanceCreators); - JsonFormatter formatter = prettyPrinting ? - new JsonPrintFormatter(escapeHtmlChars) : new JsonCompactFormatter(escapeHtmlChars); Gson gson = new Gson(serializationExclusionStrategy, deserializationExclusionStrategy, - fieldNamingPolicy, objConstructor, formatter, serializeNulls, customSerializers, + fieldNamingPolicy, objConstructor, serializeNulls, customSerializers, customDeserializers, generateNonExecutableJson, escapeHtmlChars); return gson; } diff --git a/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java b/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java index 72b269fe..e37aedf8 100644 --- a/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonArrayDeserializationVisitor.java @@ -51,9 +51,9 @@ final class JsonArrayDeserializationVisitor extends JsonDeserializationVisito // this typecasting is safe. return (T) objectConstructor.constructArray(arrayTypeInfo.getSecondLevelType(), jsonArray.size()); - } else { // is a collection - return (T) objectConstructor.construct(typeInfo.getRawClass()); } + // is a collection + return (T) objectConstructor.construct(typeInfo.getRawClass()); } public void visitArray(Object array, Type arrayType) { diff --git a/gson/src/main/java/com/google/gson/JsonElement.java b/gson/src/main/java/com/google/gson/JsonElement.java index 3424844e..b1ab94ad 100644 --- a/gson/src/main/java/com/google/gson/JsonElement.java +++ b/gson/src/main/java/com/google/gson/JsonElement.java @@ -79,9 +79,8 @@ public abstract class JsonElement { public JsonObject getAsJsonObject() { if (isJsonObject()) { return (JsonObject) this; - } else { - throw new IllegalStateException("This is not a JSON Object."); } + throw new IllegalStateException("This is not a JSON Object."); } /** @@ -96,9 +95,8 @@ public abstract class JsonElement { public JsonArray getAsJsonArray() { if (isJsonArray()) { return (JsonArray) this; - } else { - throw new IllegalStateException("This is not a JSON Array."); } + throw new IllegalStateException("This is not a JSON Array."); } /** @@ -113,9 +111,8 @@ public abstract class JsonElement { public JsonPrimitive getAsJsonPrimitive() { if (isJsonPrimitive()) { return (JsonPrimitive) this; - } else { - throw new IllegalStateException("This is not a JSON Primitive."); } + throw new IllegalStateException("This is not a JSON Primitive."); } /** @@ -131,9 +128,8 @@ public abstract class JsonElement { public JsonNull getAsJsonNull() { if (isJsonNull()) { return (JsonNull) this; - } else { - throw new IllegalStateException("This is not a JSON Null."); } + throw new IllegalStateException("This is not a JSON Null."); } /** diff --git a/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java b/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java index 08623196..55d174f6 100644 --- a/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java +++ b/gson/src/main/java/com/google/gson/JsonFieldNameValidator.java @@ -50,8 +50,7 @@ class JsonFieldNameValidator { Matcher matcher = JSON_FIELD_NAME_PATTERN.matcher(fieldName); if (!matcher.matches()) { throw new IllegalArgumentException(fieldName + " is not a valid JSON field name."); - } else { - return fieldName; } + return fieldName; } } diff --git a/gson/src/main/java/com/google/gson/JsonObject.java b/gson/src/main/java/com/google/gson/JsonObject.java index 11f78cdc..625900da 100644 --- a/gson/src/main/java/com/google/gson/JsonObject.java +++ b/gson/src/main/java/com/google/gson/JsonObject.java @@ -121,11 +121,7 @@ public final class JsonObject extends JsonElement { * @return a {@link JsonPrimitive} if the {@code value} is not null, otherwise a {@link JsonNull} */ private JsonElement createJsonElement(Object value) { - if (value == null) { - return JsonNull.createJsonNull(); - } else { - return new JsonPrimitive(value); - } + return value == null ? JsonNull.createJsonNull() : new JsonPrimitive(value); } /** @@ -158,9 +154,8 @@ public final class JsonObject extends JsonElement { if (members.containsKey(memberName)) { JsonElement member = members.get(memberName); return member == null ? JsonNull.createJsonNull() : member; - } else { - return null; } + return null; } /** diff --git a/gson/src/main/java/com/google/gson/JsonParser.java b/gson/src/main/java/com/google/gson/JsonParser.java index 0aecf4bf..7b775bdb 100755 --- a/gson/src/main/java/com/google/gson/JsonParser.java +++ b/gson/src/main/java/com/google/gson/JsonParser.java @@ -71,9 +71,8 @@ public final class JsonParser { } catch (JsonParseException e) { if (e.getCause() instanceof EOFException) { return JsonNull.createJsonNull(); - } else { - throw e; } + throw e; } finally { json.setLenient(lenient); } diff --git a/gson/src/main/java/com/google/gson/JsonPrimitive.java b/gson/src/main/java/com/google/gson/JsonPrimitive.java index 5692be4a..b00e46ea 100644 --- a/gson/src/main/java/com/google/gson/JsonPrimitive.java +++ b/gson/src/main/java/com/google/gson/JsonPrimitive.java @@ -126,11 +126,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public boolean getAsBoolean() { - if (isBoolean()) { - return getAsBooleanWrapper().booleanValue(); - } else { - return Boolean.parseBoolean(getAsString()); - } + return isBoolean() ? getAsBooleanWrapper().booleanValue() : Boolean.parseBoolean(getAsString()); } /** @@ -158,9 +154,8 @@ public final class JsonPrimitive extends JsonElement { long longValue = Long.parseLong(value); if (longValue >= Integer.MIN_VALUE && longValue <= Integer.MAX_VALUE) { return (int) longValue; - } else { - return longValue; } + return longValue; } catch (NumberFormatException ignored) { } @@ -205,11 +200,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public double getAsDouble() { - if (isNumber()) { - return getAsNumber().doubleValue(); - } else { - return Double.parseDouble(getAsString()); - } + return isNumber() ? getAsNumber().doubleValue() : Double.parseDouble(getAsString()); } /** @@ -220,11 +211,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public BigDecimal getAsBigDecimal() { - if (value instanceof BigDecimal) { - return (BigDecimal) value; - } else { - return new BigDecimal(value.toString()); - } + return value instanceof BigDecimal ? (BigDecimal) value : new BigDecimal(value.toString()); } /** @@ -235,11 +222,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public BigInteger getAsBigInteger() { - if (value instanceof BigInteger) { - return (BigInteger) value; - } else { - return new BigInteger(value.toString()); - } + return value instanceof BigInteger ? (BigInteger) value : new BigInteger(value.toString()); } /** @@ -250,11 +233,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public float getAsFloat() { - if (isNumber()) { - return getAsNumber().floatValue(); - } else { - return Float.parseFloat(getAsString()); - } + return isNumber() ? getAsNumber().floatValue() : Float.parseFloat(getAsString()); } /** @@ -265,11 +244,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public long getAsLong() { - if (isNumber()) { - return getAsNumber().longValue(); - } else { - return Long.parseLong(getAsString()); - } + return isNumber() ? getAsNumber().longValue() : Long.parseLong(getAsString()); } /** @@ -280,11 +255,7 @@ public final class JsonPrimitive extends JsonElement { */ @Override public short getAsShort() { - if (isNumber()) { - return getAsNumber().shortValue(); - } else { - return Short.parseShort(getAsString()); - } + return isNumber() ? getAsNumber().shortValue() : Short.parseShort(getAsString()); } /** @@ -295,20 +266,12 @@ public final class JsonPrimitive extends JsonElement { */ @Override public int getAsInt() { - if (isNumber()) { - return getAsNumber().intValue(); - } else { - return Integer.parseInt(getAsString()); - } + return isNumber() ? getAsNumber().intValue() : Integer.parseInt(getAsString()); } @Override public byte getAsByte() { - if (isNumber()) { - return getAsNumber().byteValue(); - } else { - return Byte.parseByte(getAsString()); - } + return isNumber() ? getAsNumber().byteValue() : Byte.parseByte(getAsString()); } @Override diff --git a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java index 49d3e0c8..56c8fb4d 100644 --- a/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java +++ b/gson/src/main/java/com/google/gson/JsonSerializationVisitor.java @@ -161,9 +161,8 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor { if (element != null) { assignToRoot(element); return true; - } else { - return false; } + return false; } catch (CircularReferenceException e) { throw e.createDetailedException(null); } @@ -205,9 +204,8 @@ final class JsonSerializationVisitor implements ObjectNavigator.Visitor { if (child != null) { addChildAsElement(f, child); return true; - } else { - return false; } + return false; } catch (IllegalAccessException e) { throw new RuntimeException(); } catch (CircularReferenceException e) { diff --git a/gson/src/main/java/com/google/gson/JsonStreamParser.java b/gson/src/main/java/com/google/gson/JsonStreamParser.java index 7a2ce3f8..6f345da8 100644 --- a/gson/src/main/java/com/google/gson/JsonStreamParser.java +++ b/gson/src/main/java/com/google/gson/JsonStreamParser.java @@ -88,11 +88,7 @@ public final class JsonStreamParser implements Iterator { } catch (OutOfMemoryError e) { throw new JsonParseException("Failed parsing JSON source to Json", e); } catch (JsonParseException e) { - if (e.getCause() instanceof EOFException) { - throw new NoSuchElementException(); - } else { - throw e; - } + throw e.getCause() instanceof EOFException ? new NoSuchElementException() : e; } } diff --git a/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java b/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java index a648a353..a5884397 100644 --- a/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java +++ b/gson/src/main/java/com/google/gson/ModifyFirstLetterNamingPolicy.java @@ -100,10 +100,8 @@ final class ModifyFirstLetterNamingPolicy extends RecursiveFieldNamingPolicy { } private String modifyString(char firstCharacter, String srcString, int indexOfSubstring) { - if (indexOfSubstring < srcString.length()) { - return firstCharacter + srcString.substring(indexOfSubstring); - } else { - return String.valueOf(firstCharacter); - } + return indexOfSubstring < srcString.length() ? + firstCharacter + srcString.substring(indexOfSubstring) + : String.valueOf(firstCharacter); } } diff --git a/gson/src/main/java/com/google/gson/ObjectNavigator.java b/gson/src/main/java/com/google/gson/ObjectNavigator.java index 91f6d9c3..f294eb1d 100644 --- a/gson/src/main/java/com/google/gson/ObjectNavigator.java +++ b/gson/src/main/java/com/google/gson/ObjectNavigator.java @@ -152,17 +152,16 @@ final class ObjectNavigator { if (exclusionStrategy.shouldSkipField(fieldAttributes) || exclusionStrategy.shouldSkipClass(fieldAttributes.getDeclaredClass())) { continue; // skip - } else { - TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.type); - Type declaredTypeOfField = fieldTypeInfo.getActualType(); - boolean visitedWithCustomHandler = - visitor.visitFieldUsingCustomHandler(fieldAttributes, declaredTypeOfField, obj); - if (!visitedWithCustomHandler) { - if (fieldTypeInfo.isArray()) { - visitor.visitArrayField(fieldAttributes, declaredTypeOfField, obj); - } else { - visitor.visitObjectField(fieldAttributes, declaredTypeOfField, obj); - } + } + TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.type); + Type declaredTypeOfField = fieldTypeInfo.getActualType(); + boolean visitedWithCustomHandler = + visitor.visitFieldUsingCustomHandler(fieldAttributes, declaredTypeOfField, obj); + if (!visitedWithCustomHandler) { + if (fieldTypeInfo.isArray()) { + visitor.visitArrayField(fieldAttributes, declaredTypeOfField, obj); + } else { + visitor.visitObjectField(fieldAttributes, declaredTypeOfField, obj); } } } diff --git a/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java b/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java index 25f1bd1c..230dfc43 100644 --- a/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java +++ b/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java @@ -68,19 +68,18 @@ final class ParameterizedTypeImpl implements ParameterizedType { public boolean equals(Object o) { if (!(o instanceof ParameterizedType)) { return false; - } else { - // Check that information is equivalent - ParameterizedType that = (ParameterizedType) o; - if (this == that) - return true; - - Type thatOwner = that.getOwnerType(); - Type thatRawType = that.getRawType(); - - return (owner == null ? thatOwner == null : owner.equals(thatOwner)) - && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) - && Arrays.equals(actualTypeArguments, that.getActualTypeArguments()); } + // Check that information is equivalent + ParameterizedType that = (ParameterizedType) o; + if (this == that) { + return true; + } + Type thatOwner = that.getOwnerType(); + Type thatRawType = that.getRawType(); + + return (owner == null ? thatOwner == null : owner.equals(thatOwner)) + && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) + && Arrays.equals(actualTypeArguments, that.getActualTypeArguments()); } @Override diff --git a/gson/src/main/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicy.java b/gson/src/main/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicy.java index 4f1de30f..37155415 100644 --- a/gson/src/main/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicy.java +++ b/gson/src/main/java/com/google/gson/SerializedNameAnnotationInterceptingNamingPolicy.java @@ -42,10 +42,7 @@ final class SerializedNameAnnotationInterceptingNamingPolicy implements FieldNam public String translateName(FieldAttributes f) { Preconditions.checkNotNull(f); SerializedName serializedName = f.getAnnotation(SerializedName.class); - if (serializedName != null) { - return fieldNameValidator.validate(serializedName.value()); - } else { - return delegate.translateName(f); - } + return serializedName == null ? delegate.translateName(f) + : fieldNameValidator.validate(serializedName.value()); } } diff --git a/gson/src/main/java/com/google/gson/TypeInfoArray.java b/gson/src/main/java/com/google/gson/TypeInfoArray.java index c1860cb4..a950a001 100644 --- a/gson/src/main/java/com/google/gson/TypeInfoArray.java +++ b/gson/src/main/java/com/google/gson/TypeInfoArray.java @@ -40,12 +40,8 @@ final class TypeInfoArray extends TypeInfo { } private static Type extractSecondLevelType(Type actualType, Class rawClass) { - if (actualType instanceof GenericArrayType) { - GenericArrayType castedType = (GenericArrayType) actualType; - return castedType.getGenericComponentType(); - } else { - return rawClass.getComponentType(); - } + return actualType instanceof GenericArrayType ? + ((GenericArrayType) actualType).getGenericComponentType() : rawClass.getComponentType(); } /** diff --git a/gson/src/main/java/com/google/gson/TypeInfoFactory.java b/gson/src/main/java/com/google/gson/TypeInfoFactory.java index 1be0fac1..ae5b6972 100644 --- a/gson/src/main/java/com/google/gson/TypeInfoFactory.java +++ b/gson/src/main/java/com/google/gson/TypeInfoFactory.java @@ -72,13 +72,10 @@ final class TypeInfoFactory { Type actualType = getActualType(componentType, parentType, rawParentClass); if (componentType.equals(actualType)) { return castedType; - } else { - if (actualType instanceof Class) { - return TypeUtils.wrapWithArray(TypeUtils.toRawClass(actualType)); - } else { - return new GenericArrayTypeImpl(actualType); - } } + return actualType instanceof Class ? + TypeUtils.wrapWithArray(TypeUtils.toRawClass(actualType)) + : new GenericArrayTypeImpl(actualType); } else if (typeToEvaluate instanceof TypeVariable) { if (parentType instanceof ParameterizedType) { // The class definition has the actual types used for the type variables. @@ -93,11 +90,10 @@ final class TypeInfoFactory { int indexOfActualTypeArgument = getIndex(classTypeVariables, fieldTypeVariable); Type[] actualTypeArguments = objParameterizedType.getActualTypeArguments(); return actualTypeArguments[indexOfActualTypeArgument]; - } else { - throw new UnsupportedOperationException("Expecting parameterized type, got " + parentType - + ".\n Are you missing the use of TypeToken idiom?\n See " - + "http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener"); } + throw new UnsupportedOperationException("Expecting parameterized type, got " + parentType + + ".\n Are you missing the use of TypeToken idiom?\n See " + + "http://sites.google.com/site/gson/gson-user-guide#TOC-Serializing-and-Deserializing-Gener"); } else if (typeToEvaluate instanceof WildcardType) { WildcardType castedType = (WildcardType) typeToEvaluate; return getActualType(castedType.getUpperBounds()[0], parentType, rawParentClass); diff --git a/gson/src/main/java/com/google/gson/stream/JsonReader.java b/gson/src/main/java/com/google/gson/stream/JsonReader.java index ab11f26a..df788c08 100644 --- a/gson/src/main/java/com/google/gson/stream/JsonReader.java +++ b/gson/src/main/java/com/google/gson/stream/JsonReader.java @@ -381,9 +381,8 @@ public final class JsonReader implements Closeable { JsonToken token = nextValue(); if (lenient) { return token; - } else { - throw syntaxError("Expected EOF"); } + throw syntaxError("Expected EOF"); } catch (EOFException e) { hasToken = true; // TODO: avoid throwing here? return token = JsonToken.END_DOCUMENT; diff --git a/gson/src/test/java/com/google/gson/FunctionWithInternalDependenciesTest.java b/gson/src/test/java/com/google/gson/FunctionWithInternalDependenciesTest.java index 11a214c4..3db4b48a 100644 --- a/gson/src/test/java/com/google/gson/FunctionWithInternalDependenciesTest.java +++ b/gson/src/test/java/com/google/gson/FunctionWithInternalDependenciesTest.java @@ -41,7 +41,7 @@ public class FunctionWithInternalDependenciesTest extends TestCase { ExclusionStrategy exclusionStrategy = new DisjunctionExclusionStrategy(strategies); Gson gson = new Gson(exclusionStrategy, exclusionStrategy, Gson.DEFAULT_NAMING_POLICY, new MappedObjectConstructor(DefaultTypeAdapters.getDefaultInstanceCreators()), - Gson.DEFAULT_JSON_FORMATTER, false, DefaultTypeAdapters.getDefaultSerializers(), + false, DefaultTypeAdapters.getDefaultSerializers(), DefaultTypeAdapters.getDefaultDeserializers(), Gson.DEFAULT_JSON_NON_EXECUTABLE, true); assertEquals("{}", gson.toJson(new ClassWithNoFields() { // empty anonymous class diff --git a/gson/src/test/java/com/google/gson/MixedStreamTest.java b/gson/src/test/java/com/google/gson/MixedStreamTest.java index de123b36..4cf00b0a 100644 --- a/gson/src/test/java/com/google/gson/MixedStreamTest.java +++ b/gson/src/test/java/com/google/gson/MixedStreamTest.java @@ -223,7 +223,7 @@ public final class MixedStreamTest extends TestCase { this.color = color; } - @SuppressWarnings("unused") // used by Gson + // used by Gson Car() {} @Override public int hashCode() { diff --git a/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java b/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java index 871ed6fa..90637e9f 100644 --- a/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java +++ b/gson/src/test/java/com/google/gson/PrimitiveTypeAdapter.java @@ -39,9 +39,8 @@ final class PrimitiveTypeAdapter { String value = from.toString(); if (value.length() == 1) { return (T) (Character) from.toString().charAt(0); - } else { - throw new JsonParseException("The value: " + value + " contains more than a character."); } + throw new JsonParseException("The value: " + value + " contains more than a character."); } try { diff --git a/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java index 015cf75e..03d7333b 100644 --- a/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/CustomTypeAdaptersTest.java @@ -233,10 +233,9 @@ public class CustomTypeAdaptersTest extends TestCase { customDeserializerInvoked.value = true; if (json == null || json.isJsonNull()) { return null; - } else { - Number number = json.getAsJsonPrimitive().getAsNumber(); - return number == null ? null : number.longValue(); } + Number number = json.getAsJsonPrimitive().getAsNumber(); + return number == null ? null : number.longValue(); } }).create(); String json = "{'value':null}"; diff --git a/gson/src/test/java/com/google/gson/functional/EnumTest.java b/gson/src/test/java/com/google/gson/functional/EnumTest.java index 1fc549e4..bdd7b4da 100644 --- a/gson/src/test/java/com/google/gson/functional/EnumTest.java +++ b/gson/src/test/java/com/google/gson/functional/EnumTest.java @@ -16,19 +16,17 @@ package com.google.gson.functional; -import com.google.gson.Gson; -import com.google.gson.common.MoreAsserts; -import com.google.gson.reflect.TypeToken; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import junit.framework.TestCase; - import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Collection; +import java.util.EnumSet; +import java.util.Set; + +import junit.framework.TestCase; + +import com.google.gson.Gson; +import com.google.gson.common.MoreAsserts; +import com.google.gson.reflect.TypeToken; /** * Functional tests for Java 5.0 enums.