Removing unused files with the new Types class.
This commit is contained in:
parent
0e5f6704cd
commit
3926afbd30
|
@ -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:
|
|
||||||
* <pre>
|
|
||||||
* class Foo<T> {
|
|
||||||
* private final List<T>[] arrayOfListT;
|
|
||||||
*
|
|
||||||
* Foo(List<T>[] arrayList) {
|
|
||||||
* this.arrayOfListT = arrayList;
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* <p>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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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}.
|
|
||||||
*
|
|
||||||
* <p>Here's an example class:
|
|
||||||
* <pre>
|
|
||||||
* class Foo<T> {
|
|
||||||
* private List<T> someList;
|
|
||||||
*
|
|
||||||
* Foo(List<T> list) {
|
|
||||||
* this.someList = list;
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
* @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());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,30 +20,29 @@ import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.lang.reflect.GenericArrayType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.List;
|
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 Inderjeet Singh
|
||||||
* @author Joel Leitch
|
* @author Joel Leitch
|
||||||
*/
|
*/
|
||||||
public class GenericArrayTypeImplTest extends TestCase {
|
public class GenericArrayTypeTest extends TestCase {
|
||||||
|
private GenericArrayType ourType;
|
||||||
private Type parameterizedType;
|
|
||||||
private Type genericArrayType;
|
|
||||||
private GenericArrayTypeImpl ourType;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
parameterizedType = new TypeToken<List<String>>() {}.getType();
|
ourType = Types.arrayOf(Types.newParameterizedTypeWithOwner(null, List.class, String.class));
|
||||||
genericArrayType = new TypeToken<List<String>[]>() {}.getType();
|
|
||||||
ourType = new GenericArrayTypeImpl(parameterizedType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOurTypeFunctionality() throws Exception {
|
public void testOurTypeFunctionality() throws Exception {
|
||||||
|
Type parameterizedType = new TypeToken<List<String>>() {}.getType();
|
||||||
|
Type genericArrayType = new TypeToken<List<String>[]>() {}.getType();
|
||||||
|
|
||||||
assertEquals(parameterizedType, ourType.getGenericComponentType());
|
assertEquals(parameterizedType, ourType.getGenericComponentType());
|
||||||
assertEquals(genericArrayType, ourType);
|
assertEquals(genericArrayType, ourType);
|
||||||
assertEquals(genericArrayType.hashCode(), ourType.hashCode());
|
assertEquals(genericArrayType.hashCode(), ourType.hashCode());
|
||||||
|
@ -51,7 +50,6 @@ public class GenericArrayTypeImplTest extends TestCase {
|
||||||
|
|
||||||
public void testNotEquals() throws Exception {
|
public void testNotEquals() throws Exception {
|
||||||
Type differentGenericArrayType = new TypeToken<List<String>[][]>() {}.getType();
|
Type differentGenericArrayType = new TypeToken<List<String>[][]>() {}.getType();
|
||||||
|
|
||||||
assertFalse(differentGenericArrayType.equals(ourType));
|
assertFalse(differentGenericArrayType.equals(ourType));
|
||||||
assertFalse(ourType.equals(differentGenericArrayType));
|
assertFalse(ourType.equals(differentGenericArrayType));
|
||||||
}
|
}
|
|
@ -20,28 +20,27 @@ import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.List;
|
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 Inderjeet Singh
|
||||||
* @author Joel Leitch
|
* @author Joel Leitch
|
||||||
*/
|
*/
|
||||||
public class ParameterizedTypeImplTest extends TestCase {
|
public class ParameterizedTypeTest extends TestCase {
|
||||||
|
private ParameterizedType ourType;
|
||||||
private Type parameterizedType;
|
|
||||||
private ParameterizedTypeImpl ourType;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
parameterizedType = new TypeToken<List<String>>() {}.getType();
|
ourType = Types.newParameterizedTypeWithOwner(null, List.class, String.class);
|
||||||
ourType = new ParameterizedTypeImpl(List.class, new Type[] { String.class }, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testOurTypeFunctionality() throws Exception {
|
public void testOurTypeFunctionality() throws Exception {
|
||||||
|
Type parameterizedType = new TypeToken<List<String>>() {}.getType();
|
||||||
assertNull(ourType.getOwnerType());
|
assertNull(ourType.getOwnerType());
|
||||||
assertEquals(String.class, ourType.getActualTypeArguments()[0]);
|
assertEquals(String.class, ourType.getActualTypeArguments()[0]);
|
||||||
assertEquals(List.class, ourType.getRawType());
|
assertEquals(List.class, ourType.getRawType());
|
Loading…
Reference in New Issue
Block a user