use of java.lang.reflect.ParameterizedType in project byte-buddy by raphw.
the class AbstractTypeDescriptionGenericTest method testNestedStaticTypeVariableType.
@Test
public void testNestedStaticTypeVariableType() throws Exception {
TypeDescription.Generic typeDescription = describeType(NestedStaticTypeVariableType.class.getDeclaredField(FOO));
assertThat(typeDescription.getTypeName(), is(NestedStaticTypeVariableType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(typeDescription.getStackSize(), is(StackSize.SINGLE));
assertThat(typeDescription.getTypeArguments().size(), is(1));
assertThat(typeDescription.getTypeArguments().getOnly(), is((TypeDefinition) new TypeDescription.ForLoadedType(String.class)));
Type ownerType = ((ParameterizedType) NestedStaticTypeVariableType.class.getDeclaredField(FOO).getGenericType()).getOwnerType();
assertThat(typeDescription.getOwnerType(), is(TypeDefinition.Sort.describe(ownerType)));
assertThat(typeDescription.getOwnerType().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
}
use of java.lang.reflect.ParameterizedType in project roboguice by roboguice.
the class TypeLiteral method getSuperclassTypeParameter.
/**
* Returns the type from super class's type parameter in {@link MoreTypes#canonicalize(Type)
* canonical form}.
*/
static Type getSuperclassTypeParameter(Class<?> subclass) {
Type superclass = MoreTypes.getGenericSuperclass(subclass);
if (superclass instanceof Class) {
throw new RuntimeException("Missing type parameter.");
}
ParameterizedType parameterized = (ParameterizedType) superclass;
return canonicalize(parameterized.getActualTypeArguments()[0]);
}
use of java.lang.reflect.ParameterizedType in project roboguice by roboguice.
the class MiniGuice method requireKey.
private void requireKey(Key key, Object requiredBy) {
if (key.type instanceof ParameterizedType && (((ParameterizedType) key.type).getRawType() == Provider.class || ((ParameterizedType) key.type).getRawType() == javax.inject.Provider.class)) {
Type type = ((ParameterizedType) key.type).getActualTypeArguments()[0];
key = new Key(type, key.annotation);
}
requiredKeys.add(new RequiredKey(key, requiredBy));
}
use of java.lang.reflect.ParameterizedType in project centipede by paulhoule.
the class TestAnnotationExtraction method testDefaults.
@Test
public void testDefaults() {
// 8 primitive types get defaults from the JLS
assertEquals((byte) 0, defaultValueFor(Byte.TYPE));
assertEquals((short) 0, defaultValueFor(Short.TYPE));
assertEquals(0, defaultValueFor(Integer.TYPE));
assertEquals(0L, defaultValueFor(Long.TYPE));
assertEquals(0.0f, defaultValueFor(Float.TYPE));
assertEquals(0.0, defaultValueFor(Double.TYPE));
assertEquals(false, defaultValueFor(Boolean.TYPE));
assertEquals('\0', defaultValueFor(Character.TYPE));
// For a string we get the empty String
assertEquals("", defaultValueFor(String.class));
assertEquals(new ArrayList(), defaultValueFor(List.class));
ParameterizedType t = (ParameterizedType) ((new ArrayList<Exception>()).getClass().getGenericSuperclass());
assertEquals(new ArrayList<Exception>(), defaultValueFor(t));
assertEquals(new ArrayList<Long>(), defaultValueFor(t));
}
use of java.lang.reflect.ParameterizedType in project robovm by robovm.
the class Types method appendGenericType.
public static void appendGenericType(StringBuilder out, Type type) {
if (type instanceof TypeVariable) {
out.append(((TypeVariable) type).getName());
} else if (type instanceof ParameterizedType) {
out.append(type.toString());
} else if (type instanceof GenericArrayType) {
Type simplified = ((GenericArrayType) type).getGenericComponentType();
appendGenericType(out, simplified);
out.append("[]");
} else if (type instanceof Class) {
Class c = (Class<?>) type;
if (c.isArray()) {
String[] as = c.getName().split("\\[");
int len = as.length - 1;
if (as[len].length() > 1) {
out.append(as[len].substring(1, as[len].length() - 1));
} else {
char ch = as[len].charAt(0);
if (ch == 'I') {
out.append("int");
} else if (ch == 'B') {
out.append("byte");
} else if (ch == 'J') {
out.append("long");
} else if (ch == 'F') {
out.append("float");
} else if (ch == 'D') {
out.append("double");
} else if (ch == 'S') {
out.append("short");
} else if (ch == 'C') {
out.append("char");
} else if (ch == 'Z') {
out.append("boolean");
} else if (ch == 'V') {
out.append("void");
}
}
for (int i = 0; i < len; i++) {
out.append("[]");
}
} else {
out.append(c.getName());
}
}
}
Aggregations