From 3926afbd3022d8939e279cbd2a9c83aa4984f160 Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Mon, 10 Jan 2011 22:47:42 +0000 Subject: [PATCH] Removing unused files with the new Types class. --- .../com/google/gson/GenericArrayTypeImpl.java | 70 -------------- .../google/gson/ParameterizedTypeImpl.java | 91 ------------------- ...mplTest.java => GenericArrayTypeTest.java} | 18 ++-- ...plTest.java => ParameterizedTypeTest.java} | 13 ++- 4 files changed, 14 insertions(+), 178 deletions(-) delete mode 100644 gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java delete mode 100644 gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java rename gson/src/test/java/com/google/gson/{GenericArrayTypeImplTest.java => GenericArrayTypeTest.java} (75%) rename gson/src/test/java/com/google/gson/{ParameterizedTypeImplTest.java => ParameterizedTypeTest.java} (80%) diff --git a/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java b/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java deleted file mode 100644 index dd11894d..00000000 --- a/gson/src/main/java/com/google/gson/GenericArrayTypeImpl.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gson; - -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.Type; - -/** - * An simple pojo-like immutable instance of the {@link GenericArrayType}. This object provides - * us the ability to create reflective types on demand. This object is required for support - * object similar to the one defined below: - *
- * class Foo {
- *   private final List[] arrayOfListT;
- *
- *   Foo(List[] arrayList) {
- *     this.arrayOfListT = arrayList;
- *   }
- * }
- * 
- * - *

During parsing or serialization, we know the real variable type parameter {@code T}, - * so we can build a new {@code GenericTypeArray} with the "real" type parameters and - * pass that object along instead. - * - * @author Inderjeet Singh - * @author Joel Leitch - */ -final class GenericArrayTypeImpl implements GenericArrayType { - - private final Type genericComponentType; - - public GenericArrayTypeImpl(Type genericComponentType) { - this.genericComponentType = genericComponentType; - } - - public Type getGenericComponentType() { - return genericComponentType; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof GenericArrayType)) { - return false; - } - GenericArrayType that = (GenericArrayType) o; - Type thatComponentType = that.getGenericComponentType(); - return genericComponentType == null ? - thatComponentType == null : genericComponentType.equals(thatComponentType); - } - - @Override - public int hashCode() { - return (genericComponentType == null) ? 0 : genericComponentType.hashCode(); - } -} diff --git a/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java b/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java deleted file mode 100644 index 230dfc43..00000000 --- a/gson/src/main/java/com/google/gson/ParameterizedTypeImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2008 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.gson; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.Arrays; - -/** - * An immutable implementation of the {@link ParameterizedType} interface. This object allows - * us to build a reflective {@link Type} objects on demand. This object is used to support - * serialization and deserialization of classes with an {@code ParameterizedType} field where - * as least one of the actual type parameters is a {@code TypeVariable}. - * - *

Here's an example class: - *

- * class Foo {
- *   private List someList;
- *
- *   Foo(List list) {
- *     this.someList = list;
- *   }
- * }
- * 
- * - * @author Inderjeet Singh - * @author Joel Leitch - */ -final class ParameterizedTypeImpl implements ParameterizedType { - - private final Type rawType; - private final Type[] actualTypeArguments; - private final Type owner; - - public ParameterizedTypeImpl(Type rawType, Type[] actualTypeArguments, Type owner) { - this.rawType = rawType; - this.actualTypeArguments = actualTypeArguments; - this.owner = owner; - } - - public Type getRawType() { - return rawType; - } - - public Type[] getActualTypeArguments() { - return actualTypeArguments; - } - - public Type getOwnerType() { - return owner; - } - - @Override - public boolean equals(Object o) { - if (!(o instanceof ParameterizedType)) { - return false; - } - // 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 - public int hashCode() { - return Arrays.hashCode(actualTypeArguments) - ^ (owner == null ? 0 : owner.hashCode()) - ^ (rawType == null ? 0 : rawType.hashCode()); - } -} diff --git a/gson/src/test/java/com/google/gson/GenericArrayTypeImplTest.java b/gson/src/test/java/com/google/gson/GenericArrayTypeTest.java similarity index 75% rename from gson/src/test/java/com/google/gson/GenericArrayTypeImplTest.java rename to gson/src/test/java/com/google/gson/GenericArrayTypeTest.java index c50acb29..217c228c 100644 --- a/gson/src/test/java/com/google/gson/GenericArrayTypeImplTest.java +++ b/gson/src/test/java/com/google/gson/GenericArrayTypeTest.java @@ -20,30 +20,29 @@ import com.google.gson.reflect.TypeToken; import junit.framework.TestCase; +import java.lang.reflect.GenericArrayType; import java.lang.reflect.Type; import java.util.List; /** - * Unit tests for the {@link GenericArrayTypeImpl} class. + * Unit tests for the {@code GenericArrayType}s created by the {@link Types} class. * * @author Inderjeet Singh * @author Joel Leitch */ -public class GenericArrayTypeImplTest extends TestCase { - - private Type parameterizedType; - private Type genericArrayType; - private GenericArrayTypeImpl ourType; +public class GenericArrayTypeTest extends TestCase { + private GenericArrayType ourType; @Override protected void setUp() throws Exception { super.setUp(); - parameterizedType = new TypeToken>() {}.getType(); - genericArrayType = new TypeToken[]>() {}.getType(); - ourType = new GenericArrayTypeImpl(parameterizedType); + ourType = Types.arrayOf(Types.newParameterizedTypeWithOwner(null, List.class, String.class)); } public void testOurTypeFunctionality() throws Exception { + Type parameterizedType = new TypeToken>() {}.getType(); + Type genericArrayType = new TypeToken[]>() {}.getType(); + assertEquals(parameterizedType, ourType.getGenericComponentType()); assertEquals(genericArrayType, ourType); assertEquals(genericArrayType.hashCode(), ourType.hashCode()); @@ -51,7 +50,6 @@ public class GenericArrayTypeImplTest extends TestCase { public void testNotEquals() throws Exception { Type differentGenericArrayType = new TypeToken[][]>() {}.getType(); - assertFalse(differentGenericArrayType.equals(ourType)); assertFalse(ourType.equals(differentGenericArrayType)); } diff --git a/gson/src/test/java/com/google/gson/ParameterizedTypeImplTest.java b/gson/src/test/java/com/google/gson/ParameterizedTypeTest.java similarity index 80% rename from gson/src/test/java/com/google/gson/ParameterizedTypeImplTest.java rename to gson/src/test/java/com/google/gson/ParameterizedTypeTest.java index 50a0401d..dbe354f8 100644 --- a/gson/src/test/java/com/google/gson/ParameterizedTypeImplTest.java +++ b/gson/src/test/java/com/google/gson/ParameterizedTypeTest.java @@ -20,28 +20,27 @@ import com.google.gson.reflect.TypeToken; import junit.framework.TestCase; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.List; /** - * Unit tests for the {@link ParameterizedTypeImpl} class. + * Unit tests for {@code ParamterizedType}s created by the {@link Types} class. * * @author Inderjeet Singh * @author Joel Leitch */ -public class ParameterizedTypeImplTest extends TestCase { - - private Type parameterizedType; - private ParameterizedTypeImpl ourType; +public class ParameterizedTypeTest extends TestCase { + private ParameterizedType ourType; @Override protected void setUp() throws Exception { super.setUp(); - parameterizedType = new TypeToken>() {}.getType(); - ourType = new ParameterizedTypeImpl(List.class, new Type[] { String.class }, null); + ourType = Types.newParameterizedTypeWithOwner(null, List.class, String.class); } public void testOurTypeFunctionality() throws Exception { + Type parameterizedType = new TypeToken>() {}.getType(); assertNull(ourType.getOwnerType()); assertEquals(String.class, ourType.getActualTypeArguments()[0]); assertEquals(List.class, ourType.getRawType());