use of java.lang.reflect.ParameterizedType in project Genius-Android by qiujuer.
the class Reflector method replaceTypeActualArgument.
/**
* Replace {@link ParameterizedType#getActualTypeArguments()} method return value.
* In this we use {@link ParameterizeTypeActualArgsDelegate} delegate {@link ParameterizedType};
* Let {@link ParameterizedType#getActualTypeArguments()} return really class type.
*
* @param inType Type
* @param resolvedTypes a Map<Type, Type>, {@link #getActualTypeArguments(Class, Class)}
* @return {@link ParameterizeTypeActualArgsDelegate}
*/
private static Type replaceTypeActualArgument(Type inType, final Map<Type, Type> resolvedTypes) {
Type outType = inType;
if (inType instanceof ParameterizedType) {
final ParameterizedType finalType = ((ParameterizedType) inType);
final Type[] actualArgs = ((ParameterizedType) inType).getActualTypeArguments();
for (int i = 0; i < actualArgs.length; i++) {
Type argType = actualArgs[i];
while (resolvedTypes.containsKey(argType)) {
argType = resolvedTypes.get(argType);
}
// Do replace ActualArgument
argType = replaceTypeActualArgument(argType, resolvedTypes);
actualArgs[i] = argType;
}
outType = new ParameterizeTypeActualArgsDelegate(finalType, actualArgs);
}
return outType;
}
use of java.lang.reflect.ParameterizedType in project roboguice by roboguice.
the class TypesTest method testDefensiveCopies.
public void testDefensiveCopies() {
Type[] arguments = new Type[] { String.class, Integer.class };
ParameterizedType parameterizedType = Types.newParameterizedType(Map.class, arguments);
arguments[0] = null;
assertEquals(String.class, parameterizedType.getActualTypeArguments()[0]);
parameterizedType.getActualTypeArguments()[1] = null;
assertEquals(Integer.class, parameterizedType.getActualTypeArguments()[1]);
}
use of java.lang.reflect.ParameterizedType in project roboguice by roboguice.
the class TypesTest method testEqualsAndHashcode.
public void testEqualsAndHashcode() {
ParameterizedType parameterizedType = Types.newParameterizedType(Map.class, String.class, Integer.class);
assertEqualsBothWays(mapStringInteger, parameterizedType);
assertEquals(mapStringInteger.toString(), parameterizedType.toString());
GenericArrayType genericArrayType = Types.arrayOf(Types.arrayOf(Types.newParameterizedType(Set.class, String.class)));
assertEqualsBothWays(setStringArray, genericArrayType);
assertEquals(setStringArray.toString(), genericArrayType.toString());
}
use of java.lang.reflect.ParameterizedType in project roboguice by roboguice.
the class TypesTest method testInnerParameterizedEvenWithZeroArgs.
public void testInnerParameterizedEvenWithZeroArgs() {
TypeLiteral<Outer<String>.Inner<String>> type = new TypeLiteral<Outer<String>.Inner<String>>() {
};
assertEqualsBothWays(outerInner, type.getType());
ParameterizedType parameterizedType = (ParameterizedType) type.getType();
assertEquals(0, parameterizedType.getActualTypeArguments().length);
assertEquals(new TypeLiteral<Outer<String>>() {
}.getType(), parameterizedType.getOwnerType());
assertEquals(Outer.Inner.class, parameterizedType.getRawType());
}
use of java.lang.reflect.ParameterizedType in project byte-buddy by raphw.
the class AbstractTypeDescriptionGenericTest method testNestedSpecifiedTypeVariableType.
@Test
public void testNestedSpecifiedTypeVariableType() throws Exception {
TypeDescription.Generic typeDescription = describeType(NestedSpecifiedTypeVariableType.class.getDeclaredField(FOO));
assertThat(typeDescription.getTypeName(), is(NestedSpecifiedTypeVariableType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(typeDescription.getStackSize(), is(StackSize.SINGLE));
assertThat(typeDescription.getTypeArguments().size(), is(0));
Type ownerType = ((ParameterizedType) NestedSpecifiedTypeVariableType.class.getDeclaredField(FOO).getGenericType()).getOwnerType();
assertThat(typeDescription.getOwnerType(), is(TypeDefinition.Sort.describe(ownerType)));
assertThat(typeDescription.getOwnerType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(typeDescription.getOwnerType().getTypeArguments().size(), is(1));
assertThat(typeDescription.getOwnerType().getTypeArguments().getOnly().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
assertThat(typeDescription.getOwnerType().getTypeArguments().getOnly(), is((TypeDefinition) new TypeDescription.ForLoadedType(String.class)));
}
Aggregations